コード例 #1
0
 /**
  * Initialize the extension manager by loading extensions in EXTENSIONS_PATH.
  *
  * A valid extension is a directory containing metadata.json and
  * extension.php files.
  * metadata.json is a JSON structure where the only required fields are
  * `name` and `entry_point`.
  * extension.php should contain at least a class named <name>Extension where
  * <name> must match with the entry point in metadata.json. This class must
  * inherit from Minz_Extension class.
  */
 public static function init()
 {
     $list_potential_extensions = array_values(array_diff(scandir(EXTENSIONS_PATH), array('..', '.')));
     $system_conf = Minz_Configuration::get('system');
     self::$ext_auto_enabled = $system_conf->extensions_enabled;
     foreach ($list_potential_extensions as $ext_dir) {
         $ext_pathname = EXTENSIONS_PATH . '/' . $ext_dir;
         if (!is_dir($ext_pathname)) {
             continue;
         }
         $metadata_filename = $ext_pathname . '/' . self::$ext_metaname;
         // Try to load metadata file.
         if (!file_exists($metadata_filename)) {
             // No metadata file? Invalid!
             continue;
         }
         $meta_raw_content = file_get_contents($metadata_filename);
         $meta_json = json_decode($meta_raw_content, true);
         if (!$meta_json || !self::isValidMetadata($meta_json)) {
             // metadata.json is not a json file? Invalid!
             // or metadata.json is invalid (no required information), invalid!
             Minz_Log::warning('`' . $metadata_filename . '` is not a valid metadata file');
             continue;
         }
         $meta_json['path'] = $ext_pathname;
         // Try to load extension itself
         $extension = self::load($meta_json);
         if (!is_null($extension)) {
             self::register($extension);
         }
     }
 }
コード例 #2
0
ファイル: Log.php プロジェクト: buggithubs/FreshRSS
 /**
  * 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);
         }
     }
 }
コード例 #3
0
ファイル: FreshRSS.php プロジェクト: buggithubs/FreshRSS
 /**
  * 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);
     }
 }
コード例 #4
0
ファイル: Error.php プロジェクト: buggithubs/FreshRSS
 /**
  * Permet de retourner les logs de façon à n'avoir que
  * ceux que l'on veut réellement
  * @param $logs les logs rangés par catégories (error, warning, notice)
  * @return la liste des logs, sans catégorie,
  *       > en fonction de l'environment
  */
 private static function processLogs($logs)
 {
     $conf = Minz_Configuration::get('system');
     $env = $conf->environment;
     $logs_ok = array();
     $error = array();
     $warning = array();
     $notice = array();
     if (isset($logs['error'])) {
         $error = $logs['error'];
     }
     if (isset($logs['warning'])) {
         $warning = $logs['warning'];
     }
     if (isset($logs['notice'])) {
         $notice = $logs['notice'];
     }
     if ($env == 'production') {
         $logs_ok = $error;
     }
     if ($env == 'development') {
         $logs_ok = array_merge($error, $warning, $notice);
     }
     return $logs_ok;
 }
コード例 #5
0
ファイル: Context.php プロジェクト: Damstre/FreshRSS
 /**
  * Initialize the context.
  *
  * Set the correct configurations and $categories variables.
  */
 public static function init()
 {
     // Init configuration.
     self::$system_conf = Minz_Configuration::get('system');
     self::$user_conf = Minz_Configuration::get('user');
     $catDAO = FreshRSS_Factory::createCategoryDAO();
     self::$categories = $catDAO->listCategories();
 }
コード例 #6
0
ファイル: Factory.php プロジェクト: buggithubs/FreshRSS
 public static function createDatabaseDAO($username = null)
 {
     $conf = Minz_Configuration::get('system');
     if ($conf->db['type'] === 'sqlite') {
         return new FreshRSS_DatabaseDAOSQLite($username);
     } else {
         return new FreshRSS_DatabaseDAO($username);
     }
 }
コード例 #7
0
ファイル: ttrss.php プロジェクト: krisfremen/Extensions
 public function __construct($params)
 {
     $this->seq = isset($params['seq']) ? $params['seq'] : 0;
     $this->user = Minz_Session::param('currentUser', '');
     $this->method = $params['op'];
     $this->params = $params;
     $this->system_conf = Minz_Configuration::get('system');
     if ($this->user != '') {
         $this->user_conf = get_user_configuration($this->user);
     }
 }
コード例 #8
0
ファイル: Factory.php プロジェクト: Damstre/FreshRSS
 public static function createDatabaseDAO($username = null)
 {
     $conf = Minz_Configuration::get('system');
     switch ($conf->db['type'] === 'sqlite') {
         case 'sqlite':
             return new FreshRSS_DatabaseDAOSQLite($username);
             break;
         case 'pgsql':
             return new FreshRSS_DatabaseDAOpgSQL($username);
             break;
         default:
             return new FreshRSS_DatabaseDAO($username);
     }
 }
