1
|
#!/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
|
function more($text, $count=24) {
|
17
|
$counter=0;
|
18
|
$lines = split("\n", $text);
|
19
|
foreach($lines as $line) {
|
20
|
if($counter > $count) {
|
21
|
echo "Press RETURN to continue ...";
|
22
|
$fp = fopen('php://stdin', 'r');
|
23
|
$pressreturn = chop(fgets($fp));
|
24
|
if($pressreturn == "q" || $pressreturn == "quit")
|
25
|
return;
|
26
|
fclose($fp);
|
27
|
$counter = 0;
|
28
|
}
|
29
|
echo "{$line}\n";
|
30
|
$counter++;
|
31
|
}
|
32
|
}
|
33
|
|
34
|
function show_help() {
|
35
|
echo "\nExample commands:\n";
|
36
|
|
37
|
echo "\nparse_config(true); # reloads the \$config array\n";
|
38
|
|
39
|
echo "\n\$temp = print_r(\$config, true);\n";
|
40
|
echo "more(\$temp);\n";
|
41
|
|
42
|
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
|
$fp = fopen('php://stdin', 'r');
|
93
|
|
94
|
echo ".\n\n";
|
95
|
|
96
|
$pkg_interface='console';
|
97
|
|
98
|
$shell_active = true;
|
99
|
|
100
|
echo "Type \"help\" to show common usage scnenarios.";
|
101
|
|
102
|
while($shell_active == true) {
|
103
|
$command = readline("\n\npfSense shell: ");
|
104
|
if($command == "exit") {
|
105
|
$shell_active = false;
|
106
|
echo "\n";
|
107
|
break;
|
108
|
}
|
109
|
readline_add_history($command);
|
110
|
if($command == "help") {
|
111
|
show_help();
|
112
|
$command = "";
|
113
|
}
|
114
|
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
|
$command = readline("Command: ");
|
122
|
readline_add_history($command);
|
123
|
if($command == "help")
|
124
|
show_help();
|
125
|
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
|
}
|
138
|
|