Project

General

Profile

Download (1.91 KB) Statistics
| Branch: | Tag: | Revision:
1
#! /usr/local/bin/php-cgi -f
2
<?php
3
/*
4
 * rc.initial.toggle_sshd
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7
 * Copyright (c) 2004 Fred Mol <fredmol@xs4all.nl>.
8
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 * http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23

    
24
require_once("config.inc");
25
require_once("functions.inc");
26
require_once("filter.inc");
27

    
28

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

    
31
if (isset($config['system']['enablesshd'])) {
32
	echo "SSHD is currently enabled.  Would you like to disable? [y/n]? ";
33
	$yn = chop(fgets($fp));
34
	if ($yn[0] == "y") {
35
		unset($config['system']['enablesshd']);
36
		echo "\nWriting configuration...";
37
		write_config(gettext("Disabled SSHD from console menu."));
38
		echo " done.\n";
39
		echo "\nDisabling SSHD...";
40
		send_event("service reload sshd");
41
		echo "\nReloading firewall rules.";
42
		filter_configure();
43
		echo " done.\n";
44
		exec("ps awux | grep '/usr/sbin/sshd' | grep -v grep | awk '{print $2}' | xargs kill");
45
	}
46

    
47
} else {
48
	echo "SSHD is currently disabled.  Would you like to enable? [y/n]? ";
49
	$yn = chop(fgets($fp));
50
	if ($yn[0] == "y") {
51
		$config['system']['enablesshd'] = true;
52
		echo "\nWriting configuration...";
53
		write_config(gettext("Enabled SSHD from console menu."));
54
		echo " done.\n";
55
		echo "\nEnabling SSHD...";
56
		send_event("service reload sshd");
57
		echo "\nReloading firewall rules.";
58
		filter_configure();
59
		echo " done.\n\n";
60
	}
61
}
62

    
63
fclose($fp);
64

    
(45-45/79)