Project

General

Profile

Download (1.91 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 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
9 ac24dc24 Renato Botelho
 * All rights reserved.
10
 *
11 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 ac24dc24 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 */
23 069f9bae Scott Ullrich
24 91224d9a Matthew Grooms
require_once("config.inc");
25 5f2d078e Scott Ullrich
require_once("functions.inc");
26 146ee078 PiBa-NL
require_once("filter.inc");
27 069f9bae Scott Ullrich
28 519d2f03 Scott Ullrich
29 069f9bae Scott Ullrich
$fp = fopen('php://stdin', 'r');
30
31 4d16b797 Scott Ullrich
if (isset($config['system']['enablesshd'])) {
32 069f9bae Scott Ullrich
	echo "SSHD is currently enabled.  Would you like to disable? [y/n]? ";
33
	$yn = chop(fgets($fp));
34
	if ($yn[0] == "y") {
35 4d16b797 Scott Ullrich
		unset($config['system']['enablesshd']);
36 069f9bae Scott Ullrich
		echo "\nWriting configuration...";
37 1044256f doktornotor
		write_config(gettext("Disabled SSHD from console menu."));
38 44f1247e Scott Ullrich
		echo " done.\n";
39
		echo "\nDisabling SSHD...";
40 08b64f79 Ermal
		send_event("service reload sshd");
41 146ee078 PiBa-NL
		echo "\nReloading firewall rules.";
42
		filter_configure();
43 44f1247e Scott Ullrich
		echo " done.\n";
44 91224d9a Matthew Grooms
		exec("ps awux | grep '/usr/sbin/sshd' | grep -v grep | awk '{print $2}' | xargs kill");
45 069f9bae Scott Ullrich
	}
46 e173dd74 Phil Davis
47 4d16b797 Scott Ullrich
} else {
48 069f9bae Scott Ullrich
	echo "SSHD is currently disabled.  Would you like to enable? [y/n]? ";
49
	$yn = chop(fgets($fp));
50
	if ($yn[0] == "y") {
51 4d16b797 Scott Ullrich
		$config['system']['enablesshd'] = true;
52 069f9bae Scott Ullrich
		echo "\nWriting configuration...";
53 1044256f doktornotor
		write_config(gettext("Enabled SSHD from console menu."));
54 44f1247e Scott Ullrich
		echo " done.\n";
55
		echo "\nEnabling SSHD...";
56 08b64f79 Ermal
		send_event("service reload sshd");
57 146ee078 PiBa-NL
		echo "\nReloading firewall rules.";
58
		filter_configure();
59 44f1247e Scott Ullrich
		echo " done.\n\n";
60 e173dd74 Phil Davis
	}
61 069f9bae Scott Ullrich
}
62
63
fclose($fp);