Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#! /usr/local/bin/php-cgi -f
2 069f9bae Scott Ullrich
<?php
3
/*
4 ac24dc24 Renato Botelho
 * rc.initial.toggle_sshd
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 c5d81585 Renato Botelho
 * Copyright (c) 2004 Fred Mol <fredmol@xs4all.nl>.
8 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
9
 * Copyright (c) 2013-2016 Electric Sheep Fencing
10 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
11 ac24dc24 Renato Botelho
 * All rights reserved.
12
 *
13 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 ac24dc24 Renato Botelho
 *
19 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 */
25 069f9bae Scott Ullrich
26 91224d9a Matthew Grooms
require_once("config.inc");
27 5f2d078e Scott Ullrich
require_once("functions.inc");
28 146ee078 PiBa-NL
require_once("filter.inc");
29 069f9bae Scott Ullrich
30 519d2f03 Scott Ullrich
31 069f9bae Scott Ullrich
$fp = fopen('php://stdin', 'r');
32
33 ec439957 jim-p
if (isset($config['system']['ssh']['enable'])) {
34 069f9bae Scott Ullrich
	echo "SSHD is currently enabled.  Would you like to disable? [y/n]? ";
35
	$yn = chop(fgets($fp));
36
	if ($yn[0] == "y") {
37 ec439957 jim-p
		unset($config['system']['ssh']['enable']);
38 069f9bae Scott Ullrich
		echo "\nWriting configuration...";
39 1044256f doktornotor
		write_config(gettext("Disabled SSHD from console menu."));
40 44f1247e Scott Ullrich
		echo " done.\n";
41
		echo "\nDisabling SSHD...";
42 08b64f79 Ermal
		send_event("service reload sshd");
43 146ee078 PiBa-NL
		echo "\nReloading firewall rules.";
44
		filter_configure();
45 44f1247e Scott Ullrich
		echo " done.\n";
46 91224d9a Matthew Grooms
		exec("ps awux | grep '/usr/sbin/sshd' | grep -v grep | awk '{print $2}' | xargs kill");
47 069f9bae Scott Ullrich
	}
48 e173dd74 Phil Davis
49 4d16b797 Scott Ullrich
} else {
50 069f9bae Scott Ullrich
	echo "SSHD is currently disabled.  Would you like to enable? [y/n]? ";
51
	$yn = chop(fgets($fp));
52
	if ($yn[0] == "y") {
53 ec439957 jim-p
		init_config_arr(array('system', 'ssh'));
54
		$config['system']['ssh']['enable'] = "enabled";
55 069f9bae Scott Ullrich
		echo "\nWriting configuration...";
56 1044256f doktornotor
		write_config(gettext("Enabled SSHD from console menu."));
57 44f1247e Scott Ullrich
		echo " done.\n";
58
		echo "\nEnabling SSHD...";
59 08b64f79 Ermal
		send_event("service reload sshd");
60 146ee078 PiBa-NL
		echo "\nReloading firewall rules.";
61
		filter_configure();
62 44f1247e Scott Ullrich
		echo " done.\n\n";
63 e173dd74 Phil Davis
	}
64 069f9bae Scott Ullrich
}
65
66
fclose($fp);