Merge pull request #4339 from zeroadam/feature/Network

Move Network to src
This commit is contained in:
Hypolite Petovan 2018-01-27 12:20:52 -05:00 committed by GitHub
commit d53e53cceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 1385 additions and 1335 deletions

View File

@ -32,7 +32,6 @@ use Friendica\Model\Contact;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\Module\Login; use Friendica\Module\Login;
require_once 'include/network.php';
require_once 'include/text.php'; require_once 'include/text.php';
require_once 'include/datetime.php'; require_once 'include/datetime.php';

View File

@ -11,6 +11,7 @@ use Friendica\Core\L10n;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Util\Network;
require_once "mod/proxy.php"; require_once "mod/proxy.php";
@ -733,7 +734,7 @@ function navbar_complete(App $a) {
if (! $localsearch) { if (! $localsearch) {
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
$x = z_fetch_url(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); $x = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search));
if ($x['success']) { if ($x['success']) {
$j = json_decode($x['body'],true); $j = json_decode($x['body'],true);
if ($j && isset($j['results'])) { if ($j && isset($j['results'])) {

View File

@ -35,6 +35,7 @@ use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Network\HTTPException\TooManyRequestsException; use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
require_once 'include/bbcode.php'; require_once 'include/bbcode.php';
@ -5073,7 +5074,7 @@ function api_get_nick($profile)
if ($StatusnetHost != $profile) { if ($StatusnetHost != $profile) {
$StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
if ($StatusnetUser != $profile) { if ($StatusnetUser != $profile) {
$UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
$user = json_decode($UserData); $user = json_decode($UserData);
if ($user) { if ($user) {
$nick = $user->screen_name; $nick = $user->screen_name;

View File

@ -1,5 +1,6 @@
<?php <?php
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System; use Friendica\Core\System;
@ -82,7 +83,7 @@ function diaspora2bb($s) {
$s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s); $s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s);
// Don't show link to full picture (until it is fixed) // Don't show link to full picture (until it is fixed)
$s = scale_external_images($s, false); $s = BBCode::scaleExternalImages($s, false);
return $s; return $s;
} }

View File

@ -13,6 +13,7 @@ use Friendica\Core\System;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Util\Map; use Friendica\Util\Map;
use Friendica\Util\Network;
require_once 'include/event.php'; require_once 'include/event.php';
require_once 'mod/proxy.php'; require_once 'mod/proxy.php';
@ -688,7 +689,7 @@ function GetProfileUsername($profile, $username, $compact = false, $getnetwork =
$StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
if ($StatusnetUser != $profile) { if ($StatusnetUser != $profile) {
/// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here /// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here
$UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
$user = json_decode($UserData); $user = json_decode($UserData);
if ($user) { if ($user) {
if ($getnetwork) { if ($getnetwork) {
@ -747,9 +748,7 @@ function bb_RemovePictureLinks($match) {
$text = "[url=".$match[2]."]".$match[2]."[/url]"; $text = "[url=".$match[2]."]".$match[2]."[/url]";
// if its not a picture then look if its a page that contains a picture link // if its not a picture then look if its a page that contains a picture link
require_once("include/network.php"); $body = Network::fetchUrl($match[1]);
$body = fetch_url($match[1]);
$doc = new DOMDocument(); $doc = new DOMDocument();
@$doc->loadHTML($body); @$doc->loadHTML($body);
@ -804,9 +803,7 @@ function bb_CleanPictureLinksSub($match) {
$text = "[img]".$match[2]."[/img]"; $text = "[img]".$match[2]."[/img]";
// if its not a picture then look if its a page that contains a picture link // if its not a picture then look if its a page that contains a picture link
require_once("include/network.php"); $body = Network::fetchUrl($match[1]);
$body = fetch_url($match[1]);
$doc = new DOMDocument(); $doc = new DOMDocument();
@$doc->loadHTML($body); @$doc->loadHTML($body);

View File

@ -15,6 +15,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Object\Thread; use Friendica\Object\Thread;
use Friendica\Object\Post; use Friendica\Object\Post;
use Friendica\Util\XML;
require_once "include/bbcode.php"; require_once "include/bbcode.php";
require_once "include/acl_selectors.php"; require_once "include/acl_selectors.php";
@ -184,8 +185,8 @@ function localize_item(&$item) {
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
$obj = parse_xml_string($xmlhead.$item['object']); $obj = XML::parseString($xmlhead.$item['object']);
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>"); $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title; $Bname = $obj->title;
$Blink = ""; $Bphoto = ""; $Blink = ""; $Bphoto = "";
@ -220,8 +221,8 @@ function localize_item(&$item) {
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = parse_xml_string($xmlhead.$item['object']); $obj = XML::parseString($xmlhead.$item['object']);
$links = parse_xml_string($xmlhead."<links>".unxmlify($obj->link)."</links>"); $links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
$Bname = $obj->title; $Bname = $obj->title;
$Blink = ""; $Blink = "";
@ -295,7 +296,7 @@ function localize_item(&$item) {
} }
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
$parsedobj = parse_xml_string($xmlhead.$item['object']); $parsedobj = XML::parseString($xmlhead.$item['object']);
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
@ -312,7 +313,7 @@ function localize_item(&$item) {
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = parse_xml_string($xmlhead.$item['object']); $obj = XML::parseString($xmlhead.$item['object']);
if (strlen($obj->id)) { if (strlen($obj->id)) {
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($obj->id), dbesc($obj->id),

View File

@ -9,6 +9,7 @@
*/ */
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb) function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb)
@ -362,7 +363,7 @@ function addHostnameSub($matches, $basepath)
$url = $matches[1]; $url = $matches[1];
$parts = array_merge($base, parse_url($url)); $parts = array_merge($base, parse_url($url));
$url2 = unParseUrl($parts); $url2 = Network::unparseURL($parts);
return str_replace($url, $url2, $link); return str_replace($url, $url2, $link);
} }

View File

@ -22,6 +22,7 @@ use Friendica\Object\Image;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Protocol\Feed; use Friendica\Protocol\Feed;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
require_once 'include/bbcode.php'; require_once 'include/bbcode.php';
@ -1480,7 +1481,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
} }
post_url($url, $params); Network::post($url, $params);
logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG); logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG);

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,11 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
require_once("mod/hostxrd.php"); require_once 'mod/hostxrd.php';
require_once("mod/nodeinfo.php"); require_once 'mod/nodeinfo.php';
require_once("mod/xrd.php"); require_once 'mod/xrd.php';
function _well_known_init(App $a) function _well_known_init(App $a)
{ {
@ -25,7 +26,7 @@ function _well_known_init(App $a)
break; break;
} }
} }
http_status_exit(404); System::httpExit(404);
killme(); killme();
} }

View File

@ -30,6 +30,8 @@ use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML;
require_once 'include/enotify.php'; require_once 'include/enotify.php';
require_once 'include/items.php'; require_once 'include/items.php';
@ -220,7 +222,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
* *
*/ */
$res = post_url($dfrn_confirm, $params, null, $redirects, 120); $res = Network::post($dfrn_confirm, $params, null, $redirects, 120);
logger(' Confirm: received data: ' . $res, LOGGER_DATA); logger(' Confirm: received data: ' . $res, LOGGER_DATA);
@ -251,7 +253,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
return; return;
} }
$xml = parse_xml_string($res); $xml = XML::parseString($res);
$status = (int) $xml->status; $status = (int) $xml->status;
$message = unxmlify($xml->message); // human readable text of what may have gone wrong. $message = unxmlify($xml->message); // human readable text of what may have gone wrong.
switch ($status) { switch ($status) {
@ -492,7 +494,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
$user = dba::selectFirst('user', [], ['nickname' => $node]); $user = dba::selectFirst('user', [], ['nickname' => $node]);
if (!DBM::is_result($user)) { if (!DBM::is_result($user)) {
$message = L10n::t('No user record found for \'%s\' ', $node); $message = L10n::t('No user record found for \'%s\' ', $node);
xml_status(3, $message); // failure System::xmlExit(3, $message); // failure
// NOTREACHED // NOTREACHED
} }
@ -502,7 +504,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (!strstr($my_prvkey, 'PRIVATE KEY')) { if (!strstr($my_prvkey, 'PRIVATE KEY')) {
$message = L10n::t('Our site encryption key is apparently messed up.'); $message = L10n::t('Our site encryption key is apparently messed up.');
xml_status(3, $message); System::xmlExit(3, $message);
} }
// verify everything // verify everything
@ -513,7 +515,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (!strlen($decrypted_source_url)) { if (!strlen($decrypted_source_url)) {
$message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.'); $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.');
xml_status(3, $message); System::xmlExit(3, $message);
// NOTREACHED // NOTREACHED
} }
@ -529,7 +531,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (!DBM::is_result($contact)) { if (!DBM::is_result($contact)) {
// this is either a bogus confirmation (?) or we deleted the original introduction. // this is either a bogus confirmation (?) or we deleted the original introduction.
$message = L10n::t('Contact record was not found for you on our site.'); $message = L10n::t('Contact record was not found for you on our site.');
xml_status(3, $message); System::xmlExit(3, $message);
return; // NOTREACHED return; // NOTREACHED
} }
} }
@ -543,7 +545,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (!$foreign_pubkey) { if (!$foreign_pubkey) {
$message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url); $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url);
xml_status(3, $message); System::xmlExit(3, $message);
} }
$decrypted_dfrn_id = ""; $decrypted_dfrn_id = "";
@ -559,7 +561,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) { if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) {
$message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.'); $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.');
xml_status(1, $message); // Birthday paradox - duplicate dfrn-id System::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id
// NOTREACHED // NOTREACHED
} }
@ -570,7 +572,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
); );
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
$message = L10n::t('Unable to set your contact credentials on our system.'); $message = L10n::t('Unable to set your contact credentials on our system.');
xml_status(3, $message); System::xmlExit(3, $message);
} }
// It's possible that the other person also requested friendship. // It's possible that the other person also requested friendship.
@ -625,7 +627,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
); );
if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure
$message = L10n::t('Unable to update your contact profile details on our system'); $message = L10n::t('Unable to update your contact profile details on our system');
xml_status(3, $message); System::xmlExit(3, $message);
} }
// Otherwise everything seems to have worked and we are almost done. Yay! // Otherwise everything seems to have worked and we are almost done. Yay!
@ -706,7 +708,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
} }
} }
} }
xml_status(0); // Success System::xmlExit(0); // Success
return; // NOTREACHED return; // NOTREACHED
////////////////////// End of this scenario /////////////////////////////////////////////// ////////////////////// End of this scenario ///////////////////////////////////////////////
} }

View File

@ -8,6 +8,7 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
@ -48,7 +49,7 @@ function dfrn_notify_post(App $a) {
); );
if (! DBM::is_result($r)) { if (! DBM::is_result($r)) {
logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge);
xml_status(3, 'Could not match challenge'); System::xmlExit(3, 'Could not match challenge');
} }
$r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'",
@ -70,7 +71,7 @@ function dfrn_notify_post(App $a) {
$sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id)); $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id));
break; break;
default: default:
xml_status(3, 'Invalid direction'); System::xmlExit(3, 'Invalid direction');
break; // NOTREACHED break; // NOTREACHED
} }
@ -96,7 +97,7 @@ function dfrn_notify_post(App $a) {
if (! DBM::is_result($r)) { if (! DBM::is_result($r)) {
logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id);
xml_status(3, 'Contact not found'); System::xmlExit(3, 'Contact not found');
//NOTREACHED //NOTREACHED
} }
@ -122,7 +123,7 @@ function dfrn_notify_post(App $a) {
// if contact's ssl policy changed, update our links // if contact's ssl policy changed, update our links
fix_contact_ssl_policy($importer,$ssl_policy); $importer = Contact::updateSslPolicy($importer, $ssl_policy);
logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']);
logger('dfrn_notify: data: ' . $data, LOGGER_DATA); logger('dfrn_notify: data: ' . $data, LOGGER_DATA);
@ -131,7 +132,7 @@ function dfrn_notify_post(App $a) {
// Relationship is dissolved permanently // Relationship is dissolved permanently
Contact::remove($importer['id']); Contact::remove($importer['id']);
logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']); logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']);
xml_status(0, 'relationship dissolved'); System::xmlExit(0, 'relationship dissolved');
} }
$rino = Config::get('system', 'rino_encrypt'); $rino = Config::get('system', 'rino_encrypt');
@ -145,7 +146,7 @@ function dfrn_notify_post(App $a) {
// but only for $remote_rino > 1, because old code did't send rino version // but only for $remote_rino > 1, because old code did't send rino version
if ($rino_remote > 1 && $rino < $rino_remote) { if ($rino_remote > 1 && $rino < $rino_remote) {
logger("rino version '$rino_remote' is lower than supported '$rino'"); logger("rino version '$rino_remote' is lower than supported '$rino'");
xml_status(0, "rino version '$rino_remote' is lower than supported '$rino'"); System::xmlExit(0, "rino version '$rino_remote' is lower than supported '$rino'");
} }
$rawkey = hex2bin(trim($key)); $rawkey = hex2bin(trim($key));
@ -175,14 +176,14 @@ function dfrn_notify_post(App $a) {
break; break;
default: default:
logger("rino: invalid sent version '$rino_remote'"); logger("rino: invalid sent version '$rino_remote'");
xml_status(0, "Invalid sent version '$rino_remote'"); System::xmlExit(0, "Invalid sent version '$rino_remote'");
} }
logger('rino: decrypted data: ' . $data, LOGGER_DATA); logger('rino: decrypted data: ' . $data, LOGGER_DATA);
} }
$ret = DFRN::import($data, $importer); $ret = DFRN::import($data, $importer);
xml_status($ret, 'Processed'); System::xmlExit($ret, 'Processed');
// NOTREACHED // NOTREACHED
} }

View File

