From d269e8950493e509765577c2920fe410242a1eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sat, 7 Jan 2017 15:47:50 +0100 Subject: [PATCH] update programupdate-API (re-add log functionality) --- www/protected/components/MsHelper.php | 9 ++++ www/protected/config/main.php | 2 +- www/protected/controllers/ApiController.php | 54 +++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/www/protected/components/MsHelper.php b/www/protected/components/MsHelper.php index 6376aee..c79ded9 100644 --- a/www/protected/components/MsHelper.php +++ b/www/protected/components/MsHelper.php @@ -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; diff --git a/www/protected/config/main.php b/www/protected/config/main.php index 28008c3..a9cde9a 100644 --- a/www/protected/config/main.php +++ b/www/protected/config/main.php @@ -90,7 +90,7 @@ return ArrayX::merge( 'update.php/' => 'api/update2', 'update' => 'api/update', 'update/' => 'api/update2', - + 'blog/' => 'blogPost/index', 'blog/ajaxMarkdownPreview' => 'blogPost/ajaxMarkdownPreview', 'blog/admin' => 'blogPost/admin', diff --git a/www/protected/controllers/ApiController.php b/www/protected/controllers/ApiController.php index 3ccfb82..6c85fbf 100644 --- a/www/protected/controllers/ApiController.php +++ b/www/protected/controllers/ApiController.php @@ -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', []);