forked from EvilHero90/TFS-lua-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_ui.php
executable file
·115 lines (98 loc) · 2.69 KB
/
api_ui.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once 'engine/init.php';
include 'layout/overall/header.php';
require_once 'lua_api/sender.php';
$protocol_API = new Tibia_protocol_API();
$action = $_GET['action'];
foreach ($_GET as $k => $v) {
if ($k !== 'action') {
$header = $k;
$value = $v;
}
}
$header = ($header ? $header : 'lua');
$value = ($value ? $value : '');
$response = "";
$online = true;
$codes = array(
'pong' => 100,
'execute' => 101,
'request' => 102,
);
try {
$response = $protocol_API->send_request($codes['pong']);
if ($response) {
$response = "Server online!";
}
} catch (exception $e) {
$online = false;
}
if ($online && isset($action)) {
if (isset($codes[$action])) {
$response = $protocol_API->send_request($codes[$action], $action, $header, $value);
if ($response) {
$response = substr($response, 5 + strlen($action) + 3);
}
}
}
echo '<!-- Action -->
<div class="parent">
<form action="" method="get" onsubmit="send()">
<p>Action</p>
<select id="action" name="action" onchange="switchLayout()">
<option value="execute">Execute</option>
<option value="request">HTTP request</option>
</select>
<input type="submit" value="Send">
<br>
<br>
<div id="msg" class="left">
<p>Send to server</p>
<input type="text" id="header" value="'.$header.'" disabled="disabled" style="width: 325px">
<br><br>
<textarea id="hvalue" name="'.$header.'">'.$value.'</textarea>
<br><br>
</div>
</form>
<div id="resp" class="right">
<p>Response from server</p>
<input type="text" value="'.($action ? $action.' action returned:' : 'n/a').'" disabled="disabled" style="width: 325px">
<br><br>
<textarea disabled="disabled">'.($online ? $response : "Server is offline...").'</textarea>
<br>
</div>
<br>
<br>
</div>
<style type="text/css">
textarea {
width: 325px;
height: 200px;
}
p {
padding: 0 0 5px 0;
margin-bottom: 0;
font-weight: bold;
}
.parent {
clear: both;
}
.left, .center, .right{
float: left;
}
</style>
<script>
function send() {
document.getElementById("hvalue").name = document.getElementById("header").value;
}
function switchLayout() {
if (document.getElementById("action").value === "execute") {
document.getElementById("header").value = "lua";
document.getElementById("header").disabled = "disabled";
} else {
document.getElementById("header").disabled = "";
}
}
</script>';
include 'layout/overall/footer.php';
?>