1 |
069f9bae
|
Scott Ullrich
|
#! /usr/local/bin/php -f
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
|
|
sshd - Modified to work on disk based system
|
5 |
|
|
Copyright 2004 Scott K Ullrich
|
6 |
|
|
|
7 |
|
|
Original Copyright (C) 2004 Fred Mol <fredmol@xs4all.nl>.
|
8 |
|
|
All rights reserved.
|
9 |
|
|
|
10 |
|
|
Redistribution and use in source and binary forms, with or without
|
11 |
|
|
modification, are permitted provided that the following conditions are met:
|
12 |
|
|
|
13 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
this list of conditions and the following disclaimer.
|
15 |
|
|
|
16 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
notice, this list of conditions and the following disclaimer in the
|
18 |
|
|
documentation and/or other materials provided with the distribution.
|
19 |
|
|
|
20 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
*/
|
31 |
|
|
|
32 |
91224d9a
|
Matthew Grooms
|
require_once("config.inc");
|
33 |
5f2d078e
|
Scott Ullrich
|
require_once("functions.inc");
|
34 |
069f9bae
|
Scott Ullrich
|
|
35 |
519d2f03
|
Scott Ullrich
|
conf_mount_rw();
|
36 |
|
|
|
37 |
069f9bae
|
Scott Ullrich
|
$fp = fopen('php://stdin', 'r');
|
38 |
|
|
|
39 |
4d16b797
|
Scott Ullrich
|
if (isset($config['system']['enablesshd'])) {
|
40 |
069f9bae
|
Scott Ullrich
|
echo "SSHD is currently enabled. Would you like to disable? [y/n]? ";
|
41 |
|
|
$yn = chop(fgets($fp));
|
42 |
|
|
if ($yn[0] == "y") {
|
43 |
4d16b797
|
Scott Ullrich
|
unset($config['system']['enablesshd']);
|
44 |
069f9bae
|
Scott Ullrich
|
echo "\nWriting configuration...";
|
45 |
|
|
write_config();
|
46 |
44f1247e
|
Scott Ullrich
|
echo " done.\n";
|
47 |
|
|
echo "\nDisabling SSHD...";
|
48 |
069f9bae
|
Scott Ullrich
|
exec("/etc/sshd");
|
49 |
44f1247e
|
Scott Ullrich
|
echo " done.\n";
|
50 |
91224d9a
|
Matthew Grooms
|
exec("ps awux | grep '/usr/sbin/sshd' | grep -v grep | awk '{print $2}' | xargs kill");
|
51 |
069f9bae
|
Scott Ullrich
|
}
|
52 |
|
|
|
53 |
4d16b797
|
Scott Ullrich
|
} else {
|
54 |
069f9bae
|
Scott Ullrich
|
echo "SSHD is currently disabled. Would you like to enable? [y/n]? ";
|
55 |
|
|
$yn = chop(fgets($fp));
|
56 |
|
|
if ($yn[0] == "y") {
|
57 |
4d16b797
|
Scott Ullrich
|
$config['system']['enablesshd'] = true;
|
58 |
069f9bae
|
Scott Ullrich
|
echo "\nWriting configuration...";
|
59 |
|
|
write_config();
|
60 |
44f1247e
|
Scott Ullrich
|
echo " done.\n";
|
61 |
|
|
echo "\nEnabling SSHD...";
|
62 |
069f9bae
|
Scott Ullrich
|
exec("/etc/sshd");
|
63 |
44f1247e
|
Scott Ullrich
|
echo " done.\n\n";
|
64 |
069f9bae
|
Scott Ullrich
|
}
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
fclose($fp);
|
68 |
519d2f03
|
Scott Ullrich
|
|
69 |
|
|
conf_mount_ro();
|