1
0

update programupdate-API (re-add log functionality)

This commit is contained in:
Mike Schwörer 2017-01-07 15:47:50 +01:00
parent d1b7b3e46d
commit d269e89504
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 64 additions and 1 deletions

View File

@ -11,6 +11,15 @@ class MsHelper {
return $val;
}
public static function setStringDBVar($name, $value)
{
$connection = Yii::app()->db;
$command=$connection->createCommand("REPLACE INTO {{othervalues}} (Name, SValue) VALUES ('$name', '$value')");
$command->query();
}
public static function getIntDBVar($name)
{
$connection = Yii::app()->db;

View File

@ -52,9 +52,63 @@ class APIController extends MSController
throw new CHttpException(404,'Invalid Request - [Name] not found');
}
$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();
$this->render('update', ['data' => $data]);
}
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';
}
public function actionTest()
{
$this->render('test', []);