123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- require_once('log.inc.php');
-
- class PhotoLogAPI extends WebAPI {
- private $operationPemission = "admin";
-
- function __construct() {
- parent::__construct(SZ_WEBAPI_API_DESCRIPTION_PATH);
- }
-
- protected function Process()
- {
- if (!strcasecmp($this->method, "list")) {
- $this->LogList();
- } else if (!strcasecmp($this->method, "clear")) {
- $this->Clear();
- } else if (!strcasecmp($this->method, "export")) {
- $this->Export();
- }
- }
-
- private function LogList()
- {
- $resp = array();
-
- $params = $this->GetParams_List();
- if (!$params) {
- $this->SetError(WEBAPI_ERR_BAD_REQUEST);
- goto End;
- }
-
- $res = PhotoLog::ListItem($params['offset'], $params['limit']);
-
- $resp['items'] = $res['data'];
- $resp['total'] = $res['total'];
- $offset = (0 > (int)$params['limit']) ? $resp['total'] : $params['offset'] + $params['limit'];
- $resp['offset'] = ($offset > $resp['total']) ? $resp['total'] : $offset;
-
- $this->SetResponse($resp);
- End:
- return;
- }
-
- private function Clear()
- {
- $params = $this->GetParams_Clear();
- if (!$params) {
- $this->SetError(WEBAPI_ERR_BAD_REQUEST);
- goto End;
- }
-
- PhotoLog::Clear($params['user']);
-
- End:
- return;
- }
-
- private function Export()
- {
- $params = $this->GetParams_Export();
- if (!$params) {
- $this->SetError(WEBAPI_ERR_BAD_REQUEST);
- goto End;
- }
-
- PhotoLog::ExportFile($params['format']);
-
- End:
- return;
- }
-
- private function GetParams_List()
- {
- // $variable + 0 => convert to integer
- $params = array(
- 'offset' => !isset($_REQUEST['offset']) || $_REQUEST['offset'] < 0 ? 0 : $_REQUEST['offset'] + 0,
- 'limit' => !isset($_REQUEST['limit']) || $_REQUEST['limit'] < 0 ? NULL : $_REQUEST['limit'] + 0
- );
- return $params;
- }
-
- private function GetParams_Export()
- {
- $format = strtolower($_REQUEST['format']);
- if (!in_array($format, PhotoLog::$SupportFormat)) {
- return false;
- }
-
- return array("format" => $format);
- }
-
- private function GetParams_Clear()
- {
- $user = $this->GetUser();
-
- if (!$user) {
- return false;
- }
-
- return array("user" => $user);
- }
-
- private function GetUser()
- {
- $user = false;
-
- if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user'])) {
- $user = $_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user'];
- } else if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
- $user = ("root" === SYNOPHOTO_ADMIN_USER)? "admin" : SYNOPHOTO_ADMIN_NAME;
- }
- return $user;
- }
-
- protected function CheckPermission()
- {
- $res = true;
- $check = array(
- "list" => $this->operationPemission,
- "clear" => $this->operationPemission,
- "export" => $this->operationPemission
- );
-
- if (!array_key_exists($this->method, $check)) {
- goto End;
- }
-
- $funcName = "check_".$check[$this->method];
-
- if (!method_exists($this, $funcName)) {
- $res = false;
- goto End;
- }
-
- $res = $this->$funcName();
-
- End:
- if (!$res) {
- $this->SetError(PHOTOSTATION_LOG_ACCESS_DENY);
- }
- return $res;
- }
-
- private function check_admin()
- {
- csSYNOPhotoDB::GetDBInstance()->SetSessionCache();
- csSYNOPhotoMisc::CheckSessionTimeOut();
- return isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
- }
- }
- $api = new PhotoLogAPI();
- $api->Run();
-
- ?>
|