Exemplo n.º 1
0
 /**
  * Enregistre un message dans un fichier de log spécifique
  * Message non loggué si
  * 	- environment = SILENT
  * 	- level = WARNING et environment = PRODUCTION
  * 	- level = NOTICE et environment = PRODUCTION
  * @param $information message d'erreur / information à enregistrer
  * @param $level niveau d'erreur
  * @param $file_name fichier de log
  */
 public static function record($information, $level, $file_name = null)
 {
     try {
         $conf = Minz_Configuration::get('system');
         $env = $conf->environment;
     } catch (Minz_ConfigurationException $e) {
         $env = 'production';
     }
     if (!($env === 'silent' || $env === 'production' && $level >= Minz_Log::NOTICE)) {
         if ($file_name === null) {
             $file_name = join_path(USERS_PATH, Minz_Session::param('currentUser', '_'), 'log.txt');
         }
         switch ($level) {
             case Minz_Log::ERROR:
                 $level_label = 'error';
                 break;
             case Minz_Log::WARNING:
                 $level_label = 'warning';
                 break;
             case Minz_Log::NOTICE:
                 $level_label = 'notice';
                 break;
             case Minz_Log::DEBUG:
                 $level_label = 'debug';
                 break;
             default:
                 $level_label = 'unknown';
         }
         $log = '[' . date('r') . ']' . ' [' . $level_label . ']' . ' --- ' . $information . "\n";
         if (file_put_contents($file_name, $log, FILE_APPEND | LOCK_EX) === false) {
             throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR);
         }
     }
 }
