Example #1
0
 public function testDolog()
 {
     global $_log_fh;
     $tmpfile = tempnam('/tmp', 'LTS');
     if (file_exists($tmpfile)) {
         unlink($tmpfile);
     }
     $config = null;
     if (is_object(Config::$inst)) {
         $config = clone Config::$inst;
     }
     Config::set('log', 'file', $tmpfile);
     Config::set('log', 'level', LOG_INFO);
     Config::set('log', 'date_format', 'mdY');
     Config::set('log', 'format', '[%s] %s - %s');
     dolog('test info', LOG_INFO);
     _closelog();
     $log = file_get_contents($tmpfile);
     $this->assertEquals(18, strpos($log, 'test info'));
     unlink($tmpfile);
     //restore original config
     if (is_object($config)) {
         Config::$inst = $config;
     }
     $_log_fh = false;
 }
Example #2
0
 public static function receive($payload, $crypt = null)
 {
     $stream = self::_get();
     if (!is_object($crypt)) {
         $stream->setCrypt(Crypt::_get(Config::get('xport', 'crypt.key'), Config::get('xport', 'crypt.iv')));
     } else {
         $stream->setCrypt($crypt);
     }
     $stream->setup($payload);
     return $stream;
 }
Example #3
0
 public static function auth($params)
 {
     if (is_null(Config::get('xport', 'auth_key'))) {
         throw new Exception('Cannot auth request, no auth key defined');
     }
     if (!isset($params['xport_auth_key'])) {
         throw new Exception('No auth key present for authenticated request');
     }
     if ($params['xport_auth_key'] != Config::get('xport', 'auth_key')) {
         throw new Exception('Invalid auth key passed with request');
     }
     return true;
 }
Example #4
0
 public static function load()
 {
     //get our crypt instance
     $crypt = Crypt::_get(Config::get('vidcache', 'crypt_key'), Config::get('vidcache', 'crypt_iv'));
     //load up xport and the environment
     $obj = static::_get('localhost', Config::get('vidcache', 'server_port'), Config::get('vidcache', 'server_scheme'), Log::DEBUG);
     $obj->setEncoding(Xport::ENC_SERIALIZE);
     $obj->stream->setCrypt($crypt);
     $obj->block_stream->setCrypt($crypt);
     $obj->vc = SDK::load();
     $obj->vc->connect(Config::get('vidcache', 'api_key'));
     return $obj;
 }
Example #5
0
function dolog($msg, $level = LOG_INFO)
{
    global $_log_fh;
    if ($level > Config::get('log', 'level')) {
        return null;
    }
    if (!$_log_fh) {
        $file = Config::get('log', 'file');
        if ($file === false) {
            return null;
        }
        //assume logging is off
        $_log_fh = fopen($file, 'a');
        if (!$_log_fh) {
            throw new Exception('Could not open log: ' . $file);
        }
        register_shutdown_function('_closelog');
    }
    switch ($level) {
        case LOG_DEBUG:
            $lword = 'DEBUG';
            break;
        case LOG_INFO:
            $lword = 'INFO';
            break;
        case LOG_NOTICE:
            $lword = 'NOTICE';
            break;
        case LOG_WARN:
            $lword = 'WARNING';
            break;
        case LOG_ERROR:
            $lword = 'ERROR';
            break;
        default:
            $lword = 'UNKNOWN';
            break;
    }
    $date = date(Config::get('log', 'date_format'));
    //we dont want newlines in output, let the output wrap naturally
    //$msg = str_replace("\n",' ',$msg);
    $fmtd_msg = sprintf(Config::get('log', 'format'), $lword, $date, $msg) . PHP_EOL;
    if (php_sapi_name() == 'cli' && !defined('LOG_QUIET')) {
        if (strlen($fmtd_msg) < 1024) {
            echo $fmtd_msg;
        } else {
            echo substr($fmtd_msg, 0, 1024) . "<SNIP>\n";
        }
    }
    return fwrite($_log_fh, $fmtd_msg);
}
Example #6
0
 public function connect($api_key)
 {
     //check if we have a token in a session
     if (isset($_SESSION[$api_key])) {
         self::$token = $_SESSION[$api_key];
         $this->connected = true;
         return self::$token;
     }
     //make the connect call
     $rv = $this->call($this->buildURI('/index.php?act=connect&client_id=' . Config::get('vidcache', 'client_id')), array('api_key' => $api_key));
     //check for token
     if (!isset($rv['token'])) {
         throw new Exception('Couldnt connect, failed to receive token');
     }
     self::$token = $rv['token'];
     $_SESSION[$api_key] = self::$token;
     $this->connected = true;
     return self::$token;
 }
 *	GNU Lesser General Public License along with OpenLSS.
 *	If not, see <http://www.gnu.org/licenses/>.
 */
