Update webpagetool.php
This commit is contained in:
parent
ae0e6f85db
commit
dc56f6b737
|
@ -18,6 +18,7 @@
|
||||||
/* * GET/FGC: $response = get_web_page($url, "get.fgc"); */
|
/* * GET/FGC: $response = get_web_page($url, "get.fgc"); */
|
||||||
/* * GET/WGET: $response = get_web_page($url, "get.wget"); */
|
/* * GET/WGET: $response = get_web_page($url, "get.wget"); */
|
||||||
/* * GET/ARIA: $response = get_web_page($url, "get.aria"); */
|
/* * GET/ARIA: $response = get_web_page($url, "get.aria"); */
|
||||||
|
/* * GET/HTTPIE: $response = get_web_page($url, "get.httpie"); */
|
||||||
/* * PRINT: echo $response['content']; */
|
/* * PRINT: echo $response['content']; */
|
||||||
/****** } // END EXAMPLES *****/
|
/****** } // END EXAMPLES *****/
|
||||||
|
|
||||||
|
@ -324,13 +325,12 @@ if(!is_fn("get_web_aria")) {
|
||||||
|
|
||||||
// set headers
|
// set headers
|
||||||
foreach($headers as $k=>$v) {
|
foreach($headers as $k=>$v) {
|
||||||
// the same as --header
|
|
||||||
if(is_array($v)) {
|
if(is_array($v)) {
|
||||||
if($k == "Authentication") {
|
if($k == "Authentication") {
|
||||||
if($v[0] == "Basic" && check_array_length($v, 3) == 0) {
|
if($v[0] == "Basic" && check_array_length($v, 3) == 0) {
|
||||||
$args[] = sprintf("--header='Authentication: Basic %s'", base64_decode($v[1] . ":" . $v[2]));
|
$args[] = sprintf("--header='%s: Basic %s'", $k, base64_decode($v[1] . ":" . $v[2]));
|
||||||
} else {
|
} else {
|
||||||
$args[] = sprintf("--header='%s: %s'", $k, make_safe_argument(implode("", $v)));
|
$args[] = sprintf("--header='%s: %s %s'", $k, make_safe_argument(implode(" ", $v)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -354,6 +354,73 @@ if(!is_fn("get_web_aria")) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!is_fn("get_web_httpie")) {
|
||||||
|
function get_web_httpie($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) {
|
||||||
|
$content = false;
|
||||||
|
|
||||||
|
$filename = make_random_id(32);
|
||||||
|
$fw = write_storage_file("", array(
|
||||||
|
"filename" => $filename,
|
||||||
|
"mode" => "fake"
|
||||||
|
));
|
||||||
|
|
||||||
|
// init args
|
||||||
|
$args = array();
|
||||||
|
|
||||||
|
// make args
|
||||||
|
$args[] = "http";
|
||||||
|
|
||||||
|
// set method, URL
|
||||||
|
if($method == "jsondata") {
|
||||||
|
$args[] = "POST";
|
||||||
|
$args[] = $url;
|
||||||
|
$args[] = sprintf("body='%s'", json_encode($data));
|
||||||
|
} elseif($method == "post") {
|
||||||
|
$args[] = "POST";
|
||||||
|
$args[] = $url;
|
||||||
|
$args[] = sprintf("body='%s'", http_build_query($data));
|
||||||
|
} else {
|
||||||
|
$args[] = get_web_build_qs($url, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set timeout
|
||||||
|
$args[] = "--timeout=" . $t_out;
|
||||||
|
|
||||||
|
// set proxy
|
||||||
|
if(!empty($proxy)) {
|
||||||
|
$args[] = "--proxy=" . $proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set headers
|
||||||
|
foreach($headers as $k=>$v) {
|
||||||
|
if(is_array($v)) {
|
||||||
|
if($k == "Authentication") {
|
||||||
|
if($v[0] == "Basic" && check_array_length($v, 3) == 0) {
|
||||||
|
$args[] = sprintf("-a '%s:%s'", $v[1], $v[2]);
|
||||||
|
} else {
|
||||||
|
$args[] = sprintf("'%s:%s'", $k, make_safe_argument(implode(" ", $v)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$args[] = sprintf("'%s:%s'", make_safe_argument($k), make_safe_argument($v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set output file
|
||||||
|
$args[] = ">";
|
||||||
|
$args[] = $fw;
|
||||||
|
|
||||||
|
// execute a command
|
||||||
|
$cmd = implode(" ", $args);
|
||||||
|
exec_command($cmd);
|
||||||
|
|
||||||
|
// read contents
|
||||||
|
$content = read_storage_file($filename);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!is_fn("get_web_curl")) {
|
if(!is_fn("get_web_curl")) {
|
||||||
function get_web_curl($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) {
|
function get_web_curl($url, $method="get", $data=array(), $proxy="", $ua="", $ct_out=45, $t_out=45, $headers=array()) {
|
||||||
$content = false;
|
$content = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user