summaryrefslogtreecommitdiffstats
path: root/usr/local/sbin/pfSsh.php
blob: ca3e82fbda07fbc02c735ccb418bd0ebb615a31c (plain)
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
#!/usr/local/bin/php -f
 
<?php

echo "Starting the pfSense shell system";

echo ".";
require("globals.inc");
$g['booting'] = true;
require("functions.inc");
echo ".";
require("config.inc");
echo ".";
$g['booting'] = false;

$fp = fopen('php://stdin', 'r');

echo ".\n\n";

$shell_active = true;

echo "\nExample commands:\n";

echo "\n/* to output a configuration array */\n";
echo "nprint_r(\$config);\n";

echo "\n/* to enable multiline input mode */\n";
echo "multiline\n";

echo "\n/* to exit the php pfSense shell */\n";
echo "exit\n";

echo "\n/* to enable SSH */\n";
echo "\$config['system']['enablesshd'] = true;\n";

echo "\n/* change OPTX to the OPT interface name such as BACKHAUL */\n";
echo "\$config['interfaces']['optx']['wireless']['standard'] = \"11a\";\n";
echo "\$config['interfaces']['optx']['wireless']['mode'] = \"hostap\";\n";
echo "\$config['interfaces']['optx']['wireless']['channel'] = \"6\";\n";

echo "\n/* to enable server */\n";
echo "\$config['dhcpd']['optx']['enable'] = true;\n";
echo "\$config['dhcpd']['optx']['range']['from'] = \"192.168.31.100\";\n";
echo "\$config['dhcpd']['optx']['range']['to'] = \"192.168.31.150\";\n";

echo "\n/* to disable the firewall filter */\n";
echo "\$config['system']['disablefilter'] = true;\n";

echo "\n/* to enable an interface and set it for dhcp */\n";
echo "\$config['interfaces']['optx']['disabled'] = false;\n";
echo "\$config['interfaces']['optx']['ipaddr'] = \"dhcp\";\n";

echo "\n/* to enable an interface and set a static ip address */\n";
echo "\$config['interfaces']['wan']['disabled'] = false;\n";
echo "\$config['interfaces']['wan']['ipaddr'] = \"192.168.100.1\";\n";
echo "\$config['interfaces']['wan']['subnet'] = \"24\";\n";

echo "\n/* to save out the new configuration (config.xml) */\n";
echo "write_config();\n";

while($shell_active == true) {
        echo "\n\npfSense shell> ";
        $command = chop(fgets($fp));
        if($command == "exit") {
                $shell_active = false;
                echo "\n";
                break;
		}
		if($command == "multiline" or $command == "ml") {
			echo "\nmultiline mode enabled.  enter EOF on a blank line to execute.\n\n";
			$command = "";
			$mlcommand = "";
			$xxxyzyz = 0;
			while($command <> "EOF") {
				echo "pfSense multiline shell[$xxxyzyz]> ";
		        $command = chop(fgets($fp));
		        if($command == "exit") 
		        	die;
		        if($command <> "EOF") 
		        	$mlcommand .= $command;
		        $xxxyzyz++;
			}
			$command = $mlcommand;
		}
		if($command) {
			echo "\n";
	        eval($command); 
	    }
}
OpenPOWER on IntegriCloud