use LSS\Account\Client;
use LSS\Account\ClientSession;
use LSS\Config;
use LSS\Url;
if (session_id() != '') {
    //check for session
    try {
        if (ClientSession::checkLogin()) {
            //register session
            $token = ClientSession::fetchByToken(ClientSession::getTokenFromSession());
            $session = array_merge(Client::fetch($token['staff_id']), $token);
            ClientSession::storeSession($session);
            unset($session, $token);
            //set tpl globals (if Tpl is available)
            if (is_callable(array('Tpl', '_get'))) {
                Tpl::_get()->set(array('client_name' => ClientSession::get('name'), 'client_lastlogin' => date(Config::get('account.date.general_format'), ClientSession::get('last_login'))));
            }
        } else {
            if (server('REQUEST_URI') != Url::login()) {
                redirect(Url::login());
            }
        }
    } catch (Exception $e) {
        ClientSession::tokenDestroy(ClientSession::getTokenFromSession());
        ClientSession::destroySession();
        redirect(Url::login());
    }
}
Example #8
0
 public function testConnect()
 {
     $this->vc->connect(Config::get('vidcache', 'api_key'));
     $this->assertTrue($this->vc->isConnected());
 }
Example #9
0
 protected static final function addMacroFields($c)
 {
     if (!is_array($c)) {
         return false;
     }
     //inject some value-added calculated pseudofields (rather than dupe this logic in multiple controllers)
     //add account_id for legacy purposes and generic purposes
     $c['account_id'] = $c[static::$account_key];
     //check if this contact has a account_id (is an account)
     $c['__is_account'] = is_numeric(mda_get($c, 'account_id')) ? true : false;
     //generate standard displayed contact and account_id
     $c['contact_id_display'] = sprintf('%08d', mda_get($c, 'contact_id'));
     $c['account_id_display'] = mda_get($c, '__is_account') ? sprintf('%08d', mda_get($c, 'account_id')) : '(none)';
     //generate standard displayed dates
     $c['created_display'] = date(Config::get('account.date.standard_format'), mda_get($c, 'created'));
     $c['contact_created_display'] = date(Config::get('account.date.standard_format'), mda_get($c, 'contact_created'));
     $c['last_login_display'] = mda_get($c, 'last_login') > 0 ? date(Config::get('account.date.standard_format'), mda_get($c, 'last_login')) : '(never)';
     $c['contact_last_login_display'] = mda_get($c, 'contact_last_login') > 0 ? date(Config::get('account.date.standard_format'), mda_get($c, 'contact_last_login')) : '(never)';
     $c['header_last_login'] = mda_get($c, 'contact_last_login_display');
     if (mda_get($c, '__auth') & 2) {
         $c['header_last_login'] = mda_get($c, 'last_login_display');
     }
     return array_merge($c);
 }
Example #10
0
<?php

/**
 *  OpenLSS - Lighter Smarter Simpler
 *
 *	This file is part of OpenLSS.
 *
 *	OpenLSS is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as
 *	published by the Free Software Foundation, either version 3 of
 *	the License, or (at your option) any later version.
 *
 *	OpenLSS is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.
 *
 *	You should have received a copy of the 
 *	GNU Lesser General Public License along with OpenLSS.
 *	If not, see <http://www.gnu.org/licenses/>.
 */
//db
$config['db']['driver'] = 'mysql';
$config['db']['host'] = 'localhost';
$config['db']['port'] = '';
$config['db']['user'] = '******';
$config['db']['password'] = '';
$config['db']['database'] = 'lss';
\LSS\Config::setDefaults($config);
unset($config);
Example #11
0
 public static function _prep()
 {
     return Config::get('url', 'url');
 }
Example #12
0
 *	published by the Free Software Foundation, either version 3 of
 *	the License, or (at your option) any later version.
 *
 *	OpenLSS is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.
 *
 *	You should have received a copy of the 
 *	GNU Lesser General Public License along with OpenLSS.
 *	If not, see <http://www.gnu.org/licenses/>.
 */
