commit | author | age
|
fa029b
|
1 |
<?php |
TB |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2014, Till Brehm, ISPConfig UG |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
1ed92e
|
31 |
require "/usr/local/ispconfig/server/lib/config.inc.php"; |
TB |
32 |
require "/usr/local/ispconfig/server/lib/app.inc.php"; |
fa029b
|
33 |
|
TB |
34 |
set_time_limit(0); |
|
35 |
ini_set('error_reporting', E_ALL & ~E_NOTICE); |
|
36 |
|
|
37 |
// make sure server_id is always an int |
|
38 |
$conf['server_id'] = intval($conf['server_id']); |
|
39 |
|
|
40 |
|
|
41 |
// Load required base-classes |
|
42 |
$app->uses('ini_parser,file,services,getconf,system'); |
|
43 |
|
1ed92e
|
44 |
// get security config |
TB |
45 |
$security_config = $app->getconf->get_security_config('systemcheck'); |
|
46 |
|
|
47 |
$alert = ''; |
|
48 |
$data_dir = '/usr/local/ispconfig/security/data'; |
|
49 |
|
|
50 |
|
|
51 |
// Check if a new ispconfig user has been added |
|
52 |
if($security_config['warn_new_admin'] == 'yes') { |
|
53 |
$data_file = $data_dir.'/admincount'; |
|
54 |
//get number of admins |
|
55 |
$tmp = $app->db->queryOneRecord("SELECT count(userid) AS number FROM sys_user WHERE typ = 'admin'"); |
cd50a4
|
56 |
if($tmp) { |
MB |
57 |
$admin_user_count_new = intval($tmp['number']); |
|
58 |
|
|
59 |
if(is_file($data_file)) { |
|
60 |
$admin_user_count_old = intval(file_get_contents($data_file)); |
|
61 |
if($admin_user_count_new != $admin_user_count_old) { |
|
62 |
$alert .= "The number of ISPConfig administrator users has changed. Old: $admin_user_count_old New: $admin_user_count_new \n"; |
|
63 |
file_put_contents($data_file,$admin_user_count_new); |
|
64 |
} |
|
65 |
} else { |
|
66 |
// first run, so we save the current count |
1ed92e
|
67 |
file_put_contents($data_file,$admin_user_count_new); |
cd50a4
|
68 |
chmod($data_file,0700); |
1ed92e
|
69 |
} |
TB |
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
// Check if /etc/passwd file has been changed |
|
74 |
if($security_config['warn_passwd_change'] == 'yes') { |
|
75 |
$data_file = $data_dir.'/passwd.md5'; |
|
76 |
$md5sum_new = md5_file('/etc/passwd'); |
|
77 |
|
|
78 |
if(is_file($data_file)) { |
|
79 |
$md5sum_old = trim(file_get_contents($data_file)); |
|
80 |
if($md5sum_new != $md5sum_old) { |
|
81 |
$alert .= "The file /etc/passwd has been changed.\n"; |
|
82 |
file_put_contents($data_file,$md5sum_new); |
|
83 |
} |
|
84 |
} else { |
|
85 |
file_put_contents($data_file,$md5sum_new); |
|
86 |
chmod($data_file,0700); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
// Check if /etc/shadow file has been changed |
|
91 |
if($security_config['warn_shadow_change'] == 'yes') { |
|
92 |
$data_file = $data_dir.'/shadow.md5'; |
|
93 |
$md5sum_new = md5_file('/etc/shadow'); |
|
94 |
|
|
95 |
if(is_file($data_file)) { |
|
96 |
$md5sum_old = trim(file_get_contents($data_file)); |
|
97 |
if($md5sum_new != $md5sum_old) { |
|
98 |
$alert .= "The file /etc/shadow has been changed.\n"; |
|
99 |
file_put_contents($data_file,$md5sum_new); |
|
100 |
} |
|
101 |
} else { |
|
102 |
file_put_contents($data_file,$md5sum_new); |
|
103 |
chmod($data_file,0700); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
// Check if /etc/group file has been changed |
|
108 |
if($security_config['warn_group_change'] == 'yes') { |
|
109 |
$data_file = $data_dir.'/group.md5'; |
|
110 |
$md5sum_new = md5_file('/etc/group'); |
|
111 |
|
|
112 |
if(is_file($data_file)) { |
|
113 |
$md5sum_old = trim(file_get_contents($data_file)); |
|
114 |
if($md5sum_new != $md5sum_old) { |
|
115 |
$alert .= "The file /etc/group has been changed.\n"; |
|
116 |
file_put_contents($data_file,$md5sum_new); |
|
117 |
} |
|
118 |
} else { |
|
119 |
file_put_contents($data_file,$md5sum_new); |
|
120 |
chmod($data_file,0700); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
if($alert != '') { |
|
126 |
$admin_email = $security_config['security_admin_email']; |
|
127 |
$admin_email_subject = $security_config['security_admin_email_subject']; |
|
128 |
mail($admin_email, $admin_email_subject, $alert); |
|
129 |
//$app->log(str_replace("\n"," -- ",$alert),1); |
|
130 |
echo str_replace("\n"," -- ",$alert)."\n"; |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
fa029b
|
154 |
|
TB |
155 |
|
|
156 |
?> |