Changeset 532


Ignore:
Timestamp:
Jul 13, 2015 8:11:33 PM (9 years ago)
Author:
anonymous
Message:

Added common config for codebase cli scripts. Changed behavior of db_auth.json loading. validSignature() now fails on empty string.

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/acl.cli.php

    r502 r532  
    1 #!/usr/bin/php
     1#!/usr/bin/env php
    22<?php
    33/**
     
    2626*
    2727* @author   Quinn Comendant <quinn@strangecode.com>
    28 * @version  1.0
     28* @version  1.1
    2929* @since    14 Jun 2006 23:10:45
    3030*/
    3131
    32 
    3332/********************************************************************
    34 * STARTUP
     33* CONFIG
    3534********************************************************************/
    3635
    37 $this_script = basename($_SERVER['argv'][0]);
     36require_once dirname(__FILE__) . '/_config.inc.php';
    3837
    3938// Give them a fighting chance. Show the help message. ;P
     
    4140    help();
    4241}
    43 
    44 // Make sure necessary files exist.
    45 define('COMMON_BASE', realpath('.'));
    46 $db_auth_file = false;
    47 $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(COMMON_BASE));
    48 $rii->setMaxDepth(2);
    49 foreach ($rii as $filename => $file) {
    50     if (mb_strpos($filename, 'db_auth.inc.php') !== false) {
    51         $db_auth_file = $filename;
    52         break;
    53     }
    54 }
    55 if (!$db_auth_file) {
    56     die(sprintf("%s error: the current directory must be common site directory (i.e. the parent directory of the document root) AND the db_auth.inc.php file must exist.\n", $this_script));
    57 }
    58 if (fileowner($db_auth_file) != getmyuid()) {
    59     die(sprintf("%s error: you must execute this script as the owner of the web files.\n", $this_script));
    60 }
    61 
    62 // Set include path.
    63 ini_set('include_path', get_include_path() . PATH_SEPARATOR . COMMON_BASE);
    64 
    65 /********************************************************************
    66 * CONFIG
    67 ********************************************************************/
    68 
    69 // Include core libraries.
    70 require_once 'codebase/lib/App.inc.php';
    71 require_once 'codebase/lib/Utilities.inc.php';
    72 
    73 define('_CLI', true);
    74 $app =& App::getInstance('module_maker');
    75 $app->setParam(array(
    76     'site_name' => 'ACL cli',
    77     'site_email' => 'codebase@strangecode.com',
    78     'enable_session' => false,
    79     'enable_db' => true,
    80     'db_always_debug' => false,
    81     'db_debug' => true,
    82     'db_die_on_failure' => true,
    83     'display_errors' => true,
    84     'error_reporting' => E_ALL,
    85     'log_file_priority' => LOG_INFO,
    86     'log_screen_priority' => LOG_ERR,
    87     'log_directory' => COMMON_BASE . '/log',
    88     'log_filename' => 'site_log',
    89 ));
    90 require_once $db_auth_file;
    91 
    92 // Start application-based functionality: database, session, environment, ini setup, etc.
    93 // Most configuration parameters must be set before starting the App.
    94 $app->start();
    95 
    96 // Global DB object. Automatically pre-configured by $app->start().
    97 $db =& DB::getInstance();
    9842
    9943// ACL!
  • trunk/lib/App.inc.php

    r529 r532  
    349349            }
    350350
    351             // DB credentials for CLI scripts stored in a JSON file with read rights given only to the user who will be executing the scripts: -rw-------
    352             // But only if db_pass hasn't been defined yet by other means.
    353             if (defined('_CLI') && !$this->getParam('db_server') && !$this->getParam('db_name') && !$this->getParam('db_user') && !$this->getParam('db_pass')) {
     351            // DB credentials for CLI scripts stored in a JSON file with read rights given only to the user who will be executing the scripts: -r--------
     352            // But not if all DB credentials have been defined already by other means.
     353            if (defined('_CLI') && (!$this->getParam('db_server') || !$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass'))) {
    354354                if (false !== $db_auth_file = stream_resolve_include_path($this->getParam('db_auth_file'))) {
    355355                    if (is_readable($db_auth_file)) {
  • trunk/lib/DB.inc.php

    r502 r532  
    378378    public function columnExists($table, $columns, $strict=true, $use_cached_results=true)
    379379    {
    380         if (!$this->_connected) {
     380        $app =& App::getInstance();
     381
     382        if (!$this->_connected) {
     383            $app->logMsg(sprintf('No DB connection to run %s', __METHOD__), LOG_NOTICE, __FILE__, __LINE__);
    381384            return false;
    382385        }
     
    384387        // Ensure the table exists.
    385388        if (!$this->tableExists($table, $use_cached_results)) {
     389            $app->logMsg(sprintf('Table does not exist: %s', $table), LOG_DEBUG, __FILE__, __LINE__);
    386390            return false;
    387391        }
  • trunk/lib/Utilities.inc.php

    r531 r532  
    10911091    $val = removeSignature($signed_val);
    10921092    // If the signed value matches the original signed value we consider the value safe.
    1093     if ($signed_val == addSignature($val, $salt, $length)) {
     1093    if ('' != $signed_val && $signed_val == addSignature($val, $salt, $length)) {
    10941094        // Signature verified.
    10951095        return true;
  • trunk/lib/Version.inc.php

    r523 r532  
    5353        // This value is overwritten by the $app->getParam('db_create_tables') setting if it is available.
    5454        'create_table' => true,
     55
    5556        // If true, makes an exact comparison of saved vs. live table schemas. If false, just checks that the saved columns are available.
    5657        'db_schema_strict' => true,
Note: See TracChangeset for help on using the changeset viewer.