1 |
cb7d18d5
|
Renato Botelho
|
#!/usr/local/bin/php-cgi -f
|
2 |
7d61beba
|
Phil Davis
|
|
3 |
d776e077
|
Scott Ullrich
|
<?php
|
4 |
8acd654a
|
Renato Botelho
|
/*
|
5 |
|
|
* pfSsh
|
6 |
|
|
*
|
7 |
|
|
* part of pfSense (https://www.pfsense.org)
|
8 |
|
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
9 |
|
|
* All rights reserved.
|
10 |
|
|
*
|
11 |
|
|
* Redistribution and use in source and binary forms, with or without
|
12 |
|
|
* modification, are permitted provided that the following conditions are met:
|
13 |
|
|
*
|
14 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
* this list of conditions and the following disclaimer.
|
16 |
|
|
*
|
17 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
* notice, this list of conditions and the following disclaimer in
|
19 |
|
|
* the documentation and/or other materials provided with the
|
20 |
|
|
* distribution.
|
21 |
|
|
*
|
22 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
23 |
|
|
* must display the following acknowledgment:
|
24 |
|
|
* "This product includes software developed by the pfSense Project
|
25 |
|
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
26 |
|
|
*
|
27 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28 |
|
|
* endorse or promote products derived from this software without
|
29 |
|
|
* prior written permission. For written permission, please contact
|
30 |
|
|
* coreteam@pfsense.org.
|
31 |
|
|
*
|
32 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
33 |
|
|
* nor may "pfSense" appear in their names without prior written
|
34 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
35 |
|
|
*
|
36 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
37 |
|
|
* acknowledgment:
|
38 |
|
|
*
|
39 |
|
|
* "This product includes software developed by the pfSense Project
|
40 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41 |
|
|
*
|
42 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54 |
|
|
*/
|
55 |
d776e077
|
Scott Ullrich
|
|
56 |
8a7712ea
|
Scott Ullrich
|
require_once("globals.inc");
|
57 |
f643a1f1
|
Chris Buechler
|
echo "Starting the {$g['product_name']} developer shell";
|
58 |
8a7712ea
|
Scott Ullrich
|
require_once("functions.inc");
|
59 |
d776e077
|
Scott Ullrich
|
echo ".";
|
60 |
8a7712ea
|
Scott Ullrich
|
require_once("config.inc");
|
61 |
d776e077
|
Scott Ullrich
|
echo ".";
|
62 |
8a7712ea
|
Scott Ullrich
|
require_once("util.inc");
|
63 |
415c850d
|
Scott Ullrich
|
echo ".";
|
64 |
d776e077
|
Scott Ullrich
|
|
65 |
7d61beba
|
Phil Davis
|
$shell_cmds = array("alias", "alloc", "bg", "bind", "bindkey", "break",
|
66 |
|
|
"breaksw", "builtins", "case", "cd", "chdir", "command", "complete", "continue", "default",
|
67 |
|
|
"dirs", "do", "done", "echo", "echotc", "elif", "else", "end", "endif", "endsw", "esac", "eval",
|
68 |
|
|
"exec", "exit", "export", "false", "fc", "fg", "filetest", "fi", "for", "foreach", "getopts",
|
69 |
|
|
"glob", "goto", "hash", "hashstat", "history", "hup", "if", "jobid", "jobs", "kill", "limit",
|
70 |
|
|
"local", "log", "login", "logout", "ls-F", "nice", "nohup", "notify", "onintr", "popd",
|
71 |
|
|
"printenv", "pushd", "pwd", "read", "readonly", "rehash", "repeat", "return", "sched", "set",
|
72 |
|
|
"setenv", "settc", "setty", "setvar", "shift", "source", "stop", "suspend", "switch",
|
73 |
|
|
"telltc", "test", "then", "time", "trap", "true", "type", "ulimit", "umask", "unalias",
|
74 |
|
|
"uncomplete", "unhash", "unlimit", "unset", "unsetenv", "until", "wait", "where", "which",
|
75 |
|
|
"while");
|
76 |
7116ab7f
|
Scott Ullrich
|
|
77 |
50fa05d1
|
Scott Ullrich
|
function pipe_cmd($command, $text_to_pipe) {
|
78 |
|
|
$descriptorspec = array(
|
79 |
7d61beba
|
Phil Davis
|
0 => array("pipe", "r"), // stdin
|
80 |
|
|
1 => array("pipe", "w"), // stdout
|
81 |
|
|
2 => array("pipe", "w")); // stderr ?? instead of a file
|
82 |
|
|
|
83 |
50fa05d1
|
Scott Ullrich
|
$fd = proc_open("$command", $descriptorspec, $pipes);
|
84 |
|
|
if (is_resource($fd)) {
|
85 |
7d61beba
|
Phil Davis
|
fwrite($pipes[0], "{$text_to_pipe}");
|
86 |
|
|
fclose($pipes[0]);
|
87 |
|
|
while ($s= fgets($pipes[1], 1024)) {
|
88 |
|
|
// read from the pipe
|
89 |
|
|
$buffer .= $s;
|
90 |
|
|
}
|
91 |
|
|
fclose($pipes[1]);
|
92 |
|
|
fclose($pipes[2]);
|
93 |
50fa05d1
|
Scott Ullrich
|
}
|
94 |
|
|
return $buffer;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
7d61beba
|
Phil Davis
|
if (!function_exists("readline")) {
|
98 |
3d3be836
|
Scott Ullrich
|
function readline() {
|
99 |
|
|
$fp = fopen('php://stdin', 'r');
|
100 |
|
|
$textinput = chop(fgets($fp));
|
101 |
|
|
fclose($fp);
|
102 |
6fee314b
|
Phil Davis
|
return $textinput;
|
103 |
3d3be836
|
Scott Ullrich
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
cd8ca22f
|
Scott Ullrich
|
function more($text, $count=24) {
|
107 |
7d61beba
|
Phil Davis
|
$counter=0;
|
108 |
|
|
$lines = explode("\n", $text);
|
109 |
|
|
foreach ($lines as $line) {
|
110 |
|
|
if ($counter > $count) {
|
111 |
|
|
echo "Press RETURN to continue ...";
|
112 |
|
|
$fp = fopen('php://stdin', 'r');
|
113 |
|
|
$pressreturn = chop(fgets($fp));
|
114 |
|
|
if ($pressreturn == "q" || $pressreturn == "quit") {
|
115 |
|
|
return;
|
116 |
|
|
}
|
117 |
|
|
fclose($fp);
|
118 |
|
|
$counter = 0;
|
119 |
|
|
}
|
120 |
|
|
echo "{$line}\n";
|
121 |
|
|
$counter++;
|
122 |
|
|
}
|
123 |
5003c48a
|
Scott Ullrich
|
}
|
124 |
|
|
|
125 |
46d53988
|
Scott Ullrich
|
function show_help() {
|
126 |
60ff8601
|
Scott Ullrich
|
|
127 |
|
|
$show_help_text = <<<EOF
|
128 |
415c850d
|
Scott Ullrich
|
|
129 |
|
|
Enter a series of commands and then execute the set with "exec".
|
130 |
7d61beba
|
Phil Davis
|
|
131 |
415c850d
|
Scott Ullrich
|
For example:
|
132 |
|
|
echo "foo"; // php command
|
133 |
|
|
echo "foo2"; // php command
|
134 |
|
|
! echo "heh" # shell command
|
135 |
|
|
exec
|
136 |
|
|
|
137 |
60ff8601
|
Scott Ullrich
|
Example commands:
|
138 |
02105da4
|
Scott Ullrich
|
|
139 |
d17af2a5
|
jim-p
|
record <recordingfilename>
|
140 |
|
|
stoprecording
|
141 |
02105da4
|
Scott Ullrich
|
showrecordings
|
142 |
|
|
|
143 |
60ff8601
|
Scott Ullrich
|
parse_config(true); # reloads the \$config array
|
144 |
5003c48a
|
Scott Ullrich
|
|
145 |
60ff8601
|
Scott Ullrich
|
\$temp = print_r(\$config, true);
|
146 |
|
|
more(\$temp);
|
147 |
5003c48a
|
Scott Ullrich
|
|
148 |
60ff8601
|
Scott Ullrich
|
/* to output a configuration array */
|
149 |
|
|
print_r(\$config);
|
150 |
7d61beba
|
Phil Davis
|
|
151 |
4c12ef0a
|
Scott Ullrich
|
/* to output the interfaces configuration portion of config.xml */
|
152 |
60ff8601
|
Scott Ullrich
|
print_r(\$config['interfaces']);
|
153 |
7d61beba
|
Phil Davis
|
|
154 |
60ff8601
|
Scott Ullrich
|
/* to output the dhcp server configuration */
|
155 |
|
|
print_r(\$config['dhcpd']);
|
156 |
415c850d
|
Scott Ullrich
|
|
157 |
f643a1f1
|
Chris Buechler
|
/* to exit the {$g['product_name']} developer shell */
|
158 |
60ff8601
|
Scott Ullrich
|
exit
|
159 |
7d61beba
|
Phil Davis
|
|
160 |
60ff8601
|
Scott Ullrich
|
/* to output supported wireless modes for an interface */
|
161 |
|
|
print_r(get_wireless_modes(\"ath0\"));
|
162 |
7d61beba
|
Phil Davis
|
|
163 |
60ff8601
|
Scott Ullrich
|
/* to enable SSH */
|
164 |
|
|
\$config['system']['enablesshd'] = true;
|
165 |
7d61beba
|
Phil Davis
|
|
166 |
60ff8601
|
Scott Ullrich
|
/* change OPTX to the OPT interface name such as BACKHAUL */
|
167 |
00ea455f
|
Scott Ullrich
|
\$config['interfaces']['optx']['wireless']['standard'] = "11a";
|
168 |
|
|
\$config['interfaces']['optx']['wireless']['mode'] = "hostap";
|
169 |
|
|
\$config['interfaces']['optx']['wireless']['channel'] = "6";
|
170 |
7d61beba
|
Phil Davis
|
|
171 |
60ff8601
|
Scott Ullrich
|
/* to enable dhcp server for an optx interface */
|
172 |
|
|
\$config['dhcpd']['optx']['enable'] = true;
|
173 |
00ea455f
|
Scott Ullrich
|
\$config['dhcpd']['optx']['range']['from'] = "192.168.31.100";
|
174 |
|
|
\$config['dhcpd']['optx']['range']['to'] = "192.168.31.150";
|
175 |
7d61beba
|
Phil Davis
|
|
176 |
60ff8601
|
Scott Ullrich
|
/* to disable the firewall filter */
|
177 |
|
|
\$config['system']['disablefilter'] = true;
|
178 |
7d61beba
|
Phil Davis
|
|
179 |
51b24a30
|
Chris Buechler
|
/* to enable an interface and configure it as a DHCP client */
|
180 |
60ff8601
|
Scott Ullrich
|
\$config['interfaces']['optx']['disabled'] = false;
|
181 |
00ea455f
|
Scott Ullrich
|
\$config['interfaces']['optx']['ipaddr'] = "dhcp";
|
182 |
7d61beba
|
Phil Davis
|
|
183 |
51b24a30
|
Chris Buechler
|
/* to enable an interface and set a static IPv4 address */
|
184 |
|
|
\$config['interfaces']['wan']['enable'] = true;
|
185 |
00ea455f
|
Scott Ullrich
|
\$config['interfaces']['wan']['ipaddr'] = "192.168.100.1";
|
186 |
|
|
\$config['interfaces']['wan']['subnet'] = "24";
|
187 |
7d61beba
|
Phil Davis
|
|
188 |
60ff8601
|
Scott Ullrich
|
/* to save out the new configuration (config.xml) */
|
189 |
|
|
write_config();
|
190 |
7d61beba
|
Phil Davis
|
|
191 |
60ff8601
|
Scott Ullrich
|
/* to reboot the system after saving */
|
192 |
328ab0ae
|
Scott Ullrich
|
system_reboot_sync();
|
193 |
7d61beba
|
Phil Davis
|
|
194 |
60ff8601
|
Scott Ullrich
|
EOF;
|
195 |
|
|
|
196 |
|
|
more($show_help_text);
|
197 |
7d61beba
|
Phil Davis
|
|
198 |
46d53988
|
Scott Ullrich
|
}
|
199 |
|
|
|
200 |
d776e077
|
Scott Ullrich
|
$fp = fopen('php://stdin', 'r');
|
201 |
|
|
|
202 |
|
|
echo ".\n\n";
|
203 |
|
|
|
204 |
1b8a2f5c
|
Scott Ullrich
|
$pkg_interface='console';
|
205 |
|
|
|
206 |
d776e077
|
Scott Ullrich
|
$shell_active = true;
|
207 |
f6907eb4
|
sullrich
|
$tccommands = array();
|
208 |
|
|
|
209 |
|
|
function completion($string, $index) {
|
210 |
|
|
global $tccommands;
|
211 |
|
|
return $tccommands;
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
readline_completion_function("completion");
|
215 |
d776e077
|
Scott Ullrich
|
|
216 |
36cb313b
|
jim-p
|
function get_playback_files() {
|
217 |
|
|
$playback_files = array();
|
218 |
|
|
$files = scandir("/etc/phpshellsessions/");
|
219 |
|
|
foreach ($files as $file) {
|
220 |
d17af2a5
|
jim-p
|
if ($file <> "." && $file <> "..") {
|
221 |
36cb313b
|
jim-p
|
$playback_files[] = $file;
|
222 |
|
|
}
|
223 |
|
|
}
|
224 |
|
|
return $playback_files;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
7d61beba
|
Phil Davis
|
if ($argc < 2) {
|
228 |
f643a1f1
|
Chris Buechler
|
echo "Welcome to the {$g['product_name']} developer shell\n";
|
229 |
b1de6b8b
|
Scott Ullrich
|
echo "\nType \"help\" to show common usage scenarios.\n";
|
230 |
|
|
echo "\nAvailable playback commands:\n ";
|
231 |
f6907eb4
|
sullrich
|
$tccommands[] = "playback";
|
232 |
36cb313b
|
jim-p
|
$playback_files = get_playback_files();
|
233 |
|
|
foreach ($playback_files as $pbf) {
|
234 |
|
|
echo "{$pbf} ";
|
235 |
|
|
if (function_exists("readline_add_history")) {
|
236 |
9e4c0b1f
|
NOYB
|
readline_add_history("playback $pbf");
|
237 |
|
|
$tccommands[] = "$pbf";
|
238 |
f6907eb4
|
sullrich
|
}
|
239 |
b1de6b8b
|
Scott Ullrich
|
}
|
240 |
|
|
echo "\n\n";
|
241 |
415c850d
|
Scott Ullrich
|
}
|
242 |
d776e077
|
Scott Ullrich
|
|
243 |
34af0cab
|
Scott Ullrich
|
$recording = false;
|
244 |
93a3d242
|
Scott Ullrich
|
$playback_file_split = array();
|
245 |
|
|
$playbackbuffer = "";
|
246 |
|
|
|
247 |
7d61beba
|
Phil Davis
|
if ($argv[1]=="playback" or $argv[1]=="run") {
|
248 |
36cb313b
|
jim-p
|
if (empty($argv[2]) || !file_exists("/etc/phpshellsessions/" . basename($argv[2]))) {
|
249 |
|
|
echo "Error: Invalid playback file specified.\n\n";
|
250 |
e296be60
|
Chris Buechler
|
show_recordings();
|
251 |
36cb313b
|
jim-p
|
exit(-1);
|
252 |
47643f5b
|
Scott Ullrich
|
}
|
253 |
36cb313b
|
jim-p
|
playback_file(basename($argv[2]));
|
254 |
415c850d
|
Scott Ullrich
|
exit;
|
255 |
|
|
}
|
256 |
|
|
|
257 |
f6907eb4
|
sullrich
|
// Define more commands
|
258 |
|
|
$tccommands[] = "exit";
|
259 |
|
|
$tccommands[] = "quit";
|
260 |
|
|
$tccommands[] = "?";
|
261 |
|
|
$tccommands[] = "exec";
|
262 |
|
|
$tccommands[] = "stoprecording";
|
263 |
|
|
$tccommands[] = "showrecordings";
|
264 |
|
|
$tccommands[] = "record";
|
265 |
|
|
$tccommands[] = "reset";
|
266 |
e788b01d
|
sullrich
|
$tccommands[] = "master";
|
267 |
|
|
$tccommands[] = "RELENG_1_2";
|
268 |
f6907eb4
|
sullrich
|
|
269 |
7d61beba
|
Phil Davis
|
while ($shell_active == true) {
|
270 |
b9e3a295
|
Scott Ullrich
|
$command = readline("{$g['product_name']} shell: ");
|
271 |
415c850d
|
Scott Ullrich
|
readline_add_history($command);
|
272 |
7d61beba
|
Phil Davis
|
$command_split = explode(" ", $command);
|
273 |
|
|
$first_command = $command_split[0];
|
274 |
|
|
if ($first_command == "playback" || $first_command == "run") {
|
275 |
415c850d
|
Scott Ullrich
|
$playback_file = $command_split[1];
|
276 |
7d61beba
|
Phil Davis
|
if (!$playback_file || !file_exists("/etc/phpshellsessions/{$playback_file}")) {
|
277 |
415c850d
|
Scott Ullrich
|
$command = "";
|
278 |
|
|
echo "Could not locate playback file.\n";
|
279 |
|
|
} else {
|
280 |
|
|
$command = "";
|
281 |
|
|
echo "\nPlayback of file {$command_split[1]} started.\n\n";
|
282 |
|
|
playback_file("{$playback_file}");
|
283 |
|
|
continue;
|
284 |
|
|
}
|
285 |
|
|
}
|
286 |
7d61beba
|
Phil Davis
|
if ($first_command == "exit" or $first_command == "quit") {
|
287 |
9f2820d8
|
Scott Ullrich
|
die;
|
288 |
7d61beba
|
Phil Davis
|
}
|
289 |
|
|
if ($first_command == "help" or $first_command == "?") {
|
290 |
9f2820d8
|
Scott Ullrich
|
show_help();
|
291 |
|
|
$playbackbuffer = "";
|
292 |
|
|
continue;
|
293 |
|
|
}
|
294 |
7d61beba
|
Phil Davis
|
if ($first_command == "exec" or $first_command == "exec;") {
|
295 |
415c850d
|
Scott Ullrich
|
playback_text($playbackbuffer);
|
296 |
|
|
$playbackbuffer = "";
|
297 |
|
|
continue;
|
298 |
|
|
}
|
299 |
7d61beba
|
Phil Davis
|
if ($first_command == "stoprecording" || $first_command == "stoprecord" || $first_command == "stop") {
|
300 |
|
|
if ($recording) {
|
301 |
415c850d
|
Scott Ullrich
|
fwrite($recording_fd, $playbackbuffer);
|
302 |
|
|
fclose($recording_fd);
|
303 |
|
|
$command = "";
|
304 |
|
|
conf_mount_ro();
|
305 |
|
|
echo "Recording stopped.\n";
|
306 |
7d61beba
|
Phil Davis
|
$recording = false;
|
307 |
415c850d
|
Scott Ullrich
|
} else {
|
308 |
|
|
echo "No recording session in progress.\n";
|
309 |
|
|
$command = "";
|
310 |
|
|
}
|
311 |
|
|
}
|
312 |
7d61beba
|
Phil Davis
|
if ($first_command == "showrecordings") {
|
313 |
4c12ef0a
|
Scott Ullrich
|
show_recordings();
|
314 |
7d61beba
|
Phil Davis
|
$command = "";
|
315 |
415c850d
|
Scott Ullrich
|
}
|
316 |
7d61beba
|
Phil Davis
|
if ($first_command == "reset") {
|
317 |
415c850d
|
Scott Ullrich
|
$playbackbuffer = "";
|
318 |
|
|
echo "\nBuffer reset.\n\n";
|
319 |
|
|
continue;
|
320 |
|
|
}
|
321 |
7d61beba
|
Phil Davis
|
if ($first_command == "record") {
|
322 |
|
|
if (!$command_split[1]) {
|
323 |
415c850d
|
Scott Ullrich
|
echo "usage: record playbackname\n";
|
324 |
d17af2a5
|
jim-p
|
echo "\tplaybackname will be created in /etc/phpshellsessions.\n";
|
325 |
415c850d
|
Scott Ullrich
|
$command = "";
|
326 |
|
|
} else {
|
327 |
|
|
/* time to record */
|
328 |
|
|
conf_mount_rw();
|
329 |
|
|
safe_mkdir("/etc/phpshellsessions");
|
330 |
d17af2a5
|
jim-p
|
$recording_fn = basename($command_split[1]);
|
331 |
|
|
$recording_fd = fopen("/etc/phpshellsessions/{$recording_fn}","w");
|
332 |
7d61beba
|
Phil Davis
|
if (!$recording_fd) {
|
333 |
415c850d
|
Scott Ullrich
|
echo "Could not start recording session.\n";
|
334 |
34af0cab
|
Scott Ullrich
|
$command = "";
|
335 |
7d61beba
|
Phil Davis
|
} else {
|
336 |
415c850d
|
Scott Ullrich
|
$recording = true;
|
337 |
d17af2a5
|
jim-p
|
echo "Recording of {$recording_fn} started.\n";
|
338 |
34af0cab
|
Scott Ullrich
|
$command = "";
|
339 |
|
|
}
|
340 |
93a3d242
|
Scott Ullrich
|
}
|
341 |
415c850d
|
Scott Ullrich
|
}
|
342 |
|
|
$playbackbuffer .= $command . "\n";
|
343 |
93a3d242
|
Scott Ullrich
|
}
|
344 |
|
|
|
345 |
4c12ef0a
|
Scott Ullrich
|
function show_recordings() {
|
346 |
|
|
echo "==> Sessions available for playback are:\n";
|
347 |
d17af2a5
|
jim-p
|
$playback_files = get_playback_files();
|
348 |
|
|
foreach (get_playback_files() as $pbf) {
|
349 |
|
|
echo "{$pbf} ";
|
350 |
|
|
}
|
351 |
|
|
echo "\n\n";
|
352 |
7d61beba
|
Phil Davis
|
echo "==> end of list.\n";
|
353 |
4c12ef0a
|
Scott Ullrich
|
}
|
354 |
|
|
|
355 |
93a3d242
|
Scott Ullrich
|
function returnlastchar($command) {
|
356 |
|
|
$commandlen = strlen($command);
|
357 |
|
|
$endofstring = substr($command, ($commandlen-1));
|
358 |
7d61beba
|
Phil Davis
|
return $endofstring;
|
359 |
93a3d242
|
Scott Ullrich
|
}
|
360 |
|
|
|
361 |
|
|
function returnfirstchar($command) {
|
362 |
|
|
$commandlen = strlen($command);
|
363 |
|
|
$endofstring = substr($command, 0, 1);
|
364 |
7d61beba
|
Phil Davis
|
return $endofstring;
|
365 |
93a3d242
|
Scott Ullrich
|
}
|
366 |
|
|
|
367 |
|
|
function str_replace_all($search,$replace,$subject) {
|
368 |
7d61beba
|
Phil Davis
|
while (strpos($subject,$search)!==false) {
|
369 |
93a3d242
|
Scott Ullrich
|
$subject = str_replace($search,$replace,$subject);
|
370 |
7d61beba
|
Phil Davis
|
}
|
371 |
93a3d242
|
Scott Ullrich
|
return $subject;
|
372 |
d776e077
|
Scott Ullrich
|
}
|
373 |
46d53988
|
Scott Ullrich
|
|
374 |
415c850d
|
Scott Ullrich
|
function playback_text($playback_file_contents) {
|
375 |
cfbfd941
|
smos
|
$playback_file_split = explode("\n", $playback_file_contents);
|
376 |
8586a962
|
Scott Ullrich
|
$playback_text = "require_once('functions.inc');\n";
|
377 |
|
|
$playback_text .= "require_once('globals.inc');\n";
|
378 |
|
|
$playback_text .= "require_once('config.inc');\n";
|
379 |
415c850d
|
Scott Ullrich
|
$toquote = '"';
|
380 |
7d61beba
|
Phil Davis
|
$toquotereplace = '\\"';
|
381 |
|
|
foreach ($playback_file_split as $pfs) {
|
382 |
415c850d
|
Scott Ullrich
|
$firstchar = returnfirstchar($pfs);
|
383 |
|
|
$currentline = $pfs;
|
384 |
7d61beba
|
Phil Davis
|
if ($firstchar == "!") {
|
385 |
415c850d
|
Scott Ullrich
|
/* XXX: encode " in $pfs */
|
386 |
|
|
$pfsa = str_replace($toquote, $toquotereplace, $currentline);
|
387 |
|
|
$playback_text .= str_replace("!", "system(\"", $pfsa) . "\");\n";
|
388 |
|
|
} else if ($firstchar == "=") {
|
389 |
|
|
/* XXX: encode " in $pfs */
|
390 |
|
|
$pfsa = str_replace($toquote, $toquotereplace, $currentline);
|
391 |
|
|
$currentline .= str_replace("!", "system(\"", $pfsa) . "\");\n";
|
392 |
|
|
} else {
|
393 |
|
|
$playback_text .= $pfs . "\n";
|
394 |
|
|
}
|
395 |
|
|
}
|
396 |
bde982dd
|
jim-p
|
global $config;
|
397 |
415c850d
|
Scott Ullrich
|
eval($playback_text);
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
function playback_file($playback_file) {
|
401 |
|
|
$playback_file_contents = file_get_contents("/etc/phpshellsessions/{$playback_file}");
|
402 |
|
|
playback_text($playback_file_contents);
|
403 |
|
|
}
|
404 |
|
|
|
405 |
cfbfd941
|
smos
|
?>
|