This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
/
input.php
110 lines (83 loc) · 3.25 KB
/
input.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
<?php
$text = `ifconfig`;
preg_match('/([0-9a-f]{2}:){5}\w\w/i', $text, $mac);
$devicemac = $mac[0];
file_put_contents('macaddr.txt', $devicemac);
$url = 'https://yami.run.ymi.com.br/devices/';
$data = array("deviceid" => $devicemac,"cli" => "online");
$ch=curl_init($url);
$data_string = urlencode(json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
system('clear');
echo "DEVICE ID: ".$devicemac."\n";
echo "\nType exit to finish\n";
echo "YMI IOT ready, waiting for command, if you need type help:\n ";
do {
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
$url = 'https://yami.run.ymi.com.br/devices/';
$data = array("deviceid" => $devicemac,"send" => trim($line), "module" => $module);
$ch=curl_init($url);
$data_string = urlencode(json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
$convert_json = (object)json_decode($result);
system('clear');
echo "DEVICE ID: ".$devicemac."\n\n";
$array_not_show = array("back","welcome","exit","help");
if(!in_array($convert_json->answer,$array_not_show)) {
echo "LAST CALL:\n".$convert_json->question."\n\n";
echo "ANSWER: \n";
echo $convert_json->answer."\n\n";
} else if ($convert_json->answer != "welcome" || $convert_json->answer == "help" ) {
echo "You are back to main command line\n\n";
}
if($convert_json->question == "clear") {
system('clear');
echo "DEVICE ID: ".$devicemac."\n";
echo "\nType exit to finish, if you need type help\n";
}
if($convert_json->modules != "") {
echo "\nType the module you want to use\n ";
foreach ($convert_json->modules as $valor) {
echo "".$valor."\n ";
}
echo "\n\n";
}
if($convert_json->answer == "welcome") {
echo "You are in module ".$convert_json->module.":\n ";
if($convert_json->options != "") {
foreach ($convert_json->options as $indice => $valor) {
echo "[".$indice."] ".$valor."\n ";
}
echo "\nType exit to back to main command line\n ";
}
$module = $convert_json->module;
}
if($convert_json->answer == "back") {
$module = "";
}
fclose($handle);
echo "YMI IOT ready, waiting for command, if you need type help:\n ";
} while ($convert_json->answer != "exit");
$url = 'https://yami.run.ymi.com.br/devices/';
$data = array("deviceid" => $devicemac,"cli" => "offline");
$ch=curl_init($url);
$data_string = urlencode(json_encode($data));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
system('clear');
echo "DEVICE ID: ".$devicemac."\n";
echo "Bye bye :) https://ymi.global\n\n\n";
die();
?>