forked from Alanaktion/MCHostPanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli-run.php
49 lines (42 loc) · 1.4 KB
/
cli-run.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
<?php
// Command-line single-action interface, designed for cron jobs
// Pass parameteres to start/stop servers, more features coming later.
// WARNING: This interface gives direct access to all servers, DO NOT allow any user to access this interface.
// If you are the only one with shell access to your server, this is already protected, otherwise ensure only you can read/execute this file.
/* Example usage:
Start a server: php cli-run.php action=start server=alanaktion
Stop a server: php cli-run.php action=stop server=alanaktion
Restart a server: php cli-run.php action=restart server=alanaktion
Kill a server: php cli-run.php action=kill server=alanaktion
*/
// Verify running from command line
if(php_sapi_name() !== 'cli') {
die();
}
// Parse parameters into $_GET superglobal
parse_str(implode('&', array_slice($argv, 1)), $_GET);
// Verify an action was recieved
if(empty($_GET['action'])) {
die("No action specified. Example usage: php -f action=start server=alanaktion");
}
// Initialize core
chdir(dirname(__FILE__));
require_once 'inc/lib.php';
// Handle actions
switch($_GET['action']) {
case "start":
server_start($_GET['server']);
break;
case "stop":
server_stop($_GET['server']);
break;
case "restart":
server_stop($_GET['server']);
server_start($_GET['server']);
break;
case "kill":
server_kill($_GET['server']);
break;
default:
die("Unknown action: {$_GET['action']}");
}