some cleanup

This commit is contained in:
zotlabs 2019-04-11 20:26:38 -07:00
parent 7efc231b11
commit 5cb0e7600b
7 changed files with 149 additions and 170 deletions

View file

@ -889,8 +889,8 @@ class Libsync {
$current_site = true;
}
if($current_site && intval($r[0]['hubloc_error'])) {
q("update hubloc set hubloc_error = 0 where hubloc_id = %d",
if($current_site && (intval($r[0]['hubloc_error']) || intval($r[0]['hubloc_deleted']))) {
q("update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d",
intval($r[0]['hubloc_id'])
);
if(intval($r[0]['hubloc_orphancheck'])) {

View file

@ -3183,8 +3183,8 @@ class Libzot {
// a dead hub came back to life - reset any tombstones we might have
if (intval($hub['hubloc_error'])) {
q("update hubloc set hubloc_error = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
if (intval($hub['hubloc_error']) || intval($hub['hubloc_deleted'])) {
q("update hubloc set hubloc_error = 0, hubloc_deleted = 0 where hubloc_id = %d and hubloc_site_id = '%s' ",
intval($hub['hubloc_id']),
dbesc($site_id)
);

View file

@ -3,10 +3,11 @@
namespace Zotlabs\Lib;
/**
* @brief Account configuration storage is built on top of the under-utilised xconfig.
* @brief Site configuration storage is built on top of the under-utilised xconfig.
*
* @see XConfig
*/
class SConfig {
static public function Load($server_id) {

View file

@ -1,15 +1,24 @@
<?php
namespace Zotlabs\Module;
use App;
use Zotlabs\Web\Controller;
use Zotlabs\Web\HTTPSig;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\SConfig;
class Magic extends \Zotlabs\Web\Controller {
class Magic extends Controller {
function init() {
$ret = array('success' => false, 'url' => '', 'message' => '');
$ret = [
'success' => false,
'url' => '',
'message' => ''
];
logger('mod_magic: invoked', LOGGER_DEBUG);
logger('args: ' . print_r($_REQUEST,true),LOGGER_DATA);
@ -21,45 +30,41 @@ class Magic extends \Zotlabs\Web\Controller {
$owa = ((x($_REQUEST,'owa')) ? intval($_REQUEST['owa']) : 0);
$delegate = ((x($_REQUEST,'delegate')) ? $_REQUEST['delegate'] : '');
if($bdest)
// bdest is preferred as it is hex-encoded and can survive url rewrite and argument parsing
if ($bdest) {
$dest = hex2bin($bdest);
}
$parsed = parse_url($dest);
if (! $parsed) {
if($test) {
$ret['message'] .= 'could not parse ' . $dest . EOL;
return($ret);
}
goaway($dest);
}
$basepath = $parsed['scheme'] . '://' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : '');
$owapath = SConfig::get($basepath,'system','openwebauth', $basepath . '/owa');
// This is ready-made for a plugin that provides a blacklist or "ask me" before blindly authenticating.
// By default, we'll proceed without asking.
$arr = array(
$arr = [
'channel_id' => local_channel(),
'destination' => $dest,
'proceed' => true
);
];
call_hooks('magic_auth',$arr);
$dest = $arr['destination'];
if (! $arr['proceed']) {
if($test) {
$ret['message'] .= 'cancelled by plugin.' . EOL;
return $ret;
}
goaway($dest);
}
if((get_observer_hash()) && (stripos($dest,z_root()) === 0)) {
// We are already authenticated on this site and a registered observer.
// Just redirect.
// First check if this is a delegate request on the local system and process accordingly.
// Otherwise redirect.
if ($delegate) {
@ -85,7 +90,7 @@ class Magic extends \Zotlabs\Web\Controller {
}
if (local_channel()) {
$channel = \App::get_channel();
$channel = App::get_channel();
// OpenWebAuth
@ -94,6 +99,8 @@ class Magic extends \Zotlabs\Web\Controller {
$dest = strip_zids($dest);
$dest = strip_query_param($dest,'f');
// We now post to the OWA endpoint. This improves security by providing a signed digest
$data = json_encode([ 'OpenWebAuth' => random_string() ]);
$headers = [];
@ -105,14 +112,16 @@ class Magic extends \Zotlabs\Web\Controller {
$headers['(request-target)'] = 'post ' . '/owa';
$headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512');
$x = z_post_url($basepath . '/owa',$data,$redirects,[ 'headers' => $headers ]);
$x = z_post_url($owapath,$data,$redirects,[ 'headers' => $headers ]);
logger('owa fetch returned: ' . print_r($x,true),LOGGER_DATA);
if ($x['success']) {
$j = json_decode($x['body'],true);
if ($j['success'] && $j['encrypted_token']) {
// decrypt the token using our private key
$token = '';
openssl_private_decrypt(base64url_decode($j['encrypted_token']),$token,$channel['channel_prvkey']);
$x = strpbrk($dest,'?&');
// redirect using the encrypted token which will be exchanged for an authenticated session
$args = (($x) ? '&owt=' . $token : '?f=&owt=' . $token) . (($delegate) ? '&delegate=1' : '');
goaway($dest . $args);
}

139
boot.php
View file

@ -1,6 +1,14 @@
<?php
use Zotlabs\Lib\Libzot;
use Zotlabs\Web\Session;
use Zotlabs\Web\HttpMeta;
use Zotlabs\Render\SmartyTemplate;
use Zotlabs\Render\Comanche;
use Zotlabs\Render\Theme;
use Zotlabs\Lib\DB_Upgrade;
use Zotlabs\Lib\System;
use Zotlabs\Daemon\Master;
/**
* @file boot.php
@ -594,8 +602,6 @@ function sys_boot() {
@include('.htconfig.php');
if(defined('NOMADIC')) {
define ( 'PLATFORM_NAME', 'zap' );
define ( 'PLATFORM_ARCHITECTURE', 'zap' );
@ -630,7 +636,6 @@ function sys_boot() {
define( 'DEFAULT_NOTIFY_ICON', '/images/hz-white-64.png' );
}
// App::head_set_icon(DEFAULT_PLATFORM_ICON);
/*
* Try to open the database;
@ -653,7 +658,7 @@ function sys_boot() {
load_config('system');
load_config('feature');
App::$session = new Zotlabs\Web\Session();
App::$session = new Session();
App::$session->init();
load_hooks();
/**
@ -705,16 +710,17 @@ class App {
public static $profile_uid = 0; // If applicable, the channel_id of the "page owner"
public static $poi = null; // "person of interest", generally a referenced connection
private static $oauth_key = null; // consumer_id of oauth request, if used
public static $layout = array(); // Comanche parsed template
public static $layout = []; // Comanche parsed template
public static $pdl = null; // Comanche page description
private static $perms = null; // observer permissions
private static $widgets = array(); // widgets for this page
public static $config = array(); // config cache
public static $override_intltext_templates = array();
public static $override_markup_templates = array();
private static $widgets = []; // widgets for this page
public static $config = []; // config cache
public static $override_intltext_templates = [];
public static $override_markup_templates = [];
public static $override_templateroot = null;
public static $override_helproot = null;
public static $override_helpfiles = array();
public static $override_helpfiles = [];
public static $session = null;
public static $groups;
@ -731,7 +737,7 @@ class App {
public static $contact;
public static $contacts;
public static $content;
public static $data = array();
public static $data = [];
public static $error = false;
public static $emojitab = false;
public static $cmd;
@ -745,21 +751,18 @@ class App {
public static $timezone;
public static $interactive = true;
public static $plugins;
private static $apps = array();
private static $apps = [];
public static $identities;
public static $css_sources = array();
public static $js_sources = array();
public static $linkrel = array();
public static $theme_info = array();
public static $css_sources = [];
public static $js_sources = [];
public static $linkrel = [];
public static $theme_info = [];
public static $is_sys = false;
public static $nav_sel;
public static $comanche;
public static $httpheaders = null;
public static $httpsig = null;
public static $channel_links;
public static $category;
// Allow themes to control internal parameters
@ -777,7 +780,7 @@ class App {
* Mostly unimplemented yet. Only options 'template_engine' and
* beyond are used.
*/
private static $theme = array(
private static $theme = [
'sourcename' => '',
'videowidth' => 425,
'videoheight' => 350,
@ -785,25 +788,25 @@ class App {
'thread_allow' => true,
'stylesheet' => '',
'template_engine' => 'smarty3',
);
];
/**
* @brief An array of registered template engines ('name'=>'class name')
*/
public static $template_engines = array();
public static $template_engines = [];
/**
* @brief An array of instanced template engines ('name'=>'instance')
*/
public static $template_engine_instance = array();
public static $template_engine_instance = [];
private static $ldelim = array(
private static $ldelim = [
'internal' => '',
'smarty3' => '{{'
);
private static $rdelim = array(
];
private static $rdelim = [
'internal' => '',
'smarty3' => '}}'
);
];
// These represent the URL which was used to access the page
@ -825,9 +828,11 @@ class App {
// we'll reset this after we read our config file
date_default_timezone_set('UTC');
self::$config = array('system'=>array());
self::$page = array();
self::$pager= array();
self::$config = [
'system' => []
];
self::$page = [];
self::$pager= [];
self::$query_string = '';
@ -922,21 +927,19 @@ class App {
self::$pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1);
self::$pager['itemspage'] = 60;
self::$pager['start'] = (self::$pager['page'] * self::$pager['itemspage']) - self::$pager['itemspage'];
if(self::$pager['start'] < 0)
self::$pager['start'] = 0;
self::$pager['total'] = 0;
if (self::$pager['start'] < 0) {
self::$pager['start'] = 0;
}
self::$meta = new HttpMeta();
/*
* register template engines
* register template engines (probably just smarty, but this can be extended)
*/
self::$meta= new Zotlabs\Web\HttpMeta();
// create an instance of the smarty template engine so we can register it.
$smarty = new Zotlabs\Render\SmartyTemplate();
/// @todo validate if this is still the desired behavior
self::register_template_engine(get_class($smarty));
self::register_template_engine(get_class(new SmartyTemplate));
}
@ -1105,7 +1108,7 @@ class App {
if(! self::$meta->get_field('og:title'))
self::$meta->set('og:title',self::$page['title']);
self::$meta->set('generator', Zotlabs\Lib\System::get_platform_name());
self::$meta->set('generator', System::get_platform_name());
$i = head_get_icon();
if($i) {
@ -1202,6 +1205,8 @@ class App {
}
}
// If we fell through to this step, it is considered fatal.
echo "template engine <tt>$template_engine</tt> is not registered!\n";
killme();
}
@ -1381,8 +1386,9 @@ function killme_if_ajax() {
function check_config() {
$saved = get_config('system','urlverify');
if(! $saved)
if (! $saved) {
set_config('system','urlverify', bin2hex(z_root()));
}
if(($saved) && ($saved != bin2hex(z_root()))) {
// our URL changed. Do something.
@ -1416,8 +1422,7 @@ function check_config() {
if (! $syschan_exists)
create_sys_channel();
$x = new \Zotlabs\Lib\DB_Upgrade(DB_UPDATE_VERSION);
$x = new DB_Upgrade(DB_UPDATE_VERSION);
plugins_sync();
@ -1517,7 +1522,7 @@ function fix_system_urls($oldurl, $newurl) {
}
}
Zotlabs\Daemon\Master::Summon(array('Notifier', 'refresh_all', $c[0]['channel_id']));
Master::Summon( [ 'Notifier', 'refresh_all', $c[0]['channel_id'] ]);
}
}
@ -1752,7 +1757,7 @@ function notice($s) {
if(! session_id())
return;
if(! x($_SESSION, 'sysmsg')) $_SESSION['sysmsg'] = array();
if(! x($_SESSION, 'sysmsg')) $_SESSION['sysmsg'] = [];
// ignore duplicated error messages which haven't yet been displayed
// - typically seen as multiple 'permission denied' messages
@ -1780,7 +1785,7 @@ function info($s) {
if(! session_id())
return;
if(! x($_SESSION, 'sysmsg_info'))
$_SESSION['sysmsg_info'] = array();
$_SESSION['sysmsg_info'] = [];
if(in_array($s, $_SESSION['sysmsg_info']))
return;
@ -1816,8 +1821,6 @@ function proc_run(){
$args = func_get_args();
$newargs = array();
if(! count($args))
return;
@ -1827,12 +1830,14 @@ function proc_run(){
'args' => $args,
'run_cmd' => true
];
/**
* @hooks proc_run
* Called when invoking PHP sub processes.
* * \e array \b args
* * \e boolean \b run_cmd
*/
call_hooks('proc_run', $arr);
if (! $arr['run_cmd'])
@ -1842,33 +1847,17 @@ function proc_run(){
$args[0] = ((x(App::$config,'system')) && (x(App::$config['system'],'php_path')) && (strlen(App::$config['system']['php_path'])) ? App::$config['system']['php_path'] : 'php');
// redirect proc_run statements of legacy daemon processes to the newer Daemon Master object class
// We will keep this interface until everybody has transitioned. (2016-05-20)
if(strstr($args[1],'include/')) {
// convert 'include/foo.php' to 'Foo'
$orig = substr(ucfirst(substr($args[1],8)),0,-4);
logger('proc_run_redirect: ' . $orig);
if(file_exists('Zotlabs/Daemon/' . $orig . '.php')) {
array_shift($args); // daemons are all run by php, pop it off the top of the array
$args[0] = $orig; // replace with the new daemon name
logger('Redirecting old proc_run interface: ' . print_r($args,true), LOGGER_DEBUG, LOG_DEBUG);
\Zotlabs\Daemon\Master::Summon($args); // summon the daemon
return;
}
}
$args = array_map('escapeshellarg',$args);
$cmdline = implode($args," ");
if (is_windows()) {
$cwd = getcwd();
$cmd = "cmd /c start \"title\" /D \"$cwd\" /b $cmdline";
proc_close(proc_open($cmd, array(), $foo));
proc_close(proc_open($cmd, [], $foo));
}
else {
if (get_config('system','use_proc_open'))
proc_close(proc_open($cmdline ." &", array(), $foo));
proc_close(proc_open($cmdline ." &", [], $foo));
else
exec($cmdline . ' > /dev/null &');
}
@ -1933,7 +1922,7 @@ function is_developer() {
function load_contact_links($uid) {
$ret = array();
$ret = [];
if(! $uid || x(App::$contacts,'empty'))
return;
@ -2067,7 +2056,7 @@ function get_custom_nav($navname) {
*/
function load_pdl() {
App::$comanche = new Zotlabs\Render\Comanche();
App::$comanche = new Comanche();
if (! count(App::$layout)) {
@ -2152,10 +2141,10 @@ function construct_page() {
}
$current_theme = Zotlabs\Render\Theme::current();
$current_theme = Theme::current();
// logger('current_theme: ' . print_r($current_theme,true));
// Zotlabs\Render\Theme::debug();
// Theme::debug();
if (($p = theme_include($current_theme[0] . '.js')) != '')
head_add_js('/' . $p);
@ -2173,7 +2162,7 @@ function construct_page() {
if (($p = theme_include('mod_' . App::$module . '.css')) != '')
head_add_css('mod_' . App::$module . '.css');
head_add_css(Zotlabs\Render\Theme::url($installing));
head_add_css(Theme::url($installing));
if (($p = theme_include('mod_' . App::$module . '.js')) != '')
head_add_js('mod_' . App::$module . '.js');
@ -2414,7 +2403,7 @@ function z_check_cert() {
function cert_bad_email() {
return z_mail(
[
'toEmail' => \App::$config['system']['admin_email'],
'toEmail' => App::$config['system']['admin_email'],
'messageSubject' => sprintf(t('[$Projectname] Website SSL error for %s'), App::get_hostname()),
'textVersion' => replace_macros(get_intltext_template('cert_bad_eml.tpl'),
[
@ -2438,7 +2427,7 @@ function check_cron_broken() {
$d = get_config('system','lastcron');
if((! $d) || ($d < datetime_convert('UTC','UTC','now - 4 hours'))) {
Zotlabs\Daemon\Master::Summon(array('Cron'));
Master::Summon(array('Cron'));
set_config('system','lastcron',datetime_convert());
}
@ -2463,7 +2452,7 @@ function check_cron_broken() {
return z_mail(
[
'toEmail' => \App::$config['system']['admin_email'],
'toEmail' => App::$config['system']['admin_email'],
'messageSubject' => sprintf(t('[$Projectname] Cron tasks not running on %s'), App::get_hostname()),
'textVersion' => replace_macros(get_intltext_template('cron_bad_eml.tpl'),
[

View file

@ -210,32 +210,19 @@ function mark_orphan_hubsxchans() {
if($dirmode == DIRECTORY_MODE_NORMAL)
return;
$r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0
$r = q("update hubloc set hubloc_deleted = 1 where hubloc_deleted = 0
and hubloc_network = 'zot6' and hubloc_connected < %s - interval %s",
db_utcnow(), db_quoteinterval('36 day')
);
// $realm = get_directory_realm();
// if($realm == DIRECTORY_REALM) {
// $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') order by rand()",
// dbesc($realm)
// );
// }
// else {
// $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' order by rand()",
// dbesc($realm)
// );
// }
$r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_error = 0 and hubloc_orphancheck = 0");
$r = q("select hubloc_id, hubloc_hash from hubloc where hubloc_deleted = 1 and hubloc_orphancheck = 0");
if($r) {
foreach($r as $rr) {
// see if any other hublocs are still alive for this channel
$x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_error = 0",
$x = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0",
dbesc($rr['hubloc_hash'])
);
if($x) {

View file

@ -212,13 +212,6 @@ function import_hublocs($channel, $hublocs, $seize, $moving = false) {
// continue;
// }
if(! array_key_exists('hubloc_primary',$hubloc)) {
$hubloc['hubloc_primary'] = (($hubloc['hubloc_flags'] & 0x0001) ? 1 : 0);
$hubloc['hubloc_orphancheck'] = (($hubloc['hubloc_flags'] & 0x0004) ? 1 : 0);
$hubloc['hubloc_error'] = (($hubloc['hubloc_status'] & 0x0003) ? 1 : 0);
$hubloc['hubloc_deleted'] = (($hubloc['hubloc_flags'] & 0x1000) ? 1 : 0);
}
if($moving && $hubloc['hubloc_hash'] === $channel['channel_hash'] && $hubloc['hubloc_url'] !== z_root()) {
$hubloc['hubloc_deleted'] = 1;
}