use LSS\Config;
use LSS\Tpl;
//load tpl
$theme = Config::get('theme', 'name') ? Config::get('theme', 'name') : 'default';
Tpl::_get()->setPath(ROOT_GROUP . '/theme/' . $theme);
Tpl::_get()->setUri('/theme/' . $theme . '/');
Tpl::_get()->set(array('lss_version' => LSS_VERSION, 'version' => VERSION, 'site_name' => Config::get('site_name'), 'site_title' => Config::get('site_name'), 'uri' => Config::get('url', 'uri'), 'url' => Config::get('url', 'url'), 'theme_path' => Tpl::_get()->uri, 'copyright' => '© ' . date('Y') . ' ' . Config::get('site_name')));
//set delayed alerts
if (session('delayed_alert')) {
    $alert = Tpl::_get()->get('alert');
    if (!is_array($alert)) {
        $alert = array();
    }
    $alert = array_merge($alert, session('delayed_alert'));
    Tpl::_get()->set('alert', $alert);
    session('delayed_alert', '');
}
//cleanup
unset($theme);
Example #13
0
function __boot_pre()
{
    define('START', microtime(true));
    //load config
    if (is_dir(ROOT . '/conf')) {
        __init_load_files(ROOT . '/conf', '__export_config', array(&$config));
    }
    if (defined('ROOT_GROUP') && is_dir(ROOT_GROUP . '/conf')) {
        __init_load_files(ROOT_GROUP . '/conf', '__export_config', array(&$config));
    }
    if (file_exists(ROOT . '/config.php')) {
        include ROOT . '/config.php';
    }
    if (defined('ROOT_GROUP') && file_exists(ROOT_GROUP . '/config.php')) {
        include ROOT_GROUP . '/config.php';
    }
    //set the config if we can
    if (class_exists('\\LSS\\Config') && is_callable(array(\LSS\Config::_get(), 'setConfig'))) {
        \LSS\Config::_get()->setConfig($config);
    }
    //set timezone
    if (isset($config['timezone'])) {
        date_default_timezone_set($config['timezone']);
    }
    unset($config);
}
Example #14
0
 public function testSetLongPath()
 {
     Config::set('does', 'this.extra.long.dotted.path.work.properly.wonk.wonk.wonk', true);
     $this->assertTrue(Config::get('does', 'this.extra.long.dotted.path.work.properly.wonk.wonk.wonk'));
 }
Example #15
0
 public function output($file, $tags = array(), $echo = true)
 {
     //if there is anything in the buffer, move it to debug
     if (($content = ob_get_contents()) !== '') {
         $this->addDebug('<pre>' . $content . '</pre>');
     }
     //init template handler
     $stub_overrides = $this->stub;
     //backup before initTheme or requested stubs get stomped
     $this->initTheme();
     //start up template engine
     $tpl = new PHPTAL($this->getTplFile($file));
     //init the tpl (load overrides)
     $this->initTpl($tpl, $file);
     //merge stub defaults with the overrides from earlier
     $tpl->stub = $this->stub;
     //setup env for template engine
     $this->setupEnv($tpl);
     //add tags to context
     if (is_array($tags)) {
         foreach ($tags as $name => $val) {
             //dont add invalid vars
             if (strpos($name, '_') === 0) {
                 continue;
             }
             if (strpos($name, ' ') !== false) {
                 continue;
             }
             $tpl->{$name} = $val;
         }
     }
     //execute template call
     try {
         $out = $tpl->execute();
     } catch (Exception $e) {
         //before we throw this upstream we want to restore
         //	the buffer and get more verbose output
         ob_clean();
         echo $content;
         throw $e;
     }
     //if we dont have the tidy extension lets just output now
     if (!extension_loaded('tidy')) {
         //print output to browser / terminal
         if ($echo) {
             $this->reset();
             ob_end_clean();
             echo $out;
             return true;
         } else {
             $this->add($out);
             return $out;
         }
         //we do have tidy so lets do some cleanup
     } else {
         //cleanup the output
         $tidy = new tidy();
         $tidy->parseString($out, Config::get('theme', 'tidy'), 'utf8');
         $tidy->cleanRepair();
         if ($echo) {
             ob_end_clean();
             echo $tidy;
             return true;
         } else {
             $this->add($tidy);
             return $tidy;
         }
     }
 }
Example #16
0
 public static function tokenCreate($id, $remote_ip, $user_agent)
 {
     //try to reuse an existing token
     $token = self::findToken($id, $remote_ip, $user_agent);
     if ($token) {
         return $token['token'];
     }
     //create a new token
     $token = gen_guid();
     $expires = time() + Config::get(static::$config_name, 'token_life');
     Db::_get()->insert(static::$session_table, array('token' => $token, self::$user_primary_key => $id, 'remote_ip' => $remote_ip, 'user_agent' => $user_agent, 'expires' => $expires, 'is_active' => 1));
     return $token;
 }