Subversion Repositories logviewer

Rev

Rev 4 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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