|
Revision 1405, 6.3 kB
(checked in by scitech, 5 days ago)
|
Fixed #837: AWStats password protection
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
final class Config { |
|---|
| 5 |
|
|---|
| 6 |
private static $_file; |
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
// array with all options from config file - predefined with null |
|---|
| 10 |
private static $_values = array( |
|---|
| 11 |
'BuildDate' => null, |
|---|
| 12 |
'Version' => null, |
|---|
| 13 |
'CodeName' => null, |
|---|
| 14 |
'DEFAULT_ADMIN_ADDRESS' => null, |
|---|
| 15 |
'SERVER_HOSTNAME' => null, |
|---|
| 16 |
'BASE_SERVER_IP' => null, |
|---|
| 17 |
'BASE_SERVER_VHOST' => null, |
|---|
| 18 |
'MR_LOCK_FILE' => null, |
|---|
| 19 |
'CMD_AWK' => null, |
|---|
| 20 |
'CMD_BZCAT' => null, |
|---|
| 21 |
'CMD_BZIP' => null, |
|---|
| 22 |
'CMD_CHOWN' => null, |
|---|
| 23 |
'CMD_CAT' => null, |
|---|
| 24 |
'CMD_CHMOD' => null, |
|---|
| 25 |
'CMD_CP' => null, |
|---|
| 26 |
'CMD_DIFF' => null, |
|---|
| 27 |
'CMD_CMP' => null, |
|---|
| 28 |
'CMD_DU' => null, |
|---|
| 29 |
'CMD_ECHO' => null, |
|---|
| 30 |
'CMD_EGREP' => null, |
|---|
| 31 |
'CMD_GZCAT' => null, |
|---|
| 32 |
'CMD_GZIP' => null, |
|---|
| 33 |
'CMD_GREP' => null, |
|---|
| 34 |
'CMD_GROUPADD' => null, |
|---|
| 35 |
'CMD_GROUPDEL' => null, |
|---|
| 36 |
'CMD_HOSTNAME' => null, |
|---|
| 37 |
'CMD_IFCONFIG' => null, |
|---|
| 38 |
'CMD_IPTABLES' => null, |
|---|
| 39 |
'CMD_LN' => null, |
|---|
| 40 |
'CMD_MYSQL' => null, |
|---|
| 41 |
'CMD_MV' => null, |
|---|
| 42 |
'CMD_PS' => null, |
|---|
| 43 |
'CMD_RM' => null, |
|---|
| 44 |
'CMD_SED' => null, |
|---|
| 45 |
'CMD_SHELL' => null, |
|---|
| 46 |
'CMD_TAR' => null, |
|---|
| 47 |
'CMD_TOUCH' => null, |
|---|
| 48 |
'CMD_USERADD' => null, |
|---|
| 49 |
'CMD_USERDEL' => null, |
|---|
| 50 |
'CMD_WC' => null, |
|---|
| 51 |
'PEAR_DIR' => null, |
|---|
| 52 |
'DATABASE_TYPE' => null, |
|---|
| 53 |
'DATABASE_HOST' => null, |
|---|
| 54 |
'DATABASE_NAME' => null, |
|---|
| 55 |
'DATABASE_PASSWORD' => null, |
|---|
| 56 |
'DATABASE_USER' => null, |
|---|
| 57 |
'DATABASE_DIR' => null, |
|---|
| 58 |
'CMD_MYSQLDUMP' => null, |
|---|
| 59 |
'DATABASE_UTF8' => null, |
|---|
| 60 |
'CONF_DIR' => null, |
|---|
| 61 |
'LOG_DIR' => null, |
|---|
| 62 |
'PHP_STARTER_DIR' => null, |
|---|
| 63 |
'ROOT_DIR' => null, |
|---|
| 64 |
'ROOT_USER' => null, |
|---|
| 65 |
'ROOT_GROUP' => null, |
|---|
| 66 |
'GUI_ROOT_DIR' => null, |
|---|
| 67 |
'APACHE_WWW_DIR' => null, |
|---|
| 68 |
'SCOREBOARDS_DIR' => null, |
|---|
| 69 |
'ZIP' => null, |
|---|
| 70 |
'PHP5_FASTCGI_BIN' => null, |
|---|
| 71 |
'PHP_VERSION' => null, |
|---|
| 72 |
'FTPD_CONF_FILE' => null, |
|---|
| 73 |
'FTPD_CONF_DIR' => null, |
|---|
| 74 |
'BIND_CONF_FILE' => null, |
|---|
| 75 |
'BIND_DB_DIR' => null, |
|---|
| 76 |
'SECONDARY_DNS' => null, |
|---|
| 77 |
'AWSTATS_ACTIVE' => null, |
|---|
| 78 |
'AWSTATS_MODE' => null, |
|---|
| 79 |
'AWSTATS_CACHE_DIR' => null, |
|---|
| 80 |
'AWSTATS_CONFIG_DIR' => null, |
|---|
| 81 |
'AWSTATS_ENGINE_DIR' => null, |
|---|
| 82 |
'AWSTATS_WEB_DIR' => null, |
|---|
| 83 |
'AWSTATS_ROOT_DIR' => null, |
|---|
| 84 |
'AWSTATS_GROUP_AUTH' => null, |
|---|
| 85 |
'APACHE_NAME' => null, |
|---|
| 86 |
'APACHE_RESTART_TRY' => null, |
|---|
| 87 |
'APACHE_CONF_DIR' => null, |
|---|
| 88 |
'APACHE_CMD' => null, |
|---|
| 89 |
'APACHE_LOG_DIR' => null, |
|---|
| 90 |
'APACHE_BACKUP_LOG_DIR' => null, |
|---|
| 91 |
'APACHE_USERS_LOG_DIR' => null, |
|---|
| 92 |
'APACHE_MODS_DIR' => null, |
|---|
| 93 |
'APACHE_SITES_DIR' => null, |
|---|
| 94 |
'APACHE_CUSTOM_SITES_CONFIG_DIR' => null, |
|---|
| 95 |
'APACHE_SUEXEC_USER_PREF' => null, |
|---|
| 96 |
'APACHE_SUEXEC_MIN_GID' => null, |
|---|
| 97 |
'APACHE_SUEXEC_MAX_GID' => null, |
|---|
| 98 |
'APACHE_SUEXEC_MIN_UID' => null, |
|---|
| 99 |
'APACHE_SUEXEC_MAX_UID' => null, |
|---|
| 100 |
'APACHE_USER' => null, |
|---|
| 101 |
'APACHE_GROUP' => null, |
|---|
| 102 |
'POSTFIX_CONF_FILE' => null, |
|---|
| 103 |
'POSTFIX_MASTER_CONF_FILE' => null, |
|---|
| 104 |
'MTA_LOCAL_MAIL_DIR' => null, |
|---|
| 105 |
'MTA_VIRTUAL_MAIL_DIR' => null, |
|---|
| 106 |
'MTA_LOCAL_ALIAS_HASH' => null, |
|---|
| 107 |
'MTA_VIRTUAL_CONF_DIR' => null, |
|---|
| 108 |
'MTA_VIRTUAL_ALIAS_HASH' => null, |
|---|
| 109 |
'MTA_VIRTUAL_DMN_HASH' => null, |
|---|
| 110 |
'MTA_VIRTUAL_MAILBOX_HASH' => null, |
|---|
| 111 |
'MTA_TRANSPORT_HASH' => null, |
|---|
| 112 |
'MTA_SENDER_ACCESS_HASH' => null, |
|---|
| 113 |
'MTA_MAILBOX_MIN_UID' => null, |
|---|
| 114 |
'MTA_MAILBOX_UID' => null, |
|---|
| 115 |
'MTA_MAILBOX_UID_NAME' => null, |
|---|
| 116 |
'MTA_MAILBOX_GID' => null, |
|---|
| 117 |
'MTA_MAILBOX_GID_NAME' => null, |
|---|
| 118 |
'MTA_SASLDB_FILE' => null, |
|---|
| 119 |
'ETC_SASLDB_FILE' => null, |
|---|
| 120 |
'CMD_SASLDB_LISTUSERS2' => null, |
|---|
| 121 |
'CMD_SASLDB_PASSWD2' => null, |
|---|
| 122 |
'CMD_POSTMAP' => null, |
|---|
| 123 |
'CMD_NEWALIASES' => null, |
|---|
| 124 |
'AUTHLIB_CONF_DIR' => null, |
|---|
| 125 |
'CMD_MAKEUSERDB' => null, |
|---|
| 126 |
'BACKUP_HOUR' => null, |
|---|
| 127 |
'BACKUP_MINUTE' => null, |
|---|
| 128 |
'BACKUP_ISPCP' => null, |
|---|
| 129 |
'BACKUP_DOMAINS' => null, |
|---|
| 130 |
'BACKUP_ROOT_DIR' => null, |
|---|
| 131 |
'CMD_CRONTAB' => null, |
|---|
| 132 |
'CMD_AMAVIS' => null, |
|---|
| 133 |
'CMD_AUTHD' => null, |
|---|
| 134 |
'CMD_FTPD' => null, |
|---|
| 135 |
'CMD_HTTPD' => null, |
|---|
| 136 |
'CMD_IMAP' => null, |
|---|
| 137 |
'CMD_IMAP_SSL' => null, |
|---|
| 138 |
'CMD_MTA' => null, |
|---|
| 139 |
'CMD_NAMED' => null, |
|---|
| 140 |
'CMD_POP' => null, |
|---|
| 141 |
'CMD_POP_SSL' => null, |
|---|
| 142 |
'CMD_ISPCPD' => null, |
|---|
| 143 |
'CMD_ISPCPN' => null, |
|---|
| 144 |
'CMD_PFLOGSUM' => null, |
|---|
| 145 |
'TRAFF_LOG_DIR' => null, |
|---|
| 146 |
'FTP_TRAFF_LOG' => null, |
|---|
| 147 |
'MAIL_TRAFF_LOG' => null, |
|---|
| 148 |
'TRAFF_ROOT_DIR' => null, |
|---|
| 149 |
'TOOLS_ROOT_DIR' => null, |
|---|
| 150 |
'QUOTA_ROOT_DIR' => null, |
|---|
| 151 |
'MAIL_LOG_INC_AMAVIS' => null, |
|---|
| 152 |
'USER_INITIAL_THEME' => null, |
|---|
| 153 |
'FTP_USERNAME_SEPARATOR' => null, |
|---|
| 154 |
'FTP_HOMEDIR' => null, |
|---|
| 155 |
'IPS_LOGO_PATH' => null, |
|---|
| 156 |
'ISPCP_SUPPORT_SYSTEM_PATH' => null, |
|---|
| 157 |
'ISPCP_SUPPORT_SYSTEM_TARGET' => null, |
|---|
| 158 |
'MYSQL_PREFIX' => null, |
|---|
| 159 |
'MYSQL_PREFIX_TYPE' => null, |
|---|
| 160 |
'WEBMAIL_PATH' => null, |
|---|
| 161 |
'WEBMAIL_TARGET' => null, |
|---|
| 162 |
'PMA_PATH' => null, |
|---|
| 163 |
'PMA_TARGET' => null, |
|---|
| 164 |
'FILEMANAGER_PATH' => null, |
|---|
| 165 |
'FILEMANAGER_TARGET' => null, |
|---|
| 166 |
'DATE_FORMAT' => null, |
|---|
| 167 |
'RKHUNTER_LOG' => null, |
|---|
| 168 |
'CHKROOTKIT_LOG' => null, |
|---|
| 169 |
'OTHER_ROOTKIT_LOG' => null, |
|---|
| 170 |
'HTACCESS_USERS_FILE_NAME' => null, |
|---|
| 171 |
'HTACCESS_GROUPS_FILE_NAME' => null, |
|---|
| 172 |
'HTPASSWD_CMD' => null, |
|---|
| 173 |
'BACKUP_FILE_DIR' => null, |
|---|
| 174 |
'DEBUG' => null |
|---|
| 175 |
); |
|---|
| 176 |
private static $_status = false; |
|---|
| 177 |
|
|---|
| 178 |
public static function load($cfg = '/etc/ispcp/ispcp.conf') { |
|---|
| 179 |
self::$_file = $cfg; |
|---|
| 180 |
|
|---|
| 181 |
if (!self::_parseFile()) |
|---|
| 182 |
throw new Exception('Cannot open the ispcp.conf config file!'); |
|---|
| 183 |
|
|---|
| 184 |
self::$_status = true; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
public static function getValues() { |
|---|
| 188 |
if(!self::$_status) |
|---|
| 189 |
throw new Exception('Config not loaded!'); |
|---|
| 190 |
|
|---|
| 191 |
return self::$_values; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
public static function get($param) { |
|---|
| 195 |
if(!isset(self::$_values[$param])) |
|---|
| 196 |
throw new Exception("Config variable '$param' is missing!"); |
|---|
| 197 |
|
|---|
| 198 |
if(!self::$_status) |
|---|
| 199 |
throw new Exception('Config not loaded!'); |
|---|
| 200 |
|
|---|
| 201 |
return self::$_values[$param]; |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
public static function set($param, $value) { |
|---|
| 205 |
self::$_values[$param] = $value; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
public static function exists($param) { |
|---|
| 209 |
return isset(self::$_values[$param]); |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
private static function _parseFile() { |
|---|
| 213 |
|
|---|
| 214 |
@$fd = fopen(self::$_file, 'r'); |
|---|
| 215 |
if (!$fd) { |
|---|
| 216 |
return false; |
|---|
| 217 |
} while (!feof($fd)) { |
|---|
| 218 |
$buffer = fgets($fd, 4096); |
|---|
| 219 |
|
|---|
| 220 |
$buffer = ltrim($buffer); |
|---|
| 221 |
if (strlen($buffer) > 3 && $buffer[0] != '#' && $buffer[0] != ';' && |
|---|
| 222 |
strpos($buffer, '=') !== false) { |
|---|
| 223 |
$pair = explode('=', $buffer, 2); |
|---|
| 224 |
|
|---|
| 225 |
$pair[0] = trim($pair[0]); |
|---|
| 226 |
$pair[1] = trim($pair[1]); |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
self::$_values[$pair[0]] = $pair[1]; |
|---|
| 230 |
} |
|---|
| 231 |
} |
|---|
| 232 |
fclose($fd); |
|---|
| 233 |
|
|---|
| 234 |
foreach (self::$_values as $k => $v) { |
|---|
| 235 |
if ($v === null) { |
|---|
| 236 |
throw new Exception("Config variable '$k' is missing!"); |
|---|
| 237 |
return false; |
|---|
| 238 |
} |
|---|
| 239 |
} |
|---|
| 240 |
|
|---|
| 241 |
return true; |
|---|
| 242 |
} |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
?> |
|---|
|