Project

General

Profile

Download (2.44 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-2013 BSD Perimeter
9
 * Copyright (c) 2013-2016 Electric Sheep Fencing
10
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
require_once("config.inc");
27
require_once("functions.inc");
28
require_once("filter.inc");
29

    
30

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

    
33
if (isset($config['system']['ssh']['enable'])) {
34
	if (!empty(getenv('SSH_CONNECTION'))) {
35
		echo gettext("!!! WARNING !!!");
36
		echo "\n\n";
37
		echo gettext("This session is currently established via SSH. Disabling SSH will terminate this session and prevent future SSH connections from any user. Before disabling SSH, ensure that administrators have alternate means of accessing the firewall, such as the GUI or serial console.");
38
		echo "\n\n";
39
	}
40
	echo "SSHD is currently enabled.  Would you like to disable? [y/n]? ";
41
	$yn = chop(fgets($fp));
42
	if ($yn[0] == "y") {
43
		unset($config['system']['ssh']['enable']);
44
		echo "\nWriting configuration...";
45
		write_config(gettext("Disabled SSHD from console menu."));
46
		echo " done.\n";
47
		echo "\nDisabling SSHD...";
48
		send_event("service reload sshd");
49
		echo "\nReloading firewall rules.";
50
		filter_configure();
51
		echo " done.\n";
52
		exec("ps awux | grep '/usr/sbin/sshd' | grep -v grep | awk '{print $2}' | xargs kill");
53
	}
54

    
55
} else {
56
	echo "SSHD is currently disabled.  Would you like to enable? [y/n]? ";
57
	$yn = chop(fgets($fp));
58
	if ($yn[0] == "y") {
59
		init_config_arr(array('system', 'ssh'));
60
		$config['system']['ssh']['enable'] = "enabled";
61
		echo "\nWriting configuration...";
62
		write_config(gettext("Enabled SSHD from console menu."));
63
		echo " done.\n";
64
		echo "\nEnabling SSHD...";
65
		send_event("service reload sshd");
66
		echo "\nReloading firewall rules.";
67
		filter_configure();
68
		echo " done.\n\n";
69
	}
70
}
71

    
72
fclose($fp);
(47-47/85)