Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 229 → Rev 230

/trunk/includes/classes/OIDplus.class.php
72,7 → 72,7
return $sesHandler;
}
 
# --- Database Plugin
# --- Database plugin
 
private static function registerDatabasePlugin(OIDplusDatabasePlugin $plugin) {
$name = $plugin->name();
111,15 → 111,18
return true;
}
 
public static function getPagePlugins($type) {
if ($type == '*') {
public static function getPagePlugins($type='*') {
if ($type === '*') {
$res = array();
foreach (self::$pagePlugins as $data) {
$res = array_merge($res, $data);
}
} else {
$types = explode(',', $type);
foreach ($types as $type) {
$res = isset(self::$pagePlugins[$type]) ? self::$pagePlugins[$type] : array();
}
}
ksort($res);
return $res;
}
245,8 → 248,6
# --- Initialization of OIDplus
 
public static function init($html=true) {
define('OIDPLUS_HTML_OUTPUT', $html);
 
// Include config file
 
if (file_exists(__DIR__ . '/../config.inc.php')) {
264,7 → 265,8
die();
}
 
// Auto-fill non-existing config values
// Auto-fill non-existing config values, so that there won't be any PHP errors
// if something would be missing in config.inc.php (which should not happen!)
 
if (!defined('OIDPLUS_CONFIG_VERSION')) define('OIDPLUS_CONFIG_VERSION', 0.0);
if (!defined('OIDPLUS_ADMIN_PASSWORD')) define('OIDPLUS_ADMIN_PASSWORD', '');
304,7 → 306,7
 
// Do redirect stuff etc.
 
define('OIDPLUS_SSL_AVAILABLE', self::isSslAvailable());
self::isSslAvailable(); // This function does automatic redirects
 
// System config settings
 
318,7 → 320,7
 
OIDplus::getPkiStatus(true);
 
// Register plugins
// Register other plugins
 
$ary = glob(__DIR__ . '/../../plugins/objectTypes/'.'*'.'/plugin.inc.php');
foreach ($ary as $a) include $a;
345,12 → 347,21
}
}
 
// Initialize page plugins
// Initialize plugins
 
foreach (OIDplus::getDatabasePlugins() as $plugin) {
$plugin->init($html);
}
foreach (OIDplus::getPagePlugins('*') as $plugin) {
$plugin->init($html);
}
foreach (OIDplus::getAuthPlugins() as $plugin) {
$plugin->init($html);
}
foreach (OIDplus::getObjectTypePlugins() as $plugin) {
$plugin->init($html);
}
}
 
# --- System URL, System ID, PKI, and other functions
 
497,7 → 508,15
return $svn_version;
}
 
private static function isSslAvailable() {
private static $sslAvailableCache = null;
public static function isSslAvailable() {
if (!is_null(self::$sslAvailableCache)) return self::$sslAvailableCache;
if (php_sapi_name() == 'cli') {
self::$sslAvailableCache = false;
return false;
}
 
$timeout = 2;
$already_ssl = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == "on");
$ssl_port = 443;
504,10 → 523,9
$cookie_path = OIDplus::getSystemUrl(true);
if (empty($cookie_path)) $cookie_path = '/';
 
if (php_sapi_name() == 'cli') return false;
 
if (OIDPLUS_ENFORCE_SSL == 0) {
// No SSL available
self::$sslAvailableCache = $already_ssl;
return $already_ssl;
}
 
514,11 → 532,13
if (OIDPLUS_ENFORCE_SSL == 1) {
// Force SSL
if ($already_ssl) {
self::$sslAvailableCache = true;
return true;
} else {
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('Location:'.$location);
die('Redirect to HTTPS');
self::$sslAvailableCache = true;
return true;
}
}
529,6 → 549,7
if ($already_ssl) {
// we are already on HTTPS
setcookie('SSL_CHECK', '1', 0, $cookie_path, '', false, true);
self::$sslAvailableCache = true;
return true;
} else {
if (isset($_COOKIE['SSL_CHECK'])) {
538,9 → 559,11
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('Location:'.$location);
die('Redirect to HTTPS');
self::$sslAvailableCache = true;
return true;
} else {
// No HTTPS available. Do nothing.
self::$sslAvailableCache = false;
return false;
}
} else {
551,10 → 574,12
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('Location:'.$location);
die('Redirect to HTTPS');
self::$sslAvailableCache = true;
return true;
} else {
// No HTTPS detected. Do nothing, and next time, don't try to detect HTTPS again.
setcookie('SSL_CHECK', '0', 0, $cookie_path, '', false, true);
self::$sslAvailableCache = false;
return false;
}
}
/trunk/includes/classes/OIDplusPagePlugin.class.php
26,7 → 26,6
public function cfgSetValue($name, $value) {}
public function gui($id, &$out, &$handled) {}
public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {}
public function init($html=true) {}
public function modifyContent($id, &$title, &$icon, &$text) {}
public function tree_search($request) {}
}
/trunk/includes/classes/OIDplusPlugin.class.php
21,6 → 21,8
 
