summaryrefslogtreecommitdiffstats
path: root/usr/local/sbin/pfSsh.php
blob: 0d77220d8074f1cb35d45e0a75ede009d960cd65 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/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;

function show_help() {
	echo "\nExample commands:\n";
	
	echo "\nparse_config(true);  # reloads the \$config array\n";
	
	echo "\n/* to output a configuration array */\n";
	echo "print_r(\$config);\n";
	
	echo "\n/* to output the interfaces configuration portion of the configuration */\n";
	echo "print_r(\$config['interfaces']);\n";
	
	echo "\n/* to output the dhcp server configuration */\n";
	echo "print_r(\$config['dhcpd']);\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 output supported wireless modes for an interface */\n";
	echo "print_r(get_wireless_modes(\"ath0\"));\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 dhcp server for an optx interface */\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";
	
	echo "\n/* to reboot the system after saving */\n";
	echo "system_reboot_sync();";
}

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

echo ".\n\n";

$pkg_interface='console';

$shell_active = true;

echo "Type \"help\" to show common usage scnenarios.";

while($shell_active == true) {
        $command = readline("\n\npfSense shell: ");
        if($command == "exit") {
                $shell_active = false;
                echo "\n";
                break;
		}
		readline_add_history($command);
	    if($command == "help") {
	    	show_help();
	    	$command = "";
	    }
		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 = readline("Command: ");
		        readline_add_history($command);
		        if($command == "help") 
		        	show_help();
		        if($command == "exit") 
		        	die;
		        if($command <> "EOF") 
		        	$mlcommand .= $command;
		        $xxxyzyz++;
			}
			$command = $mlcommand;
		}
		if($command) {
			echo "\n";
	        eval($command); 
	    }
}

OpenPOWER on IntegriCloud