コード例 #9
0
ファイル: ModelPdo.php プロジェクト: Damstre/FreshRSS
 /**
  * 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);
     }
 }
コード例 #10
0
ファイル: greader.php プロジェクト: krisfremen/FreshRSS
function checkToken($conf, $token)
{
    //http://code.google.com/p/google-reader-api/wiki/ActionToken
    $user = Minz_Session::param('currentUser', '_');
    logMe('checkToken(' . $token . ")\n");
    $system_conf = Minz_Configuration::get('system');
    if ($token === str_pad(sha1($system_conf->salt . $user . $conf->apiPasswordHash), 57, 'Z')) {
        return true;
    }
    unauthorized();
}
コード例 #11
0
ファイル: lib_rss.php プロジェクト: krisfremen/FreshRSS
/**
 * Register and return the configuration for a given user.
 *
 * Note this function has been created to generate temporary configuration
 * objects. If you need a long-time configuration, please don't use this function.
 *
 * @param $username the name of the user of which we want the configuration.
 * @return a Minz_Configuration object, null if the configuration cannot be loaded.
 */
function get_user_configuration($username)
{
    $namespace = 'user_' . $username;
    try {
        Minz_Configuration::register($namespace, join_path(USERS_PATH, $username, 'config.php'), join_path(USERS_PATH, '_', 'config.default.php'));
    } catch (Minz_ConfigurationNamespaceException $e) {
        // namespace already exists, do nothing.
    } catch (Minz_FileNotExistException $e) {
        Minz_Log::warning($e->getMessage());
        return null;
    }
    return Minz_Configuration::get($namespace);
}
コード例 #12
0
ファイル: View.php プロジェクト: buggithubs/FreshRSS
 /**
  * Constructeur
  * Détermine si on utilise un layout ou non
  */
 public function __construct()
 {
     $this->change_view(Minz_Request::controllerName(), Minz_Request::actionName());
     $conf = Minz_Configuration::get('system');
     self::$title = $conf->title;
 }
コード例 #13
0
ファイル: install.php プロジェクト: buggithubs/FreshRSS
function printStep3()
{
    $system_default_config = Minz_Configuration::get('default_system');
    ?>
	<?php 
    $s3 = checkStep3();
    if ($s3['all'] == 'ok') {
        ?>
	<p class="alert alert-success"><span class="alert-head"><?php 
        echo _t('gen.short.ok');
        ?>
</span> <?php 
        echo _t('install.bdd.conf.ok');
        ?>
</p>
	<?php 
    } elseif ($s3['conn'] == 'ko') {
        ?>
	<p class="alert alert-error"><span class="alert-head"><?php 
        echo _t('gen.short.damn');
        ?>
</span> <?php 
        echo _t('install.bdd.conf.ko'), empty($_SESSION['bd_error']) ? '' : ' : ' . $_SESSION['bd_error'];
        ?>
</p>
	<?php 
    }
    ?>

	<form action="index.php?step=3" method="post">
		<legend><?php 
    echo _t('install.bdd.conf');
    ?>
</legend>
		<div class="form-group">
			<label class="group-name" for="type"><?php 
    echo _t('install.bdd.type');
    ?>
</label>
			<div class="group-controls">
				<select name="type" id="type" onchange="mySqlShowHide()" tabindex="1" >
				<?php 
    if (extension_loaded('pdo_mysql')) {
        ?>
				<option value="mysql"
					<?php 
        echo isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql' ? 'selected="selected"' : '';
        ?>
>
					MySQL
				</option>
				<?php 
    }
    ?>
				<?php 
    if (extension_loaded('pdo_sqlite')) {
        ?>
				<option value="sqlite"
					<?php 
        echo isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite' ? 'selected="selected"' : '';
        ?>
>
					SQLite
				</option>
				<?php 
    }
    ?>
				</select>
			</div>
		</div>

		<div id="mysql">
		<div class="form-group">
			<label class="group-name" for="host"><?php 
    echo _t('install.bdd.host');
    ?>
</label>
			<div class="group-controls">
				<input type="text" id="host" name="host" pattern="[0-9A-Za-z_.-]{1,64}" value="<?php 
    echo isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host'];
    ?>
" tabindex="2" />
			</div>
		</div>

		<div class="form-group">
			<label class="group-name" for="user"><?php 
    echo _t('install.bdd.username');
    ?>
</label>
			<div class="group-controls">
				<input type="text" id="user" name="user" maxlength="16" pattern="[0-9A-Za-z_.-]{1,16}" value="<?php 
    echo isset($_SESSION['bd_user']) ? $_SESSION['bd_user'] : '';
    ?>
" tabindex="3" />
			</div>
		</div>

		<div class="form-group">
			<label class="group-name" for="pass"><?php 
    echo _t('install.bdd.password');
    ?>
</label>
			<div class="group-controls">
				<input type="password" id="pass" name="pass" value="<?php 
    echo isset($_SESSION['bd_password']) ? $_SESSION['bd_password'] : '';
    ?>
" tabindex="4" />
			</div>
		</div>

		<div class="form-group">
			<label class="group-name" for="base"><?php 
    echo _t('install.bdd');
    ?>
</label>
			<div class="group-controls">
				<input type="text" id="base" name="base" maxlength="64" pattern="[0-9A-Za-z_]{1,64}" value="<?php 
    echo isset($_SESSION['bd_base']) ? $_SESSION['bd_base'] : '';
    ?>
" tabindex="5" />
			</div>
		</div>

		<div class="form-group">
			<label class="group-name" for="prefix"><?php 
    echo _t('install.bdd.prefix');
    ?>
</label>
			<div class="group-controls">
				<input type="text" id="prefix" name="prefix" maxlength="16" pattern="[0-9A-Za-z_]{1,16}" value="<?php 
    echo isset($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : $system_default_config->db['prefix'];
    ?>
" tabindex="6" />
			</div>
		</div>
		</div>
		<script>
			function mySqlShowHide() {
				document.getElementById('mysql').style.display = document.getElementById('type').value === 'mysql' ? 'block' : 'none';
				if (document.getElementById('type').value !== 'mysql') {
					document.getElementById('host').value = '';
					document.getElementById('user').value = '';
					document.getElementById('pass').value = '';
					document.getElementById('base').value = '';
					document.getElementById('prefix').value = '';
				}
			}
			mySqlShowHide();
		</script>

		<div class="form-group form-actions">
			<div class="group-controls">
				<button type="submit" class="btn btn-important" tabindex="7" ><?php 
    echo _t('gen.action.submit');
    ?>
</button>
				<button type="reset" class="btn" tabindex="8" ><?php 
    echo _t('gen.action.cancel');
    ?>
</button>
				<?php 
    if ($s3['all'] == 'ok') {
        ?>
				<a class="btn btn-important next-step" href="?step=4" tabindex="9" ><?php 
        echo _t('install.action.next_step');
        ?>
</a>
				<?php 
    }
    ?>
			</div>
		</div>
	</form>
<?php 
}
コード例 #14
0
 private function setReporting()
 {
     $conf = Minz_Configuration::get('system');
     switch ($conf->environment) {
         case 'production':
             error_reporting(E_ALL);
             ini_set('display_errors', 'Off');
             ini_set('log_errors', 'On');
             break;
         case 'development':
             error_reporting(E_ALL);
             ini_set('display_errors', 'On');
             ini_set('log_errors', 'On');
             break;
         case 'silent':
             error_reporting(0);
             break;
     }
 }
コード例 #15
0
ファイル: Auth.php プロジェクト: buggithubs/FreshRSS
 public static function makeCookie($username, $password_hash)
 {
     do {
         $conf = Minz_Configuration::get('system');
         $token = sha1($conf->salt . $username . uniqid(mt_rand(), true));
         $token_file = DATA_PATH . '/tokens/' . $token . '.txt';
     } while (file_exists($token_file));
     if (@file_put_contents($token_file, $username . "\t" . $password_hash) === false) {
         return false;
     }
     $expire = time() + 2629744;
     //1 month	//TODO: Use a configuration instead
     Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);
     return $token;
 }