Exemplo n.º 2
0
 public function applyAction()
 {
     if (!file_exists(UPDATE_FILENAME) || !is_writable(FRESHRSS_PATH)) {
         Minz_Request::forward(array('c' => 'update'), true);
     }
     require UPDATE_FILENAME;
     if (Minz_Request::param('post_conf', false)) {
         $res = do_post_update();
         Minz_ExtensionManager::callHook('post_update');
         if ($res === true) {
             @unlink(UPDATE_FILENAME);
             @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), '');
             Minz_Request::good(_t('feedback.update.finished'));
         } else {
             Minz_Request::bad(_t('feedback.update.error', $res), array('c' => 'update', 'a' => 'index'));
         }
     }
     if (Minz_Request::isPost()) {
         save_info_update();
     }
     if (!need_info_update()) {
         $res = apply_update();
         if ($res === true) {
             Minz_Request::forward(array('c' => 'update', 'a' => 'apply', 'params' => array('post_conf' => true)), true);
         } else {
             Minz_Request::bad(_t('feedback.update.error', $res), array('c' => 'update', 'a' => 'index'));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Initialize the different FreshRSS / Minz components.
  *
  * PLEASE DON'T CHANGE THE ORDER OF INITIALIZATIONS UNLESS YOU KNOW WHAT
  * YOU DO!!
  *
  * Here is the list of components:
  * - Create a configuration setter and register it to system conf
  * - Init extension manager and enable system extensions (has to be done asap)
  * - Init authentication system
  * - Init user configuration (need auth system)
  * - Init FreshRSS context (need user conf)
  * - Init i18n (need context)
  * - Init sharing system (need user conf and i18n)
  * - Init generic styles and scripts (need user conf)
  * - Init notifications
  * - Enable user extensions (need all the other initializations)
  */
 public function init()
 {
     if (!isset($_SESSION)) {
         Minz_Session::init('FreshRSS');
     }
     // Register the configuration setter for the system configuration
     $configuration_setter = new FreshRSS_ConfigurationSetter();
     $system_conf = Minz_Configuration::get('system');
     $system_conf->_configurationSetter($configuration_setter);
     // Load list of extensions and enable the "system" ones.
     Minz_ExtensionManager::init();
     // Auth has to be initialized before using currentUser session parameter
     // because it's this part which create this parameter.
     $this->initAuth();
     // Then, register the user configuration and use the configuration setter
     // created above.
     $current_user = Minz_Session::param('currentUser', '_');
     Minz_Configuration::register('user', join_path(USERS_PATH, $current_user, 'config.php'), join_path(USERS_PATH, '_', 'config.default.php'), $configuration_setter);
     // Finish to initialize the other FreshRSS / Minz components.
     FreshRSS_Context::init();
     $this->initI18n();
     FreshRSS_Share::load(join_path(DATA_PATH, 'shares.php'));
     $this->loadStylesAndScripts();
     $this->loadNotifications();
     // Enable extensions for the current (logged) user.
     if (FreshRSS_Auth::hasAccess()) {
         $ext_list = FreshRSS_Context::$user_conf->extensions_enabled;
         Minz_ExtensionManager::enableByList($ext_list);
     }
 }
Exemplo n.º 4
0
 public static function load_routes($path = '')
 {
     if ($path == '') {
         $path = join_path(ROOT_DIR, 'config', 'routes.php');
     }
     include_once $path;
 }
Exemplo n.º 5
0
 public function handleRequest()
 {
     $config = Registry::getInstance();
     $scriptdir = str_replace($config->web_root, '', $config->site_root);
     $scriptname = basename($_SERVER['SCRIPT_FILENAME']);
     $request = trim(str_replace(join_path($scriptdir, $scriptname), '', $_SERVER['REQUEST_URI']), DIRECTORY_SEPARATOR);
     $config->base_dir = $scriptdir;
     $view = 'default';
     if (strlen($request) > 0) {
         $args = explode(DIRECTORY_SEPARATOR, $request);
         if (count($args) > 0) {
             $controller = array_shift($args);
         }
         if (count($args) > 0) {
             $view = array_shift($args);
         }
         if (count($args) > 0) {
             foreach ($args as $k => $v) {
                 $args[$k] = urldecode($v);
             }
         }
     }
     if (!isset($controller)) {
         $controller = $config->default_controller;
         $args = array();
     }
     $controller = 'V7F\\Controller\\' . $controller;
     if (class_exists($controller)) {
         $active_controller = new $controller();
         $active_controller->{$view}($args);
     } else {
         trigger_error('Controller not found - ' . $controller, E_USER_ERROR);
     }
 }
Exemplo n.º 6
0
 public function setup()
 {
     //Setup session stuff
     SilkSession::setup();
     //Load up the configuration file
     if (is_file(join_path(ROOT_DIR, 'config', 'setup.yml'))) {
         $config = SilkYaml::load(join_path(ROOT_DIR, 'config', 'setup.yml'));
     } else {
         die("Config file not found!");
     }
     //Add class path entries
     if (isset($config['class_autoload'])) {
         foreach ($config['class_autoload'] as $dir) {
             add_class_directory(join_path(ROOT_DIR, $dir));
         }
     }
     //Setup the database connection
     if (!isset($config['database']['dsn'])) {
         die("No database information found in the configuration file");
     }
     if (null == SilkDatabase::connect($config['database']['dsn'], $config['debug'], true, $config['database']['prefix'])) {
         die("Could not connect to the database");
     }
     silk()->set('config', $config);
     //Load components
     SilkComponentManager::load();
 }
Exemplo n.º 7
0
 public function renderRoute($vars)
 {
     $config = Config::getInstance();
     $queries = CMS7_Queries::getInstance();
     $config->queries = $queries;
     $config->theme_path = join_path($config->base_path, 'themes');
     $config->module_path = join_path($config->base_path, 'modules');
     $config->plugin_path = join_path($config->base_path, 'plugin');
     $config->request_vars = $vars;
     $config->site = $config->queries->site->get_site_details();
     $this->site = $config->site;
     if (isset($vars->page)) {
         if (ctype_digit($vars->page)) {
             $page_id = $vars->page;
         } else {
             $page_id = $config->queries->site->find_page_id_by_name(strtolower($vars->page));
         }
     }
     if (!isset($page_id) || !$page_id) {
         $page_id = $this->site->site_home_page_id;
     }
     $this->page_id = $page_id;
     $layout = new Layout($page_id);
     $this->layout = $layout;
     $layout->vars = $vars;
     $content = $layout->render();
     return $content;
 }
Exemplo n.º 8
0
	function find_template ($template) {
		
		// Template param may be a string or an array
		// If it's not an array, put the string in a new array
		if (!is_array($template)) {
			$template = array($template);
		}
		
		// Loop through template paths config
		foreach (Frix::config('TEMPLATE_PATHS') as $path) {
			
			foreach ($template as $template_file) {
				
				$template_path = join_path(array($path, $template_file . '.php'));
				
				if (file_exists($template_path)) {
					return $template_path;
				}
				
			}
			
		}
		
		// No template found? Throw an exception.
		// debug($template);
		throw new TemplateException(sprintf('Template(s) "%s" not found!', implode('", "', $template)));
		
	}
 /**
  * Get relative path to a directory/file
  * @param  string  $path         Path to a directory/file
  * @param  boolean $use_doc_root Use document root or relative path?
  * @return string
  */
 function get_path($path, $use_doc_root = false)
 {
     $doc_root = DOCUMENT_ROOT;
     if (!$use_doc_root) {
         $doc_root = get_relative_path();
     }
     return join_path(preg_replace('/(\\/)+$/', '', $doc_root), preg_replace('/^(\\/+)/', '', $path));
 }
Exemplo n.º 10
0
 public function getURL()
 {
     $path = $this->asset_module . '_path';
     if (!isset($this->{$path})) {
         throw new AssetNoModuleException('Asset path not found! ' . var_export($this));
     }
     return join_path(Config::get('webroot'), $this->asset_module . 's', $this->{$path}, $this->asset_format_path, $this->asset_path);
 }
Exemplo n.º 11
0
 public static function truncate()
 {
     file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), '');
     if (FreshRSS_Auth::hasAccess('admin')) {
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), '');
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), '');
         file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), '');
     }
 }
