|
28 | 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 | */ |
30 | 30 |
|
31 | | -define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"])); |
32 | | -require SCRIPT_PATH."/lib/config.inc.php"; |
33 | | -require SCRIPT_PATH."/lib/app.inc.php"; |
| 31 | +require "/usr/local/ispconfig/server/lib/config.inc.php"; |
| 32 | +require "/usr/local/ispconfig/server/lib/app.inc.php"; |
34 | 33 |
|
35 | 34 | set_time_limit(0); |
36 | 35 | ini_set('error_reporting', E_ALL & ~E_NOTICE); |
|
41 | 40 |
|
42 | 41 | // Load required base-classes |
43 | 42 | $app->uses('ini_parser,file,services,getconf,system'); |
| 43 | + |
| 44 | +// get security config |
| 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 | + |
44 | 151 |
|
45 | 152 |
|
46 | 153 |
|
|
0 commit comments