Ignore:
Timestamp:
Jun 3, 2006 7:47:48 PM (18 years ago)
Author:
scdev
Message:

Q - Merged branches/2.0singleton into trunk. Completed updating classes to use singleton methods. Implemented tests. Fixed some bugs. Changed some interfaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/services/logs.php

    r42 r136  
    99$auth->requireLogin();
    1010// $auth->requireAccessClearance(ZONE_ADMIN_APPLOG);
    11 App::sslOn();
     11$app->sslOn();
    1212
    1313require_once 'codebase/lib/PageNumbers.inc.php';
     
    3939
    4040// 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');
    4344
    4445// 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');
    4647
    4748/******************************************************************************
     
    5657case 'delete' :
    5758//     $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')) {
    6162        // Display boomerang page.
    62         App::dieBoomerangURL('app_log');
     63        $app->dieBoomerangURL('app_log');
    6364    }
    6465    // Display default page.
    65     App::dieURL($_SERVER['PHP_SELF']);
     66    $app->dieURL($_SERVER['PHP_SELF']);
    6667    break;
    6768
    6869case 'clear' :
    6970//     $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')) {
    7273        // Display boomerang page.
    73         App::dieBoomerangURL('app_log');
     74        $app->dieBoomerangURL('app_log');
    7475    }
    7576    // Display default page.
    76     App::dieURL($_SERVER['PHP_SELF']);
     77    $app->dieURL($_SERVER['PHP_SELF']);
    7778    break;
    7879
    7980case 'archive' :
    8081//     $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'))) {
    8283        // 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')) {
    8687        // Display boomerang page.
    87         App::dieBoomerangURL('app_log');
     88        $app->dieBoomerangURL('app_log');
    8889    }
    8990    // Display default page.
    90     App::dieURL($_SERVER['PHP_SELF']);
     91    $app->dieURL($_SERVER['PHP_SELF']);
    9192    break;
    9293
     
    9798case 'download' :
    9899    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'));
    101102    die;
    102103    break;
    103104
    104105default :
    105     $list =& getLog(Prefs::getValue('log_file', 'logs_module'), getFormData('search_query'));
     106    $list =& getLog($prefs->get('log_file', 'logs_module'), getFormData('search_query'));
    106107    $main_template = 'log_list.ihtml';
    107108    break;
     
    125126include 'header.ihtml';
    126127if ('output' == $main_template) {
    127     printLog(Prefs::getValue('log_file', 'logs_module'));
     128    printLog($prefs->get('log_file', 'logs_module'));
    128129} else {
    129130    include 'codebase/services/templates/' . $main_template;
     
    138139function deleteLog($log_file)
    139140{
    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__);
    155158        return true;
    156159    } 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__);
    159162        return false;
    160163    }
     
    163166function clearLog($log_file)
    164167{
    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__);
    168173        return false;
    169174    }
     
    174179    fclose($fp);
    175180    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__);
    178183        return false;
    179184    } 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__);
    182187        return true;
    183188    }
     
    186191function archiveLog($log_file)
    187192{
     193    $app =& App::getInstance();
     194
    188195    $old_file_name = $log_file;
    189196    $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__);
    203210    return true;
    204211}
     
    206213function printLog($log_file)
    207214{
    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);
    215224}
    216225
    217226function &getLog($log_file, $search_query='')
    218227{
    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);
    225236
    226237    if ('' != trim($search_query)) {
     
    237248{
    238249    global $valid_file_extensions;
     250    $app =& App::getInstance();
    239251
    240252    // 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'));
    242254    $list = array();
    243255    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)) {
    245257            $list[] = array(
    246258                '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),
    249261            );
    250262        }
Note: See TracChangeset for help on using the changeset viewer.