@ -11,6 +11,8 @@ use Friendica\Database\DBM;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\Network;
use Friendica\Util\XML;
require_once 'include/items.php'; require_once 'include/items.php';
@ -47,7 +49,7 @@ function dfrn_poll_init(App $a)
if (($dfrn_id === '') && (!x($_POST, 'dfrn_id'))) { if (($dfrn_id === '') && (!x($_POST, 'dfrn_id'))) {
if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
http_status_exit(403); System::httpExit(403);
} }
$user = ''; $user = '';
@ -56,7 +58,7 @@ function dfrn_poll_init(App $a)
dbesc($a->argv[1]) dbesc($a->argv[1])
); );
if (!$r) { if (!$r) {
http_status_exit(404); System::httpExit(404);
} }
$hidewall = ($r[0]['hidewall'] && !local_user()); $hidewall = ($r[0]['hidewall'] && !local_user());
@ -98,12 +100,12 @@ function dfrn_poll_init(App $a)
); );
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check');
logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA);
if (strlen($s)) { if (strlen($s)) {
$xml = parse_xml_string($s); $xml = XML::parseString($s);
if ((int) $xml->status === 1) { if ((int) $xml->status === 1) {
$_SESSION['authenticated'] = 1; $_SESSION['authenticated'] = 1;
@ -143,7 +145,7 @@ function dfrn_poll_init(App $a)
dbesc($sec) dbesc($sec)
); );
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
xml_status(3, 'No ticket'); System::xmlExit(3, 'No ticket');
// NOTREACHED // NOTREACHED
} }
@ -156,7 +158,7 @@ function dfrn_poll_init(App $a)
intval($r[0]['cid']) intval($r[0]['cid'])
); );
if (!DBM::is_result($c)) { if (!DBM::is_result($c)) {
xml_status(3, 'No profile'); System::xmlExit(3, 'No profile');
} }
$contact = $c[0]; $contact = $c[0];
@ -183,7 +185,7 @@ function dfrn_poll_init(App $a)
if ($final_dfrn_id != $orig_id) { if ($final_dfrn_id != $orig_id) {
logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
// did not decode properly - cannot trust this site // did not decode properly - cannot trust this site
xml_status(3, 'Bad decryption'); System::xmlExit(3, 'Bad decryption');
} }
header("Content-type: text/xml"); header("Content-type: text/xml");
@ -207,10 +209,10 @@ function dfrn_poll_init(App $a)
$r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC", $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC",
dbesc($dfrn_id)); dbesc($dfrn_id));
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
xml_status(1); System::xmlExit(1);
return; // NOTREACHED return; // NOTREACHED
} }
xml_status(0); System::xmlExit(0);
return; // NOTREACHED return; // NOTREACHED
} }
} }
@ -235,7 +237,7 @@ function dfrn_poll_post(App $a)
dbesc($sec) dbesc($sec)
); );
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
xml_status(3, 'No ticket'); System::xmlExit(3, 'No ticket');
// NOTREACHED // NOTREACHED
} }
@ -248,7 +250,7 @@ function dfrn_poll_post(App $a)
intval($r[0]['cid']) intval($r[0]['cid'])
); );
if (!DBM::is_result($c)) { if (!DBM::is_result($c)) {
xml_status(3, 'No profile'); System::xmlExit(3, 'No profile');
} }
$contact = $c[0]; $contact = $c[0];
@ -275,7 +277,7 @@ function dfrn_poll_post(App $a)
if ($final_dfrn_id != $orig_id) { if ($final_dfrn_id != $orig_id) {
logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG);
// did not decode properly - cannot trust this site // did not decode properly - cannot trust this site
xml_status(3, 'Bad decryption'); System::xmlExit(3, 'Bad decryption');
} }
header("Content-type: text/xml"); header("Content-type: text/xml");
@ -481,7 +483,7 @@ function dfrn_poll_content(App $a)
if (($type === 'profile') && (strlen($sec))) { if (($type === 'profile') && (strlen($sec))) {
// URL reply // URL reply
if ($dfrn_version < 2.2) { if ($dfrn_version < 2.2) {
$s = fetch_url($r[0]['poll'] $s = Network::fetchUrl($r[0]['poll']
. '?dfrn_id=' . $encrypted_id . '?dfrn_id=' . $encrypted_id
. '&type=profile-check' . '&type=profile-check'
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
@ -489,7 +491,7 @@ function dfrn_poll_content(App $a)
. '&sec=' . $sec . '&sec=' . $sec
); );
} else { } else {
$s = post_url($r[0]['poll'], [ $s = Network::post($r[0]['poll'], [
'dfrn_id' => $encrypted_id, 'dfrn_id' => $encrypted_id,
'type' => 'profile-check', 'type' => 'profile-check',
'dfrn_version' => DFRN_PROTOCOL_VERSION, 'dfrn_version' => DFRN_PROTOCOL_VERSION,
@ -520,7 +522,7 @@ function dfrn_poll_content(App $a)
logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA);
if (strlen($s) && strstr($s, '<?xml')) { if (strlen($s) && strstr($s, '<?xml')) {
$xml = parse_xml_string($s); $xml = XML::parseString($s);
logger('dfrn_poll: profile: parsed xml: ' . print_r($xml, true), LOGGER_DATA); logger('dfrn_poll: profile: parsed xml: ' . print_r($xml, true), LOGGER_DATA);

View File

@ -23,6 +23,7 @@ use Friendica\Model\User;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Network;
require_once 'include/enotify.php'; require_once 'include/enotify.php';
@ -182,7 +183,7 @@ function dfrn_request_post(App $a)
} }
if (strlen($dfrn_request) && strlen($confirm_key)) { if (strlen($dfrn_request) && strlen($confirm_key)) {
$s = fetch_url($dfrn_request . '?confirm_key=' . $confirm_key); $s = Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key);
} }
// (ignore reply, nothing we can do it failed) // (ignore reply, nothing we can do it failed)
@ -331,20 +332,20 @@ function dfrn_request_post(App $a)
intval($contact_record['id']) intval($contact_record['id'])
); );
} else { } else {
$url = validate_url($url); $url = Network::isUrlValid($url);
if (!$url) { if (!$url) {
notice(L10n::t('Invalid profile URL.') . EOL); notice(L10n::t('Invalid profile URL.') . EOL);
goaway(System::baseUrl() . '/' . $a->cmd); goaway(System::baseUrl() . '/' . $a->cmd);
return; // NOTREACHED return; // NOTREACHED
} }
if (!allowed_url($url)) { if (!Network::isUrlAllowed($url)) {
notice(L10n::t('Disallowed profile URL.') . EOL); notice(L10n::t('Disallowed profile URL.') . EOL);
goaway(System::baseUrl() . '/' . $a->cmd); goaway(System::baseUrl() . '/' . $a->cmd);
return; // NOTREACHED return; // NOTREACHED
} }
if (blocked_url($url)) { if (Network::isUrlBlocked($url)) {
notice(L10n::t('Blocked domain') . EOL); notice(L10n::t('Blocked domain') . EOL);
goaway(System::baseUrl() . '/' . $a->cmd); goaway(System::baseUrl() . '/' . $a->cmd);
return; // NOTREACHED return; // NOTREACHED

View File

@ -14,6 +14,7 @@ use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
require_once 'mod/contacts.php'; require_once 'mod/contacts.php';
@ -45,7 +46,7 @@ function dirfind_content(App $a, $prefix = "") {
if (strpos($search,'@') === 0) { if (strpos($search,'@') === 0) {
$search = substr($search,1); $search = substr($search,1);
$header = L10n::t('People Search - %s', $search); $header = L10n::t('People Search - %s', $search);
if ((valid_email($search) && validate_email($search)) || if ((valid_email($search) && Network::isEmailDomainValid($search)) ||
(substr(normalise_link($search), 0, 7) == "http://")) { (substr(normalise_link($search), 0, 7) == "http://")) {
$user_data = Probe::uri($search); $user_data = Probe::uri($search);
$discover_user = (in_array($user_data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])); $discover_user = (in_array($user_data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA]));
@ -177,7 +178,7 @@ function dirfind_content(App $a, $prefix = "") {
$p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
if(strlen(Config::get('system','directory'))) if(strlen(Config::get('system','directory')))
$x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $x = Network::fetchUrl(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search));
$j = json_decode($x); $j = json_decode($x);
} }

View File

@ -423,7 +423,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
function displayShowFeed($item_id, $conversation) { function displayShowFeed($item_id, $conversation) {
$xml = DFRN::itemFeed($item_id, $conversation); $xml = DFRN::itemFeed($item_id, $conversation);
if ($xml == '') { if ($xml == '') {
http_status_exit(500); System::httpExit(500);
} }
header("Content-type: application/atom+xml"); header("Content-type: application/atom+xml");
echo $xml; echo $xml;

View File

@ -9,6 +9,7 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
@ -26,7 +27,7 @@ function hovercard_content()
// Get out if the system doesn't have public access allowed // Get out if the system doesn't have public access allowed
if (intval(Config::get('system', 'block_public'))) { if (intval(Config::get('system', 'block_public'))) {
http_status_exit(401); System::httpExit(401);
} }
// Return the raw content of the template. We use this to make templates usable for js functions. // Return the raw content of the template. We use this to make templates usable for js functions.
@ -90,7 +91,7 @@ function hovercard_content()
return $o; return $o;
} else { } else {
json_return_and_die($profile); System::jsonExit($profile);
} }
} }

View File

@ -8,6 +8,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
$install_wizard_pass = 1; $install_wizard_pass = 1;
@ -482,10 +483,10 @@ function check_htaccess(&$checks) {
$status = true; $status = true;
$help = ""; $help = "";
if (function_exists('curl_init')) { if (function_exists('curl_init')) {
$test = fetch_url(System::baseUrl()."/install/testrewrite"); $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite");
if ($test != "ok") { if ($test != "ok") {
$test = fetch_url(normalise_link(System::baseUrl()."/install/testrewrite")); $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite"));
} }
if ($test != "ok") { if ($test != "ok") {

View File

@ -519,7 +519,7 @@ function item_post(App $a) {
// Fold multi-line [code] sequences // Fold multi-line [code] sequences
$body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);
$body = scale_external_images($body, false); $body = BBCode::scaleExternalImages($body, false);
// Setting the object type if not defined before // Setting the object type if not defined before
if (!$objecttype) { if (!$objecttype) {

View File

@ -10,6 +10,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\Network;
require_once 'include/text.php'; require_once 'include/text.php';
require_once 'mod/proxy.php'; require_once 'mod/proxy.php';
@ -58,9 +59,9 @@ function match_content(App $a)
} }
if (strlen(Config::get('system', 'directory'))) { if (strlen(Config::get('system', 'directory'))) {
$x = post_url(get_server().'/msearch', $params); $x = Network::post(get_server().'/msearch', $params);
} else { } else {
$x = post_url(System::baseUrl() . '/msearch', $params); $x = Network::post(System::baseUrl() . '/msearch', $params);
} }
$j = json_decode($x); $j = json_decode($x);

View File

@ -9,6 +9,7 @@ use Friendica\App;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Util\Network;
function nodeinfo_wellknown(App $a) { function nodeinfo_wellknown(App $a) {
$nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0', $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
@ -21,12 +22,12 @@ function nodeinfo_wellknown(App $a) {
function nodeinfo_init(App $a) { function nodeinfo_init(App $a) {
if (!Config::get('system', 'nodeinfo')) { if (!Config::get('system', 'nodeinfo')) {
http_status_exit(404); System::httpExit(404);
killme(); killme();
} }
if (($a->argc != 2) || ($a->argv[1] != '1.0')) { if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
http_status_exit(404); System::httpExit(404);
killme(); killme();
} }
@ -246,7 +247,7 @@ function nodeinfo_cron() {
// Now trying to register // Now trying to register
$url = 'http://the-federation.info/register/'.$a->get_hostname(); $url = 'http://the-federation.info/register/'.$a->get_hostname();
logger('registering url: '.$url, LOGGER_DEBUG); logger('registering url: '.$url, LOGGER_DEBUG);
$ret = fetch_url($url); $ret = Network::fetchUrl($url);
logger('registering answer: '.$ret, LOGGER_DEBUG); logger('registering answer: '.$ret, LOGGER_DEBUG);
logger('cron_end'); logger('cron_end');

View File

@ -11,8 +11,6 @@ use Friendica\Core\NotificationsManager;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
require_once "include/network.php";
function notifications_post(App $a) { function notifications_post(App $a) {
if (! local_user()) { if (! local_user()) {
@ -139,8 +137,9 @@ function notifications_content(App $a) {
$notifs['page'] = $a->pager['page']; $notifs['page'] = $a->pager['page'];
// Json output // Json output
if(intval($json) === 1) if (intval($json) === 1) {
json_return_and_die($notifs); System::jsonExit($notifs);
}
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');

View File

@ -6,6 +6,7 @@ use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Util\Network;
function oexchange_init(App $a) { function oexchange_init(App $a) {
@ -39,7 +40,7 @@ function oexchange_content(App $a) {
$tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags']))
? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '');
$s = fetch_url(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); $s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
if (! strlen($s)) { if (! strlen($s)) {
return; return;

View File

@ -8,6 +8,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Network;
function ostatus_subscribe_content(App $a) { function ostatus_subscribe_content(App $a) {
@ -40,7 +41,7 @@ function ostatus_subscribe_content(App $a) {
$api = $contact["baseurl"]."/api/"; $api = $contact["baseurl"]."/api/";
// Fetching friends // Fetching friends
$data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]); $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
if (!$data["success"]) { if (!$data["success"]) {
return $o.L10n::t("Couldn't fetch friends for contact."); return $o.L10n::t("Couldn't fetch friends for contact.");

View File

@ -12,6 +12,7 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
require_once("include/items.php"); require_once("include/items.php");
@ -60,7 +61,7 @@ function parse_url_content(App $a) {
// the URL with the corresponding BBCode media tag // the URL with the corresponding BBCode media tag
$redirects = 0; $redirects = 0;
// Fetch the header of the URL // Fetch the header of the URL
$result = z_fetch_url($url, false, $redirects, ["novalidate" => true, "nobody" => true]); $result = Network::curl($url, false, $redirects, ["novalidate" => true, "nobody" => true]);
if($result["success"]) { if($result["success"]) {
// Convert the header fields into an array // Convert the header fields into an array
$hdrs = []; $hdrs = [];

View File

@ -6,6 +6,7 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
@ -13,7 +14,7 @@ function poco_init(App $a) {
$system_mode = false; $system_mode = false;
if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) { if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) {
http_status_exit(401); System::httpExit(401);
} }
if ($a->argc > 1) { if ($a->argc > 1) {
@ -22,7 +23,7 @@ function poco_init(App $a) {
if (! x($user)) { if (! x($user)) {
$c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1");
if (! DBM::is_result($c)) { if (! DBM::is_result($c)) {
http_status_exit(401); System::httpExit(401);
} }
$system_mode = true; $system_mode = true;
} }
@ -63,7 +64,7 @@ function poco_init(App $a) {
dbesc($user) dbesc($user)
); );
if (! DBM::is_result($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) { if (! DBM::is_result($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) {
http_status_exit(404); System::httpExit(404);
} }
$user = $users[0]; $user = $users[0];
@ -357,7 +358,7 @@ function poco_init(App $a) {
$ret['entry'][] = []; $ret['entry'][] = [];
} }
} else { } else {
http_status_exit(500); System::httpExit(500);
} }
logger("End of poco", LOGGER_DEBUG); logger("End of poco", LOGGER_DEBUG);
@ -371,6 +372,6 @@ function poco_init(App $a) {
echo json_encode($ret); echo json_encode($ret);
killme(); killme();
} else { } else {
http_status_exit(500); System::httpExit(500);
} }
} }

View File

@ -4,12 +4,13 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\Probe; use Friendica\Network\Probe;
function probe_content(App $a) function probe_content(App $a)
{ {
if (!local_user()) { if (!local_user()) {
http_status_exit(403, ["title" => L10n::t("Public access denied."), System::httpExit(403, ["title" => L10n::t("Public access denied."),
"description" => L10n::t("Only logged in users are permitted to perform a probing.")]); "description" => L10n::t("Only logged in users are permitted to perform a probing.")]);
killme(); killme();
} }

View File

@ -10,6 +10,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
define('PROXY_DEFAULT_TIME', 86400); // 1 Day define('PROXY_DEFAULT_TIME', 86400); // 1 Day
@ -161,7 +162,7 @@ function proxy_init(App $a) {
// It shouldn't happen but it does - spaces in URL // It shouldn't happen but it does - spaces in URL
$_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']);
$redirects = 0; $redirects = 0;
$img_str = fetch_url($_REQUEST['url'], true, $redirects, 10); $img_str = Network::fetchUrl($_REQUEST['url'], true, $redirects, 10);
$tempfile = tempnam(get_temppath(), 'cache'); $tempfile = tempnam(get_temppath(), 'cache');
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);

View File

@ -2,7 +2,9 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Util\Network;
function post_var($name) { function post_var($name) {
return (x($_POST, $name)) ? notags(trim($_POST[$name])) : ''; return (x($_POST, $name)) ? notags(trim($_POST[$name])) : '';
@ -12,7 +14,7 @@ function pubsubhubbub_init(App $a) {
// PuSH subscription must be considered "public" so just block it // PuSH subscription must be considered "public" so just block it
// if public access isn't enabled. // if public access isn't enabled.
if (Config::get('system', 'block_public')) { if (Config::get('system', 'block_public')) {
http_status_exit(403); System::httpExit(403);
} }
// Subscription request from subscriber // Subscription request from subscriber
@ -40,7 +42,7 @@ function pubsubhubbub_init(App $a) {
$subscribe = 0; $subscribe = 0;
} else { } else {
logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring.");
http_status_exit(404); System::httpExit(404);
} }
logger("pubsubhubbub: $hub_mode request from " . logger("pubsubhubbub: $hub_mode request from " .
@ -56,7 +58,7 @@ function pubsubhubbub_init(App $a) {
if (!$nick) { if (!$nick) {
logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.'); logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.');
http_status_exit(404); System::httpExit(404);
} }
// fetch user from database given the nickname // fetch user from database given the nickname
@ -66,7 +68,7 @@ function pubsubhubbub_init(App $a) {
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
logger('pubsubhubbub: local account not found: ' . $nick); logger('pubsubhubbub: local account not found: ' . $nick);
http_status_exit(404); System::httpExit(404);
} }
$owner = $r[0]; $owner = $r[0];
@ -75,7 +77,7 @@ function pubsubhubbub_init(App $a) {
if ($r[0]['hidewall']) { if ($r[0]['hidewall']) {
logger('pubsubhubbub: local user ' . $nick . logger('pubsubhubbub: local user ' . $nick .
'has chosen to hide wall, ignoring.'); 'has chosen to hide wall, ignoring.');
http_status_exit(403); System::httpExit(403);
} }
// get corresponding row from contact table // get corresponding row from contact table
@ -84,7 +86,7 @@ function pubsubhubbub_init(App $a) {
intval($owner['uid'])); intval($owner['uid']));
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
logger('pubsubhubbub: contact not found.'); logger('pubsubhubbub: contact not found.');
http_status_exit(404); System::httpExit(404);
} }
$contact = $r[0]; $contact = $r[0];
@ -93,7 +95,7 @@ function pubsubhubbub_init(App $a) {
if (!link_compare($hub_topic, $contact['poll'])) { if (!link_compare($hub_topic, $contact['poll'])) {
logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' .
$contact['poll']); $contact['poll']);
http_status_exit(404); System::httpExit(404);
} }
// do subscriber verification according to the PuSH protocol // do subscriber verification according to the PuSH protocol
@ -109,14 +111,14 @@ function pubsubhubbub_init(App $a) {
// we don't actually enforce the lease time because GNU // we don't actually enforce the lease time because GNU
// Social/StatusNet doesn't honour it (yet) // Social/StatusNet doesn't honour it (yet)
$body = fetch_url($hub_callback . "?" . $params); $body = Network::fetchUrl($hub_callback . "?" . $params);
$ret = $a->get_curl_code(); $ret = $a->get_curl_code();
// give up if the HTTP return code wasn't a success (2xx) // give up if the HTTP return code wasn't a success (2xx)
if ($ret < 200 || $ret > 299) { if ($ret < 200 || $ret > 299) {
logger("pubsubhubbub: subscriber verification at $hub_callback ". logger("pubsubhubbub: subscriber verification at $hub_callback ".
"returned $ret, ignoring."); "returned $ret, ignoring.");
http_status_exit(404); System::httpExit(404);
} }
// check that the correct hub_challenge code was echoed back // check that the correct hub_challenge code was echoed back
@ -124,7 +126,7 @@ function pubsubhubbub_init(App $a) {
logger("pubsubhubbub: subscriber did not echo back ". logger("pubsubhubbub: subscriber did not echo back ".
"hub.challenge, ignoring."); "hub.challenge, ignoring.");
logger("\"$hub_challenge\" != \"".trim($body)."\""); logger("\"$hub_challenge\" != \"".trim($body)."\"");
http_status_exit(404); System::httpExit(404);
} }
// fetch the old subscription if it exists // fetch the old subscription if it exists
@ -162,7 +164,7 @@ function pubsubhubbub_init(App $a) {
logger("pubsubhubbub: successfully unsubscribed [$hub_callback]."); logger("pubsubhubbub: successfully unsubscribed [$hub_callback].");
// we do nothing here, since the row was already deleted // we do nothing here, since the row was already deleted
} }
http_status_exit(202); System::httpExit(202);
} }
killme(); killme();

View File

@ -6,6 +6,7 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
@ -18,7 +19,7 @@ function receive_post(App $a)
$enabled = intval(Config::get('system', 'diaspora_enabled')); $enabled = intval(Config::get('system', 'diaspora_enabled'));
if (!$enabled) { if (!$enabled) {
logger('mod-diaspora: disabled'); logger('mod-diaspora: disabled');
http_status_exit(500); System::httpExit(500);
} }
if (($a->argc == 2) && ($a->argv[1] === 'public')) { if (($a->argc == 2) && ($a->argv[1] === 'public')) {
@ -28,13 +29,13 @@ function receive_post(App $a)
$public = false; $public = false;
if ($a->argc != 3 || $a->argv[1] !== 'users') { if ($a->argc != 3 || $a->argv[1] !== 'users') {
http_status_exit(500); System::httpExit(500);
} }
$guid = $a->argv[2]; $guid = $a->argv[2];
$importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]); $importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
if (!DBM::is_result($importer)) { if (!DBM::is_result($importer)) {
http_status_exit(500); System::httpExit(500);
} }
} }
@ -47,7 +48,7 @@ function receive_post(App $a)
if (!$xml) { if (!$xml) {
$postdata = file_get_contents("php://input"); $postdata = file_get_contents("php://input");
if ($postdata == '') { if ($postdata == '') {
http_status_exit(500); System::httpExit(500);
} }
logger('mod-diaspora: message is in the new format', LOGGER_DEBUG); logger('mod-diaspora: message is in the new format', LOGGER_DEBUG);
@ -67,7 +68,7 @@ function receive_post(App $a)
logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA); logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA);
if (!is_array($msg)) { if (!is_array($msg)) {
http_status_exit(500); System::httpExit(500);
} }
logger('mod-diaspora: dispatching', LOGGER_DEBUG); logger('mod-diaspora: dispatching', LOGGER_DEBUG);
@ -79,6 +80,6 @@ function receive_post(App $a)
$ret = Diaspora::dispatch($importer, $msg); $ret = Diaspora::dispatch($importer, $msg);
} }
http_status_exit(($ret) ? 200 : 500); System::httpExit(($ret) ? 200 : 500);
// NOTREACHED // NOTREACHED
} }

View File

@ -4,6 +4,7 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
@ -38,7 +39,7 @@ function salmon_post(App $a) {
dbesc($nick) dbesc($nick)
); );
if (! DBM::is_result($r)) { if (! DBM::is_result($r)) {
http_status_exit(500); System::httpExit(500);
} }
$importer = $r[0]; $importer = $r[0];
@ -58,7 +59,7 @@ function salmon_post(App $a) {
if(! $base) { if(! $base) {
logger('mod-salmon: unable to locate salmon data in xml '); logger('mod-salmon: unable to locate salmon data in xml ');
http_status_exit(400); System::httpExit(400);
} }
// Stash the signature away for now. We have to find their key or it won't be good for anything. // Stash the signature away for now. We have to find their key or it won't be good for anything.
@ -96,7 +97,7 @@ function salmon_post(App $a) {
if(! $author_link) { if(! $author_link) {
logger('mod-salmon: Could not retrieve author URI.'); logger('mod-salmon: Could not retrieve author URI.');
http_status_exit(400); System::httpExit(400);
} }
// Once we have the author URI, go to the web and try to find their public key // Once we have the author URI, go to the web and try to find their public key
@ -107,7 +108,7 @@ function salmon_post(App $a) {
if(! $key) { if(! $key) {
logger('mod-salmon: Could not retrieve author key.'); logger('mod-salmon: Could not retrieve author key.');
http_status_exit(400); System::httpExit(400);
} }
$key_info = explode('.',$key); $key_info = explode('.',$key);
@ -139,7 +140,7 @@ function salmon_post(App $a) {
if (! $verify) { if (! $verify) {
logger('mod-salmon: Message did not verify. Discarding.'); logger('mod-salmon: Message did not verify. Discarding.');
http_status_exit(400); System::httpExit(400);
} }
logger('mod-salmon: Message verified with mode '.$mode); logger('mod-salmon: Message verified with mode '.$mode);
@ -183,7 +184,7 @@ function salmon_post(App $a) {
//if((DBM::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { //if((DBM::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) {
if (DBM::is_result($r) && $r[0]['blocked']) { if (DBM::is_result($r) && $r[0]['blocked']) {
logger('mod-salmon: Ignoring this author.'); logger('mod-salmon: Ignoring this author.');
http_status_exit(202); System::httpExit(202);
// NOTREACHED // NOTREACHED
} }
@ -194,5 +195,5 @@ function salmon_post(App $a) {
OStatus::import($data, $importer, $contact_rec, $hub); OStatus::import($data, $importer, $contact_rec, $hub);
http_status_exit(200); System::httpExit(200);
} }

View File

@ -8,6 +8,7 @@ use Friendica\Content\Nav;
use Friendica\Core\Cache; use Friendica\Core\Cache;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
require_once "include/bbcode.php"; require_once "include/bbcode.php";
@ -99,7 +100,7 @@ function search_content(App $a) {
} }
if (Config::get('system','local_search') && !local_user() && !remote_user()) { if (Config::get('system','local_search') && !local_user() && !remote_user()) {
http_status_exit(403, System::httpExit(403,
["title" => L10n::t("Public access denied."), ["title" => L10n::t("Public access denied."),
"description" => L10n::t("Only logged in users are permitted to perform a search.")]); "description" => L10n::t("Only logged in users are permitted to perform a search.")]);
killme(); killme();
@ -124,7 +125,7 @@ function search_content(App $a) {
if (!is_null($result)) { if (!is_null($result)) {
$resultdata = json_decode($result); $resultdata = json_decode($result);
if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) { if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
http_status_exit(429, System::httpExit(429,
["title" => L10n::t("Too Many Requests"), ["title" => L10n::t("Too Many Requests"),
"description" => L10n::t("Only one search per minute is permitted for not logged in users.")]); "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]);
killme(); killme();

View File

@ -17,6 +17,7 @@ use Friendica\Model\GContact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Util\Network;
function get_theme_config_file($theme) function get_theme_config_file($theme)
{ {
@ -535,7 +536,7 @@ function settings_post(App $a)
// If openid has changed or if there's an openid but no openidserver, try and discover it. // If openid has changed or if there's an openid but no openidserver, try and discover it.
if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) { if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
if (validate_url($openid)) { if (Network::isUrlValid($openid)) {
logger('updating openidserver'); logger('updating openidserver');
require_once 'library/openid.php'; require_once 'library/openid.php';
$open_id_obj = new LightOpenID; $open_id_obj = new LightOpenID;

View File

@ -1,10 +1,10 @@
<?php <?php
/** /**
* @file mod/smilies.php * @file mod/smilies.php
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Content\Smilies; use Friendica\Content\Smilies;
use Friendica\Core\System;
/** /**
* @param object $a App * @param object $a App
@ -18,7 +18,7 @@ function smilies_content(App $a)
for ($i = 0; $i < count($tmp['texts']); $i++) { for ($i = 0; $i < count($tmp['texts']); $i++) {
$results[] = ['text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]]; $results[] = ['text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]];
} }
json_return_and_die($results); System::jsonExit($results);
} else { } else {
return Smilies::replace('', true); return Smilies::replace('', true);
} }

View File

@ -7,11 +7,12 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System;
function statistics_json_init(App $a) { function statistics_json_init(App $a) {
if (!Config::get("system", "nodeinfo")) { if (!Config::get("system", "nodeinfo")) {
http_status_exit(404); System::httpExit(404);
killme(); killme();
} }

View File

@ -4,12 +4,13 @@
*/ */
use Friendica\App; use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\Probe; use Friendica\Network\Probe;
function webfinger_content(App $a) function webfinger_content(App $a)
{ {
if (!local_user()) { if (!local_user()) {
http_status_exit( System::httpExit(
403, 403,
[ [
"title" => L10n::t("Public access denied."), "title" => L10n::t("Public access denied."),

View File

@ -69,7 +69,7 @@ text { font:12px Dialog; }
<text x="29" y="1664" style="font:13px Open Sans">getting transmitted (if $aes_allow -&gt; encrypt the the public key)</text> <text x="29" y="1664" style="font:13px Open Sans">getting transmitted (if $aes_allow -&gt; encrypt the the public key)</text>
<text x="29" y="1710" style="font:13px Open Sans"> -&gt; add duplex state and page-flags to the params</text> <text x="29" y="1710" style="font:13px Open Sans"> -&gt; add duplex state and page-flags to the params</text>
<text x="29" y="1756" style="font:13px Open Sans"> -&gt; send params to Bobs dfrn_confirm page ($res = </text> <text x="29" y="1756" style="font:13px Open Sans"> -&gt; send params to Bobs dfrn_confirm page ($res = </text>
<text x="29" y="1779" style="font:13px Open Sans">post_url($dfrn_confirm,$params);</text> <text x="29" y="1779" style="font:13px Open Sans">Network::post($dfrn_confirm,$params);</text>
<clipPath id="clip11"><path d="M1041,1319 L1619,1319 L1619,1913 L1041,1913 L1041,1319 Z" /></clipPath> <clipPath id="clip11"><path d="M1041,1319 L1619,1319 L1619,1913 L1041,1913 L1041,1319 Z" /></clipPath>
<path d="M1050,1320 C1045.5820313,1320 1042,1323.5820313 1042,1328 L1042,1903 C1042,1907.4179688 1045.5820313,1911 1050,1911 L1609,1911 C1613.4179688,1911 1617,1907.4179688 1617,1903 L1617,1328 C1617,1323.5820313 1613.4179688,1320 1609,1320 Z" style="fill:rgb(255,255,3);stroke:none" clip-path="url(#clip11)" /> <path d="M1050,1320 C1045.5820313,1320 1042,1323.5820313 1042,1328 L1042,1903 C1042,1907.4179688 1045.5820313,1911 1050,1911 L1609,1911 C1613.4179688,1911 1617,1907.4179688 1617,1903 L1617,1328 C1617,1323.5820313 1613.4179688,1320 1609,1320 Z" style="fill:rgb(255,255,3);stroke:none" clip-path="url(#clip11)" />
<text x="1055" y="1342" style="font:13px Open Sans">dfrn_confirm_post()</text> <text x="1055" y="1342" style="font:13px Open Sans">dfrn_confirm_post()</text>

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -93,9 +93,9 @@ text { font:12px Dialog; }
<text x="149" y="2112" style="font:13px Open Sans">- create a contact for Karen in the contact table with </text> <text x="149" y="2112" style="font:13px Open Sans">- create a contact for Karen in the contact table with </text>
<text x="149" y="2135" style="font:13px Open Sans">the scraped data with blocked = 1 and pending = 1 </text> <text x="149" y="2135" style="font:13px Open Sans">the scraped data with blocked = 1 and pending = 1 </text>
<text x="149" y="2158" style="font:13px Open Sans">(Karens pubkey becomes the contact site-pubkey)</text> <text x="149" y="2158" style="font:13px Open Sans">(Karens pubkey becomes the contact site-pubkey)</text>
<text x="149" y="2204" style="font:13px Open Sans">- fetch_url($dfrn_request . '?confirm_key=' . </text> <text x="149" y="2204" style="font:13px Open Sans">- Network::fetchUrl($dfrn_request . '?confirm_key=' . </text>
<text x="149" y="2227" style="font:13px Open Sans">$confirm_key);</text> <text x="149" y="2227" style="font:13px Open Sans">$confirm_key);</text>
<text x="149" y="2273" style="font:13px Open Sans">- fetch_url(http://karenhomepage.com/dfrn_request?</text> <text x="149" y="2273" style="font:13px Open Sans">- Network::fetchUrl(http://karenhomepage.com/dfrn_request?</text>
<text x="149" y="2296" style="font:13px Open Sans">confirm_key=”ABC123”)</text> <text x="149" y="2296" style="font:13px Open Sans">confirm_key=”ABC123”)</text>
<clipPath id="clip13"><path d="M1061,2027 L1238,2027 L1238,2069 L1061,2069 L1061,2027 Z" /></clipPath> <clipPath id="clip13"><path d="M1061,2027 L1238,2027 L1238,2069 L1061,2069 L1061,2027 Z" /></clipPath>
<path d="M1070,2028 C1065.5820313,2028 1062,2031.5820313 1062,2036 L1062,2059 C1062,2063.4179688 1065.5820313,2067 1070,2067 L1228,2067 C1232.4179688,2067 1236,2063.4179688 1236,2059 L1236,2036 C1236,2031.5820313 1232.4179688,2028 1228,2028 Z" style="fill:rgb(127,127,127);stroke:none" clip-path="url(#clip13)" /> <path d="M1070,2028 C1065.5820313,2028 1062,2031.5820313 1062,2036 L1062,2059 C1062,2063.4179688 1065.5820313,2067 1070,2067 L1228,2067 C1232.4179688,2067 1236,2063.4179688 1236,2059 L1236,2036 C1236,2031.5820313 1232.4179688,2028 1228,2028 Z" style="fill:rgb(127,127,127);stroke:none" clip-path="url(#clip13)" />

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -10,6 +10,7 @@ use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use dba; use dba;
use DOMDocument; use DOMDocument;
@ -77,7 +78,7 @@ class OEmbed
if (!in_array($ext, $noexts)) { if (!in_array($ext, $noexts)) {
// try oembed autodiscovery // try oembed autodiscovery
$redirects = 0; $redirects = 0;
$html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*");
if ($html_text) { if ($html_text) {
$dom = @DOMDocument::loadHTML($html_text); $dom = @DOMDocument::loadHTML($html_text);
if ($dom) { if ($dom) {
@ -85,13 +86,13 @@ class OEmbed
$entries = $xpath->query("//link[@type='application/json+oembed']"); $entries = $xpath->query("//link[@type='application/json+oembed']");
foreach ($entries as $e) { foreach ($entries as $e) {
$href = $e->getAttributeNode("href")->nodeValue; $href = $e->getAttributeNode("href")->nodeValue;
$txt = fetch_url($href . '&maxwidth=' . $a->videowidth); $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break; break;
} }
$entries = $xpath->query("//link[@type='text/json+oembed']"); $entries = $xpath->query("//link[@type='text/json+oembed']");
foreach ($entries as $e) { foreach ($entries as $e) {
$href = $e->getAttributeNode("href")->nodeValue; $href = $e->getAttributeNode("href")->nodeValue;
$txt = fetch_url($href . '&maxwidth=' . $a->videowidth); $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break; break;
} }
} }
@ -311,7 +312,7 @@ class OEmbed
$allowed = explode(',', $str_allowed); $allowed = explode(',', $str_allowed);
return allowed_domain($domain, $allowed); return Network::isDomainAllowed($domain, $allowed);
} }
public static function getHTML($url, $title = null) public static function getHTML($url, $title = null)

View File

@ -6,13 +6,15 @@ namespace Friendica\Content\Text;
use Friendica\App; use Friendica\App;
use Friendica\Content\Text\Plaintext; use Friendica\Content\Text\Plaintext;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
require_once "include/bbcode.php"; require_once "include/bbcode.php";
require_once "include/html2plain.php"; require_once "include/html2plain.php";
require_once "include/network.php";
class BBCode class BBCode
{ {
@ -476,4 +478,74 @@ class BBCode
return($post); return($post);
} }
public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false)
{
// Suppress "view full size"
if (intval(Config::get('system', 'no_view_full_size'))) {
$include_link = false;
}
// Picture addresses can contain special characters
$s = htmlspecialchars_decode($srctext);
$matches = null;
$c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
if ($c) {
foreach ($matches as $mtch) {
logger('scale_external_image: ' . $mtch[1]);
$hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3));
if (stristr($mtch[1], $hostname)) {
continue;
}
// $scale_replace, if passed, is an array of two elements. The
// first is the name of the full-size image. The second is the
// name of a remote, scaled-down version of the full size image.
// This allows Friendica to display the smaller remote image if
// one exists, while still linking to the full-size image
if ($scale_replace) {
$scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
} else {
$scaled = $mtch[1];
}
$i = self::fetchURL($scaled);
if (! $i) {
return $srctext;
}
// guess mimetype from headers or filename
$type = Image::guessType($mtch[1], true);
if ($i) {
$Image = new Image($i, $type);
if ($Image->isValid()) {
$orig_width = $Image->getWidth();
$orig_height = $Image->getHeight();
if ($orig_width > 640 || $orig_height > 640) {
$Image->scaleDown(640);
$new_width = $Image->getWidth();
$new_height = $Image->getHeight();
logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG);
$s = str_replace(
$mtch[0],
'[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]'
. "\n" . (($include_link)
? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n"
: ''),
$s
);
logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG);
}
}
}
}
}
// replace the special char encoding
$s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
return $s;
}
} }

View File

@ -13,6 +13,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\XML;
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/html2plain.php'; require_once 'include/html2plain.php';
@ -337,7 +338,7 @@ class NotificationsManager extends BaseObject
case ACTIVITY_FRIEND: case ACTIVITY_FRIEND:
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = parse_xml_string($xmlhead . $it['object']); $obj = XML::parseString($xmlhead . $it['object']);
$it['fname'] = $obj->title; $it['fname'] = $obj->title;
$notif = [ $notif = [

View File

@ -5,6 +5,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Util\XML;
/** /**
* @file include/Core/System.php * @file include/Core/System.php
@ -97,6 +98,86 @@ EOT;
killme(); killme();
} }
/**
* Generic XML return
* Outputs a basic dfrn XML status structure to STDOUT, with a <status> variable
* of $st and an optional text <message> of $message and terminates the current process.
*/
public static function xmlExit($st, $message = '')
{
$result = ['status' => $st];
if ($message != '') {
$result['message'] = $message;
}
if ($st) {
logger('xml_status returning non_zero: ' . $st . " message=" . $message);
}
header("Content-type: text/xml");
$xmldata = ["result" => $result];
echo XML::fromArray($xmldata, $xml);
killme();
}
/**
* @brief Send HTTP status header and exit.
*
* @param integer $val HTTP status result value
* @param array $description optional message
* 'title' => header title
* 'description' => optional message
*/
public static function httpExit($val, $description = [])
{
$err = '';
if ($val >= 400) {
$err = 'Error';
if (!isset($description["title"])) {
$description["title"] = $err." ".$val;
}
}
if ($val >= 200 && $val < 300) {
$err = 'OK';
}
logger('http_status_exit ' . $val);
header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err);
if (isset($description["title"])) {
$tpl = get_markup_template('http_status.tpl');
echo replace_macros(
$tpl,
[
'$title' => $description["title"],
'$description' => $description["description"]]
);
}
killme();
}
/**
* @brief Encodes content to json
*
* This function encodes an array to json format
* and adds an application/json HTTP header to the output.
* After finishing the process is getting killed.
*
* @param array $x The input content
*/
public static function jsonExit($x)
{
header("content-type: application/json");
echo json_encode($x);
killme();
}
/// @todo Move the following functions from boot.php /// @todo Move the following functions from boot.php
/* /*
function get_guid($size = 16, $prefix = "") function get_guid($size = 16, $prefix = "")

View File

@ -10,7 +10,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Process; use Friendica\Model\Process;
use Friendica\Util\Lock; use Friendica\Util\Lock;
use Friendica\Util\Network;
use dba; use dba;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -888,7 +888,7 @@ class Worker
} }
$url = System::baseUrl()."/worker"; $url = System::baseUrl()."/worker";
fetch_url($url, false, $redirects, 1); Network::fetchUrl($url, false, $redirects, 1);
} }
/** /**

View File

@ -20,6 +20,7 @@ use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Protocol\Salmon; use Friendica\Protocol\Salmon;
use Friendica\Util\Network;
use dba; use dba;
require_once 'boot.php'; require_once 'boot.php';
@ -1131,12 +1132,12 @@ class Contact extends BaseObject
// remove ajax junk, e.g. Twitter // remove ajax junk, e.g. Twitter
$url = str_replace('/#!/', '/', $url); $url = str_replace('/#!/', '/', $url);
if (!allowed_url($url)) { if (!Network::isUrlAllowed($url)) {
$result['message'] = L10n::t('Disallowed profile URL.'); $result['message'] = L10n::t('Disallowed profile URL.');
return $result; return $result;
} }
if (blocked_url($url)) { if (Network::isUrlBlocked($url)) {
$result['message'] = L10n::t('Blocked domain'); $result['message'] = L10n::t('Blocked domain');
return $result; return $result;
} }
@ -1320,4 +1321,37 @@ class Contact extends BaseObject
$result['success'] = true; $result['success'] = true;
return $result; return $result;
} }
public static function updateSslPolicy($contact, $new_policy)
{
$ssl_changed = false;
if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) {
$ssl_changed = true;
$contact['url'] = str_replace('https:', 'http:', $contact['url']);
$contact['request'] = str_replace('https:', 'http:', $contact['request']);
$contact['notify'] = str_replace('https:', 'http:', $contact['notify']);
$contact['poll'] = str_replace('https:', 'http:', $contact['poll']);
$contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']);
$contact['poco'] = str_replace('https:', 'http:', $contact['poco']);
}
if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) {
$ssl_changed = true;
$contact['url'] = str_replace('http:', 'https:', $contact['url']);
$contact['request'] = str_replace('http:', 'https:', $contact['request']);
$contact['notify'] = str_replace('http:', 'https:', $contact['notify']);
$contact['poll'] = str_replace('http:', 'https:', $contact['poll']);
$contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']);
$contact['poco'] = str_replace('http:', 'https:', $contact['poco']);
}
if ($ssl_changed) {
$fields = ['url' => $contact['url'], 'request' => $contact['request'],
'notify' => $contact['notify'], 'poll' => $contact['poll'],
'confirm' => $contact['confirm'], 'poco' => $contact['poco']];
dba::update('contact', $fields, ['id' => $contact['id']]);
}
return $contact;
}
} }

View File

@ -13,12 +13,12 @@ use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
use dba; use dba;
use Exception; use Exception;
require_once 'include/datetime.php'; require_once 'include/datetime.php';
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/network.php';
require_once 'include/html2bbcode.php'; require_once 'include/html2bbcode.php';
/** /**
@ -568,7 +568,7 @@ class GContact
$done[] = System::baseUrl() . '/poco'; $done[] = System::baseUrl() . '/poco';
if (strlen(Config::get('system', 'directory'))) { if (strlen(Config::get('system', 'directory'))) {
$x = fetch_url(get_server()."/pubsites"); $x = Network::fetchUrl(get_server()."/pubsites");
if ($x) { if ($x) {
$j = json_decode($x); $j = json_decode($x);
if ($j->entries) { if ($j->entries) {
@ -980,7 +980,7 @@ class GContact
$url = $server."/main/statistics"; $url = $server."/main/statistics";
$result = z_fetch_url($url); $result = Network::curl($url);
if (!$result["success"]) { if (!$result["success"]) {
return false; return false;
} }

View File

@ -12,6 +12,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
use dba; use dba;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -101,7 +102,7 @@ class Photo
$photo_failure = false; $photo_failure = false;
$filename = basename($image_url); $filename = basename($image_url);
$img_str = fetch_url($image_url, true); $img_str = Network::fetchUrl($image_url, true);
if ($quit_on_error && ($img_str == "")) { if ($quit_on_error && ($img_str == "")) {
return false; return false;

View File

@ -17,6 +17,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Util\Network;
use dba; use dba;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -963,7 +964,7 @@ class Profile
public static function zrlInit(App $a) public static function zrlInit(App $a)
{ {
$my_url = self::getMyURL(); $my_url = self::getMyURL();
$my_url = validate_url($my_url); $my_url = Network::isUrlValid($my_url);
if ($my_url) { if ($my_url) {
// Is it a DDoS attempt? // Is it a DDoS attempt?
// The check fetches the cached value from gprobe to reduce the load for this system // The check fetches the cached value from gprobe to reduce the load for this system

View File

@ -17,13 +17,13 @@ use Friendica\Model\Group;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use dba; use dba;
use Exception; use Exception;
require_once 'boot.php'; require_once 'boot.php';
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/enotify.php'; require_once 'include/enotify.php';
require_once 'include/network.php';
require_once 'library/openid.php'; require_once 'library/openid.php';
require_once 'include/text.php'; require_once 'include/text.php';
/** /**
@ -281,7 +281,7 @@ class User
if (!x($username) || !x($email) || !x($nickname)) { if (!x($username) || !x($email) || !x($nickname)) {
if ($openid_url) { if ($openid_url) {
if (!validate_url($openid_url)) { if (!Network::isUrlValid($openid_url)) {
throw new Exception(L10n::t('Invalid OpenID url')); throw new Exception(L10n::t('Invalid OpenID url'));
} }
$_SESSION['register'] = 1; $_SESSION['register'] = 1;
@ -304,7 +304,7 @@ class User
throw new Exception(L10n::t('Please enter the required information.')); throw new Exception(L10n::t('Please enter the required information.'));
} }
if (!validate_url($openid_url)) { if (!Network::isUrlValid($openid_url)) {
$openid_url = ''; $openid_url = '';
} }
@ -329,11 +329,11 @@ class User
} }
} }
if (!allowed_email($email)) { if (!Network::isEmailDomainAllowed($email)) {
throw new Exception(L10n::t('Your email domain is not among those allowed on this site.')); throw new Exception(L10n::t('Your email domain is not among those allowed on this site.'));
} }
if (!valid_email($email) || !validate_email($email)) { if (!valid_email($email) || !Network::isEmailDomainValid($email)) {
throw new Exception(L10n::t('Not a valid email address.')); throw new Exception(L10n::t('Not a valid email address.'));
} }
@ -460,7 +460,7 @@ class User
// if we have no OpenID photo try to look up an avatar // if we have no OpenID photo try to look up an avatar
if (!strlen($photo)) { if (!strlen($photo)) {
$photo = avatar_img($email); $photo = Network::lookupAvatarByEmail($email);
} }
// unless there is no avatar-addon loaded // unless there is no avatar-addon loaded
@ -468,7 +468,7 @@ class User
$photo_failure = false; $photo_failure = false;
$filename = basename($photo); $filename = basename($photo);
$img_str = fetch_url($photo, true); $img_str = Network::fetchUrl($photo, true);
// guess mimetype from headers or filename // guess mimetype from headers or filename
$type = Image::guessType($photo, true); $type = Image::guessType($photo, true);

View File

@ -3,6 +3,7 @@
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\System;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
/** /**
@ -31,7 +32,7 @@ class Feed extends BaseModule
$nocache = x($_GET, 'nocache') && local_user(); $nocache = x($_GET, 'nocache') && local_user();
if ($a->argc < 2) { if ($a->argc < 2) {
http_status_exit(400); System::httpExit(400);
} }
$type = null; $type = null;

View File

@ -10,6 +10,7 @@ use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Network;
use dba; use dba;
require_once 'boot.php'; require_once 'boot.php';
@ -59,7 +60,7 @@ class Login extends BaseModule
$openid_url = trim($_POST['openid_url'] ? : $_POST['username']); $openid_url = trim($_POST['openid_url'] ? : $_POST['username']);
// if it's an email address or doesn't resolve to a URL, fail. // if it's an email address or doesn't resolve to a URL, fail.
if ($noid || strpos($openid_url, '@') || !validate_url($openid_url)) { if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) {
notice(L10n::t('Login failed.') . EOL); notice(L10n::t('Login failed.') . EOL);
goaway(self::getApp()->get_baseurl()); goaway(self::getApp()->get_baseurl());
// NOTREACHED // NOTREACHED

View File

@ -18,6 +18,7 @@ use Friendica\Model\Profile;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Protocol\Feed; use Friendica\Protocol\Feed;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use dba; use dba;
@ -25,7 +26,6 @@ use DOMXPath;
use DOMDocument; use DOMDocument;
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/network.php';
/** /**
* @brief This class contain functions for probing URL * @brief This class contain functions for probing URL
@ -107,21 +107,21 @@ class Probe
logger("Probing for ".$host, LOGGER_DEBUG); logger("Probing for ".$host, LOGGER_DEBUG);
$ret = z_fetch_url($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); $ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
if ($ret['success']) { if ($ret['success']) {
$xml = $ret['body']; $xml = $ret['body'];
$xrd = parse_xml_string($xml, false); $xrd = XML::parseString($xml, false);
$host_url = 'https://'.$host; $host_url = 'https://'.$host;
} }
if (!is_object($xrd)) { if (!is_object($xrd)) {
$ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
logger("Probing timeout for ".$url, LOGGER_DEBUG); logger("Probing timeout for ".$url, LOGGER_DEBUG);
return false; return false;
} }
$xml = $ret['body']; $xml = $ret['body'];
$xrd = parse_xml_string($xml, false); $xrd = XML::parseString($xml, false);
$host_url = 'http://'.$host; $host_url = 'http://'.$host;
} }
if (!is_object($xrd)) { if (!is_object($xrd)) {
@ -209,7 +209,7 @@ class Probe
/** /**
* @brief Check an URI for LRDD data * @brief Check an URI for LRDD data
* *
* this is a replacement for the "lrdd" function in include/network.php. * this is a replacement for the "lrdd" function.
* It isn't used in this class and has some redundancies in the code. * It isn't used in this class and has some redundancies in the code.
* When time comes we can check the existing calls for "lrdd" if we can rework them. * When time comes we can check the existing calls for "lrdd" if we can rework them.
* *
@ -331,7 +331,7 @@ class Probe
} }
if (x($data, "photo")) { if (x($data, "photo")) {
$data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"])); $data["baseurl"] = Network::getUrlMatch(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
} else { } else {
$data["photo"] = System::baseUrl().'/images/person-175.jpg'; $data["photo"] = System::baseUrl().'/images/person-175.jpg';
} }
@ -692,7 +692,7 @@ class Probe
$xrd_timeout = Config::get('system', 'xrd_timeout', 20); $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
$redirects = 0; $redirects = 0;
$ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -708,7 +708,7 @@ class Probe
} }
// If it is not JSON, maybe it is XML // If it is not JSON, maybe it is XML
$xrd = parse_xml_string($data, false); $xrd = XML::parseString($data, false);
if (!is_object($xrd)) { if (!is_object($xrd)) {
logger("No webfinger data retrievable for ".$url, LOGGER_DEBUG); logger("No webfinger data retrievable for ".$url, LOGGER_DEBUG);
return false; return false;
@ -759,7 +759,7 @@ class Probe
*/ */
private static function pollNoscrape($noscrape_url, $data) private static function pollNoscrape($noscrape_url, $data)
{ {
$ret = z_fetch_url($noscrape_url); $ret = Network::curl($noscrape_url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -993,7 +993,7 @@ class Probe
*/ */
private static function pollHcard($hcard_url, $data, $dfrn = false) private static function pollHcard($hcard_url, $data, $dfrn = false)
{ {
$ret = z_fetch_url($hcard_url); $ret = Network::curl($hcard_url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -1232,7 +1232,7 @@ class Probe
$pubkey = substr($pubkey, 5); $pubkey = substr($pubkey, 5);
} }
} elseif (normalise_link($pubkey) == 'http://') { } elseif (normalise_link($pubkey) == 'http://') {
$ret = z_fetch_url($pubkey); $ret = Network::curl($pubkey);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -1264,7 +1264,7 @@ class Probe
} }
// Fetch all additional data from the feed // Fetch all additional data from the feed
$ret = z_fetch_url($data["poll"]); $ret = Network::curl($data["poll"]);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -1448,7 +1448,7 @@ class Probe
*/ */
private static function feed($url, $probe = true) private static function feed($url, $probe = true)
{ {
$ret = z_fetch_url($url); $ret = Network::curl($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return false; return false;
} }
@ -1509,7 +1509,7 @@ class Probe
*/ */
private static function mail($uri, $uid) private static function mail($uri, $uid)
{ {
if (!validate_email($uri)) { if (!Network::isEmailDomainValid($uri)) {
return false; return false;
} }
@ -1543,7 +1543,7 @@ class Probe
$data["network"] = NETWORK_MAIL; $data["network"] = NETWORK_MAIL;
$data["name"] = substr($uri, 0, strpos($uri, '@')); $data["name"] = substr($uri, 0, strpos($uri, '@'));
$data["nick"] = $data["name"]; $data["nick"] = $data["name"];
$data["photo"] = avatar_img($uri); $data["photo"] = Network::lookupAvatarByEmail($uri);
$data["url"] = 'mailto:'.$uri; $data["url"] = 'mailto:'.$uri;
$data["notify"] = 'smtp '.random_string(); $data["notify"] = 'smtp '.random_string();
$data["poll"] = 'email '.random_string(); $data["poll"] = 'email '.random_string();

View File

@ -12,6 +12,7 @@ use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Util\Network;
use Exception; use Exception;
use Imagick; use Imagick;
use ImagickPixel; use ImagickPixel;
@ -773,7 +774,7 @@ class Image
$data = Cache::get($url); $data = Cache::get($url);
if (is_null($data) || !$data || !is_array($data)) { if (is_null($data) || !$data || !is_array($data)) {
$img_str = fetch_url($url, true, $redirects, 4); $img_str = Network::fetchUrl($url, true, $redirects, 4);
$filesize = strlen($img_str); $filesize = strlen($img_str);
if (function_exists("getimagesizefromstring")) { if (function_exists("getimagesizefromstring")) {

View File

@ -25,6 +25,7 @@ use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use dba; use dba;
@ -792,7 +793,7 @@ class DFRN
if ($activity) { if ($activity) {
$entry = $doc->createElement($element); $entry = $doc->createElement($element);
$r = parse_xml_string($activity, false); $r = XML::parseString($activity, false);
if (!$r) { if (!$r) {
return false; return false;
} }
@ -815,7 +816,7 @@ class DFRN
$r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link); $r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
// XML does need a single element as root element so we add a dummy element here // XML does need a single element as root element so we add a dummy element here
$data = parse_xml_string("<dummy>" . $r->link . "</dummy>", false); $data = XML::parseString("<dummy>" . $r->link . "</dummy>", false);
if (is_object($data)) { if (is_object($data)) {
foreach ($data->link as $link) { foreach ($data->link as $link) {
$attributes = []; $attributes = [];
@ -1186,7 +1187,7 @@ class DFRN
logger('dfrn_deliver: ' . $url); logger('dfrn_deliver: ' . $url);
$ret = z_fetch_url($url); $ret = Network::curl($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
return -2; // timed out return -2; // timed out
@ -1211,7 +1212,7 @@ class DFRN
return 3; return 3;
} }
$res = parse_xml_string($xml); $res = XML::parseString($xml);
if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) {
return (($res->status) ? $res->status : 3); return (($res->status) ? $res->status : 3);
@ -1332,7 +1333,7 @@ class DFRN
logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA); logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA);
$xml = post_url($contact['notify'], $postvars); $xml = Network::post($contact['notify'], $postvars);
logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA); logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
@ -1356,7 +1357,7 @@ class DFRN
Contact::unmarkForArchival($contact); Contact::unmarkForArchival($contact);
} }
$res = parse_xml_string($xml); $res = XML::parseString($xml);
if (!isset($res->status)) { if (!isset($res->status)) {
return -11; return -11;
@ -2187,7 +2188,7 @@ class DFRN
if (!$verb) { if (!$verb) {
return; return;
} }
$xo = parse_xml_string($item["object"], false); $xo = XML::parseString($item["object"], false);
if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) {
// somebody was poked/prodded. Was it me? // somebody was poked/prodded. Was it me?
@ -2309,8 +2310,8 @@ class DFRN
} }
if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
$xo = parse_xml_string($item["object"], false); $xo = XML::parseString($item["object"], false);
$xt = parse_xml_string($item["target"], false); $xt = XML::parseString($item["target"], false);
if ($xt->type == ACTIVITY_OBJ_NOTE) { if ($xt->type == ACTIVITY_OBJ_NOTE) {
$r = q( $r = q(
@ -2517,7 +2518,7 @@ class DFRN
$item["object"] = self::transformActivity($xpath, $object, "object"); $item["object"] = self::transformActivity($xpath, $object, "object");
if (trim($item["object"]) != "") { if (trim($item["object"]) != "") {
$r = parse_xml_string($item["object"], false); $r = XML::parseString($item["object"], false);
if (isset($r->type)) { if (isset($r->type)) {
$item["object-type"] = $r->type; $item["object-type"] = $r->type;
} }
@ -2786,8 +2787,8 @@ class DFRN
} }
if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
$xo = parse_xml_string($item["object"], false); $xo = XML::parseString($item["object"], false);
$xt = parse_xml_string($item["target"], false); $xt = XML::parseString($item["target"], false);
if ($xt->type == ACTIVITY_OBJ_NOTE) { if ($xt->type == ACTIVITY_OBJ_NOTE) {
$i = q( $i = q(

View File

@ -25,8 +25,8 @@ use Friendica\Model\Queue;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use dba; use dba;
use SimpleXMLElement; use SimpleXMLElement;
@ -186,7 +186,7 @@ class Diaspora
*/ */
private static function verifyMagicEnvelope($envelope) private static function verifyMagicEnvelope($envelope)
{ {
$basedom = parse_xml_string($envelope); $basedom = XML::parseString($envelope);
if (!is_object($basedom)) { if (!is_object($basedom)) {
logger("Envelope is no XML file"); logger("Envelope is no XML file");
@ -285,7 +285,7 @@ class Diaspora
if (!is_object($j_outer_key_bundle)) { if (!is_object($j_outer_key_bundle)) {
logger('Outer Salmon did not verify. Discarding.'); logger('Outer Salmon did not verify. Discarding.');
http_status_exit(400); System::httpExit(400);
} }
$outer_iv = base64_decode($j_outer_key_bundle->iv); $outer_iv = base64_decode($j_outer_key_bundle->iv);
@ -296,11 +296,11 @@ class Diaspora
$xml = $raw; $xml = $raw;
} }
$basedom = parse_xml_string($xml); $basedom = XML::parseString($xml);
if (!is_object($basedom)) { if (!is_object($basedom)) {
logger('Received data does not seem to be an XML. Discarding. '.$xml); logger('Received data does not seem to be an XML. Discarding. '.$xml);
http_status_exit(400); System::httpExit(400);
} }
$base = $basedom->children(NAMESPACE_SALMON_ME); $base = $basedom->children(NAMESPACE_SALMON_ME);
@ -325,7 +325,7 @@ class Diaspora
$verify = Crypto::rsaVerify($signed_data, $signature, $key); $verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) { if (!$verify) {
logger('Message did not verify. Discarding.'); logger('Message did not verify. Discarding.');
http_status_exit(400); System::httpExit(400);
} }
return ['message' => (string)base64url_decode($base->data), return ['message' => (string)base64url_decode($base->data),
@ -347,7 +347,7 @@ class Diaspora
public static function decode($importer, $xml) public static function decode($importer, $xml)
{ {
$public = false; $public = false;
$basedom = parse_xml_string($xml); $basedom = XML::parseString($xml);
if (!is_object($basedom)) { if (!is_object($basedom)) {
logger("XML is not parseable."); logger("XML is not parseable.");
@ -381,7 +381,7 @@ class Diaspora
$decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext); $decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext);
logger('decrypted: '.$decrypted, LOGGER_DEBUG); logger('decrypted: '.$decrypted, LOGGER_DEBUG);
$idom = parse_xml_string($decrypted); $idom = XML::parseString($decrypted);
$inner_iv = base64_decode($idom->iv); $inner_iv = base64_decode($idom->iv);
$inner_aes_key = base64_decode($idom->aes_key); $inner_aes_key = base64_decode($idom->aes_key);
@ -403,7 +403,7 @@ class Diaspora
if (!$base) { if (!$base) {
logger('unable to locate salmon data in xml'); logger('unable to locate salmon data in xml');
http_status_exit(400); System::httpExit(400);
} }
@ -441,7 +441,7 @@ class Diaspora
if (!$author_link) { if (!$author_link) {
logger('Could not retrieve author URI.'); logger('Could not retrieve author URI.');
http_status_exit(400); System::httpExit(400);
} }
// Once we have the author URI, go to the web and try to find their public key // Once we have the author URI, go to the web and try to find their public key
// (first this will look it up locally if it is in the fcontact cache) // (first this will look it up locally if it is in the fcontact cache)
@ -452,14 +452,14 @@ class Diaspora
if (!$key) { if (!$key) {
logger('Could not retrieve author key.'); logger('Could not retrieve author key.');
http_status_exit(400); System::httpExit(400);
} }
$verify = Crypto::rsaVerify($signed_data, $signature, $key); $verify = Crypto::rsaVerify($signed_data, $signature, $key);
if (!$verify) { if (!$verify) {
logger('Message did not verify. Discarding.'); logger('Message did not verify. Discarding.');
http_status_exit(400); System::httpExit(400);
} }
logger('Message verified.'); logger('Message verified.');
@ -631,7 +631,7 @@ class Diaspora
*/ */
private static function validPosting($msg) private static function validPosting($msg)
{ {
$data = parse_xml_string($msg["message"]); $data = XML::parseString($msg["message"]);
if (!is_object($data)) { if (!is_object($data)) {
logger("No valid XML ".$msg["message"], LOGGER_DEBUG); logger("No valid XML ".$msg["message"], LOGGER_DEBUG);
@ -1257,7 +1257,7 @@ class Diaspora
logger("Fetch post from ".$source_url, LOGGER_DEBUG); logger("Fetch post from ".$source_url, LOGGER_DEBUG);
$envelope = fetch_url($source_url); $envelope = Network::fetchUrl($source_url);
if ($envelope) { if ($envelope) {
logger("Envelope was fetched.", LOGGER_DEBUG); logger("Envelope was fetched.", LOGGER_DEBUG);
$x = self::verifyMagicEnvelope($envelope); $x = self::verifyMagicEnvelope($envelope);
@ -1275,13 +1275,13 @@ class Diaspora
$source_url = $server."/p/".urlencode($guid).".xml"; $source_url = $server."/p/".urlencode($guid).".xml";
logger("Fetch post from ".$source_url, LOGGER_DEBUG); logger("Fetch post from ".$source_url, LOGGER_DEBUG);
$x = fetch_url($source_url); $x = Network::fetchUrl($source_url);
if (!$x) { if (!$x) {
return false; return false;
} }
} }
$source_xml = parse_xml_string($x); $source_xml = XML::parseString($x);
if (!is_object($source_xml)) { if (!is_object($source_xml)) {
return false; return false;
@ -3229,7 +3229,7 @@ class Diaspora
if (!intval(Config::get("system", "diaspora_test"))) { if (!intval(Config::get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
post_url($dest_url."/", $envelope, ["Content-Type: ".$content_type]); Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
$return_code = $a->get_curl_code(); $return_code = $a->get_curl_code();
} else { } else {
logger("test_mode"); logger("test_mode");

View File

@ -9,6 +9,7 @@ namespace Friendica\Protocol;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Util\Network;
use dba; use dba;
use DOMDocument; use DOMDocument;
use DOMXPath; use DOMXPath;
@ -243,7 +244,7 @@ class Feed {
$orig_plink = $item["plink"]; $orig_plink = $item["plink"];
$item["plink"] = original_url($item["plink"]); $item["plink"] = Network::finalUrl($item["plink"]);
$item["parent-uri"] = $item["uri"]; $item["parent-uri"] = $item["uri"];

View File

@ -17,6 +17,7 @@ use Friendica\Model\Conversation;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Lock; use Friendica\Util\Lock;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use dba; use dba;
use DOMDocument; use DOMDocument;
@ -725,7 +726,7 @@ class OStatus
self::$conv_list[$conversation] = true; self::$conv_list[$conversation] = true;
$conversation_data = z_fetch_url($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
if (!$conversation_data['success']) { if (!$conversation_data['success']) {
return; return;
@ -753,7 +754,7 @@ class OStatus
} }
} }
if ($file != '') { if ($file != '') {
$conversation_atom = z_fetch_url($attribute['href']); $conversation_atom = Network::curl($attribute['href']);
if ($conversation_atom['success']) { if ($conversation_atom['success']) {
$xml = $conversation_atom['body']; $xml = $conversation_atom['body'];
@ -869,7 +870,7 @@ class OStatus
return; return;
} }
$self_data = z_fetch_url($self); $self_data = Network::curl($self);
if (!$self_data['success']) { if (!$self_data['success']) {
return; return;
@ -914,7 +915,7 @@ class OStatus
} }
$stored = false; $stored = false;
$related_data = z_fetch_url($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
if (!$related_data['success']) { if (!$related_data['success']) {
return; return;
@ -945,7 +946,7 @@ class OStatus
} }
} }
if ($atom_file != '') { if ($atom_file != '') {
$related_atom = z_fetch_url($atom_file); $related_atom = Network::curl($atom_file);
if ($related_atom['success']) { if ($related_atom['success']) {
logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG); logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG);
@ -957,7 +958,7 @@ class OStatus
// Workaround for older GNU Social servers // Workaround for older GNU Social servers
if (($xml == '') && strstr($related, '/notice/')) { if (($xml == '') && strstr($related, '/notice/')) {
$related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom');
if ($related_atom['success']) { if ($related_atom['success']) {
logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG); logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG);
@ -968,7 +969,7 @@ class OStatus
// Even more worse workaround for GNU Social ;-) // Even more worse workaround for GNU Social ;-)
if ($xml == '') { if ($xml == '') {
$related_guess = OStatus::convertHref($related_uri); $related_guess = OStatus::convertHref($related_uri);
$related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom');
if ($related_atom['success']) { if ($related_atom['success']) {
logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG); logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG);

View File

@ -15,6 +15,7 @@ use Friendica\Database\DBM;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Network;
use dba; use dba;
use DOMDocument; use DOMDocument;
use DOMXPath; use DOMXPath;
@ -22,7 +23,6 @@ use Exception;
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/datetime.php'; require_once 'include/datetime.php';
require_once 'include/network.php';
require_once 'include/html2bbcode.php'; require_once 'include/html2bbcode.php';
class PortableContact class PortableContact
@ -85,7 +85,7 @@ class PortableContact
logger('load: ' . $url, LOGGER_DEBUG); logger('load: ' . $url, LOGGER_DEBUG);
$s = fetch_url($url); $s = Network::fetchUrl($url);
logger('load: returns ' . $s, LOGGER_DATA); logger('load: returns ' . $s, LOGGER_DATA);
@ -287,7 +287,7 @@ class PortableContact
} }
// Fetch the host-meta to check if this really is a server // Fetch the host-meta to check if this really is a server
$serverret = z_fetch_url($server_url."/.well-known/host-meta"); $serverret = Network::curl($server_url."/.well-known/host-meta");
if (!$serverret["success"]) { if (!$serverret["success"]) {
return ""; return "";
} }
@ -366,7 +366,7 @@ class PortableContact
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url))); $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url)));
if ($server) { if ($server) {
$noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); $noscraperet = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
if ($noscraperet["success"] && ($noscraperet["body"] != "")) { if ($noscraperet["success"] && ($noscraperet["body"] != "")) {
$noscrape = json_decode($noscraperet["body"], true); $noscrape = json_decode($noscraperet["body"], true);
@ -480,7 +480,7 @@ class PortableContact
GContact::update($contact); GContact::update($contact);
$feedret = z_fetch_url($data["poll"]); $feedret = Network::curl($data["poll"]);
if (!$feedret["success"]) { if (!$feedret["success"]) {
$fields = ['last_failure' => datetime_convert()]; $fields = ['last_failure' => datetime_convert()];
@ -631,7 +631,7 @@ class PortableContact
*/ */
private static function fetchNodeinfo($server_url) private static function fetchNodeinfo($server_url)
{ {
$serverret = z_fetch_url($server_url."/.well-known/nodeinfo"); $serverret = Network::curl($server_url."/.well-known/nodeinfo");
if (!$serverret["success"]) { if (!$serverret["success"]) {
return false; return false;
} }
@ -663,7 +663,7 @@ class PortableContact
return false; return false;
} }
$serverret = z_fetch_url($nodeinfo_url); $serverret = Network::curl($nodeinfo_url);
if (!$serverret["success"]) { if (!$serverret["success"]) {
return false; return false;
} }
@ -872,7 +872,7 @@ class PortableContact
$server_url = str_replace("http://", "https://", $server_url); $server_url = str_replace("http://", "https://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
$serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
// Quit if there is a timeout. // Quit if there is a timeout.
// But we want to make sure to only quit if we are mostly sure that this server url fits. // But we want to make sure to only quit if we are mostly sure that this server url fits.
@ -889,7 +889,7 @@ class PortableContact
$server_url = str_replace("https://", "http://", $server_url); $server_url = str_replace("https://", "http://", $server_url);
// We set the timeout to 20 seconds since this operation should be done in no time if the server was vital // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
$serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
// Quit if there is a timeout // Quit if there is a timeout
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
@ -925,7 +925,7 @@ class PortableContact
// Look for poco // Look for poco
if (!$failure) { if (!$failure) {
$serverret = z_fetch_url($server_url."/poco"); $serverret = Network::curl($server_url."/poco");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->totalResults)) { if (isset($data->totalResults)) {
@ -951,7 +951,7 @@ class PortableContact
if (!$failure) { if (!$failure) {
// Test for Diaspora, Hubzilla, Mastodon or older Friendica servers // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers
$serverret = z_fetch_url($server_url); $serverret = Network::curl($server_url);
if (!$serverret["success"] || ($serverret["body"] == "")) { if (!$serverret["success"] || ($serverret["body"] == "")) {
$failure = true; $failure = true;
@ -990,7 +990,7 @@ class PortableContact
// Test for Statusnet // Test for Statusnet
// Will also return data for Friendica and GNU Social - but it will be overwritten later // Will also return data for Friendica and GNU Social - but it will be overwritten later
// The "not implemented" is a special treatment for really, really old Friendica versions // The "not implemented" is a special treatment for really, really old Friendica versions
$serverret = z_fetch_url($server_url."/api/statusnet/version.json"); $serverret = Network::curl($server_url."/api/statusnet/version.json");
if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
$platform = "StatusNet"; $platform = "StatusNet";
@ -1001,7 +1001,7 @@ class PortableContact
} }
// Test for GNU Social // Test for GNU Social
$serverret = z_fetch_url($server_url."/api/gnusocial/version.json"); $serverret = Network::curl($server_url."/api/gnusocial/version.json");
if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') &&
($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) {
$platform = "GNU Social"; $platform = "GNU Social";
@ -1013,7 +1013,7 @@ class PortableContact
// Test for Mastodon // Test for Mastodon
$orig_version = $version; $orig_version = $version;
$serverret = z_fetch_url($server_url."/api/v1/instance"); $serverret = Network::curl($server_url."/api/v1/instance");
if ($serverret["success"] && ($serverret["body"] != '')) { if ($serverret["success"] && ($serverret["body"] != '')) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
@ -1036,7 +1036,7 @@ class PortableContact
if (!$failure) { if (!$failure) {
// Test for Hubzilla and Red // Test for Hubzilla and Red
$serverret = z_fetch_url($server_url."/siteinfo.json"); $serverret = Network::curl($server_url."/siteinfo.json");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->url)) { if (isset($data->url)) {
@ -1064,7 +1064,7 @@ class PortableContact
} }
} else { } else {
// Test for Hubzilla, Redmatrix or Friendica // Test for Hubzilla, Redmatrix or Friendica
$serverret = z_fetch_url($server_url."/api/statusnet/config.json"); $serverret = Network::curl($server_url."/api/statusnet/config.json");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
if (isset($data->site->server)) { if (isset($data->site->server)) {
@ -1119,7 +1119,7 @@ class PortableContact
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) { if (!$failure) {
$serverret = z_fetch_url($server_url."/statistics.json"); $serverret = Network::curl($server_url."/statistics.json");
if ($serverret["success"]) { if ($serverret["success"]) {
$data = json_decode($serverret["body"]); $data = json_decode($serverret["body"]);
@ -1181,10 +1181,10 @@ class PortableContact
// Check for noscrape // Check for noscrape
// Friendica servers could be detected as OStatus servers // Friendica servers could be detected as OStatus servers
if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) { if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) {
$serverret = z_fetch_url($server_url."/friendica/json"); $serverret = Network::curl($server_url."/friendica/json");
if (!$serverret["success"]) { if (!$serverret["success"]) {
$serverret = z_fetch_url($server_url."/friendika/json"); $serverret = Network::curl($server_url."/friendika/json");
} }
if ($serverret["success"]) { if ($serverret["success"]) {
@ -1294,7 +1294,7 @@ class PortableContact
*/ */
private static function fetchServerlist($poco) private static function fetchServerlist($poco)
{ {
$serverret = z_fetch_url($poco."/@server"); $serverret = Network::curl($poco."/@server");
if (!$serverret["success"]) { if (!$serverret["success"]) {
return; return;
} }
@ -1343,7 +1343,7 @@ class PortableContact
if (!empty($accesstoken)) { if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0'; $api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken]; $header = ['Authorization: Bearer '.$accesstoken];
$serverdata = z_fetch_url($api, false, $redirects, ['headers' => $header]); $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
if ($serverdata['success']) { if ($serverdata['success']) {
$servers = json_decode($serverdata['body']); $servers = json_decode($serverdata['body']);
foreach ($servers->instances as $server) { foreach ($servers->instances as $server) {
@ -1360,7 +1360,7 @@ class PortableContact
//if (!Config::get('system','ostatus_disabled')) { //if (!Config::get('system','ostatus_disabled')) {
// $serverdata = "http://gstools.org/api/get_open_instances/"; // $serverdata = "http://gstools.org/api/get_open_instances/";
// $result = z_fetch_url($serverdata); // $result = Network::curl($serverdata);
// if ($result["success"]) { // if ($result["success"]) {
// $servers = json_decode($result["body"]); // $servers = json_decode($result["body"]);
@ -1389,7 +1389,7 @@ class PortableContact
logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG); logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG);
$retdata = z_fetch_url($url); $retdata = Network::curl($url);
if ($retdata["success"]) { if ($retdata["success"]) {
$data = json_decode($retdata["body"]); $data = json_decode($retdata["body"]);
@ -1408,7 +1408,7 @@ class PortableContact
$success = false; $success = false;
$retdata = z_fetch_url($url); $retdata = Network::curl($url);
if ($retdata["success"]) { if ($retdata["success"]) {
logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG);
$success = self::discoverServer(json_decode($retdata["body"])); $success = self::discoverServer(json_decode($retdata["body"]));
@ -1493,7 +1493,7 @@ class PortableContact
// Fetch all contacts from a given user from the other server // Fetch all contacts from a given user from the other server
$url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
$retdata = z_fetch_url($url); $retdata = Network::curl($url);
if ($retdata["success"]) { if ($retdata["success"]) {
self::discoverServer(json_decode($retdata["body"]), 3); self::discoverServer(json_decode($retdata["body"]), 3);
} }

View File

@ -6,6 +6,7 @@ namespace Friendica\Protocol;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
/** /**
@ -50,7 +51,7 @@ class Salmon
$ret[$x] = substr($ret[$x], 5); $ret[$x] = substr($ret[$x], 5);
} }
} elseif (normalise_link($ret[$x]) == 'http://') { } elseif (normalise_link($ret[$x]) == 'http://') {
$ret[$x] = fetch_url($ret[$x]); $ret[$x] = Network::fetchUrl($ret[$x]);
} }
} }
} }
@ -132,7 +133,7 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, [ Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
]); ]);
@ -158,7 +159,7 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, [ Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
]); ]);
@ -181,10 +182,9 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
post_url($url, $salmon, [ Network::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon)] 'Content-length: ' . strlen($salmon)]);
);
$return_code = $a->get_curl_code(); $return_code = $a->get_curl_code();
} }

View File

@ -38,9 +38,9 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Network;
use dba; use dba;
require_once 'include/dba.php';
require_once 'include/dba.php'; require_once 'include/dba.php';
class ExAuth class ExAuth
@ -181,7 +181,7 @@ class ExAuth
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
$data = z_fetch_url($url); $data = Network::curl($url);
if (!is_array($data)) { if (!is_array($data)) {
return false; return false;

889
src/Util/Network.php Normal file
View File

@ -0,0 +1,889 @@
<?php
/**
* @file src/Util/Network.php
*/
namespace Friendica\Util;
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Util\XML;
use DOMDocument;
use DomXPath;
require_once 'library/slinky.php';
class Network
{
/**
* @brief Curl wrapper
*
* If binary flag is true, return binary results.
* Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
* to preserve cookies from one request to the next.
*
* @param string $url URL to fetch
* @param boolean $binary default false
* TRUE if asked to return binary results (file download)
* @param integer $redirects The recursion counter for internal use - default 0
* @param integer $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param string $cookiejar Path to cookie jar file
*
* @return string The fetched content
*/
public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0)
{
$ret = self::curl(
$url,
$binary,
$redirects,
['timeout'=>$timeout,
'accept_content'=>$accept_content,
'cookiejar'=>$cookiejar
]
);
return($ret['body']);
}
/**
* @brief fetches an URL.
*
* @param string $url URL to fetch
* @param boolean $binary default false
* TRUE if asked to return binary results (file download)
* @param int $redirects The recursion counter for internal use - default 0
* @param array $opts (optional parameters) assoziative array with:
* 'accept_content' => supply Accept: header with 'accept_content' as the value
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'http_auth' => username:password
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
* 'nobody' => only return the header
* 'cookiejar' => path to cookie jar file
*
* @return array an assoziative array with:
* int 'return_code' => HTTP return code or 0 if timeout or failure
* boolean 'success' => boolean true (if HTTP 2xx result) or false
* string 'redirect_url' => in case of redirect, content was finally retrieved from this URL
* string 'header' => HTTP headers
* string 'body' => fetched content
*/
public static function curl($url, $binary = false, &$redirects = 0, $opts = [])
{
$ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => ''];
$stamp1 = microtime(true);
$a = get_app();
if (self::isUrlBlocked($url)) {
logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA);
return $ret;
}
$ch = @curl_init($url);
if (($redirects > 8) || (!$ch)) {
return $ret;
}
@curl_setopt($ch, CURLOPT_HEADER, true);
if (x($opts, "cookiejar")) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
}
// These settings aren't needed. We're following the location already.
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
if (x($opts, 'accept_content')) {
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
['Accept: ' . $opts['accept_content']]
);
}
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
$range = intval(Config::get('system', 'curl_range_bytes', 0));
if ($range > 0) {
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
}
// Without this setting it seems as if some webservers send compressed content
// This seems to confuse curl so that it shows this uncompressed.
/// @todo We could possibly set this value to "gzip" or something similar
curl_setopt($ch, CURLOPT_ENCODING, '');
if (x($opts, 'headers')) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
if (x($opts, 'nobody')) {
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
}
if (x($opts, 'timeout')) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
} else {
$curl_time = Config::get('system', 'curl_timeout', 60);
@curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
// by default we will allow self-signed certs
// but you can override this
$check_cert = Config::get('system', 'verifyssl');
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = Config::get('system', 'proxy');
if (strlen($proxy)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = @Config::get('system', 'proxyuser');
if (strlen($proxyuser)) {
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
if (Config::get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
$a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
// Special treatment for HTTP Code 416
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416
if (($curl_info['http_code'] == 416) && ($range > 0)) {
@curl_setopt($ch, CURLOPT_RANGE, '');
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
}
if (curl_errno($ch) !== CURLE_OK) {
logger('fetch_url error fetching ' . $url . ': ' . curl_error($ch), LOGGER_NORMAL);
}
$ret['errno'] = curl_errno($ch);
$base = $s;
$ret['info'] = $curl_info;
$http_code = $curl_info['http_code'];
logger('fetch_url ' . $url . ': ' . $http_code . " " . $s, LOGGER_DATA);
$header = '';
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) {
$chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4);
$header .= $chunk;
$base = substr($base, strlen($chunk));
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
$a->set_curl_headers($header);
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$new_location_info = @parse_url($curl_info['redirect_url']);
$old_location_info = @parse_url($curl_info['url']);
$newurl = $curl_info['redirect_url'];
if (($new_location_info['path'] == '') && ( $new_location_info['host'] != '')) {
$newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path'];
}
$matches = [];
if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) {
$newurl = trim(array_pop($matches));
}
if (strpos($newurl, '/') === 0) {
$newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
}
if (filter_var($newurl, FILTER_VALIDATE_URL)) {
$redirects++;
@curl_close($ch);
return self::curl($newurl, $binary, $redirects, $opts);
}
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
$rc = intval($http_code);
$ret['return_code'] = $rc;
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
$ret['redirect_url'] = $url;
if (!$ret['success']) {
$ret['error'] = curl_error($ch);
$ret['debug'] = $curl_info;
logger('z_fetch_url: error: '.$url.': '.$ret['return_code'].' - '.$ret['error'], LOGGER_DEBUG);
logger('z_fetch_url: debug: '.print_r($curl_info, true), LOGGER_DATA);
}
$ret['body'] = substr($s, strlen($header));
$ret['header'] = $header;
if (x($opts, 'debug')) {
$ret['debug'] = $curl_info;
}
@curl_close($ch);
$a->save_timestamp($stamp1, 'network');
return($ret);
}
/**
* @brief Send POST request to $url
*
* @param string $url URL to post
* @param mixed $params array of POST variables
* @param string $headers HTTP headers
* @param integer $redirects Recursion counter for internal use - default = 0
* @param integer $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return string The content
*/
public static function post($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
{
$stamp1 = microtime(true);
if (self::isUrlBlocked($url)) {
logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA);
return false;
}
$a = get_app();
$ch = curl_init($url);
if (($redirects > 8) || (!$ch)) {
return false;
}
logger('post_url: start ' . $url, LOGGER_DATA);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
if (Config::get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if (intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
} else {
$curl_time = Config::get('system', 'curl_timeout', 60);
curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
if (defined('LIGHTTPD')) {
if (!is_array($headers)) {
$headers = ['Expect:'];
} else {
if (!in_array('Expect:', $headers)) {
array_push($headers, 'Expect:');
}
}
}
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$check_cert = Config::get('system', 'verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = Config::get('system', 'proxy');
if (strlen($proxy)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = Config::get('system', 'proxyuser');
if (strlen($proxyuser)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
$a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$base = $s;
$curl_info = curl_getinfo($ch);
$http_code = $curl_info['http_code'];
logger('post_url: result ' . $http_code . ' - ' . $url, LOGGER_DATA);
$header = '';
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) {
$chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4);
$header .= $chunk;
$base = substr($base, strlen($chunk));
}
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$matches = [];
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
if (strpos($newurl, '/') === 0) {
$newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl;
}
if (filter_var($newurl, FILTER_VALIDATE_URL)) {
$redirects++;
logger('post_url: redirect ' . $url . ' to ' . $newurl);
return self::post($newurl, $params, $headers, $redirects, $timeout);
}
}
$a->set_curl_code($http_code);
$body = substr($s, strlen($header));
$a->set_curl_headers($header);
curl_close($ch);
$a->save_timestamp($stamp1, 'network');
logger('post_url: end ' . $url, LOGGER_DATA);
return $body;
}
/**
* @brief Check URL to see if it's real
*
* Take a URL from the wild, prepend http:// if necessary
* and check DNS to see if it's real (or check if is a valid IP address)
*
* @param string $url The URL to be validated
* @return string|boolean The actual working URL, false else
*/
public static function isUrlValid($url)
{
if (Config::get('system', 'disable_url_validation')) {
return $url;
}
// no naked subdomains (allow localhost for tests)
if (strpos($url, '.') === false && strpos($url, '/localhost/') === false) {
return false;
}
if (substr($url, 0, 4) != 'http') {
$url = 'http://' . $url;
}
/// @TODO Really suppress function outcomes? Why not find them + debug them?
$h = @parse_url($url);
if ((is_array($h)) && (@dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) {
return $url;
}
return false;
}
/**
* @brief Checks that email is an actual resolvable internet address
*
* @param string $addr The email address
* @return boolean True if it's a valid email address, false if it's not
*/
public static function isEmailDomainValid($addr)
{
if (Config::get('system', 'disable_email_validation')) {
return true;
}
if (! strpos($addr, '@')) {
return false;
}
$h = substr($addr, strpos($addr, '@') + 1);
if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) {
return true;
}
return false;
}
/**
* @brief Check if URL is allowed
*
* Check $url against our list of allowed sites,
* wildcards allowed. If allowed_sites is unset return true;
*
* @param string $url URL which get tested
* @return boolean True if url is allowed otherwise return false
*/
public static function isUrlAllowed($url)
{
$h = @parse_url($url);
if (! $h) {
return false;
}
$str_allowed = Config::get('system', 'allowed_sites');
if (! $str_allowed) {
return true;
}
$found = false;
$host = strtolower($h['host']);
// always allow our own site
if ($host == strtolower($_SERVER['SERVER_NAME'])) {
return true;
}
$fnmatch = function_exists('fnmatch');
$allowed = explode(',', $str_allowed);
if (count($allowed)) {
foreach ($allowed as $a) {
$pat = strtolower(trim($a));
if (($fnmatch && fnmatch($pat, $host)) || ($pat == $host)) {
$found = true;
break;
}
}
}
return $found;
}
/**
* Checks if the provided url domain is on the domain blocklist.
* Returns true if it is or malformed URL, false if not.
*
* @param string $url The url to check the domain from
*
* @return boolean
*/
public static function isUrlBlocked($url)
{
$h = @parse_url($url);
if (! $h) {
return true;
}
$domain_blocklist = Config::get('system', 'blocklist', []);
if (! $domain_blocklist) {
return false;
}
$host = strtolower($h['host']);
foreach ($domain_blocklist as $domain_block) {
if (strtolower($domain_block['domain']) == $host) {
return true;
}
}
return false;
}
/**
* @brief Check if email address is allowed to register here.
*
* Compare against our list (wildcards allowed).
*
* @param string $email email address
* @return boolean False if not allowed, true if allowed
* or if allowed list is not configured
*/
public static function isEmailDomainAllowed($email)
{
$domain = strtolower(substr($email, strpos($email, '@') + 1));
if (!$domain) {
return false;
}
$str_allowed = Config::get('system', 'allowed_email', '');
if (!x($str_allowed)) {
return true;
}
$allowed = explode(',', $str_allowed);
return self::isDomainAllowed($domain, $allowed);
}
/**
* Checks for the existence of a domain in a domain list
*
* @brief Checks for the existence of a domain in a domain list
* @param string $domain
* @param array $domain_list
* @return boolean
*/
public static function isDomainAllowed($domain, array $domain_list)
{
$found = false;
foreach ($domain_list as $item) {
$pat = strtolower(trim($item));
if (fnmatch($pat, $domain) || ($pat == $domain)) {
$found = true;
break;
}
}
return $found;
}
public static function lookupAvatarByEmail($email)
{
$avatar['size'] = 175;
$avatar['email'] = $email;
$avatar['url'] = '';
$avatar['success'] = false;
Addon::callHooks('avatar_lookup', $avatar);
if (! $avatar['success']) {
$avatar['url'] = System::baseUrl() . '/images/person-175.jpg';
}
logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG);
return $avatar['url'];
}
/**
* @brief Remove Google Analytics and other tracking platforms params from URL
*
* @param string $url Any user-submitted URL that may contain tracking params
* @return string The same URL stripped of tracking parameters
*/
public static function stripTrackingQueryParams($url)
{
$urldata = parse_url($url);
if (is_string($urldata["query"])) {
$query = $urldata["query"];
parse_str($query, $querydata);
if (is_array($querydata)) {
foreach ($querydata as $param => $value) {
if (in_array(
$param,
[
"utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign",
"wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid",
"fb_action_ids", "fb_action_types", "fb_ref",
"awesm", "wtrid",
"woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term"]
)
) {
$pair = $param . "=" . urlencode($value);
$url = str_replace($pair, "", $url);
// Second try: if the url isn't encoded completely
$pair = $param . "=" . str_replace(" ", "+", $value);
$url = str_replace($pair, "", $url);
// Third try: Maybey the url isn't encoded at all
$pair = $param . "=" . $value;
$url = str_replace($pair, "", $url);
$url = str_replace(["?&", "&&"], ["?", ""], $url);
}
}
}
if (substr($url, -1, 1) == "?") {
$url = substr($url, 0, -1);
}
}
return $url;
}
/**
* @brief Returns the original URL of the provided URL
*
* This function strips tracking query params and follows redirections, either
* through HTTP code or meta refresh tags. Stops after 10 redirections.
*
* @todo Remove the $fetchbody parameter that generates an extraneous HEAD request
*
* @see ParseUrl::getSiteinfo
*
* @param string $url A user-submitted URL
* @param int $depth The current redirection recursion level (internal)
* @param bool $fetchbody Wether to fetch the body or not after the HEAD requests
* @return string A canonical URL
*/
public static function finalUrl($url, $depth = 1, $fetchbody = false)
{
$a = get_app();
$url = self::stripTrackingQueryParams($url);
if ($depth > 10) {
return($url);
}
$url = trim($url, "'");
$stamp1 = microtime(true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
curl_exec($ch);
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
curl_close($ch);
$a->save_timestamp($stamp1, "network");
if ($http_code == 0) {
return($url);
}
if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302"))
&& (($curl_info['redirect_url'] != "") || ($curl_info['location'] != ""))
) {
if ($curl_info['redirect_url'] != "") {
return(self::finalUrl($curl_info['redirect_url'], ++$depth, $fetchbody));
} else {
return(self::finalUrl($curl_info['location'], ++$depth, $fetchbody));
}
}
// Check for redirects in the meta elements of the body if there are no redirects in the header.
if (!$fetchbody) {
return(self::finalUrl($url, ++$depth, true));
}
// if the file is too large then exit
if ($curl_info["download_content_length"] > 1000000) {
return($url);
}
// if it isn't a HTML file then exit
if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]), "html")) {
return($url);
}
$stamp1 = microtime(true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
$body = curl_exec($ch);
curl_close($ch);
$a->save_timestamp($stamp1, "network");
if (trim($body) == "") {
return($url);
}
// Check for redirect in meta elements
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DomXPath($doc);
$list = $xpath->query("//meta[@content]");
foreach ($list as $node) {
$attr = [];
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
}
}
if (@$attr["http-equiv"] == 'refresh') {
$path = $attr["content"];
$pathinfo = explode(";", $path);
foreach ($pathinfo as $value) {
if (substr(strtolower($value), 0, 4) == "url=") {
return(self::finalUrl(substr($value, 4), ++$depth));
}
}
}
}
return $url;
}
public static function shortenUrl($url)
{
$slinky = new Slinky($url);
$yourls_url = Config::get('yourls', 'url1');
if ($yourls_url) {
$yourls_username = Config::get('yourls', 'username1');
$yourls_password = Config::get('yourls', 'password1');
$yourls_ssl = Config::get('yourls', 'ssl1');
$yourls = new Slinky_YourLS();
$yourls->set('username', $yourls_username);
$yourls->set('password', $yourls_password);
$yourls->set('ssl', $yourls_ssl);
$yourls->set('yourls-url', $yourls_url);
$slinky->set_cascade([$yourls, new Slinky_Ur1ca(), new Slinky_TinyURL()]);
} else {
// setup a cascade of shortening services
// try to get a short link from these services
// in the order ur1.ca, tinyurl
$slinky->set_cascade([new Slinky_Ur1ca(), new Slinky_TinyURL()]);
}
return $slinky->short();
}
/**
* @brief Find the matching part between two url
*
* @param string $url1
* @param string $url2
* @return string The matching part
*/
public static function getUrlMatch($url1, $url2)
{
if (($url1 == "") || ($url2 == "")) {
return "";
}
$url1 = normalise_link($url1);
$url2 = normalise_link($url2);
$parts1 = parse_url($url1);
$parts2 = parse_url($url2);
if (!isset($parts1["host"]) || !isset($parts2["host"])) {
return "";
}
if ($parts1["scheme"] != $parts2["scheme"]) {
return "";
}
if ($parts1["host"] != $parts2["host"]) {
return "";
}
if ($parts1["port"] != $parts2["port"]) {
return "";
}
$match = $parts1["scheme"]."://".$parts1["host"];
if ($parts1["port"]) {
$match .= ":".$parts1["port"];
}
$pathparts1 = explode("/", $parts1["path"]);
$pathparts2 = explode("/", $parts2["path"]);
$i = 0;
$path = "";
do {
$path1 = $pathparts1[$i];
$path2 = $pathparts2[$i];
if ($path1 == $path2) {
$path .= $path1."/";
}
} while (($path1 == $path2) && ($i++ <= count($pathparts1)));
$match .= $path;
return normalise_link($match);
}
/**
* @brief Glue url parts together
*
* @param array $parsed URL parts
*
* @return string The glued URL
*/
public static function unparseURL($parsed)
{
$get = function ($key) use ($parsed) {
return isset($parsed[$key]) ? $parsed[$key] : null;
};
$pass = $get('pass');
$user = $get('user');
$userinfo = $pass !== null ? "$user:$pass" : $user;
$port = $get('port');
$scheme = $get('scheme');
$query = $get('query');
$fragment = $get('fragment');
$authority = ($userinfo !== null ? $userinfo."@" : '') .
$get('host') .
($port ? ":$port" : '');
return (strlen($scheme) ? $scheme.":" : '') .
(strlen($authority) ? "//".$authority : '') .
$get('path') .
(strlen($query) ? "?".$query : '') .
(strlen($fragment) ? "#".$fragment : '');
}
}

View File

@ -8,6 +8,7 @@ namespace Friendica\Util;
use Friendica\Content\OEmbed; use Friendica\Content\OEmbed;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Network;
use Friendica\Util\XML; use Friendica\Util\XML;
use dba; use dba;
@ -15,7 +16,6 @@ use DOMXPath;
use DOMDocument; use DOMDocument;
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once "include/network.php";
/** /**
* @brief Class with methods for extracting certain content from an url * @brief Class with methods for extracting certain content from an url
@ -140,12 +140,12 @@ class ParseUrl
$url = trim($url, "'"); $url = trim($url, "'");
$url = trim($url, '"'); $url = trim($url, '"');
$url = strip_tracking_query_params($url); $url = Network::stripTrackingQueryParams($url);
$siteinfo["url"] = $url; $siteinfo["url"] = $url;
$siteinfo["type"] = "link"; $siteinfo["type"] = "link";
$data = z_fetch_url($url); $data = Network::curl($url);
if (!$data['success']) { if (!$data['success']) {
return($siteinfo); return($siteinfo);
} }

View File

@ -413,4 +413,20 @@ class XML
$child->parentNode->removeChild($child); $child->parentNode->removeChild($child);
} }
} }
public static function parseString($s, $strict = true)
{
// the "strict" parameter is deactivated
libxml_use_internal_errors(true);
$x = @simplexml_load_string($s);
if (!$x) {
logger('libxml: parse: error: ' . $s, LOGGER_DATA);
foreach (libxml_get_errors() as $err) {
logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
}
libxml_clear_errors();
}
return $x;
}
} }

View File

@ -8,6 +8,7 @@
namespace Friendica\Worker; namespace Friendica\Worker;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Util\Network;
/** /**
* @brief check the git repository VERSION file and save the version to the DB * @brief check the git repository VERSION file and save the version to the DB
@ -37,7 +38,7 @@ class CheckVersion {
logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG); logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG);
// fetch the VERSION file // fetch the VERSION file
$gitversion = dbesc(trim(fetch_url($checked_url))); $gitversion = dbesc(trim(Network::fetchUrl($checked_url)));
logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG); logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG);
Config::set('system', 'git_friendica_version', $gitversion); Config::set('system', 'git_friendica_version', $gitversion);

View File

@ -299,7 +299,7 @@ class Delivery {
} }
$ssl_policy = Config::get('system','ssl_policy'); $ssl_policy = Config::get('system','ssl_policy');
fix_contact_ssl_policy($x[0],$ssl_policy); $x[0] = Contact::updateSslPolicy($x[0], $ssl_policy);
// If we are setup as a soapbox we aren't accepting top level posts from this person // If we are setup as a soapbox we aren't accepting top level posts from this person

View File

@ -10,9 +10,12 @@ use Friendica\Core\Addon;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Util\Network;
class Directory { class Directory
public static function execute($url = '') { {
public static function execute($url = '')
{
$dir = Config::get('system', 'directory'); $dir = Config::get('system', 'directory');
if (!strlen($dir)) { if (!strlen($dir)) {
@ -32,7 +35,7 @@ class Directory {
logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG);
if (strlen($arr['url'])) { if (strlen($arr['url'])) {
fetch_url($dir . '?url=' . bin2hex($arr['url'])); Network::fetchUrl($dir . '?url=' . bin2hex($arr['url']));
} }
return; return;

View File

@ -11,6 +11,7 @@ use Friendica\Database\DBM;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
require_once 'include/datetime.php'; require_once 'include/datetime.php';
@ -217,7 +218,7 @@ class DiscoverPoCo {
} }
} }
$x = fetch_url(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $x = Network::fetchUrl(get_server()."/lsearch?p=1&n=500&search=".urlencode($search));
$j = json_decode($x); $j = json_decode($x);
if (count($j->results)) { if (count($j->results)) {
@ -280,7 +281,7 @@ class DiscoverPoCo {
$url = "http://gstools.org/api/users_search/".urlencode($search); $url = "http://gstools.org/api/users_search/".urlencode($search);
$result = z_fetch_url($url); $result = Network::curl($url);
if (!$result["success"]) { if (!$result["success"]) {
return false; return false;
} }

View File

@ -10,6 +10,8 @@ use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Network;
use Friendica\Util\XML;
use dba; use dba;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -176,7 +178,7 @@ class OnePoll
. '&type=data&last_update=' . $last_update . '&type=data&last_update=' . $last_update
. '&perm=' . $perm ; . '&perm=' . $perm ;
$ret = z_fetch_url($url); $ret = Network::curl($url);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
@ -218,7 +220,7 @@ class OnePoll
} }
$res = parse_xml_string($handshake_xml); $res = XML::parseString($handshake_xml);
if (intval($res->status) == 1) { if (intval($res->status) == 1) {
logger("$url replied status 1 - marking for death "); logger("$url replied status 1 - marking for death ");
@ -280,7 +282,7 @@ class OnePoll
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
$postvars['perm'] = 'rw'; $postvars['perm'] = 'rw';
$xml = post_url($contact['poll'], $postvars); $xml = Network::post($contact['poll'], $postvars);
} elseif (($contact['network'] === NETWORK_OSTATUS) } elseif (($contact['network'] === NETWORK_OSTATUS)
|| ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DIASPORA)
@ -311,7 +313,7 @@ class OnePoll
} }
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
$ret = z_fetch_url($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); $ret = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
unlink($cookiejar); unlink($cookiejar);
if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) {

View File

@ -11,6 +11,7 @@ use Friendica\Core\Config;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\Network;
require_once 'include/items.php'; require_once 'include/items.php';
@ -68,7 +69,7 @@ class PubSubPublish {
logger('POST '.print_r($headers, true)."\n".$params, LOGGER_DEBUG); logger('POST '.print_r($headers, true)."\n".$params, LOGGER_DEBUG);
post_url($rr['callback_url'], $params, $headers); Network::post($rr['callback_url'], $params, $headers);
$ret = $a->get_curl_code(); $ret = $a->get_curl_code();
if ($ret >= 200 && $ret <= 299) { if ($ret >= 200 && $ret <= 299) {