class OIDplusPlugin {
 
public function init($html=true) {}
 
public static function getPluginInformation() {
$out = array();
$out['name'] = null;
/trunk/includes/classes/OIDplusSessionHandler.class.php
37,7 → 37,7
@ini_set('session.use_trans_sid', 0);
 
// Uses a secure connection (HTTPS) if possible
@ini_set('session.cookie_secure', OIDPLUS_SSL_AVAILABLE);
@ini_set('session.cookie_secure', OIDplus::isSslAvailable());
 
$path = OIDplus::getSystemUrl(true);
if (!empty($path)) {
/trunk/plugins/database/mysqli/plugin.inc.php
106,16 → 106,19
return !empty($this->mysqli->connect_error) ? $this->mysqli->connect_error : $this->mysqli->error;
}
 
private $html = null;
public function init($html) {
$this->html = $html;
}
 
public function connect() {
if (OIDPLUS_MYSQL_QUERYLOG) file_put_contents("query.log", '');
 
$html = OIDPLUS_HTML_OUTPUT;
 
// Try connecting to the database
list($hostname,$port) = explode(':', OIDPLUS_MYSQL_HOST.':'.ini_get("mysqli.default_port"));
$this->mysqli = @new mysqli($hostname, OIDPLUS_MYSQL_USERNAME, base64_decode(OIDPLUS_MYSQL_PASSWORD), OIDPLUS_MYSQL_DATABASE, $port);
if (!empty($this->mysqli->connect_error) || ($this->mysqli->connect_errno != 0)) {
if ($html) {
if ($this->html) {
echo "<h1>Error</h1><p>Database connection failed! (".$this->error().")</p>";
if (is_dir(__DIR__.'/../../../setup')) {
echo '<p>If you believe that the login credentials are wrong, please run <a href="setup/">setup</a> again.</p>';
130,7 → 133,7
}
 
$this->query("SET NAMES 'utf8'");
$this->afterConnect($html);
$this->afterConnect($this->html);
$this->connected = true;
}
 
/trunk/plugins/database/odbc/plugin.inc.php
110,14 → 110,16
public function error() {
return odbc_errormsg($this->odbc);
}
private $html = null;
public function init($html) {
$this->html = $html;
}
public function connect() {
$html = OIDPLUS_HTML_OUTPUT;
 
// Try connecting to the database
$this->odbc = @odbc_connect(OIDPLUS_ODBC_DSN, OIDPLUS_ODBC_USERNAME, base64_decode(OIDPLUS_ODBC_PASSWORD));
 
if (!$this->odbc) {
if ($html) {
if ($this->html) {
echo "<h1>Error</h1><p>Database connection failed! (".odbc_errormsg().")</p>";
if (is_dir(__DIR__.'/../../../setup')) {
echo '<p>If you believe that the login credentials are wrong, please run <a href="setup/">setup</a> again.</p>';
132,7 → 134,7
}
 
$this->query("SET NAMES 'utf8'"); // Does most likely NOT work with ODBC. Try adding ";CHARSET=UTF8" (or similar) to the DSN
$this->afterConnect($html);
$this->afterConnect($this->html);
$this->connected = true;
}
 
/trunk/plugins/database/pdo/plugin.inc.php
104,9 → 104,11
public function error() {
return $this->pdo->errorInfo()[2];
}
private $html = null;
public function init($html) {
$this->html = $html;
}
public function connect() {
$html = OIDPLUS_HTML_OUTPUT;
 
try {
$options = [
# PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
117,7 → 119,7
// Try connecting to the database
$this->pdo = new PDO(OIDPLUS_PDO_DSN, OIDPLUS_PDO_USERNAME, base64_decode(OIDPLUS_PDO_PASSWORD), $options);
} catch (PDOException $e) {
if ($html) {
if ($this->html) {
echo "<h1>Error</h1><p>Database connection failed! (".$e->getMessage().")</p>";
if (is_dir(__DIR__.'/../../../setup')) {
echo '<p>If you believe that the login credentials are wrong, please run <a href="setup/">setup</a> again.</p>';
132,7 → 134,7
}
 
$this->query("SET NAMES 'utf8'");
$this->afterConnect($html);
$this->afterConnect($this->html);
$this->connected = true;
}