Changeset 129 for branches/2.0singleton/services/logs.php
- Timestamp:
- May 26, 2006 9:40:35 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0singleton/services/logs.php
r42 r129 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');41 Prefs::setDefault('log_file', $app->getParam('log_filename'), 'logs_module'); 42 42 Prefs::setValue('log_file', getFormData('log'), 'logs_module'); 43 43 … … 57 57 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET); 58 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 Prefs::setValue('log_file', $app->getParam('log_filename'), 'logs_module'); 60 if ($app->validBoomerangURL('app_log')) { 61 61 // Display boomerang page. 62 App::dieBoomerangURL('app_log');62 $app->dieBoomerangURL('app_log'); 63 63 } 64 64 // Display default page. 65 App::dieURL($_SERVER['PHP_SELF']);65 $app->dieURL($_SERVER['PHP_SELF']); 66 66 break; 67 67 … … 69 69 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET); 70 70 clearLog(Prefs::getValue('log_file', 'logs_module')); 71 if ( App::validBoomerangURL('app_log')) {71 if ($app->validBoomerangURL('app_log')) { 72 72 // Display boomerang page. 73 App::dieBoomerangURL('app_log');73 $app->dieBoomerangURL('app_log'); 74 74 } 75 75 // Display default page. 76 App::dieURL($_SERVER['PHP_SELF']);76 $app->dieURL($_SERVER['PHP_SELF']); 77 77 break; 78 78 … … 81 81 if (archiveLog(Prefs::getValue('log_file', 'logs_module'))) { 82 82 // Now flush current log. 83 App::dieURL($_SERVER['PHP_SELF'] . '?op=clear');84 } 85 if ( App::validBoomerangURL('app_log')) {83 $app->dieURL($_SERVER['PHP_SELF'] . '?op=clear'); 84 } 85 if ($app->validBoomerangURL('app_log')) { 86 86 // Display boomerang page. 87 App::dieBoomerangURL('app_log');87 $app->dieBoomerangURL('app_log'); 88 88 } 89 89 // Display default page. 90 App::dieURL($_SERVER['PHP_SELF']);90 $app->dieURL($_SERVER['PHP_SELF']); 91 91 break; 92 92 … … 138 138 function deleteLog($log_file) 139 139 { 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__); 140 $app =& App::getInstance(); 141 142 if (!file_exists($app->getParam('log_directory') . '/' . $log_file)) { 143 $app->raiseMsg(sprintf(_("Log file %s does not exist."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 144 $app->logMsg(sprintf('Cannot delete nonexistent log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 145 return false; 146 } 147 148 if (!is_writable($app->getParam('log_directory') . '/' . $log_file) && !is_writable($app->getParam('log_directory'))) { 149 $app->raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 150 $app->logMsg(sprintf('Cannot delete log file %s, not writable.', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 151 return false; 152 } 153 154 if (unlink($app->getParam('log_directory') . '/' . $log_file)) { 155 $app->raiseMsg(sprintf(_("Log file %s has been deleted."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 156 $app->logMsg(sprintf('Log file %s has been deleted', $log_file), LOG_INFO, __FILE__, __LINE__); 155 157 return true; 156 158 } 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__);159 $app->raiseMsg(sprintf(_("Log file %s could not be deleted."), $log_file), MSG_WARNING, __FILE__, __LINE__); 160 $app->logMsg(sprintf('unlink failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 159 161 return false; 160 162 } … … 163 165 function clearLog($log_file) 164 166 { 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__); 167 $app =& App::getInstance(); 168 169 if (!$fp = fopen($app->getParam('log_directory') . '/' . $log_file, 'r+')) { 170 $app->raiseMsg(sprintf(_("Log file %s could not be opened."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 171 $app->logMsg(sprintf('fopen failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_INFO, __FILE__, __LINE__); 168 172 return false; 169 173 } … … 174 178 fclose($fp); 175 179 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__);180 $app->raiseMsg(sprintf(_("Log file %s could not be cleared."), $log_file), MSG_WARNING, __FILE__, __LINE__); 181 $app->logMsg(sprintf('ftruncate failed on log file %s', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 178 182 return false; 179 183 } 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__);184 $app->raiseMsg(sprintf(_("Log file %s has been cleared."), $log_file), MSG_NOTICE, __FILE__, __LINE__); 185 $app->logMsg(sprintf('Log file %s has been cleared', $log_file), LOG_INFO, __FILE__, __LINE__); 182 186 return true; 183 187 } … … 186 190 function archiveLog($log_file) 187 191 { 192 $app =& App::getInstance(); 193 188 194 $old_file_name = $log_file; 189 195 $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__);196 If (!is_writable($app->getParam('log_directory') . '')) { 197 $app->raiseMsg(sprintf('Cannot archive log, log directory not writable: %s', $app->getParam('log_directory')), MSG_WARNING, __FILE__, __LINE__); 198 $app->logMsg(sprintf('Cannot archive log, log directory not writable: %s', $app->getParam('log_directory')), LOG_WARNING, __FILE__, __LINE__); 199 return false; 200 } 201 If (!copy($app->getParam('log_directory') . '/' . $old_file_name, $app->getParam('log_directory') . '/' . $new_file_name)) { 202 $app->raiseMsg(sprintf(_("Cannot archive log, copying old log file failed."), null), MSG_WARNING, __FILE__, __LINE__); 203 $app->logMsg(sprintf('Cannot archive log, copying old log file failed.', null), LOG_WARNING, __FILE__, __LINE__); 204 return false; 205 } 206 207 $app->raiseMsg(sprintf(_("Log file %s has been archived to %s."), $old_file_name, $new_file_name), MSG_NOTICE, __FILE__, __LINE__); 208 $app->logMsg(sprintf('Log file %s has been archived to %s.', $old_file_name, $new_file_name), LOG_NOTICE, __FILE__, __LINE__); 203 209 return true; 204 210 } … … 206 212 function printLog($log_file) 207 213 { 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); 214 $app =& App::getInstance(); 215 216 if (!is_file($app->getParam('log_directory') . '/' . $log_file)) { 217 $app->raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 218 $app->logMsg(sprintf('Log file %s not found.', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 219 return false; 220 } 221 222 readfile($app->getParam('log_directory') . '/' . $log_file); 215 223 } 216 224 217 225 function &getLog($log_file, $search_query='') 218 226 { 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); 227 $app =& App::getInstance(); 228 229 if (!is_file($app->getParam('log_directory') . '/' . $log_file)) { 230 $app->raiseMsg(sprintf(_("Log file %s not found."), $log_file), MSG_WARNING, __FILE__, __LINE__); 231 $app->logMsg(sprintf('Log file %s not found.', $app->getParam('log_directory') . '/' . $log_file), LOG_WARNING, __FILE__, __LINE__); 232 return false; 233 } 234 $log = file($app->getParam('log_directory') . '/' . $log_file); 225 235 226 236 if ('' != trim($search_query)) { … … 237 247 { 238 248 global $valid_file_extensions; 249 $app =& App::getInstance(); 239 250 240 251 // Get a list of all files in the log directory. 241 $dir_handle = opendir( App::getParam('log_directory'));252 $dir_handle = opendir($app->getParam('log_directory')); 242 253 $list = array(); 243 254 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)) {255 if (!preg_match('/^\./', $file) && is_file($app->getParam('log_directory') . '/' . $file) && in_array(strtolower(Upload::getFilenameExtension($file)), $valid_file_extensions)) { 245 256 $list[] = array( 246 257 'filename' => $file, 247 'filesize' => filesize( App::getParam('log_directory') . '/' . $file),248 'modified' => filemtime( App::getParam('log_directory') . '/' . $file),258 'filesize' => filesize($app->getParam('log_directory') . '/' . $file), 259 'modified' => filemtime($app->getParam('log_directory') . '/' . $file), 249 260 ); 250 261 }
Note: See TracChangeset
for help on using the changeset viewer.