コード例 #16
0
ファイル: pshb.php プロジェクト: buggithubs/FreshRSS
        unset($hubJson['lease_end']);
    }
    $hubJson['lease_start'] = time();
    if (!isset($hubJson['error'])) {
        $hubJson['error'] = true;
        //Do not assume that PubSubHubbub works until the first successul push
    }
    file_put_contents('./!hub.json', json_encode($hubJson));
    exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : '');
}
if ($ORIGINAL_INPUT == '') {
    header('HTTP/1.1 422 Unprocessable Entity');
    die('Missing XML payload!');
}
Minz_Configuration::register('system', DATA_PATH . '/config.php', DATA_PATH . '/config.default.php');
$system_conf = Minz_Configuration::get('system');
$system_conf->auth_type = 'none';
// avoid necessity to be logged in (not saved!)
Minz_Translate::init('en');
Minz_Request::_param('ajax', true);
$feedController = new FreshRSS_feed_Controller();
$simplePie = customSimplePie();
$simplePie->set_raw_data($ORIGINAL_INPUT);
$simplePie->init();
unset($ORIGINAL_INPUT);
$links = $simplePie->get_links('self');
$self = isset($links[0]) ? $links[0] : null;
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!');
コード例 #17
0
ファイル: Request.php プロジェクト: buggithubs/FreshRSS
 /**
  * Return the base_url from configuration and add a suffix if given.
  *
  * @param $base_url_suffix a string to add at base_url (default: empty string)
  * @return the base_url with a suffix.
  */
 public static function getBaseUrl($base_url_suffix = '')
 {
     $conf = Minz_Configuration::get('system');
     $url = rtrim($conf->base_url, '/\\') . $base_url_suffix;
     return filter_var($url, FILTER_SANITIZE_URL);
 }
コード例 #18
0
ファイル: Request.php プロジェクト: krisfremen/FreshRSS
 /**
  * Détermine la base de l'url
  * @return la base de l'url
  */
 public static function getBaseUrl()
 {
     $conf = Minz_Configuration::get('system');
     $defaultBaseUrl = $conf->base_url;
     if (!empty($defaultBaseUrl)) {
         return $defaultBaseUrl;
     } elseif (isset($_SERVER['REQUEST_URI'])) {
         return dirname($_SERVER['REQUEST_URI']) . '/';
     } else {
         return '/';
     }
 }