Till Brehm
2016-04-22 ebd0e986ed11f2a34fb58cdd33efbfab192083ad
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'");
56     $admin_user_count_new = intval($tmp['number']);
57     
58     if(is_file($data_file)) {
59         $admin_user_count_old = intval(file_get_contents($data_file));
60         if($admin_user_count_new != $admin_user_count_old) {
61             $alert .= "The number of ISPConfig administrator users has changed. Old: $admin_user_count_old New: $admin_user_count_new \n";
62             file_put_contents($data_file,$admin_user_count_new);
63         }
64     } else {
65         // first run, so we save the current count
66         file_put_contents($data_file,$admin_user_count_new);
67         chmod($data_file,0700);
68     }
69 }
70
71 // Check if /etc/passwd file has been changed
72 if($security_config['warn_passwd_change'] == 'yes') {
73     $data_file = $data_dir.'/passwd.md5';
74     $md5sum_new = md5_file('/etc/passwd');
75     
76     if(is_file($data_file)) {
77         $md5sum_old = trim(file_get_contents($data_file));
78         if($md5sum_new != $md5sum_old) {
79             $alert .= "The file /etc/passwd has been changed.\n";
80             file_put_contents($data_file,$md5sum_new);
81         }
82     } else {
83         file_put_contents($data_file,$md5sum_new);
84         chmod($data_file,0700);
85     }
86 }
87
88 // Check if /etc/shadow file has been changed
89 if($security_config['warn_shadow_change'] == 'yes') {
90     $data_file = $data_dir.'/shadow.md5';
91     $md5sum_new = md5_file('/etc/shadow');
92     
93     if(is_file($data_file)) {
94         $md5sum_old = trim(file_get_contents($data_file));
95         if($md5sum_new != $md5sum_old) {
96             $alert .= "The file /etc/shadow has been changed.\n";
97             file_put_contents($data_file,$md5sum_new);
98         }
99     } else {
100         file_put_contents($data_file,$md5sum_new);
101         chmod($data_file,0700);
102     }
103 }
104
105 // Check if /etc/group file has been changed
106 if($security_config['warn_group_change'] == 'yes') {
107     $data_file = $data_dir.'/group.md5';
108     $md5sum_new = md5_file('/etc/group');
109     
110     if(is_file($data_file)) {
111         $md5sum_old = trim(file_get_contents($data_file));
112         if($md5sum_new != $md5sum_old) {
113             $alert .= "The file /etc/group has been changed.\n";
114             file_put_contents($data_file,$md5sum_new);
115         }
116     } else {
117         file_put_contents($data_file,$md5sum_new);
118         chmod($data_file,0700);
119     }
120 }
121
122
123 if($alert != '') {
124     $admin_email = $security_config['security_admin_email'];
125     $admin_email_subject = $security_config['security_admin_email_subject'];
126     mail($admin_email, $admin_email_subject, $alert);
127     //$app->log(str_replace("\n"," -- ",$alert),1);
128     echo str_replace("\n"," -- ",$alert)."\n";
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
fa029b 152
TB 153
154 ?>