1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
<?php /** * user_groups log--tabs * @author Stephen Billard (sbillard) * @package plugins */ define('OFFSET_PATH', 1); require_once(dirname(__FILE__) . '/admin-globals.php');
admin_securityChecks(NULL, currentRelativeURL());
if (isset($_GET['action'])) { $action = sanitize($_GET['action'], 3); $what = sanitize($_GET['filename'], 3); $file = SERVERPATH . '/' . DATA_FOLDER . '/' . $what . '.log'; XSRFdefender($action); if (zp_apply_filter('admin_log_actions', true, $file, $action)) { switch ($action) { case 'clear_log': $_zp_mutex->lock(); $f = fopen($file, 'w'); if (@ftruncate($f, 0)) { $class = 'messagebox'; $result = sprintf(gettext('%s log was emptied.'), $what); } else { $class = 'errorbox'; $result = sprintf(gettext('%s log could not be emptied.'), $what); } fclose($f); clearstatcache(); $_zp_mutex->unlock(); if (basename($file) == 'security.log') { zp_apply_filter('admin_log_actions', true, $file, $action); // have to record the fact } break; case 'delete_log': $_zp_mutex->lock(); @chmod($file, 0777); if (@unlink($file)) { $class = 'messagebox'; $result = sprintf(gettext('%s log was removed.'), $what); } else { $class = 'errorbox'; $result = sprintf(gettext('%s log could not be removed.'), $what); } clearstatcache(); $_zp_mutex->unlock(); unset($_GET['tab']); // it is gone, after all if (basename($file) == 'security.log') { zp_apply_filter('admin_log_actions', true, $file, $action); // have to record the fact } break; case 'download_log': include_once(SERVERPATH . '/' . ZENFOLDER . '/lib-zipStream.php'); $zip = new ZipStream(sanitize($_GET['tab'], 3) . '.zip'); $zip->add_file_from_path(basename($file), $file); $zip->finish(); break; } } }
list($subtabs, $default) = getLogTabs(); $zenphoto_tabs['logs'] = array('text' => gettext("logs"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-logs.php?page=logs', 'subtabs' => $subtabs, 'default' => $default);
printAdminHeader('logs', $default); echo "\n</head>"; ?>
<body>
<?php printLogoAndLinks(); ?> <div id="main"> <?php printTabs(); ?> <div id="content"> <?php if ($default) { $logfiletext = str_replace('_', ' ', $default); $logfiletext = strtoupper(substr($logfiletext, 0, 1)) . substr($logfiletext, 1); $logfile = SERVERPATH . "/" . DATA_FOLDER . '/' . $default . '.log'; if (file_exists($logfile) && filesize($logfile) > 0) { $logtext = explode("\n", file_get_contents($logfile)); } else { $logtext = array(); } ?> <h1><?php echo gettext("View logs:"); ?></h1>
<?php $subtab = printSubtabs(); ?> <!-- A log --> <div id="theme-editor" class="tabbox"> <?php zp_apply_filter('admin_note', 'logs', $subtab); ?> <?php if (isset($result)) { ?> <div class="<?php echo $class; ?> fade-message"> <h2><?php echo $result; ?></h2> </div> <?php } ?> <form method="post" action="<?php echo WEBPATH . '/' . ZENFOLDER . '/admin-logs.php'; ?>?action=change_size&page=logs&tab=<?php echo html_encode($subtab) . '&filename=' . html_encode($subtab); ?>" > <span class="button buttons"> <a href="<?php echo WEBPATH . '/' . ZENFOLDER . '/admin-logs.php?action=delete_log&page=logs&tab=' . html_encode($subtab) . '&filename=' . html_encode($subtab); ?>&XSRFToken=<?php echo getXSRFToken('delete_log'); ?>"> <img src="images/edit-delete.png" /><?php echo gettext('Delete'); ?></a> </span> <?php if (!empty($logtext)) { ?> <span class="button buttons"> <a href="<?php echo WEBPATH . '/' . ZENFOLDER . '/admin-logs.php?action=clear_log&page=logs&tab=' . html_encode($subtab) . '&filename=' . html_encode($subtab); ?>&XSRFToken=<?php echo getXSRFToken('clear_log'); ?>"> <img src="images/refresh.png" /><?php echo gettext('Reset'); ?></a> </span> <span class="button buttons"> <a href="<?php echo WEBPATH . '/' . ZENFOLDER . '/admin-logs.php?action=download_log&page=logs&tab=' . html_encode($subtab) . '&filename=' . html_encode($subtab); ?>&XSRFToken=<?php echo getXSRFToken('download_log'); ?>"> <img src="images/arrow_down.png" /><?php echo gettext('Download'); ?></a> </span> <?php } ?> </form> <br class="clearall" /> <br /> <blockquote class="logtext"> <?php if (!empty($logtext)) { $header = array_shift($logtext); $fields = explode("\t", $header); if (count($fields) > 1) { // there is a header row, display in a table ?> <table id="log_table"> <?php if (!empty($header)) { ?> <tr> <?php foreach ($fields as $field) { ?> <th> <span class="nowrap"><?php echo $field; ?></span> </th> <?php } ?> </tr> <?php } foreach ($logtext as $line) { ?> <tr> <?php $fields = explode("\t", trim($line)); foreach ($fields as $key => $field) { ?> <td> <?php if ($field) { ?> <span class="nowrap"><?php echo html_encode($field); ?></span> <?php } ?> </td> <?php } ?> </tr> <?php } ?> </table> <?php } else { array_unshift($logtext, $header); foreach ($logtext as $line) { if ($line) { ?> <p> <span class="nowrap"> <?php echo str_replace(' ', ' ', html_encode(strip_tags(trim($line)))); ?> </span> </p> <?php } } } } ?> </blockquote> </div> <?php } else { ?> <h2><?php echo gettext("There are no logs to view."); ?></h2> <?php } ?> </div> </div> <?php printAdminFooter(); ?> <?php // to fool the validator echo "\n</body>"; echo "\n</html>"; ?>
|