72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
// Global functions
|
|
|
|
function jsonify($body, $code = null)
|
|
{
|
|
if ($code) {
|
|
http_response_code($code);
|
|
}
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode($body);
|
|
|
|
exit;
|
|
}
|
|
|
|
|
|
function get_included_contents($filename) {
|
|
ob_start();
|
|
include $filename;
|
|
return ob_get_clean();
|
|
}
|
|
|
|
function get_url_content($url){
|
|
$domain = parse_url($url, PHP_URL_HOST);
|
|
if (gethostbyname($domain) === "127.0.0.1") {
|
|
jsonify(["message" => "Unacceptable URL"]);
|
|
}
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
|
|
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
|
|
$url_content = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $url_content;
|
|
}
|
|
|
|
function make_api_call($action, $data, $uri_path, $is_file = false){
|
|
if ($is_file) {
|
|
$post = [
|
|
'data' => file_get_contents($data),
|
|
'action' => $action,
|
|
'uri_path' => $uri_path
|
|
];
|
|
} else {
|
|
$post = [
|
|
'data' => $data,
|
|
'action' => $action,
|
|
'uri_path' => $uri_path
|
|
];
|
|
}
|
|
|
|
$ch = curl_init();
|
|
$url = 'http://api.haxtables.htb' . $uri_path . '/index.php';
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
|
|
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
|
|
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
|
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $response;
|
|
|
|
|
|
}
|
|
|
|
?>
|