Exemplo n.º 12
0
 public function uninstall()
 {
     $filename = 'ttrss.php';
     $file_destination = join_path(PUBLIC_PATH, 'api', $filename);
     if (file_exists($file_destination) && !unlink($file_destination)) {
         return 'API file cannot be removed';
     }
     return true;
 }
Exemplo n.º 13
0
 function __construct()
 {
     parent::__construct();
     $this->mailer_object = null;
     $fn = join_path(SILK_LIB_PATH, 'phpmailer', 'class.phpmailer.php');
     require_once $fn;
     $this->mailer_object = new PHPMailer();
     $this->reset();
 }
Exemplo n.º 14
0
 function __construct()
 {
     parent::__construct();
     $this->template_dir = join_path(ROOT_DIR, 'tmp', 'templates');
     $this->compile_dir = join_path(ROOT_DIR, 'tmp', 'templates_c');
     $this->config_dir = join_path(ROOT_DIR, 'tmp', 'configs');
     $this->cache_dir = join_path(ROOT_DIR, 'tmp', 'cache');
     $this->plugins_dir = array(join_path(SILK_LIB_DIR, 'plugins'), join_path(SILK_LIB_DIR, 'smarty', 'plugins'));
     $this->cache_plugins = false;
 }
 public static function list_controllers($component)
 {
     $controllers = array();
     $component_dir = join_path(ROOT_DIR, 'components');
     foreach (scandir(join_path($component_dir, $component, "controllers")) as $one_controller) {
         $filename = join_path($component_dir, $component, "controllers", $one_controller);
         if (is_file($filename) && substr($one_controller, 0, 1) != ".") {
             $controllers[] = $one_controller;
         }
     }
     return $controllers;
 }
Exemplo n.º 16
0
 public function render($template, $vars)
 {
     $registry = Registry::getInstance();
     require_once join_path($registry->web_root, 'system/template/h2o.php');
     $path = join_path($registry->web_root, 'view/' . $template . '.html');
     if (!file_exists($path)) {
         trigger_error('Template: View ' . $path . ' not found!');
     }
     $vars = array_merge($vars, array('config' => $registry));
     $h2o = new h2o($path, array('cache' => 'apc', 'safeClass' => array('V7F\\Helpers\\Registry', 'V7F\\Template\\Template_Helpers')));
     echo $h2o->render($vars);
 }
