1 |
d776e077
|
Scott Ullrich
|
#!/usr/local/bin/php -f
|
2 |
|
|
|
3 |
|
|
<?php
|
4 |
|
|
|
5 |
|
|
echo "Starting the pfSense shell system";
|
6 |
|
|
|
7 |
|
|
echo ".";
|
8 |
|
|
require("globals.inc");
|
9 |
|
|
$g['booting'] = true;
|
10 |
|
|
require("functions.inc");
|
11 |
|
|
echo ".";
|
12 |
|
|
require("config.inc");
|
13 |
|
|
echo ".";
|
14 |
|
|
$g['booting'] = false;
|
15 |
|
|
|
16 |
cd8ca22f
|
Scott Ullrich
|
function more($text, $count=24) {
|
17 |
5003c48a
|
Scott Ullrich
|
$counter=0;
|
18 |
|
|
$lines = split("\n", $text);
|
19 |
|
|
foreach($lines as $line) {
|
20 |
cd8ca22f
|
Scott Ullrich
|
if($counter > $count) {
|
21 |
5003c48a
|
Scott Ullrich
|
echo "Press RETURN to continue ...";
|
22 |
|
|
$fp = fopen('php://stdin', 'r');
|
23 |
|
|
$pressreturn = chop(fgets($fp));
|
24 |
cd8ca22f
|
Scott Ullrich
|
if($pressreturn == "q" || $pressreturn == "quit")
|
25 |
|
|
return;
|
26 |
5003c48a
|
Scott Ullrich
|
fclose($fp);
|
27 |
|
|
$counter = 0;
|
28 |
|
|
}
|
29 |
|
|
echo "{$line}\n";
|
30 |
|
|
$counter++;
|
31 |
|
|
}
|
32 |
|
|
}
|
33 |
|
|
|
34 |
46d53988
|
Scott Ullrich
|
function show_help() {
|
35 |
|
|
echo "\nExample commands:\n";
|
36 |
|
|
|
37 |
ebe2951e
|
Scott Ullrich
|
echo "\nparse_config(true); # reloads the \$config array\n";
|
38 |
5003c48a
|
Scott Ullrich
|
|
39 |
|
|
echo "\n\$temp = print_r(\$config, true);\n";
|
40 |
|
|
echo "more(\$temp);\n";
|
41 |
|
|
|
42 |
46d53988
|
Scott Ullrich
|
echo "\n/* to output a configuration array */\n";
|
43 |
|
|
echo "print_r(\$config);\n";
|
44 |
|
|
|
45 |
|
|
echo "\n/* to output the interfaces configuration portion of the configuration */\n";
|
46 |
|
|
echo "print_r(\$config['interfaces']);\n";
|
47 |
|
|
|
48 |
|
|
echo "\n/* to output the dhcp server configuration */\n";
|
49 |
|
|
echo "print_r(\$config['dhcpd']);\n";
|
50 |
|
|
|
51 |
|
|
echo "\n/* to enable multiline input mode */\n";
|
52 |
|
|
echo "multiline\n";
|
53 |
|
|
|
54 |
|
|
echo "\n/* to exit the php pfSense shell */\n";
|
55 |
|
|
echo "exit\n";
|
56 |
|
|
|
57 |
|
|
echo "\n/* to output supported wireless modes for an interface */\n";
|
58 |
|
|
echo "print_r(get_wireless_modes(\"ath0\"));\n";
|
59 |
|
|
|
60 |
|
|
echo "\n/* to enable SSH */\n";
|
61 |
|
|
echo "\$config['system']['enablesshd'] = true;\n";
|
62 |
|
|
|
63 |
|
|
echo "\n/* change OPTX to the OPT interface name such as BACKHAUL */\n";
|
64 |
|
|
echo "\$config['interfaces']['optx']['wireless']['standard'] = \"11a\";\n";
|
65 |
|
|
echo "\$config['interfaces']['optx']['wireless']['mode'] = \"hostap\";\n";
|
66 |
|
|
echo "\$config['interfaces']['optx']['wireless']['channel'] = \"6\";\n";
|
67 |
|
|
|
68 |
|
|
echo "\n/* to enable dhcp server for an optx interface */\n";
|
69 |
|
|
echo "\$config['dhcpd']['optx']['enable'] = true;\n";
|
70 |
|
|
echo "\$config['dhcpd']['optx']['range']['from'] = \"192.168.31.100\";\n";
|
71 |
|
|
echo "\$config['dhcpd']['optx']['range']['to'] = \"192.168.31.150\";\n";
|
72 |
|
|
|
73 |
|
|
echo "\n/* to disable the firewall filter */\n";
|
74 |
|
|
echo "\$config['system']['disablefilter'] = true;\n";
|
75 |
|
|
|
76 |
|
|
echo "\n/* to enable an interface and set it for dhcp */\n";
|
77 |
|
|
echo "\$config['interfaces']['optx']['disabled'] = false;\n";
|
78 |
|
|
echo "\$config['interfaces']['optx']['ipaddr'] = \"dhcp\";\n";
|
79 |
|
|
|
80 |
|
|
echo "\n/* to enable an interface and set a static ip address */\n";
|
81 |
|
|
echo "\$config['interfaces']['wan']['disabled'] = false;\n";
|
82 |
|
|
echo "\$config['interfaces']['wan']['ipaddr'] = \"192.168.100.1\";\n";
|
83 |
|
|
echo "\$config['interfaces']['wan']['subnet'] = \"24\";\n";
|
84 |
|
|
|
85 |
|
|
echo "\n/* to save out the new configuration (config.xml) */\n";
|
86 |
|
|
echo "write_config();\n";
|
87 |
|
|
|
88 |
|
|
echo "\n/* to reboot the system after saving */\n";
|
89 |
|
|
echo "system_reboot_sync();";
|
90 |
|
|
}
|
91 |
|
|
|
92 |
d776e077
|
Scott Ullrich
|
$fp = fopen('php://stdin', 'r');
|
93 |
|
|
|
94 |
|
|
echo ".\n\n";
|
95 |
|
|
|
96 |
1b8a2f5c
|
Scott Ullrich
|
$pkg_interface='console';
|
97 |
|
|
|
98 |
d776e077
|
Scott Ullrich
|
$shell_active = true;
|
99 |
|
|
|
100 |
46d53988
|
Scott Ullrich
|
echo "Type \"help\" to show common usage scnenarios.";
|
101 |
d776e077
|
Scott Ullrich
|
|
102 |
|
|
while($shell_active == true) {
|
103 |
ebe2951e
|
Scott Ullrich
|
$command = readline("\n\npfSense shell: ");
|
104 |
d776e077
|
Scott Ullrich
|
if($command == "exit") {
|
105 |
|
|
$shell_active = false;
|
106 |
|
|
echo "\n";
|
107 |
|
|
break;
|
108 |
|
|
}
|
109 |
ebe2951e
|
Scott Ullrich
|
readline_add_history($command);
|
110 |
46d53988
|
Scott Ullrich
|
if($command == "help") {
|
111 |
|
|
show_help();
|
112 |
|
|
$command = "";
|
113 |
|
|
}
|
114 |
40a1b7af
|
Scott Ullrich
|
if($command == "multiline" or $command == "ml") {
|
115 |
|
|
echo "\nmultiline mode enabled. enter EOF on a blank line to execute.\n\n";
|
116 |
|
|
$command = "";
|
117 |
|
|
$mlcommand = "";
|
118 |
|
|
$xxxyzyz = 0;
|
119 |
|
|
while($command <> "EOF") {
|
120 |
|
|
echo "pfSense multiline shell[$xxxyzyz]> ";
|
121 |
ebe2951e
|
Scott Ullrich
|
$command = readline("Command: ");
|
122 |
|
|
readline_add_history($command);
|
123 |
46d53988
|
Scott Ullrich
|
if($command == "help")
|
124 |
|
|
show_help();
|
125 |
40a1b7af
|
Scott Ullrich
|
if($command == "exit")
|
126 |
|
|
die;
|
127 |
|
|
if($command <> "EOF")
|
128 |
|
|
$mlcommand .= $command;
|
129 |
|
|
$xxxyzyz++;
|
130 |
|
|
}
|
131 |
|
|
$command = $mlcommand;
|
132 |
|
|
}
|
133 |
|
|
if($command) {
|
134 |
|
|
echo "\n";
|
135 |
|
|
eval($command);
|
136 |
|
|
}
|
137 |
d776e077
|
Scott Ullrich
|
}
|