Play images and video from Synology PhotoStation server

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. require_once('log.inc.php');
  3. class PhotoLogAPI extends WebAPI {
  4. private $operationPemission = "admin";
  5. function __construct() {
  6. parent::__construct(SZ_WEBAPI_API_DESCRIPTION_PATH);
  7. }
  8. protected function Process()
  9. {
  10. if (!strcasecmp($this->method, "list")) {
  11. $this->LogList();
  12. } else if (!strcasecmp($this->method, "clear")) {
  13. $this->Clear();
  14. } else if (!strcasecmp($this->method, "export")) {
  15. $this->Export();
  16. }
  17. }
  18. private function LogList()
  19. {
  20. $resp = array();
  21. $params = $this->GetParams_List();
  22. if (!$params) {
  23. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  24. goto End;
  25. }
  26. $res = PhotoLog::ListItem($params['offset'], $params['limit']);
  27. $resp['items'] = $res['data'];
  28. $resp['total'] = $res['total'];
  29. $offset = (0 > (int)$params['limit']) ? $resp['total'] : $params['offset'] + $params['limit'];
  30. $resp['offset'] = ($offset > $resp['total']) ? $resp['total'] : $offset;
  31. $this->SetResponse($resp);
  32. End:
  33. return;
  34. }
  35. private function Clear()
  36. {
  37. $params = $this->GetParams_Clear();
  38. if (!$params) {
  39. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  40. goto End;
  41. }
  42. PhotoLog::Clear($params['user']);
  43. End:
  44. return;
  45. }
  46. private function Export()
  47. {
  48. $params = $this->GetParams_Export();
  49. if (!$params) {
  50. $this->SetError(WEBAPI_ERR_BAD_REQUEST);
  51. goto End;
  52. }
  53. PhotoLog::ExportFile($params['format']);
  54. End:
  55. return;
  56. }
  57. private function GetParams_List()
  58. {
  59. // $variable + 0 => convert to integer
  60. $params = array(
  61. 'offset' => !isset($_REQUEST['offset']) || $_REQUEST['offset'] < 0 ? 0 : $_REQUEST['offset'] + 0,
  62. 'limit' => !isset($_REQUEST['limit']) || $_REQUEST['limit'] < 0 ? NULL : $_REQUEST['limit'] + 0
  63. );
  64. return $params;
  65. }
  66. private function GetParams_Export()
  67. {
  68. $format = strtolower($_REQUEST['format']);
  69. if (!in_array($format, PhotoLog::$SupportFormat)) {
  70. return false;
  71. }
  72. return array("format" => $format);
  73. }
  74. private function GetParams_Clear()
  75. {
  76. $user = $this->GetUser();
  77. if (!$user) {
  78. return false;
  79. }
  80. return array("user" => $user);
  81. }
  82. private function GetUser()
  83. {
  84. $user = false;
  85. if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user'])) {
  86. $user = $_SESSION[SYNOPHOTO_ADMIN_USER]['reg_syno_user'];
  87. } else if (isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user'])) {
  88. $user = ("root" === SYNOPHOTO_ADMIN_USER)? "admin" : SYNOPHOTO_ADMIN_NAME;
  89. }
  90. return $user;
  91. }
  92. protected function CheckPermission()
  93. {
  94. $res = true;
  95. $check = array(
  96. "list" => $this->operationPemission,
  97. "clear" => $this->operationPemission,
  98. "export" => $this->operationPemission
  99. );
  100. if (!array_key_exists($this->method, $check)) {
  101. goto End;
  102. }
  103. $funcName = "check_".$check[$this->method];
  104. if (!method_exists($this, $funcName)) {
  105. $res = false;
  106. goto End;
  107. }
  108. $res = $this->$funcName();
  109. End:
  110. if (!$res) {
  111. $this->SetError(PHOTOSTATION_LOG_ACCESS_DENY);
  112. }
  113. return $res;
  114. }
  115. private function check_admin()
  116. {
  117. csSYNOPhotoDB::GetDBInstance()->SetSessionCache();
  118. csSYNOPhotoMisc::CheckSessionTimeOut();
  119. return isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']);
  120. }
  121. }
  122. $api = new PhotoLogAPI();
  123. $api->Run();
  124. ?>