Exemplo n.º 17
0
 static function connect($dsn, $debug = false, $die = true, $prefix = null, $make_global = true)
 {
     /*
     $gCms = silk();
     $persistent = false;
     
     if ($dbms == '')
     {
     	$config = cms_config();
     	$dbms = $config['dbms'];
     	$hostname = $config['db_hostname'];
     	$username = $config['db_username'];
     	$password = $config['db_password'];
     	$dbname = $config['db_name'];
     	$debug = $config['debug'];
     	$persistent = $config['persistent_db_conn'];
     }
     */
     if ($prefix !== null) {
         self::$prefix = $prefix;
     }
     $dbinstance = null;
     $_GLOBALS['ADODB_CACHE_DIR'] = join_path(ROOT_DIR, 'tmp', 'cache');
     require_once join_path(SILK_LIB_DIR, 'adodb', 'adodb-exceptions.inc.php');
     require_once join_path(SILK_LIB_DIR, 'adodb', 'adodb.inc.php');
     try {
         $dbinstance = ADONewConnection($dsn);
         $dbinstance->fnExecute = 'count_execs';
         $dbinstance->fnCacheExecute = 'count_cached_execs';
     } catch (exception $e) {
         if ($die) {
             echo "<strong>Database Connection Failed</strong><br />";
             echo "Error: {$dbinstance->_errorMsg}<br />";
             echo "Function Performed: {$e->fn}<br />";
             echo "Host/DB: {$e->host}/{$e->database}<br />";
             die;
         } else {
             return null;
         }
     }
     $dbinstance->SetFetchMode(ADODB_FETCH_ASSOC);
     $dbinstance->debug = $debug;
     if (isset($dbms) && $dbms == 'sqlite') {
         $dbinstance->Execute("PRAGMA short_column_names = 1;");
         sqlite_create_function($dbinstance->_connectionID, 'now', 'time', 0);
     }
     if ($make_global) {
         self::$instance = $dbinstance;
     }
     //Initialize the CMS_DB_PREFIX define
     self::get_prefix();
     return $dbinstance;
 }
Exemplo n.º 18
0
 public function TextBox($name, $value = "")
 {
     $sBasePath = join_path(Registry::get('base_dir'), 'system/editor/fckeditor/');
     $oFCKeditor = new \FCKeditor($name);
     $oFCKeditor->BasePath = $sBasePath;
     $oFCKeditor->Value = $value;
     $oFCKeditor->Width = 800;
     $oFCKeditor->Height = 700;
     ob_start();
     $oFCKeditor->Create();
     unset($oFCKeditor);
     return ob_get_clean();
 }
Exemplo n.º 19
0
 public function addChild($path)
 {
     if (isset($this->methods[$path])) {
         throw new LazyLoad_Module_Name_Conflict("Module \"{$path}\" has a name conflict with an existing method");
     }
     $qualified_path = join_path($this->qualified_path, $path);
     if (!is_dir($path)) {
         throw new LazyLoad_Module_Not_Found("Module \"{$path}\" folder not found");
     }
     $qualified_path = join_path($this->qualified_path, $path);
     $class = get_called_class();
     $this->modules[$path] = new $class();
     $this->modules[$path]->_init($path, $this->qualified_path);
     return $this->modules[$path];
 }
Exemplo n.º 20
0
 public function handleConfigureAction()
 {
     $this->registerTranslates();
     $current_user = Minz_Session::param('currentUser');
     $filename = 'style.' . $current_user . '.css';
     $filepath = join_path($this->getPath(), 'static', $filename);
     if (Minz_Request::isPost()) {
         $css_rules = Minz_Request::param('css-rules', '');
         file_put_contents($filepath, $css_rules);
     }
     $this->css_rules = '';
     if (file_exists($filepath)) {
         $this->css_rules = file_get_contents($filepath);
     }
 }
