-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.php
executable file
·111 lines (81 loc) · 2.26 KB
/
shell.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
111
#!/usr/bin/php -q
<?php
/**
* Titanium PHP Console Framework
*
* @author Sean Nieuwoudt
* @copyright Wixel.net
* @license GPL
* @link http://github.com/Wixel/TitaniumPHP-Console
* @link [email protected]:Wixel/TitaniumPHP-Console.git
*/
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR']))
{
define('TITANIUM_CLI' , TRUE);
define('TITANIUM_ROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
define('TICKER' , 'php@localhost » ');
}
else
{
exit;
}
/*-------------------------------------------------
* SETUP CORE
*-------------------------------------------------*/
require_once(TITANIUM_ROOT.'titanium/titanium.php');
require_once(TITANIUM_ROOT.'bridge.inc.php');
Titanium::init();
/*-------------------------------------------------
* CMD LISTENER
*-------------------------------------------------*/
if($argc > 1)
{
if(!defined('RUN_MODE'))
{
define('RUN_MODE', 'CLI');
}
exec_cmd($argv[1], array_slice($argv, 2, count($argv) - 1));
}
else
{
if(!defined('RUN_MODE'))
{
define('RUN_MODE', 'INTERACTIVE');
}
Output::write(Template::render('introduction.tpl.php'), false, true, 2);
print_ticker();
do {
do {
$q = fgets(STDIN);
} while ( trim($q) == '' );
exec_cmd($q);
} while ( true );
}
/*-------------------------------------------------
* DISPATCHER
*-------------------------------------------------*/
function exec_cmd($q, $params = NULL)
{
$match = false;
foreach(Titanium::function_patterns() as $regex => $funct) {
if(preg_match($regex, $q, $matches) > 0) {
if(file_exists('functions/'.$funct.'.php')) {
require_once('functions/'.$funct.'.php');
$match = true;
call_user_func(str_replace('.','_',$funct), $q, $matches, $params);
print_ticker();
}
}
}
if(!$match) {
Output::write(Template::render('errors/invalid-command.tpl.php'), 'red', TRUE);
print_ticker();
}
}
function print_ticker()
{
if(RUN_MODE == 'INTERACTIVE')
{
Output::write(TICKER, 'bold');
}
}