2014-07-30 20:10:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class APIController extends MSController
|
|
|
|
{
|
|
|
|
public $layout = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array action filters
|
|
|
|
*/
|
|
|
|
public function filters()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'accessControl',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies the access control rules.
|
|
|
|
* This method is used by the 'accessControl' filter.
|
|
|
|
* @return array access control rules
|
|
|
|
*/
|
|
|
|
public function accessRules()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('allow',
|
|
|
|
'users'=>array('*'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionUpdate()
|
|
|
|
{
|
|
|
|
if (! isset($_GET['Name'])) {
|
|
|
|
throw new CHttpException(404,'Invalid Request - [Name] missing');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$Name = $_GET['Name'];
|
|
|
|
|
|
|
|
$this->actionUpdate2($Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionUpdate2($Name)
|
|
|
|
{
|
2014-09-13 17:37:47 +02:00
|
|
|
if (! isset($_GET['Name'])) {
|
|
|
|
throw new CHttpException(404,'Invalid Request - [Name] missing');
|
|
|
|
}
|
|
|
|
|
2014-07-30 20:10:00 +02:00
|
|
|
$data = ProgramUpdates::model()->findByAttributes(['Name' => $Name]);
|
|
|
|
|
2014-09-13 17:37:47 +02:00
|
|
|
if (is_null($data)) {
|
2014-07-30 20:10:00 +02:00
|
|
|
throw new CHttpException(404,'Invalid Request - [Name] not found');
|
|
|
|
}
|
|
|
|
|
2017-01-07 15:47:50 +01:00
|
|
|
$log = new ProgramUpdatesLog();
|
|
|
|
$log->programname = $data->Name;
|
|
|
|
$log->version = $data->Version;
|
|
|
|
$log->date = date('Y-m-d H:i:s');
|
|
|
|
$log->ip = $this->get_client_ip();
|
|
|
|
|
|
|
|
if ($log->ip == MsHelper::getStringDBVar('self_ip')) $log->ip = "self";
|
|
|
|
|
|
|
|
$log->save();
|
|
|
|
|
2014-07-30 20:10:00 +02:00
|
|
|
$this->render('update', ['data' => $data]);
|
|
|
|
}
|
|
|
|
|
2017-01-07 15:47:50 +01:00
|
|
|
public function actionSetSelfAdress()
|
|
|
|
{
|
|
|
|
if (! isset($_GET['ip'])) {
|
|
|
|
$ip = $this->get_client_ip();
|
|
|
|
} else {
|
|
|
|
$ip = $_GET['ip'];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MsHelper::setStringDBVar('self_ip', $ip);
|
|
|
|
|
|
|
|
echo 'Ok.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_client_ip() {
|
|
|
|
if (getenv('HTTP_CLIENT_IP'))
|
|
|
|
return getenv('HTTP_CLIENT_IP');
|
|
|
|
else if(getenv('HTTP_X_FORWARDED_FOR'))
|
|
|
|
return getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
else if(getenv('HTTP_X_FORWARDED'))
|
|
|
|
return getenv('HTTP_X_FORWARDED');
|
|
|
|
else if(getenv('HTTP_FORWARDED_FOR'))
|
|
|
|
return getenv('HTTP_FORWARDED_FOR');
|
|
|
|
else if(getenv('HTTP_FORWARDED'))
|
|
|
|
return getenv('HTTP_FORWARDED');
|
|
|
|
else if(getenv('REMOTE_ADDR'))
|
|
|
|
return getenv('REMOTE_ADDR');
|
|
|
|
else if (isset($_SERVER['HTTP_CLIENT_IP']))
|
|
|
|
return $_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
|
|
|
|
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
else if(isset($_SERVER['HTTP_X_FORWARDED']))
|
|
|
|
return $_SERVER['HTTP_X_FORWARDED'];
|
|
|
|
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
|
|
|
|
return $_SERVER['HTTP_FORWARDED_FOR'];
|
|
|
|
else if(isset($_SERVER['HTTP_FORWARDED']))
|
|
|
|
return $_SERVER['HTTP_FORWARDED'];
|
|
|
|
else if(isset($_SERVER['REMOTE_ADDR']))
|
|
|
|
return $_SERVER['REMOTE_ADDR'];
|
|
|
|
else
|
|
|
|
return 'UNKNOWN';
|
|
|
|
}
|
|
|
|
|
2014-07-30 20:10:00 +02:00
|
|
|
public function actionTest()
|
|
|
|
{
|
|
|
|
$this->render('test', []);
|
|
|
|
}
|
|
|
|
}
|