/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to services/info.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-07-12 03:28:35 UTC
  • Revision ID: csa@suren.me-20180712032835-a2hzd4gadlgoiokj
Log newly created cache tables and provide service to get this information

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    $xslt = false;
17
17
}
18
18
 
 
19
function GetInterval() {
 
20
    global $_REQUEST;
 
21
    
 
22
    $cur = time();
 
23
    $interval = $_REQUEST['interval'];
 
24
 
 
25
    if (preg_match("/^(\d+)-(\d+)$/", $interval, $m)) {
 
26
        $from = $m[1];
 
27
        $to = $m[2];
 
28
    
 
29
        if ($to > $cur) $to = $cur;
 
30
    
 
31
        if ($to < $from) {
 
32
            $from = false;
 
33
            $to = false;
 
34
        }
 
35
    } else if (preg_match("/^(\d+)$/", $interval, $m)) {
 
36
        $to = $cur;
 
37
        $from = $to - $interval;
 
38
    }
 
39
    
 
40
    return array($from, $to);
 
41
}
 
42
 
 
43
 
19
44
switch ($target) {
20
45
 case "version":
21
46
    if (file_exists("VERSION")) {
75
100
 break;
76
101
 case "log":
77
102
    try {
78
 
        $cur = time();
79
 
 
80
 
        $interval = $_REQUEST['interval'];
81
103
        $filter = json_decode(stripslashes($_REQUEST['filter']), true);
82
104
 
83
105
        if (isset($_REQUEST['priority'])) {
86
108
            $priority = LOG_ERR;
87
109
        }
88
110
 
89
 
        if (preg_match("/^(\d+)-(\d+)$/", $interval, $m)) {
90
 
            $from = $m[1];
91
 
            $to = $m[2];
92
 
    
93
 
            if ($to > $cur) $to = $cur;
94
 
    
95
 
            if ($to < $from) {
96
 
                $from = false;
97
 
                $to = false;
98
 
            }
99
 
        } else if (preg_match("/^(\d+)$/", $interval, $m)) {
100
 
            $to = $cur;
101
 
            $from = $to - $interval;
102
 
        }
103
 
        
 
111
        list($from, $to) = GetInterval();
104
112
        if ((!$from)||(!$to)) {
105
 
            $to = $cur;
 
113
            $to = time();
106
114
            $from = $to - $to%86400;
107
115
        } 
108
116
 
124
132
        $error = xml_escape($ex->getInfo());
125
133
    }
126
134
 break;
 
135
 case "cachelog":
 
136
    $filter = array();
 
137
    foreach (array('id', 'action', 'resolution', 'archive') as $key) {
 
138
        if (isset($_GET[$key])) {
 
139
            $filter[$key] = $_GET[$key];
 
140
        }
 
141
    }
 
142
 
 
143
    list($from, $to) = GetInterval();
 
144
    if ($from & $to) 
 
145
        $filter['interval'] = array($from, $to);
 
146
    
 
147
    try {
 
148
        $cache = new CACHEDB();
 
149
        $logs = $cache->CacheLogGet($filter);
 
150
    } catch (ADEIException $ex) {
 
151
        $ex->logInfo(NULL, $req);
 
152
        $error = xml_escape($ex->getInfo());
 
153
    }
 
154
 break;
127
155
 default:
128
156
    if (isset($_GET['target'])) $error = translate("Unknown info target (%s) is specified", $_GET['target']);
129
157
    else $error = translate("The info target is not specified");
169
197
    fwrite($out, " <Value$extra/>\n");
170
198
}
171
199
 
 
200
function OutputCacheLog($out, $item) {
 
201
    if (isset($item['time'])) {
 
202
        $time = new DateTime($item['time']);
 
203
        $item['time'] = $time->format("Y-m-d\Th:i:sP");
 
204
    }
 
205
    
 
206
    $extra = "";
 
207
    $properties = array("id", "time", "action", "db_server", "db_name", "db_group", "resolution");
 
208
    foreach ($item as $prop => $value) {
 
209
        if (!in_array($prop, $properties)) continue;
 
210
        $extra .= " $prop=\"" . xml_escape($value) . "\"";
 
211
    }
 
212
    fwrite($out, " <Value$extra/>\n");
 
213
}
 
214
 
 
215
 
172
216
if ($text) {
173
217
    header("Content-type: text/plain");
174
218
    header("Cache-Control: no-cache, must-revalidate");
238
282
                OutputLog($out, $log);
239
283
            }
240
284
         break;
 
285
         case "cachelog":
 
286
            foreach($logs as $log) {
 
287
                OutputCacheLog($out, $log);
 
288
            }
 
289
         break;
241
290
        }
242
291
        fwrite($out, "</result>");
243
292
    }