-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.api.php
87 lines (69 loc) · 2.48 KB
/
tool.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
define("DEBUG_MODE", true);
define("DEBUG_STRICT", false);
define("DEBUG_VERBOSE", false);
define("DEBUG_LOGGING", false);
error_reporting(-1);
set_error_handler(array('Debug', 'ErrorHandler'));
register_shutdown_function(array('Debug', 'EndOfExecution'));
Debug::Set(DEBUG_MODE, DEBUG_STRICT, DEBUG_VERBOSE, DEBUG_LOGGING);
function __autoload($class_name)
{
require_once('classes/Class.'.$class_name.'.php');
}
IncludeFromFolder("classes/");
$html = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SMPL API Tool</title>
</head>
<body id="home">
<h1>SMPL API Tool</h1>
<form action="?" method="post">
<label for="http-path">Target URI:</label>
<input type="text" value="'.$_POST['http-path'].'" id="http-path" name="http-path" /><br/>
<label for="http-header-text">HTTP Header information:</label>
<textarea id="http-header-text" name="http-header-text" style="width: 500px; height: 125px">'.$_POST['http-header-text'].'</textarea><br/>
<button type="submit" name="testHttp">Test Request</button>
</form>';
$statusMessage = null;
if (isset($_POST['testHttp'])) $statusMessage = TestHttpRequest($_POST['http-path'], $_POST['http-header-text']);
//if (isset($_POST)) $statusMessage = print_r($_POST, true);
//if (isset($_POST)) $statusMessage .= print_r(explode("\n", $_POST['http-header-text']), true);
$html .= $statusMessage
.'</body>
</html>';
echo $html;
function IncludeFromFolder($folder)
{
foreach (glob("{$folder}*.php") as $filename)
{
//print('Including '.$filename.'<br>');
require_once($filename);
}
}
function TestHttpRequest($uri, $httpRequest)
{
$ch = curl_init($uri);
$header = explode("\n", $httpRequest);
$msg = "<pre>HTTP Request:\n";
foreach($header as $line)
$msg .= $line."\n";
//curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
if($output === false)
{
echo 'Curl error: ' . curl_error($ch);
}
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$msg .= "</pre><pre style=\"color: #fff; background-color: #000;\">\n\nHTTP Response:\n".$output.'</pre>';
return $msg;
}
?>