-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin.php
55 lines (48 loc) · 1.07 KB
/
win.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
<?php
// win tools
class WinTools {
private $active;
private $commands;
public function __construct() {
$this->commands = [
'1' => ['Test DNS', 'ping -t 210.16.120.139'],
'2' => ['Shutdown in 2 hours', 'shutdown -s -t 7200'],
];
}
public function run() {
$this->active = true;
while ($this->active) {
$this->print_menu();
$input = fgets(STDIN);
$this->interpret_input(trim($input));
}
}
private function print_menu() {
$text = '';
foreach ($this->commands as $key => $value) {
list($label, $comm) = $value;
$text .= "[$key] $label\n";
}
$text .= "[q]/[exit] Close\n\n";
$text .= 'Choose: ';
echo $text;
}
private function interpret_input($input) {
echo "You chose [{$input}]\n\n";
if ($input === 'exit' || $input === 'q') {
$this->active = false;
echo "Goodbye\n";
return;
} else if (isset($this->commands[$input])) {
list($label, $comm) = $this->commands[$input];
system($comm);
return;
} else {
echo "UNRECOGNIZED\n";
}
echo "Press Enter...";
fgets(STDIN);
}
}
$p = new WinTools();
$p->run();