Project

General

Profile

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

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

    
66
fclose($fp);
(45-45/82)