Changeset 136 for trunk/services/logs.php
- Timestamp:
- Jun 3, 2006 7:47:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/services/logs.php
r42 r136 9 9 $auth->requireLogin(); 10 10 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG); 11 App::sslOn();11 $app->sslOn(); 12 12 13 13 require_once 'codebase/lib/PageNumbers.inc.php'; … … 39 39 40 40 // Set the defaults and catch incoming settings. 41 Prefs::setDefault('log_file', App::getParam('log_filename'), 'logs_module'); 42 Prefs::setValue('log_file', getFormData('log'), 'logs_module'); 41 $prefs =& Prefs::getInstance(); 42 $prefs->setDefault('log_file', $app->getParam('log_filename'), 'logs_module'); 43 $prefs->set('log_file', getFormData('log'), 'logs_module'); 43 44 44 45 // Titles and navigation header. 45 $nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), Prefs::getValue('log_file', 'logs_module')), '/admin/logs.php');46 $nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), $prefs->get('log_file', 'logs_module')), '/admin/logs.php'); 46 47 47 48 /****************************************************************************** … … 56 57 case 'delete' : 57 58 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET); 58 deleteLog( Prefs::getValue('log_file', 'logs_module'));59 Prefs::setValue('log_file', App::getParam('log_filename'), 'logs_module');60 if ( App::validBoomerangURL('app_log')) {59 deleteLog($prefs->get('log_file', 'logs_module')); 60 $prefs->set('log_file', $app->getParam('log_filename'), 'logs_module'); 61 if ($app->validBoomerangURL('app_log')) { 61 62 // Display boomerang page. 62 App::dieBoomerangURL('app_log');63 $app->dieBoomerangURL('app_log'); 63 64 } 64 65 // Display default page. 65 App::dieURL($_SERVER['PHP_SELF']);66 $app->dieURL($_SERVER['PHP_SELF']); 66 67 break; 67 68 68 69 case 'clear' : 69 70 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET); 70 clearLog( Prefs::getValue('log_file', 'logs_module'));71 if ( App::validBoomerangURL('app_log')) {71 clearLog($prefs->get('log_file', 'logs_module')); 72 if ($app->validBoomerangURL('app_log')) { 72 73 // Display boomerang page. 73 App::dieBoomerangURL('app_log');74 $app->dieBoomerangURL('app_log'); 74 75 } 75 76 // Display default page. 76 App::dieURL($_SERVER['PHP_SELF']);77 $app->dieURL($_SERVER['PHP_SELF']); 77 78 break; 78 79 79 80 case 'archive' : 80 81 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET); 81 if (archiveLog( Prefs::getValue('log_file', 'logs_module'))) {82 if (archiveLog($prefs->get('log_file', 'logs_module'))) { 82 83 // Now flush current log. 83 App::dieURL($_SERVER['PHP_SELF'] . '?op=clear');84 } 85 if ( App::validBoomerangURL('app_log')) {84 $app->dieURL($_SERVER['PHP_SELF'] . '?op=clear'); 85 } 86 if ($app->validBoomerangURL('app_log')) { 86 87 // Display boomerang page. 87 App::dieBoomerangURL('app_log');88 $app->dieBoomerangURL('app_log'); 88 89 } 89 90 // Display default page. 90 App::dieURL($_SERVER['PHP_SELF']);91 $app->dieURL($_SERVER['PHP_SELF']); 91 92 break; 92 93 … … 97 98 case 'download' : 98 99 header('Content-Type: application/octet-stream'); 99 header(sprintf('Content-Disposition: attachment; filename=%s.txt', Prefs::getValue('log_file', 'logs_module')));100 printLog( Prefs::getValue('log_file', 'logs_module'));100 header(sprintf('Content-Disposition: attachment; filename=%s.txt', $prefs->get('log_file', 'logs_module'))); 101 printLog($prefs->get('log_file', 'logs_module')); 101 102 die; 102 103 break; 103 104 104 105 default : 105 $list =& getLog( Prefs::getValue('log_file', 'logs_module'), getFormData('search_query'));106 $list =& getLog($prefs->get('log_file', 'logs_module'), getFormData('search_query')); 106 107 $main_template = 'log_list.ihtml'; 107 108 break; … … 125 126 include 'header.ihtml'; 126 127 if ('output' == $main_template) { 127 printLog( Prefs::getValue('log_file', 'logs_module'));128 printLog($prefs->get('log_file', 'logs_module')); 128 129 } else { 129 130 include 'codebase/services/templates/' . $main_template; … … 138 139 function deleteLog($log_file) 139 140 { 140 if (!file_exists(App::getParam('log_directory') . '/' . $log_file)) { 141 App::raiseMsg(sprintf(_("Log file %s does not exist."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 142 App::logMsg(sprintf('Cannot delete nonexistent log file %s', App::getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 143 return false; 144 } 145 146 if (!is_writable(App::getParam('log_directory') . '/' . $log_file) && !is_writable(App::getParam('log_directory'))) { 147 App::raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 148 App::logMsg(sprintf('Cannot delete log file %s, not writable.', App::getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 149 return false; 150 } 151 152 if (unlink(App::getParam('log_directory') . '/' . $log_file)) { 153 App::raiseMsg(sprintf(_("Log file %s has been deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 154 App::logMsg(sprintf('Log file %s has been deleted', $log_file), LOG_INFO, __FILE__, __LINE__); 141 $app =& App::getInstance(); 142 143 if (!file_exists($app->getParam('log_directory') . '/' . $log_file)) { 144 $app->raiseMsg(sprintf(_("Log file %s does not exist."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 145 $app->logMsg(sprintf('Cannot delete nonexistent log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 146 return false; 147 } 148 149 if (!is_writable($app->getParam('log_directory') . '/' . $log_file) && !is_writable($app->getParam('log_directory'))) { 150 $app->raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 151 $app->logMsg(sprintf('Cannot delete log file %s, not writable.', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 152 return false; 153 } 154 155 if (unlink($app->getParam('log_directory') . '/' . $log_file)) { 156 $app->raiseMsg(sprintf(_("Log file %s has been deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 157 $app->logMsg(sprintf('Log file %s has been deleted', $log_file), LOG_INFO, __FILE__, __LINE__); 155 158 return true; 156 159 } else { 157 App::raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_WARNING, __FILE__, __LINE__);158 App::logMsg(sprintf('unlink failed on log file %s', App::getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__);160 $app->raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_WARNING, __FILE__, __LINE__); 161 $app->logMsg(sprintf('unlink failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 159 162 return false; 160 163 } … … 163 166 function clearLog($log_file) 164 167 { 165 if (!$fp = fopen(App::getParam('log_directory') . '/' . $log_file, 'r+')) { 166 App::raiseMsg(sprintf(_("Log file %s could not be opened."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 167 App::logMsg(sprintf('fopen failed on log file %s', App::getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 168 $app =& App::getInstance(); 169 170 if (!$fp = fopen($app->getParam('log_directory') . '/' . $log_file, 'r+')) { 171 $app->raiseMsg(sprintf(_("Log file %s could not be opened."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 172 $app->logMsg(sprintf('fopen failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 168 173 return false; 169 174 } … … 174 179 fclose($fp); 175 180 if (!$ftruncate_return) { 176 App::raiseMsg(sprintf(_("Log file %s could not be cleared."), $log_file), MSG_WARNING, __FILE__, __LINE__);177 App::logMsg(sprintf('ftruncate failed on log file %s', App::getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__);181 $app->raiseMsg(sprintf(_("Log file %s could not be cleared."), $log_file), MSG_WARNING, __FILE__, __LINE__); 182 $app->logMsg(sprintf('ftruncate failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 178 183 return false; 179 184 } else { 180 App::raiseMsg(sprintf(_("Log file %s has been cleared."), $log_file), MSG_NOTICE, __FILE__, __LINE__);181 App::logMsg(sprintf('Log file %s has been cleared', $log_file), LOG_INFO, __FILE__, __LINE__);185 $app->raiseMsg(sprintf(_("Log file %s has been cleared."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 186 $app->logMsg(sprintf('Log file %s has been cleared', $log_file), LOG_INFO, __FILE__, __LINE__); 182 187 return true; 183 188 } … … 186 191 function archiveLog($log_file) 187 192 { 193 $app =& App::getInstance(); 194 188 195 $old_file_name = $log_file; 189 196 $new_file_name = $log_file . '__' . date('Y-m-d'); 190 If (!is_writable( App::getParam('log_directory') . '')) {191 App::raiseMsg(sprintf('Cannot archive log, log directory not writable: %s', App::getParam('log_directory')), MSG_WARNING, __FILE__, __LINE__);192 App::logMsg(sprintf('Cannot archive log, log directory not writable: %s', App::getParam('log_directory')), LOG_WARNING, __FILE__, __LINE__);193 return false; 194 } 195 If (!copy( App::getParam('log_directory') . '/' . $old_file_name, App::getParam('log_directory') . '/' . $new_file_name)) {196 App::raiseMsg(sprintf(_("Cannot archive log, copying old log file failed."), null), MSG_WARNING, __FILE__, __LINE__);197 App::logMsg(sprintf('Cannot archive log, copying old log file failed.', null), LOG_WARNING, __FILE__, __LINE__);198 return false; 199 } 200 201 App::raiseMsg(sprintf(_("Log file %s has been archived to %s."), $old_file_name, $new_file_name), MSG_NOTICE, __FILE__, __LINE__);202 App::logMsg(sprintf('Log file %s has been archived to %s.', $old_file_name, $new_file_name), LOG_NOTICE, __FILE__, __LINE__);197 If (!is_writable($app->getParam('log_directory') . '')) { 198 $app->raiseMsg(sprintf('Cannot archive log, log directory not writable: %s', $app->getParam('log_directory')), MSG_WARNING, __FILE__, __LINE__); 199 $app->logMsg(sprintf('Cannot archive log, log directory not writable: %s', $app->getParam('log_directory')), LOG_WARNING, __FILE__, __LINE__); 200 return false; 201 } 202 If (!copy($app->getParam('log_directory') . '/' . $old_file_name, $app->getParam('log_directory') . '/' . $new_file_name)) { 203 $app->raiseMsg(sprintf(_("Cannot archive log, copying old log file failed."), null), MSG_WARNING, __FILE__, __LINE__); 204 $app->logMsg(sprintf('Cannot archive log, copying old log file failed.', null), LOG_WARNING, __FILE__, __LINE__); 205 return false; 206 } 207 208 $app->raiseMsg(sprintf(_("Log file %s has been archived to %s."), $old_file_name, $new_file_name), MSG_NOTICE, __FILE__, __LINE__); 209 $app->logMsg(sprintf('Log file %s has been archived to %s.', $old_file_name, $new_file_name), LOG_NOTICE, __FILE__, __LINE__); 203 210 return true; 204 211 } … … 206 213 function printLog($log_file) 207 214 { 208 if (!is_file(App::getParam('log_directory') . '/' . $log_file)) { 209 App::raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 210 App::logMsg(sprintf('Log file %s not found.', App::getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 211 return false; 212 } 213 214 readfile(App::getParam('log_directory') . '/' . $log_file); 215 $app =& App::getInstance(); 216 217 if (!is_file($app->getParam('log_directory') . '/' . $log_file)) { 218 $app->raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 219 $app->logMsg(sprintf('Log file %s not found.', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 220 return false; 221 } 222 223 readfile($app->getParam('log_directory') . '/' . $log_file); 215 224 } 216 225 217 226 function &getLog($log_file, $search_query='') 218 227 { 219 if (!is_file(App::getParam('log_directory') . '/' . $log_file)) { 220 App::raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 221 App::logMsg(sprintf('Log file %s not found.', App::getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 222 return false; 223 } 224 $log = file(App::getParam('log_directory') . '/' . $log_file); 228 $app =& App::getInstance(); 229 230 if (!is_file($app->getParam('log_directory') . '/' . $log_file)) { 231 $app->raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 232 $app->logMsg(sprintf('Log file %s not found.', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 233 return false; 234 } 235 $log = file($app->getParam('log_directory') . '/' . $log_file); 225 236 226 237 if ('' != trim($search_query)) { … … 237 248 { 238 249 global $valid_file_extensions; 250 $app =& App::getInstance(); 239 251 240 252 // Get a list of all files in the log directory. 241 $dir_handle = opendir( App::getParam('log_directory'));253 $dir_handle = opendir($app->getParam('log_directory')); 242 254 $list = array(); 243 255 while ($dir_handle && ($file = readdir($dir_handle)) !== false) { 244 if (!preg_match('/^\./', $file) && is_file( App::getParam('log_directory') . '/' . $file) && in_array(strtolower(Upload::getFilenameExtension($file)), $valid_file_extensions)) {256 if (!preg_match('/^\./', $file) && is_file($app->getParam('log_directory') . '/' . $file) && in_array(strtolower(Upload::getFilenameExtension($file)), $valid_file_extensions)) { 245 257 $list[] = array( 246 258 'filename' => $file, 247 'filesize' => filesize( App::getParam('log_directory') . '/' . $file),248 'modified' => filemtime( App::getParam('log_directory') . '/' . $file),259 'filesize' => filesize($app->getParam('log_directory') . '/' . $file), 260 'modified' => filemtime($app->getParam('log_directory') . '/' . $file), 249 261 ); 250 262 }
Note: See TracChangeset
for help on using the changeset viewer.