forked from balsama/Missile-Attack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.php
50 lines (44 loc) · 1.94 KB
/
rest.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
<?php
/**
* This is a REST api for the attack.py script.
*
* usage: rest.php?cmd=right&val=500
*/
?>
<!DOCTYPE html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<link rel="stylesheet" href="main.css">
</head>
<body>
<?php
if (!empty($_GET['cmd']) && !empty($_GET['val'])) {
$cmd = 'sudo python ' . $_SERVER['DOCUMENT_ROOT'] . '/attack.py ' . $_GET['cmd'] . ' ' . $_GET['val'];
$fire = shell_exec($cmd);
echo '<h1>Send command: ' . $cmd . '</h1>';
} else {
echo '<h1>not enough parameter</h1>';
echo '<p>usage: rest.php?cmd=right&val=500</p>';
}
?>
<h2>PHP REST API</h2>
<p>jQuery.get() is used to fire a get request to the api</p>
<p>Call this site with url parameter like "?cmd=right&val=500"</p>
<ul>
<li onclick="$.get( '?cmd=right&val=500');">go right 500 ms</li>
<li onclick="$.get( '?cmd=left&val=500');">go left 500 ms</li>
<li onclick="$.get( '?cmd=up&val=500');">go up 500 ms</li>
<li onclick="$.get( '?cmd=down&val=500');">go down 500 ms</li>
<li onclick="$.get( '?cmd=zero&val=1');">go to zero</li>
<li onclick="$.get( '?cmd=fire&val=1');">FIRE!</li>
</ul>
<p>for continuous movement press and hold the mouse button.</p>
<ul>
<li onmousedown="$.get( '?cmd=right&val=-1');" onmouseup="$.get( '?cmd=stop&val=1');">continous right</li>
<li onmousedown="$.get( '?cmd=left&val=-1');" onmouseup="$.get( '?cmd=stop&val=1');">continous left</li>
<li onmousedown="$.get( '?cmd=up&val=-1');" onmouseup="$.get( '?cmd=stop&val=1');">continous up</li>
<li onmousedown="$.get( '?cmd=down&val=-1');" onmouseup="$.get( '?cmd=stop&val=1');">continous down</li>
<li onmousedown="$.get( '?cmd=stop&val=1');" onmouseup="$.get( '?cmd=stop&val=1');">emergency stop</li>
</ul>
</body>
</html>