From 0ad7c8f69eb8b0d6087ef9982af90add02770b1c Mon Sep 17 00:00:00 2001 From: root Date: Fri, 30 Oct 2020 20:01:12 +0000 Subject: HTML parsing lib change to standard PHP in scrape_feed() and scrape_vcard() (cherry picked from commit 16d450fc6980bb70f13e574d1b20406dd313110e) --- include/network.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 4457f59bc..9d4c00ee8 100644 --- a/include/network.php +++ b/include/network.php @@ -1333,14 +1333,15 @@ function fetch_xrd_links($url) { */ function scrape_feed($url) { - require_once('library/HTML5/Parser.php'); $ret = array(); $level = 0; $x = z_fetch_url($url,false,$level,array('novalidate' => true)); - if(! $x['success']) + if(! $x['success']) { + logger('ERROR fetching URL'); return $ret; + } $headers = $x['header']; $code = $x['return_code']; @@ -1374,17 +1375,16 @@ function scrape_feed($url) { } } + $dom = new DOMDocument(); try { - $dom = HTML5_Parser::parse($s); + $dom->loadHTML( $s); } catch (DOMException $e) { - logger('Parse error: ' . $e); - } - - if(! $dom) { - logger('Failed to parse.'); + logger('Feed parse error: ' . $e); + // logger('Feed parse ERROR: ' . libxml_get_last_error()->message); return $ret; } + $head = $dom->getElementsByTagName('base'); if($head) { foreach($head as $head0) { @@ -1846,15 +1846,15 @@ function probe_api_path($host) { function scrape_vcard($url) { - require_once('library/HTML5/Parser.php'); - $ret = array(); logger('url=' . $url); $x = z_fetch_url($url); - if(! $x['success']) + if(! $x['success']) { + logger('ERROR fetching URL'); return $ret; + } $s = $x['body']; @@ -1871,14 +1871,14 @@ function scrape_vcard($url) { } } + $dom = new DOMDocument(); try { - $dom = HTML5_Parser::parse($s); + $dom->loadHTML( $s); } catch (DOMException $e) { - logger('Parse error: ' . $e); - } - - if(! $dom) + logger('hCard parse error: ' . $e); + // logger('hCard fetch ERROR: ' . libxml_get_last_error()->message); return $ret; + } // Pull out hCard profile elements -- cgit v1.2.3 From d59b81f11df990c7710378f9d9b0341fc89276e9 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 31 Oct 2020 19:57:14 +0000 Subject: if restarting a previously interrupted upload just return where we ended - fix issue #1485 --- include/attach.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/attach.php b/include/attach.php index 80f71b9ea..c9649a4ce 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2807,6 +2807,12 @@ function save_chunk($channel,$start,$end,$len) { $new_path = $new_base . '/' . $_FILES['files']['name']; + if(file_exists($new_path) && intval($start) === 0) { + $result['partial'] = true; + $result['length'] = intval(filesize($new_path)); + return $result; + } + if(! file_exists($new_path)) { rename($tmp_path,$new_path); } -- cgit v1.2.3 From 953c2947782cdd34a40eafc45f90125696a2fc91 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 5 Nov 2020 08:32:21 +0000 Subject: wrong variable name --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/text.php b/include/text.php index a300ccf58..58cde7838 100644 --- a/include/text.php +++ b/include/text.php @@ -672,7 +672,7 @@ function bt_syslog($msg, $priority = LOG_INFO) { for($x = 1; $x < count($stack); $x ++) { $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; openlog("bt-log", LOG_PID | LOG_PERROR, LOG_LOCAL0); - syslog($priority, $msg); + syslog($priority, $s); closelog(); } } -- cgit v1.2.3 From 0dcbcf93c21a9e143aa580a836403c634429a90c Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Nov 2020 11:50:00 +0000 Subject: some work on include/import --- include/import.php | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/import.php b/include/import.php index 910cb8be7..82c23e116 100644 --- a/include/import.php +++ b/include/import.php @@ -210,17 +210,24 @@ function import_hublocs($channel, $hublocs, $seize, $moving = false) { if($channel && $hublocs) { foreach($hublocs as $hubloc) { - $hash = make_xchan_hash($hubloc['hubloc_guid'],$hubloc['hubloc_guid_sig']); - if($hubloc['hubloc_network'] === 'zot' && $hash !== $hubloc['hubloc_hash']) { - logger('forged hubloc: ' . print_r($hubloc,true)); - continue; - } + // verify the hash. We can only do this if we already stored the xchan corresponding to this hubloc + // as we need the public key from there - 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 ($hubloc['hubloc_network'] === 'zot6') { + $x = q("select xchan_pubkey from xchan where xchan_guid = '%s' and xchan_hash = '%s'", + dbesc($hubloc['hubloc_guid']), + dbesc($hubloc['hubloc_hash']) + ); + + if (! $x) { + logger('hubloc could not be verified. ' . print_r($hubloc,true)); + continue; + } + $hash = Libzot::make_xchan_hash($hubloc['hubloc_guid'],$x[0]['xchan_pubkey']); + if ($hash !== $hubloc['hubloc_hash']) { + logger('forged hubloc: ' . print_r($hubloc,true)); + continue; + } } if($moving && $hubloc['hubloc_hash'] === $channel['channel_hash'] && $hubloc['hubloc_url'] !== z_root()) { @@ -228,17 +235,17 @@ function import_hublocs($channel, $hublocs, $seize, $moving = false) { } $arr = [ - 'guid' => $hubloc['hubloc_guid'], - 'guid_sig' => $hubloc['hubloc_guid_sig'], - 'url' => $hubloc['hubloc_url'], - 'url_sig' => $hubloc['hubloc_url_sig'], - 'sitekey' => ((array_key_exists('hubloc_sitekey',$hubloc)) ? $hubloc['hubloc_sitekey'] : '') + 'id' => $hubloc['hubloc_guid'], + 'id_sig' => $hubloc['hubloc_guid_sig'], + 'location' => $hubloc['hubloc_url'], + 'location_sig' => $hubloc['hubloc_url_sig'] ]; - if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) + if (($hubloc['hubloc_hash'] === $channel['channel_hash']) && intval($hubloc['hubloc_primary']) && ($seize)) { $hubloc['hubloc_primary'] = 0; + } - if(($x = zot_gethub($arr,false)) === false) { + if (($x = Libzot::gethub($arr,false)) === false) { unset($hubloc['hubloc_id']); hubloc_store_lowlevel($hubloc); } @@ -1333,7 +1340,7 @@ function sync_files($channel, $files) { 'time' => $time, 'resource' => $att['hash'], 'revision' => 0, - 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])) + 'signature' => Libzot::sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey']) ); $store_path = $newfname; @@ -1419,7 +1426,7 @@ function sync_files($channel, $files) { 'time' => $time, 'resource' => $p['resource_id'], 'revision' => 0, - 'signature' => base64url_encode(rsa_sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey'])), + 'signature' => Libzot::sign($channel['channel_hash'] . '.' . $time, $channel['channel_prvkey']), 'resolution' => intval($p['imgscale']) ); -- cgit v1.2.3 From 685c569eaf094fd7f354bd3fa8026ecefadfa590 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 13 Nov 2020 13:49:39 +0000 Subject: minor queue adjustments --- include/network.php | 5 +++-- include/zot.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/network.php b/include/network.php index 9d4c00ee8..bcd66cf85 100644 --- a/include/network.php +++ b/include/network.php @@ -2,6 +2,7 @@ use Zotlabs\Lib\Zotfinger; use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Queue; /** * @file include/network.php @@ -1437,10 +1438,10 @@ function do_delivery($deliveries, $force = false) { $x = q("select count(outq_hash) as total from outq where outq_delivered = 0"); - if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',300)) && (! $force)) { + if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',3000)) && (! $force)) { logger('immediate delivery deferred.', LOGGER_DEBUG, LOG_INFO); foreach($deliveries as $d) { - update_queue_item($d); + Queue::update($d); } return; } diff --git a/include/zot.php b/include/zot.php index 8a2177de7..d61873ba2 100644 --- a/include/zot.php +++ b/include/zot.php @@ -3452,7 +3452,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $x = q("select count(outq_hash) as total from outq where outq_delivered = 0"); - if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',300))) { + if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',3000))) { logger('immediate delivery deferred.', LOGGER_DEBUG, LOG_INFO); update_queue_item($hash); continue; @@ -4286,7 +4286,7 @@ function zot_reply_message_request($data) { $x = q("select count(outq_hash) as total from outq where outq_delivered = 0"); - if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',300))) { + if(intval($x[0]['total']) > intval(get_config('system','force_queue_threshold',3000))) { logger('immediate delivery deferred.', LOGGER_DEBUG, LOG_INFO); update_queue_item($hash); continue; -- cgit v1.2.3