Exemplo n.º 21
0
function listdir($dir = '.')
{
    $contents = glob(join_path($dir, '*'));
    $dirs = array();
    $files = array();
    foreach ($contents as $file) {
        $tmp = alt_stat($file);
        if ($tmp['filetype']['is_dir']) {
            $dirs[] = $tmp;
        } else {
            $files[] = $tmp;
        }
    }
    return array_merge($dirs, $files);
}
Exemplo n.º 22
0
 function __construct($type = 'function')
 {
     parent::__construct();
     // Set a few options
     $options = array('cacheDir' => join_path(ROOT_DIR, 'tmp', 'cache' . DS), 'lifeTime' => 300);
     if ($type == 'function') {
         //if (!SilkConfig::get('function_caching') || SilkConfig::get('debug'))
         //if (!SilkConfig::get('function_caching'))
         //	$options['caching'] = false;
         require_once join_path(SILK_LIB_DIR, 'pear', 'cache', 'lite', 'Function.php');
         $this->cache = new Cache_Lite_Function($options);
     } else {
         require_once join_path(SILK_LIB_DIR, 'pear', 'cache', 'lite', 'Function.php');
         $this->cache = new Cache_Lite($options);
     }
 }
Exemplo n.º 23
0
 /**
  * Créé la connexion à la base de données à l'aide des variables
  * HOST, BASE, USER et PASS définies dans le fichier de configuration
  */
 public function __construct($currentUser = null)
 {
     if (self::$useSharedBd && self::$sharedBd != null && $currentUser === null) {
         $this->bd = self::$sharedBd;
         $this->prefix = self::$sharedPrefix;
         $this->current_user = self::$sharedCurrentUser;
         return;
     }
     $conf = Minz_Configuration::get('system');
     $db = $conf->db;
     if ($currentUser === null) {
         $currentUser = Minz_Session::param('currentUser', '_');
     }
     $this->current_user = $currentUser;
     self::$sharedCurrentUser = $currentUser;
     $driver_options = isset($conf->db['pdo_options']) && is_array($conf->db['pdo_options']) ? $conf->db['pdo_options'] : array();
     try {
         $type = $db['type'];
         if ($type === 'mysql') {
             $string = 'mysql:host=' . $db['host'] . ';dbname=' . $db['base'] . ';charset=utf8';
             $driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8';
             $this->prefix = $db['prefix'] . $currentUser . '_';
         } elseif ($type === 'pgsql') {
             $string = 'pgsql:host=' . $db['host'] . ';dbname=' . $db['base'];
             $this->prefix = $db['prefix'] . $currentUser . '_';
         } elseif ($type === 'sqlite') {
             $string = 'sqlite:' . join_path(DATA_PATH, 'users', $currentUser, 'db.sqlite');
             //$driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
             $this->prefix = '';
         } else {
             throw new Minz_PDOConnectionException('Invalid database type!', $db['user'], Minz_Exception::ERROR);
         }
         self::$sharedDbType = $type;
         self::$sharedPrefix = $this->prefix;
         $this->bd = new MinzPDO($string, $db['user'], $db['password'], $driver_options);
         if ($type === 'sqlite') {
             $this->bd->exec('PRAGMA foreign_keys = ON;');
         }
         self::$sharedBd = $this->bd;
     } catch (Exception $e) {
         throw new Minz_PDOConnectionException($string, $db['user'], Minz_Exception::ERROR);
     }
 }
Exemplo n.º 24
0
Arquivo: app.php Projeto: ricobl/frix
	function register ($model, $options = 'AdminOptions') {
		
		$opt = new $options($model);
		// Get app name from model
		$app_name = $opt->meta->app->name;
		
		// Save model URL
		$opt->meta->admin_url = join_path(array($app_name, uncamel($model)), '/');
		
		// Register the entry grouping by app
		// Start app array if not found
		if (!$this->registry[$app_name]) {
			$this->registry[$app_name] = array($opt->get_name() => $opt);
		}
		// Or include the new entry
		else {
			$this->registry[$app_name][$opt->get_name()] = $opt;
		}
		
	}
