1
0
Fork 0

Merge pull request #3080 from annando/1701-curl-range

Download limit for fetching data via "z_fetch_url"
This commit is contained in:
rabuzarus 2017-01-12 12:15:58 +01:00 committed by GitHub
commit b1120f5238
5 changed files with 127 additions and 121 deletions

View file

@ -25,6 +25,7 @@ Example: To set the directory value please add this line to your .htconfig.php:
* **allowed_link_protocols** (Array) - Allowed protocols in links URLs, add at your own risk. http is always allowed. * **allowed_link_protocols** (Array) - Allowed protocols in links URLs, add at your own risk. http is always allowed.
* **birthday_input_format** - Default value is "ymd". * **birthday_input_format** - Default value is "ymd".
* **block_local_dir** (Boolean) - Blocks the access to the directory of the local users. * **block_local_dir** (Boolean) - Blocks the access to the directory of the local users.
* **curl_range_bytes** - Maximum number of bytes that should be fetched. Default is 0, which mean "no limit".
* **dbclean** (Boolean) - Enable the automatic database cleanup process * **dbclean** (Boolean) - Enable the automatic database cleanup process
* **default_service_class** - * **default_service_class** -
* **delivery_batch_count** - Number of deliveries per process. Default value is 1. (Disabled when using the worker) * **delivery_batch_count** - Number of deliveries per process. Default value is 1. (Disabled when using the worker)

View file

@ -4,6 +4,8 @@
* @file include/network.php * @file include/network.php
*/ */
use \Friendica\Core\Config;
require_once("include/xml.php"); require_once("include/xml.php");
require_once('include/Probe.php'); require_once('include/Probe.php');
@ -93,7 +95,10 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); @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);
}
if(x($opts,'headers')){ if(x($opts,'headers')){
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);

View file

@ -1,6 +1,4 @@
<?php <?php
function oexchange_init(App $a) { function oexchange_init(App $a) {
if (($a->argc > 1) && ($a->argv[1] === 'xrd')) { if (($a->argc > 1) && ($a->argv[1] === 'xrd')) {
@ -10,8 +8,6 @@ function oexchange_init(App $a) {
echo $o; echo $o;
killme(); killme();
} }
} }
function oexchange_content(App $a) { function oexchange_content(App $a) {
@ -37,8 +33,9 @@ function oexchange_content(App $a) {
$s = fetch_url(App::get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); $s = fetch_url(App::get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
if(! strlen($s)) if (! strlen($s)) {
return; return;
}
require_once('include/html2bbcode.php'); require_once('include/html2bbcode.php');
@ -52,7 +49,4 @@ function oexchange_content(App $a) {
$_REQUEST = $post; $_REQUEST = $post;
require_once('mod/item.php'); require_once('mod/item.php');
item_post($a); item_post($a);
} }

View file

@ -16,8 +16,14 @@ function uexport_content(App $a) {
header("Content-type: application/json"); header("Content-type: application/json");
header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"'); header('Content-Disposition: attachment; filename="'.$a->user['nickname'].'.'.$a->argv[1].'"');
switch($a->argv[1]) { switch($a->argv[1]) {
case "backup": uexport_all($a); killme(); break; case "backup":
case "account": uexport_account($a); killme(); break; uexport_all($a);
killme();
break;
case "account":
uexport_account($a);
killme();
break;
default: default:
killme(); killme();
} }
@ -39,19 +45,17 @@ function uexport_content(App $a) {
'$title' => t('Export personal data'), '$title' => t('Export personal data'),
'$options' => $options '$options' => $options
)); ));
} }
function _uexport_multirow($query) { function _uexport_multirow($query) {
$result = array(); $result = array();
$r = q($query); $r = q($query);
// if (dbm::is_result($r)) { if (dbm::is_result($r)) {
if ($r){
foreach($r as $rr){ foreach($r as $rr){
$p = array(); $p = array();
foreach($rr as $k => $v) foreach($rr as $k => $v) {
$p[$k] = $v; $p[$k] = $v;
}
$result[] = $p; $result[] = $p;
} }
} }
@ -61,11 +65,12 @@ function _uexport_multirow($query) {
function _uexport_row($query) { function _uexport_row($query) {
$result = array(); $result = array();
$r = q($query); $r = q($query);
if ($r) { if (dbm::is_result($r)) {
foreach($r as $rr) foreach($r as $rr) {
foreach($rr as $k => $v) foreach($rr as $k => $v) {
$result[$k] = $v; $result[$k] = $v;
}
}
} }
return $result; return $result;
} }
@ -89,7 +94,9 @@ function uexport_account($a){
$photo = _uexport_multirow( $photo = _uexport_multirow(
sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) ) sprintf( "SELECT * FROM `photo` WHERE uid = %d AND profile = 1", intval(local_user()) )
); );
foreach ($photo as &$p) $p['data'] = bin2hex($p['data']); foreach ($photo as &$p) {
$p['data'] = bin2hex($p['data']);
}
$pconfig = _uexport_multirow( $pconfig = _uexport_multirow(
sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) ) sprintf( "SELECT * FROM `pconfig` WHERE uid = %d",intval(local_user()) )
@ -118,7 +125,6 @@ function uexport_account($a){
//echo "<pre>"; var_dump(json_encode($output)); killme(); //echo "<pre>"; var_dump(json_encode($output)); killme();
echo json_encode($output); echo json_encode($output);
} }
/** /**
@ -132,9 +138,9 @@ function uexport_all(App $a) {
$r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ", $r = q("SELECT count(*) as `total` FROM `item` WHERE `uid` = %d ",
intval(local_user()) intval(local_user())
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$total = $r[0]['total']; $total = $r[0]['total'];
}
// chunk the output to avoid exhausting memory // chunk the output to avoid exhausting memory
for ($x = 0; $x < $total; $x += 500) { for ($x = 0; $x < $total; $x += 500) {
@ -153,5 +159,4 @@ function uexport_all(App $a) {
$output = array('item' => $r); $output = array('item' => $r);
echo json_encode($output)."\n"; echo json_encode($output)."\n";
} }
} }

View file

@ -54,11 +54,12 @@ function uimport_content(App $a) {
} }
if(x($_SESSION,'theme')) if (x($_SESSION,'theme')) {
unset($_SESSION['theme']); unset($_SESSION['theme']);
if(x($_SESSION,'mobile-theme')) }
if (x($_SESSION,'mobile-theme')) {
unset($_SESSION['mobile-theme']); unset($_SESSION['mobile-theme']);
}
$tpl = get_markup_template("uimport.tpl"); $tpl = get_markup_template("uimport.tpl");
return replace_macros($tpl, array( return replace_macros($tpl, array(