Subversion Repositories logviewer

Rev

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

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
4 daniel-mar 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
 
2 daniel-mar 20
if (!isset($_REQUEST['cmd'])) _err('cmd is missing');
21
 
22
$hostname = trim(file_get_contents('/etc/hostname'));
23
 
8 daniel-mar 24
if (file_exists(__DIR__."/config_$hostname.inc.php")) {
25
        require_once __DIR__."/config_$hostname.inc.php";
26
} else {
27
        require_once __DIR__.'/config.inc.php';
28
}
29
 
2 daniel-mar 30
if (file_exists(__DIR__."/db_$hostname.inc.php")) {
31
        require_once __DIR__."/db_$hostname.inc.php";
32
} else {
33
        require_once __DIR__.'/db.inc.php';
34
}
35
 
36
if (file_exists(__DIR__."/auth_$hostname.inc.php")) {
37
        require_once __DIR__."/auth_$hostname.inc.php";
38
} else {
39
        require_once __DIR__.'/auth.inc.php';
40
}
41
 
42
try {
43
        logviewer_check_access();
44
} catch (Exception $e) {
45
        _err($e->getMessage());
46
}
47
 
48
# Please keep this code synchronized with index.php
49
$add_filters = logviewer_additional_filter();
50
$hardcoded_filters = empty($add_filters) ? '' : "and ($add_filters)";
51
$hardcoded_filters .= " and (letzter >= DATE_SUB(NOW(),INTERVAL ".MAXYEARS." YEAR))";
52
# Please keep this code synchronized with index.php
53
 
54
if ($_REQUEST['cmd'] == 'solve') {
55
        if (!is_numeric($_REQUEST['id'])) _err('Invalid solve id');
56
 
57
        try {
58
                if (file_exists(__DIR__."/db_$hostname.inc.php")) {
59
                        require_once __DIR__."/db_$hostname.inc.php";
60
                } else {
61
                        require_once __DIR__.'/db.inc.php';
62
                }
63
 
64
                if (!logviewer_allow_solvemark()) _err('No permission to mark entries as solved!');
65
        } catch (Exception $e) {
66
                _err($e->getMessage());
67
        }
68
 
6 daniel-mar 69
        $res = @db_query('select id from vts_fehlerlog where (id = '.$_REQUEST['id'].') '.$hardcoded_filters);
2 daniel-mar 70
        if (!$res) _err('mysql query failed');
6 daniel-mar 71
        if (db_num_rows($res) == 0) _err('Row not found or no permission given.');
2 daniel-mar 72
 
6 daniel-mar 73
        $res = @db_query('update vts_fehlerlog set anzahlsolved = anzahl where (id = '.$_REQUEST['id'].') '.$hardcoded_filters);
2 daniel-mar 74
        if (!$res) _err('mysql query failed');
75
 
76
        $out = array();
77
        $out['success'] = true;
78
        $out['id'] = $_REQUEST['id']; // give OK to hide the line
79
        header('Content-Type: application/json');
80
        die(json_encode($out));
81
} else {
82
        _err('unknown cmd');
83
}
84
 
85
# ---
86
 
87
function _err($msg) {
88
        $out = array();
89
        $out['success'] = false;
90
        $out['error'] = $msg;
91
        header('Content-Type: application/json');
92
        die(json_encode($out));
93
}