Exemplo n.º 25
0
 public function render($template, $vars = NULL)
 {
     if (!isset($vars)) {
         $vars = array();
     }
     if (is_object($vars)) {
         $vars = get_object_vars($vars);
     }
     if (file_exists($template)) {
         $vars = array_merge(get_object_vars($this), $vars);
         ob_start();
         extract($vars);
         include $template;
         $content = ob_get_clean();
         $assetUrl = join_path(Config::get('webroot'), 'ajax/getSecureAsset');
         $content = preg_replace('/<!\\{asset:(\\d+)\\}>/', '<img src="' . $assetUrl . '/asset/\\1"/>', $content);
         return $content;
     } else {
         trigger_error('Template did not exist: ' . $template, E_USER_ERROR);
     }
 }
Exemplo n.º 26
0
 public function size($all = false)
 {
     return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
 }
Exemplo n.º 27
0
#
# ***** END LICENSE BLOCK *****
require '../../constants.php';
require LIB_PATH . '/lib_rss.php';
//Includes class autoloader
if (file_exists(DATA_PATH . '/do-install.txt')) {
    require APP_PATH . '/install.php';
} else {
    session_cache_limiter('');
    Minz_Session::init('FreshRSS');
    Minz_Session::_param('keepAlive', 1);
    //For Persona
    if (!file_exists(DATA_PATH . '/no-cache.txt')) {
        require LIB_PATH . '/http-conditional.php';
        $currentUser = Minz_Session::param('currentUser', '');
        $dateLastModification = $currentUser === '' ? time() : max(@filemtime(join_path(USERS_PATH, $currentUser, 'log.txt')), @filemtime(join_path(DATA_PATH, 'config.php')));
        if (httpConditional($dateLastModification, 0, 0, false, PHP_COMPRESSION, true)) {
            exit;
            //No need to send anything
        }
    }
    try {
        $front_controller = new FreshRSS();
        $front_controller->init();
        $front_controller->run();
    } catch (Exception $e) {
        echo '### Fatal error! ###<br />', "\n";
        Minz_Log::error($e->getMessage());
        echo 'See logs files.';
    }
}
Exemplo n.º 28
0
if ($self !== base64url_decode($canonical64)) {
    //header('HTTP/1.1 422 Unprocessable Entity');
    logMe('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . base64url_decode($canonical64));
    //die('Self URL does not match registered canonical URL!');
    $self = base64url_decode($canonical64);
}
Minz_Request::_param('url', $self);
$nb = 0;
foreach ($users as $userFilename) {
    $username = basename($userFilename, '.txt');
    if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) {
        break;
    }
    try {
        Minz_Session::_param('currentUser', $username);
        Minz_Configuration::register('user', join_path(USERS_PATH, $username, 'config.php'), join_path(USERS_PATH, '_', 'config.default.php'));
        FreshRSS_Context::init();
        if ($feedController->actualizeAction($simplePie) > 0) {
            $nb++;
        }
    } catch (Exception $e) {
        logMe('Error: ' . $e->getMessage());
    }
}
$simplePie->__destruct();
unset($simplePie);
if ($nb === 0) {
    header('HTTP/1.1 410 Gone');
    logMe('Error: Nobody is subscribed to this feed anymore after all!: ' . $self);
    die('Nobody is subscribed to this feed anymore after all!');
} elseif (!empty($hubJson['error'])) {
Exemplo n.º 29
0
function asset_link($type, $asset)
{
    $path = $type . '_path';
    return join_path(Config::get('webroot'), $type . 's', $asset->{$path}, $asset->asset_format_path, $asset->asset_path);
}
Exemplo n.º 30
0
 public static function get_consumer()
 {
     self::include_openid();
     $store = new Auth_OpenID_FileStore(join_path(ROOT_DIR, 'tmp', 'cache'));
     $consumer = new Auth_OpenID_Consumer($store);
     return $consumer;
 }