Subversion Repositories logviewer

Rev

Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * ViaThinkSoft LogViewer
  5.  * Copyright 2018-2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. if (!isset($_REQUEST['cmd'])) _err('cmd is missing');
  21.  
  22. require_once __DIR__.'/config.inc.php';
  23.  
  24. $hostname = trim(file_get_contents('/etc/hostname'));
  25.  
  26. if (file_exists(__DIR__."/db_$hostname.inc.php")) {
  27.         require_once __DIR__."/db_$hostname.inc.php";
  28. } else {
  29.         require_once __DIR__.'/db.inc.php';
  30. }
  31.  
  32. if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
  33.         require_once __DIR__."/auth_$hostname.inc.php";
  34. } else {
  35.         require_once __DIR__.'/auth.inc.php';
  36. }
  37.  
  38. try {
  39.         logviewer_check_access();
  40. } catch (Exception $e) {
  41.         _err($e->getMessage());
  42. }
  43.  
  44. # Please keep this code synchronized with index.php
  45. $add_filters = logviewer_additional_filter();
  46. $hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
  47. $hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
  48. # Please keep this code synchronized with index.php
  49.  
  50. if ($_REQUEST['cmd'] == 'solve') {
  51.         if (!is_numeric($_REQUEST['id'])) _err('Invalid solve id');
  52.  
  53.         try {
  54.                 if (file_exists(__DIR__."/db_$hostname.inc.php")) {
  55.                         require_once __DIR__."/db_$hostname.inc.php";
  56.                 } else {
  57.                         require_once __DIR__.'/db.inc.php';
  58.                 }
  59.  
  60.                 if (!logviewer_allow_solvemark()) _err('No permission to mark entries as solved!');
  61.         } catch (Exception $e) {
  62.                 _err($e->getMessage());
  63.         }
  64.  
  65.         $res = @db_query('select id from vts_fehlerlog where (id = '.$_REQUEST['id'].') '.$hardcoded_filters);
  66.         if (!$res) _err('mysql query failed');
  67.         if (db_num_rows($res) == 0) _err('Row not found or no permission given.');
  68.  
  69.         $res = @db_query('update vts_fehlerlog set anzahlsolved = anzahl where (id = '.$_REQUEST['id'].') '.$hardcoded_filters);
  70.         if (!$res) _err('mysql query failed');
  71.  
  72.         $out = array();
  73.         $out['success'] = true;
  74.         $out['id'] = $_REQUEST['id']; // give OK to hide the line
  75.         header('Content-Type: application/json');
  76.         die(json_encode($out));
  77. } else {
  78.         _err('unknown cmd');
  79. }
  80.  
  81. # ---
  82.  
  83. function _err($msg) {
  84.         $out = array();
  85.         $out['success'] = false;
  86.         $out['error'] = $msg;
  87.         header('Content-Type: application/json');
  88.         die(json_encode($out));
  89. }
  90.