Ignore:
Timestamp:
May 26, 2006 9:40:35 PM (18 years ago)
Author:
scdev
Message:

finished updating to 2.0singleton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0singleton/services/logs.php

    r42 r129  
    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');
     41Prefs::setDefault('log_file', $app->getParam('log_filename'), 'logs_module');
    4242Prefs::setValue('log_file', getFormData('log'), 'logs_module');
    4343
     
    5757//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    5858    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')) {
    6161        // Display boomerang page.
    62         App::dieBoomerangURL('app_log');
     62        $app->dieBoomerangURL('app_log');
    6363    }
    6464    // Display default page.
    65     App::dieURL($_SERVER['PHP_SELF']);
     65    $app->dieURL($_SERVER['PHP_SELF']);
    6666    break;
    6767
     
    6969//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    7070    clearLog(Prefs::getValue('log_file', 'logs_module'));
    71     if (App::validBoomerangURL('app_log')) {
     71    if ($app->validBoomerangURL('app_log')) {
    7272        // Display boomerang page.
    73         App::dieBoomerangURL('app_log');
     73        $app->dieBoomerangURL('app_log');
    7474    }
    7575    // Display default page.
    76     App::dieURL($_SERVER['PHP_SELF']);
     76    $app->dieURL($_SERVER['PHP_SELF']);
    7777    break;
    7878
     
    8181    if (archiveLog(Prefs::getValue('log_file', 'logs_module'))) {
    8282        // 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')) {
    8686        // Display boomerang page.
    87         App::dieBoomerangURL('app_log');
     87        $app->dieBoomerangURL('app_log');
    8888    }
    8989    // Display default page.
    90     App::dieURL($_SERVER['PHP_SELF']);
     90    $app->dieURL($_SERVER['PHP_SELF']);
    9191    break;
    9292
     
    138138function deleteLog($log_file)
    139139{
    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__);
    155157        return true;
    156158    } 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__);
    159161        return false;
    160162    }
     
    163165function clearLog($log_file)
    164166{
    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__);
    168172        return false;
    169173    }
     
    174178    fclose($fp);
    175179    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__);
    178182        return false;
    179183    } 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__);
    182186        return true;
    183187    }
     
    186190function archiveLog($log_file)
    187191{
     192    $app =& App::getInstance();
     193
    188194    $old_file_name = $log_file;
    189195    $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__);
    203209    return true;
    204210}
     
    206212function printLog($log_file)
    207213{
    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);
    215223}
    216224
    217225function &getLog($log_file, $search_query='')
    218226{
    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);
    225235
    226236    if ('' != trim($search_query)) {
     
    237247{
    238248    global $valid_file_extensions;
     249    $app =& App::getInstance();
    239250
    240251    // 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'));
    242253    $list = array();
    243254    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)) {
    245256            $list[] = array(
    246257                '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),
    249260            );
    250261        }
Note: See TracChangeset for help on using the changeset viewer.