File: //etc/cPMalScan/php56/fixconfig.php
#!/usr/local/cpanel/3rdparty/bin/php
<?php
$configfile = "/etc/cPMalScan/config.ini";
$configdata = <<< CONFIG_DATA
http_scan = 1
del_http_scan = 0
block_hashbang = 1
block_ext = 1
prohibited_ext = ".pl,.php,.py,.exe,.sh"
ftp_scan = 1
del_ftp_scan = 0
quar_dir = "/cpms_quar/"
quar_days = 78
fullserverscan = "weekly"
weeklyscanday = "Wednesday"
scanemail = "root@localhost"
verbose_log = 1
db_host = "localhost"
db_name = "cpmalscan"
db_user = "cpmalscan"
db_pass = 8sawwX6bEjrxM75Ja8Ak2p8aKaF3mPBQ
live_scan = 1
dailyreport = 1
CONFIG_DATA;
if(!file_exists($configfile))
{
file_put_contents($configfile,$configdata);
}
if(filesize($configfile)<20)
{
file_put_contents($configfile,$configdata);
}
function randomPassword() {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 24; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
$dbpass = randomPassword();
$CMD = "sed -i 's@db_pass.*@db_pass = $dbpass@g' $configfile";
shell_exec($CMD);
$CMD = "mysql -e \"GRANT SELECT, INSERT, DELETE, UPDATE ON cpmalscan.* TO 'cpmalscan'@'localhost' IDENTIFIED BY '$dbpass'\"";
shell_exec($CMD);
$config = parse_ini_file($configfile,false);
$config['db_host'] = "localhost";
$config['db_name'] = "cpmalscan";
$config['db_user'] = "cpmalscan";
$config['db_pass'] = $dbpass;
function save_config()
{
global $config,$configfile;
$content = "";
foreach ($config as $k => $v) {
$content .= $k . ' = ' . (is_numeric($v) ? $v : '"' . $v . '"') . PHP_EOL;
}
file_put_contents($configfile,$content);
}
save_config();