X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=boot.php;h=56279f4ec8a0dd2af84ff3bf15cb18576ad36b15;hb=98945eb6fa4e9d9becbeebf41648ead49e32d4da;hp=2dce765cad66442ba8e6fff4e91b54a4b48f8b22;hpb=b50f1f970f6c96e45f695c69f8a40ea0bcc0dfcd;p=friendica.git diff --git a/boot.php b/boot.php index 2dce765cad..56279f4ec8 100644 --- a/boot.php +++ b/boot.php @@ -19,6 +19,8 @@ require_once('include/autoloader.php'); +use \Friendica\Core\Config; + require_once('include/config.php'); require_once('include/network.php'); require_once('include/plugin.php'); @@ -36,9 +38,9 @@ require_once('include/dbstructure.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); -define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); +define ( 'FRIENDICA_VERSION', '3.5.2-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1211 ); +define ( 'DB_UPDATE_VERSION', 1215 ); /** * @brief Constant with a HTML line break. @@ -243,6 +245,7 @@ define ( 'NETWORK_STATUSNET', 'stac'); // Statusnet connector define ( 'NETWORK_APPNET', 'apdn'); // app.net define ( 'NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol define ( 'NETWORK_ICALENDAR', 'ical'); // iCalendar +define ( 'NETWORK_PNUT', 'pnut'); // pnut.io define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder /** @}*/ @@ -272,6 +275,7 @@ $netgroup_ids = array( NETWORK_APPNET => (-17), NETWORK_NEWS => (-18), NETWORK_ICALENDAR => (-19), + NETWORK_PNUT => (-20), NETWORK_PHANTOM => (-127), ); @@ -426,6 +430,17 @@ define('PRIORITY_LOW', 40); define('PRIORITY_NEGLIGIBLE',50); /* @}*/ +/** + * @name Social Relay settings + * + * See here: https://github.com/jaywink/social-relay + * and here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts + * @{ + */ +define('SR_SCOPE_NONE', ''); +define('SR_SCOPE_ALL', 'all'); +define('SR_SCOPE_TAGS', 'tags'); +/* @}*/ // Normally this constant is defined - but not if "pcntl" isn't installed if (!defined("SIGTERM")) @@ -530,7 +545,6 @@ class App { public $videoheight = 350; public $force_max_items = 0; public $theme_thread_allow = true; - public $theme_richtext_editor = true; public $theme_events_in_profile = true; /** @@ -571,7 +585,6 @@ class App { private $scheme; private $hostname; - private $baseurl; private $db; private $curl_code; @@ -799,8 +812,6 @@ class App { * - Host name is determined either by system.hostname or inferred from request * - Path is inferred from SCRIPT_NAME * - * Caches the result (depending on $ssl value) for performance. - * * Note: $ssl parameter value doesn't directly correlate with the resulting protocol * * @param bool $ssl Whether to append http or https under SSL_POLICY_SELFSIGN @@ -813,40 +824,28 @@ class App { return self::$a->get_baseurl($ssl); } - // Arbitrary values, the resulting url protocol can be different - $cache_index = $ssl ? 'https' : 'http'; + $scheme = $this->scheme; - // Cached value found, nothing to process - if (isset($this->baseurl[$cache_index])) { - return $this->baseurl[$cache_index]; + if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { + $scheme = 'https'; } - $scheme = $this->scheme; + // Basically, we have $ssl = true on any links which can only be seen by a logged in user + // (and also the login link). Anything seen by an outsider will have it turned off. - if ((x($this->config, 'system')) && (x($this->config['system'], 'ssl_policy'))) { - if (intval($this->config['system']['ssl_policy']) === SSL_POLICY_FULL) { + if (Config::get('system', 'ssl_policy') == SSL_POLICY_SELFSIGN) { + if ($ssl) { $scheme = 'https'; - } - - // Basically, we have $ssl = true on any links which can only be seen by a logged in user - // (and also the login link). Anything seen by an outsider will have it turned off. - - if ($this->config['system']['ssl_policy'] == SSL_POLICY_SELFSIGN) { - if ($ssl) { - $scheme = 'https'; - } else { - $scheme = 'http'; - } + } else { + $scheme = 'http'; } } - if (get_config('config', 'hostname') != '') { - $this->hostname = get_config('config', 'hostname'); + if (Config::get('config', 'hostname') != '') { + $this->hostname = Config::get('config', 'hostname'); } - $this->baseurl[$cache_index] = $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); - - return $this->baseurl[$cache_index]; + return $scheme . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' ); } /** @@ -859,8 +858,6 @@ class App { function set_baseurl($url) { $parsed = @parse_url($url); - $this->baseurl = []; - if($parsed) { $this->scheme = $parsed['scheme']; @@ -1390,11 +1387,15 @@ class App { // If the last worker fork was less than 10 seconds before then don't fork another one. // This should prevent the forking of masses of workers. if (get_config("system", "worker")) { - if ((time() - get_config("system", "proc_run_started")) < 10) - return; - + $cachekey = "app:proc_run:started"; + $result = Cache::get($cachekey); + if (!is_null($result)) { + if ((time() - $result) < 10) { + return; + } + } // Set the timestamp of the last proc_run - set_config("system", "proc_run_started", time()); + Cache::set($cachekey, time(), CACHE_MINUTE); } $args[0] = ((x($this->config,'php_path')) && (strlen($this->config['php_path'])) ? $this->config['php_path'] : 'php'); @@ -1414,6 +1415,53 @@ class App { proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); } + + /** + * @brief Returns the system user that is executing the script + * + * This mostly returns something like "www-data". + * + * @return string system username + */ + static function systemuser() { + if (!function_exists('posix_getpwuid') OR !function_exists('posix_geteuid')) { + return ''; + } + + $processUser = posix_getpwuid(posix_geteuid()); + return $processUser['name']; + } + + /** + * @brief Checks if a given directory is usable for the system + * + * @return boolean the directory is usable + */ + static function directory_usable($directory) { + + if ($directory == '') { + logger("Directory is empty. This shouldn't happen.", LOGGER_DEBUG); + return false; + } + + if (!file_exists($directory)) { + logger('Path "'.$directory.'" does not exist for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (is_file($directory)) { + logger('Path "'.$directory.'" is a file for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (!is_dir($directory)) { + logger('Path "'.$directory.'" is not a directory for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + if (!is_writable($directory)) { + logger('Path "'.$directory.'" is not writable for user '.self::systemuser(), LOGGER_DEBUG); + return false; + } + return true; + } } /** @@ -1474,9 +1522,7 @@ function system_unavailable() { function clean_urls() { $a = get_app(); - // if($a->config['system']['clean_urls']) return true; - // return false; } function z_path() { @@ -1539,7 +1585,7 @@ function check_db() { * Sets the base url for use in cmdline programs which don't have * $_SERVER variables */ -function check_url(&$a) { +function check_url(App $a) { $url = get_config('system','url'); @@ -1561,7 +1607,7 @@ function check_url(&$a) { /** * @brief Automatic database updates */ -function update_db(&$a) { +function update_db(App $a) { $build = get_config('system','build'); if(! x($build)) $build = set_config('system','build',DB_UPDATE_VERSION); @@ -1570,7 +1616,7 @@ function update_db(&$a) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if($stored < $current) { - load_config('database'); + Config::load('database'); // We're reporting a different version than what is currently installed. // Run any existing update scripts to bring the database up to current. @@ -1677,7 +1723,7 @@ function run_update_function($x) { * @param App $a * */ -function check_plugins(&$a) { +function check_plugins(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if (dbm::is_result($r)) @@ -1843,11 +1889,35 @@ function goaway($s) { * @return int|bool user id or false */ function local_user() { - if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid'))) + if (x($_SESSION, 'authenticated') && x($_SESSION, 'uid')) { return intval($_SESSION['uid']); + } return false; } +/** + * @brief Returns the public contact id of logged in user or false. + * + * @return int|bool public contact id or false + */ +function public_contact() { + static $public_contact_id = false; + + if (!$public_contact_id && x($_SESSION, 'authenticated')) { + if (x($_SESSION, 'my_address')) { + // Local user + $public_contact_id = intval(get_contact($_SESSION['my_address'], 0)); + } else if (x($_SESSION, 'visitor_home')) { + // Remote user + $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0)); + } + } else if (!x($_SESSION, 'authenticated')) { + $public_contact_id = false; + } + + return $public_contact_id; +} + /** * @brief Returns contact id of authenticated site visitor or false * @@ -2040,16 +2110,18 @@ function current_theme(){ // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); $is_mobile = $a->is_mobile || $a->is_tablet; - $standard_system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : ''); + $standard_system_theme = Config::get('system', 'theme', ''); $standard_theme_name = ((isset($_SESSION) && x($_SESSION,'theme')) ? $_SESSION['theme'] : $standard_system_theme); - if($is_mobile) { - if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { + if ($is_mobile) { + if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - } - else { - $system_theme = ((isset($a->config['system']['mobile-theme'])) ? $a->config['system']['mobile-theme'] : $standard_system_theme); + } else { + $system_theme = Config::get('system', 'mobile-theme', ''); + if ($system_theme == '') { + $system_theme = $standard_system_theme; + } $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); if($theme_name === '---') { @@ -2318,8 +2390,9 @@ function get_itemcachepath() { return ""; $itemcache = get_config('system','itemcache'); - if (($itemcache != "") AND is_dir($itemcache) AND is_writable($itemcache)) - return($itemcache); + if (($itemcache != "") AND App::directory_usable($itemcache)) { + return $itemcache; + } $temppath = get_temppath(); @@ -2329,9 +2402,9 @@ function get_itemcachepath() { mkdir($itemcache); } - if (is_dir($itemcache) AND is_writable($itemcache)) { + if (App::directory_usable($itemcache)) { set_config("system", "itemcache", $itemcache); - return($itemcache); + return $itemcache; } } return ""; @@ -2339,24 +2412,33 @@ function get_itemcachepath() { function get_lockpath() { $lockpath = get_config('system','lockpath'); - if (($lockpath != "") AND is_dir($lockpath) AND is_writable($lockpath)) - return($lockpath); + if (($lockpath != "") AND App::directory_usable($lockpath)) { + // We have a lock path and it is usable + return $lockpath; + } + // We don't have a working preconfigured lock path, so we take the temp path. $temppath = get_temppath(); if ($temppath != "") { + // To avoid any interferences with other systems we create our own directory $lockpath = $temppath."/lock"; - - if (!is_dir($lockpath)) + if (!is_dir($lockpath)) { mkdir($lockpath); - elseif (!is_writable($lockpath)) - $lockpath = $temppath; + } - if (is_dir($lockpath) AND is_writable($lockpath)) { + if (App::directory_usable($lockpath)) { + // The new path is usable, we are happy set_config("system", "lockpath", $lockpath); - return($lockpath); + return $lockpath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; } } + + // Reaching this point means that the operating system is configured badly. return ""; } @@ -2367,52 +2449,73 @@ function get_lockpath() { */ function get_spoolpath() { $spoolpath = get_config('system','spoolpath'); - if (($spoolpath != "") AND is_dir($spoolpath) AND is_writable($spoolpath)) { - return($spoolpath); + if (($spoolpath != "") AND App::directory_usable($spoolpath)) { + // We have a spool path and it is usable + return $spoolpath; } + // We don't have a working preconfigured spool path, so we take the temp path. $temppath = get_temppath(); if ($temppath != "") { + // To avoid any interferences with other systems we create our own directory $spoolpath = $temppath."/spool"; - if (!is_dir($spoolpath)) { mkdir($spoolpath); - } elseif (!is_writable($spoolpath)) { - $spoolpath = $temppath; } - if (is_dir($spoolpath) AND is_writable($spoolpath)) { + if (App::directory_usable($spoolpath)) { + // The new path is usable, we are happy set_config("system", "spoolpath", $spoolpath); - return($spoolpath); + return $spoolpath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; } } + + // Reaching this point means that the operating system is configured badly. return ""; } function get_temppath() { $a = get_app(); - $temppath = get_config("system","temppath"); - if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) - return($temppath); + $temppath = get_config("system", "temppath"); + if (($temppath != "") AND App::directory_usable($temppath)) { + // We have a temp path and it is usable + return $temppath; + } + + // We don't have a working preconfigured temp path, so we take the system path. $temppath = sys_get_temp_dir(); - if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) { - $temppath .= "/".$a->get_hostname(); - if (!is_dir($temppath)) - mkdir($temppath); - - if (is_dir($temppath) AND is_writable($temppath)) { - set_config("system", "temppath", $temppath); - return($temppath); + + // Check if it is usable + if (($temppath != "") AND App::directory_usable($temppath)) { + // To avoid any interferences with other systems we create our own directory + $new_temppath .= "/".$a->get_hostname(); + if (!is_dir($new_temppath)) + mkdir($new_temppath); + + if (App::directory_usable($new_temppath)) { + // The new path is usable, we are happy + set_config("system", "temppath", $new_temppath); + return $new_temppath; + } else { + // We can't create a subdirectory, strange. + // But the directory seems to work, so we use it but don't store it. + return $temppath; } } - return(""); + // Reaching this point means that the operating system is configured badly. + return ''; } -function set_template_engine(&$a, $engine = 'internal') { +/// @deprecated +function set_template_engine(App $a, $engine = 'internal') { /// @note This function is no longer necessary, but keep it as a wrapper to the class method /// to avoid breaking themes again unnecessarily