SHOW:
|
|
- or go back to the newest paste.
1 | - | --[[ pastebin get gdUXYKyc /programs/reqTypeTest --]] |
1 | + | --[[ pastebin get 4UpdHNnr /programs/link --]] |
2 | local data= "id_machine="..os.getComputerID().."&name=test" | |
3 | - | local url = "http://pbserver.altervista.org/COMPUTERCRAFT/API/machine.php" |
3 | + | local links ={} |
4 | - | |
4 | + | links.machine = "http://pbserver.altervista.org/COMPUTERCRAFT/API/machine.php" |
5 | links.core = "http://pbserver.altervista.org/COMPUTERCRAFT/OS/core.php" | |
6 | - | local req_response |
6 | + | |
7 | local function printReq(url,data) | |
8 | - | req_response = http.get(url) |
8 | + | local req,req_response |
9 | if not data then | |
10 | - | req_response = http.post(url, data) |
10 | + | req= http.get(url) |
11 | else | |
12 | req= http.post(url, data) | |
13 | - | print(req_response.readAll()) |
13 | + | |
14 | - | req_response.close() |
14 | + | req_response=req.readAll() |
15 | req.close() | |
16 | ||
17 | - | printReq(url, data) |
17 | + | return req_response |
18 | - | printReq(url.."?id_machine="..os.getComputerID()) |
18 | + | |
19 | function split (inputstr, sep) | |
20 | if sep == nil then | |
21 | sep = "%s" | |
22 | end | |
23 | local t={} | |
24 | for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
25 | table.insert(t, str) | |
26 | end | |
27 | return t | |
28 | end | |
29 | ||
30 | if(printReq(links.machine.."?id_machine="..os.getComputerID())=="0 results") then | |
31 | printReq(links.machine,"id_machine="..os.getComputerID()) | |
32 | end | |
33 | while(true) do | |
34 | local result= printReq(links.core.."?id_machine="..os.getComputerID()) | |
35 | if(command~="null") then | |
36 | result=split(result,",") | |
37 | if not result[3] then | |
38 | result[3]="" | |
39 | end | |
40 | local status=shell.run(result[2],result[3]) | |
41 | if status== true then | |
42 | status="1" | |
43 | else | |
44 | status="0" | |
45 | end | |
46 | print(result[2]..": "..result[3]) | |
47 | printReq(links.core,"id_command="..result[1].."&status="..status) | |
48 | end | |
49 | os.sleep(30) | |
50 | end |