Esempio n. 1
0
function MysqlCheck(){
$db_file = "/usr/share/ocsinventory-reports/ocsreports/files/ocsbase.sql";
if(!is_file($db_file)){
	echo "Starting......: OCS web Engine unable to stat $db_file\n";
	return;
}

$q=new mysql();
if(!$q->DATABASE_EXISTS("ocsweb")){
	echo "Starting......: OCS web Engine creating ocsweb\n";
	$q->CREATE_DATABASE("ocsweb");
	if(!$q->DATABASE_EXISTS("ocsweb")){
		echo "Starting......: OCS web Engine unable to create ocsweb mysql database\n";
		return;
	}
}



if(CheckTables()){
	$sock=new sockets();
	$users=new usersMenus();
	$q=new mysql();
	$ocswebservername=$sock->GET_INFO("ocswebservername");
	$OCSWebPort=$sock->GET_INFO("OCSWebPort");	
	if($OCSWebPort==null){$OCSWebPort=9080;}
	if($OCSWebPortSSL==null){$OCSWebPortSSL=$OCSWebPort+50;}	
	if($ocswebservername==null){$ocswebservername=$users->hostname;}
	$sql="UPDATE config SET IVALUE=1 WHERE NAME='DOWNLOAD'";
	$q->QUERY_SQL($sql,"ocsweb");
	$sql="UPDATE config SET IVALUE=1 WHERE NAME='REGISTRY'";
	$q->QUERY_SQL($sql,"ocsweb");
	$sql="UPDATE config SET IVALUE='http://$ocswebservername:$OCSWebPort' WHERE NAME='LOCAL_SERVER'";
	$q->QUERY_SQL($sql,"ocsweb");	
	return;
}




if($dbf_handle = @fopen($db_file, "r")) {
	$sql_query = fread($dbf_handle, filesize($db_file));
	fclose($dbf_handle);
	
}



$array_commands=explode(";", "$sql_query");
while (list ($num, $sql) = each ($array_commands) ){
	if(trim($sql)==null){continue;}
	
	$q->QUERY_SQL($sql,"ocsweb");
	if(!$q->ok){
	echo "Starting......: OCS web Engine $q->mysql_error $sql\n";	
	}
}

}
Esempio n. 2
0
function initialize()
{
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("drupal")) {
        $q->CREATE_DATABASE("drupal");
        if (!$q->DATABASE_EXISTS("drupal")) {
            echo "Failed to create \"drupal\" database with error {$q->mysql_error}\n";
        }
    }
}
function MysqlCheck()
{
    $db_file = "/usr/share/ocsinventory-reports/ocsreports/files/ocsbase.sql";
    if (!is_file($db_file)) {
        die;
    }
    if (CheckTables()) {
        die;
    }
    if ($dbf_handle = @fopen($db_file, "r")) {
        $sql_query = fread($dbf_handle, filesize($db_file));
        fclose($dbf_handle);
    }
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("ocsweb")) {
        $q->CREATE_DATABASE("ocsweb");
    }
    $array_commands = explode(";", "{$sql_query}");
    while (list($num, $sql) = each($array_commands)) {
        if (trim($sql) == null) {
            continue;
        }
        $q->QUERY_SQL($sql, "ocsweb");
    }
}
Esempio n. 4
0
function TestDatabase()
{
    $sql = new mysql();
    if (!$sql->DATABASE_EXISTS("zabbix")) {
        echo "Starting......: Zabbix server daemon creating database\n";
        $sql->CREATE_DATABASE("zabbix");
        CreateTables();
    }
    if (!$sql->DATABASE_EXISTS("zabbix")) {
        echo "Starting......: Zabbix server daemon creating database FAILED\n";
        die;
    }
    if (TablesCount() < 73) {
        CreateTables();
    }
    echo "Starting......: Zabbix server daemon database success\n";
    UpdateAdmin();
}
Esempio n. 5
0
function build()
{
    echo "Starting......: " . date("H:i:s") . " GreenSQL checking Database....\n";
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("greensql")) {
        echo "Starting......: " . date("H:i:s") . " GreenSQL creating database greensql\n";
        $q->CREATE_DATABASE("greensql");
    }
    checkGreenTables();
    buildconfig();
}
Esempio n. 6
0
function TestDatabase()
{
    $sql = new mysql();
    if (!$sql->DATABASE_EXISTS("zabbix")) {
        echo "Starting......: " . date("H:i:s") . " Zabbix server daemon creating database\n";
        $sql->CREATE_DATABASE("zabbix");
        CreateTables();
    }
    if (!$sql->DATABASE_EXISTS("zabbix")) {
        echo "Starting......: " . date("H:i:s") . " Zabbix server daemon creating database FAILED\n";
        die;
    }
    $TablesCount = TablesCount();
    echo "Starting......: " . date("H:i:s") . " Zabbix server {$TablesCount} tables\n";
    if ($TablesCount < 66) {
        CreateTables();
    }
    echo "Starting......: " . date("H:i:s") . " Zabbix server daemon database success\n";
    UpdateAdmin();
}
Esempio n. 7
0
 function SaveAdminPassword()
 {
     $password = $this->params["CONF"]["joomlaadminpassword"];
     if ($password == null) {
         return null;
     }
     $q = new mysql();
     if (!$q->DATABASE_EXISTS($this->sql_db)) {
         return null;
     }
     $sql = "SELECT id FROM jos_users WHERE username=\"admin\"";
     $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, $this->sql_db));
     if (trim($ligne["id"] == null)) {
         return null;
     }
     $newpass = $this->GenPassword($password);
     $sql = "UPDATE jos_users SET password='******' WHERE id={$ligne["id"]}";
     $q->QUERY_SQL($sql, $this->sql_db);
 }
Esempio n. 8
0
function SAVE_FREEWEB_MYSQL()
{
    $servername = trim(strtolower($_POST["servername"]));
    if (substr($servername, 0, 1) == '.') {
        echo $servername . " FAILED\n";
        return;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $FreewebsStorageDirectory = $sock->GET_INFO("FreewebsStorageDirectory");
    if (!$users->AsWebMaster) {
        return "FALSE";
    }
    $uid = $_POST["uid"];
    $mysql_database = format_mysql_table($_POST["mysql_database"]);
    $mysql_password = $_POST["mysql_password"];
    $mysql_username = $_POST["mysql_username"];
    $lvm_vg = $_POST["lvm_vg"];
    $vg_size = $_POST["vg_size"];
    $ServerIP = $_POST["ServerIP"];
    $ServerPort = 0;
    if (preg_match("#(.+?):([0-9]+)#", $ServerIP, $re)) {
        $ServerIP = $re[1];
        $ServerPort = $re[2];
    }
    if (!is_numeric($vg_size)) {
        $vg_size = 5000;
    }
    $ftpuser = $_POST["ftpuser"];
    $ftppassword = $_POST["ftppassword"];
    $useSSL = $_POST["useSSL"];
    if (!$users->PUREFTP_INSTALLED) {
        $_POST["useFTP"] = 0;
        $ftpuser = null;
        $ftppassword = null;
    }
    if ($_POST["useFTP"] == 1) {
        if ($ftpuser == null) {
            $_POST["useFTP"] = 0;
            $ftpuser = null;
            $ftppassword = null;
        }
    }
    $sql = "SELECT servername FROM freeweb WHERE servername='{$_POST["servername"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    if ($ligne["servername"] != null) {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if (!$users->AsSystemAdministrator) {
            $ou = $_SESSION["ou"];
        }
        $sql = "UPDATE freeweb SET \n\t\t\tmysql_password='******',\n\t\t\tmysql_username='******',\n\t\t\tmysql_database='{$mysql_database}',\n\t\t\tmysql_instance_id='{$_POST["mysql_instance_id"]}',\n\t\t\tftpuser='******',\n\t\t\tftppassword='******',\n\t\t\tuseMysql='{$_POST["useMysql"]}',\n\t\t\tuseFTP='{$_POST["useFTP"]}'\n\t\t\tWHERE servername='{$servername}'\n\t\t";
    }
    writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->BuildTables();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        if (preg_match("#Unknown column#i", $q->mysql_error)) {
            $q->BuildTables();
            $q->QUERY_SQL($sql, "artica_backup");
        }
    }
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    if ($_POST["useFTP"] == 1) {
        if ($users->PUREFTP_INSTALLED) {
            if (trim($ftpuser) != null) {
                if (trim($ftppassword) != null) {
                    $pure = new pureftpd_user();
                    if (!$pure->CreateUser($ftpuser, $ftppassword, $servername)) {
                        echo "FTP: Failed\n";
                        return;
                    }
                    $sock->getFrameWork("services.php?reload-pure-ftpd=yes");
                }
            }
        }
    }
    if ($_POST["useMysql"] == 1) {
        if (!$q->DATABASE_EXISTS($mysql_database)) {
            $q->CREATE_DATABASE("{$mysql_database}");
        }
        if (!$q->PRIVILEGES($mysql_username, $mysql_password, $mysql_database)) {
            echo "GRANT {$mysql_database} FAILED FOR {$mysql_username}\n{$q->mysql_error}";
        }
    }
    if (isset($_POST["ADD_DNS_ENTRY"])) {
        $dnsDOM = explode(".", $_POST["servername"]);
        $netbiosname = $dnsDOM[0];
        unset($dnsDOM[0]);
        $domainname = implode(".", $dnsDOM);
        include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
        $pdns = new pdns($domainname);
        $pdns->EditIPName($netbiosname, $_POST["ADD_DNS_ENTRY"], "A");
    }
    if ($ligne["servername"] == null) {
        if ($_POST["force-groupware"] != null) {
            $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('INSTALL_GROUPWARE','{$servername}')";
            $q = new mysql();
            $q->QUERY_SQL($sql, "artica_backup");
            $sock->getFrameWork("freeweb.php?rebuild-vhost=yes&servername={$servername}");
        }
    }
    $sock->getFrameWork("services.php?freeweb-start=yes");
    sleep(2);
    $sock->getFrameWork("cmd.php?freeweb-restart=yes");
}
Esempio n. 9
0
function backup_mysql_powerdns($BaseWorkDir)
{
    $unix = new unix();
    $sock = new sockets();
    $password = null;
    $mysqldump = $unix->find_program("mysqldump");
    $gzip = $unix->find_program("gzip");
    if (!is_file($gzip)) {
        system_admin_events("Error, gzip, no such binary", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    if (!is_file($mysqldump)) {
        system_admin_events("Error, mysqldump, no such binary", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        system_admin_events("Error,/var/run/mysqld/mysqld.sock no such socket", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("powerdns")) {
        backupevents("Database PowerDNS doesn't exists...");
        return true;
    }
    $nice = $unix->EXEC_NICE();
    $LIST_TABLES_POWERDNS = $q->LIST_TABLES_POWERDNS();
    backupevents(count($LIST_TABLES_POWERDNS) . " tables to backup...");
    if ($q->mysql_password != null) {
        $password = "******" . $unix->shellEscapeChars($q->mysql_password);
    }
    $prefix = trim("{$nice} {$mysqldump} --add-drop-table --single-transaction --force --insert-ignore -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$password} powerdns");
    @mkdir("{$BaseWorkDir}/powerdns", 0755, true);
    $c = 0;
    while (list($table_name, $val) = each($LIST_TABLES_POWERDNS)) {
        $cmd = "{$prefix} {$table_name} | {$gzip} > {$BaseWorkDir}/powerdns/{$table_name}.gz";
        backupevents("{$cmd}");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$cmd}\n";
        }
        shell_exec($cmd);
        $c++;
    }
    system_admin_events("PowerDNS Databases {$c} tables done\n", __FUNCTION__, __FILE__, __LINE__);
}
Esempio n. 10
0
function OBM2_INSTALL($servername, $root, $hash = array())
{
    $GLOBALS["ADDLOG"] = "{$GLOBALS["ARTICALOGDIR"]}/{$servername}.log";
    if ($root == null) {
        events("Starting install OBM2 Unable to stat root dir");
        return false;
    }
    if (!is_dir("/opt/artica/install/sources/obm")) {
        events("Starting install OBM2 Unable to stat /opt/artica/install/sources/obm");
        return false;
    }
    $sqlfiles = array("create_obmdb_2.3.mysql.sql", "obmdb_prefs_values_2.3.sql", "obmdb_default_values_2.3.sql", "obmdb_test_values_2.3.sql", "data-fr/obmdb_nafcode_2.3.sql", "data-fr/obmdb_ref_2.3.sql", "data-en/obmdb_nafcode_2.3.sql", "data-en/obmdb_ref_2.3.sql");
    $user = $hash["wwwmysqluser"][0];
    $mysql_password = $hash[strtolower("WWWMysqlPassword")][0];
    $appli_user = $hash["wwwappliuser"];
    $appli_password = $hash["wwwapplipassword"];
    if ($user == null) {
        events("Starting install OBM2 Unable to stat Mysql username");
        return false;
    }
    if ($mysql_password == null) {
        events("Starting install OBM2 Unable to stat Mysql password");
        return false;
    }
    @mkdir($root, 0755, true);
    $server_database = str_replace(".", "_", $servername);
    $server_database = str_replace("-", "_", $server_database);
    $q = new mysql();
    if (!$q->DATABASE_EXISTS($server_database)) {
        events("Starting install OBM2 sub-system mysql database {$server_database}...");
        $q->CREATE_DATABASE($server_database);
        if (!$q->DATABASE_EXISTS($server_database)) {
            events("Starting install OBM2 unable to create MYSQL Database");
            return false;
        }
    }
    events("Starting install OBM2 installing source code in {$root}");
    shell_exec("/bin/cp -rf /opt/artica/install/sources/obm/* {$root}/");
    if ($q->mysql_password != null) {
        $password = "******";
    } else {
        events("Starting install OBM2 installing tables datas with null password");
    }
    $unix = new unix();
    //<$sql_file
    $cmd = $unix->find_program("mysql") . " --port={$q->mysql_port} --skip-column-names --database={$server_database} --silent --xml ";
    $cmd = $cmd . " --user={$q->mysql_admin}{$password}";
    if (!OBM2_CheckObmTables($server_database)) {
        while (list($num, $filesql) = each($sqlfiles)) {
            if (is_file("/opt/artica/install/sources/obm/scripts/2.3/{$filesql}")) {
                events("installing {$filesql} SQL commands");
                shell_exec($cmd . " </opt/artica/install/sources/obm/scripts/2.3/{$filesql}");
            }
        }
    }
    $version = OBM2_VERSION($root);
    if ($version == null) {
        events("Starting install unable to stat version");
        return false;
    }
    events("Starting install OBM2 version {$version}");
    if (is_file("{$root}/scripts/2.3/updates/update-2.3.1-{$version}.mysql.sql")) {
        events("Starting updating OBM2 version 2.3.1-{$version}");
        shell_exec($cmd . " <{$root}/scripts/2.3/updates/update-2.3.1-{$version}.mysql.sql");
    } else {
        events("Starting updating unable to stat {$root}/scripts/2.3/updates/update-2.3.1-{$version}.mysql.sql");
    }
    //scripts/2.3/updates/update-2.3.1-2.3.2.mysql.sql
    $q->PRIVILEGES($user, $mysql_password, $server_database);
    OBM2_INSTALL_SCRIPTS($root, $servername, $server_database, $user, $mysql_password);
}
Esempio n. 11
0
function testsDatabase()
{
    $f[] = "access_control";
    $f[] = "amavis_rules";
    $f[] = "checkhelo";
    $f[] = "checkhelo_blacklist";
    $f[] = "checkhelo_tracking";
    $f[] = "checkhelo_whitelist";
    $f[] = "checkspf";
    $f[] = "greylisting";
    $f[] = "greylisting_autoblacklist";
    $f[] = "greylisting_autowhitelist";
    $f[] = "greylisting_tracking";
    $f[] = "greylisting_whitelist";
    $f[] = "policies";
    $f[] = "policy_group_members";
    $f[] = "policy_groups";
    $f[] = "policy_members";
    $f[] = "quotas";
    $f[] = "quotas_limits";
    $f[] = "quotas_tracking";
    $f[] = "session_tracking";
    $rebuild = false;
    $q = new mysql();
    $unix = new unix();
    $dbfile = "/usr/share/artica-postfix/bin/install/cluebringer/policyd.mysql";
    if (!$q->DATABASE_EXISTS("policyd")) {
        $q->CREATE_DATABASE("policyd");
        $rebuild = true;
    }
    if (!$rebuild) {
        while (list($num, $val) = each($f)) {
            if ($q->TABLE_EXISTS($val, "policyd")) {
                echo "Starting......: cluebringer mysql table {$val} OK\n";
            } else {
                echo "Starting......: cluebringer mysql table {$val} FAILED\n";
                $rebuild = true;
                break;
            }
        }
    }
    if ($rebuild) {
        $mysqlbin = $unix->find_program("mysql");
        if (!is_file("{$mysqlbin}")) {
            echo "Starting......: cluebringer mysql binary no such file\n";
            return;
        }
        $cmd = "{$mysqlbin} --batch --host={$q->mysql_server} --port={$q->mysql_port} --user={$q->mysql_admin} --password={$q->mysql_password} --database=policyd";
        $cmd = $cmd . " <{$dbfile}";
        if ($GLOBALS["VERBOSE"]) {
            echo $cmd . "\n";
        }
        shell_exec($cmd);
    }
}
Esempio n. 12
0
function execute_database_exists($database)
{
    $q = new mysql();
    if (!$q->DATABASE_EXISTS($database)) {
        echo "FALSE\n";
        die;
    }
    echo "TRUE\n";
}
Esempio n. 13
0
function xstart()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    if (!is_file("/opt/influxdb/influxd")) {
        build_progress("{InstallingBigDataEngine}...", 10);
        system("{$php} /usr/share/artica-postfix/exec.influxdb.php --install");
    }
    if (!is_file("/opt/influxdb/influxd")) {
        $php = $unix->LOCATE_PHP5_BIN();
        build_progress("{InstallingBigDataEngine} {failed}...", 10);
    }
    build_progress("Removing old code....", 10);
    $toDelete["squid.cache.perf.stats.php"] = true;
    $toDelete["system.cpustats.php"] = true;
    $toDelete["exec.logfile_daemon-parse.php"] = true;
    $toDelete["exec.squid.stats.members.hours.php"] = true;
    $toDelete["exec.squid.hourly.tables.php"] = true;
    $toDelete["exec.squidstream.php"] = true;
    $toDelete["exec.sarg.php"] = true;
    $toDelete["exec.sarg-web.php"] = true;
    $toDelete["exec.squid-users-rttsize.php"] = true;
    $toDelete["exec.squid.stats.notcached-week.php"] = true;
    $toDelete["squid.traffic.panel.php"] = true;
    $toDelete["squid.rrt-yesterday.php"] = true;
    $toDelete["exec.squid.whitelist.ntlm.php"] = true;
    $toDelete["squid.rtt.php"] = true;
    $toDelete["exec.squid.stats.central.php"] = true;
    $toDelete["exec.squid.stats.php"] = true;
    $toDelete["{ipto}"] = true;
    $toDelete["exec.firewall.php"] = true;
    $toDelete["stats.admin.events.php"] = true;
    $toDelete["exec.squid.stats.totals.php"] = true;
    $toDelete["exec.mysar.php"] = true;
    $toDelete["exec.admin.status.postfix.flow.php"] = true;
    $toDelete["exec.squid.stats.mime.parser.php"] = true;
    $toDelete["exec.dansguardian.last.php"] = true;
    $toDelete["exec.squid.stats.month.php"] = true;
    $toDelete["exec.dansguardian.last.php"] = true;
    $toDelete["exec.squid.stats.familyday.php"] = true;
    $toDelete["exec.squid.stats.usersday.php"] = true;
    $toDelete["exec.squid.stats.quotaday.php"] = true;
    $toDelete["exec.squid.stats.protos.php"] = true;
    $toDelete["exec.squid-searchwords.php"] = true;
    $toDelete["exec.squid.words.parsers.php"] = true;
    $toDelete["exec.squid.visited.sites.php"] = true;
    $toDelete["exec.squid.reports-scheduled.php"] = true;
    $toDelete["exec.squid.hourly.tables.php"] = true;
    $toDelete["exec.squid.quotasbuild.php"] = true;
    $toDelete["exec.squid.cmdline.finduser.php"] = true;
    $toDelete["exec.squid.reports-scheduled.php"] = true;
    $toDelete["exec.squid.stats.categorize-table.php"] = true;
    $toDelete["exec.squid.stats.month.php"] = true;
    $toDelete["exec.squid.stats.not-categorized.php"] = true;
    $toDelete["exec.squid.stats.recategorize.missed.php"] = true;
    $toDelete["exec.squid.stats.recategorize.php"] = true;
    $toDelete["exec.squid.stats.uid-month.php"] = true;
    $toDelete["exec.squid.stats.usersday.php"] = true;
    $toDelete["exec.squid.logs.import.php"] = true;
    $toDelete["exec.squid.stats.quotaday.php"] = true;
    $toDelete["exec.squid.cache.optimize.php"] = true;
    $toDelete["squid.statistics.visited.day.php"] = true;
    $toDelete["squid.traffic.statistics.days.php"] = true;
    $toDelete["squid.traffic.statistics.days.graphs.php"] = true;
    $toDelete["squid.statistics.visited.day.php"] = true;
    $toDelete["squid.stats.repair.day.php"] = true;
    $toDelete["squid.stats.category.php"] = true;
    $toDelete["squid.statistics.query.categories.php"] = true;
    $toDelete["squid.statistics.querytable.php"] = true;
    $toDelete["exec.squid.stats.proto.parser.php"] = true;
    $toDelete["exec.squid.stats.central.php"] = true;
    $toDelete["exec.squid.stats.protos.php"] = true;
    $toDelete["exec.squid.stats.month.php"] = true;
    $toDelete["exec.squid.stats.members.hours.php"] = true;
    $toDelete["exec.squid.stats.recategorize.missed.php"] = true;
    $toDelete["exec.squid.stats.global.categories.php"] = true;
    $toDelete["exec.squid.stats.totals.php"] = true;
    $toDelete["exec.squid.stats.year.php"] = true;
    $toDelete["exec.squid-rrd.php"] = true;
    $toDelete["exec.squid.stats.quota-week.parser.php"] = true;
    $toDelete["exec.squid.stats.notcached-week.php"] = true;
    $toDelete["exec.squid.stats.uid-month.php"] = true;
    $toDelete["exec.squid.stats.usersday.php"] = true;
    $toDelete["exec.squid.stats.familyday.php"] = true;
    $toDelete["exec.squid.stats.days.websites.php"] = true;
    $toDelete["exec.squid.stats.days.cached.php"] = true;
    $toDelete["exec.squid.stats.blocked.week.php"] = true;
    $toDelete["exec.squid.stats.repair.php"] = true;
    $toDelete["exec.getent.php"] = true;
    $toDelete["squid.stats.filetypes.php"] = true;
    $toDelete["exec.netdiscover.php"] = true;
    $toDelete["miniadm.MembersTrack.category.php"] = true;
    $toDelete["miniadm.MembersTrack.cronozoom.php"] = true;
    $toDelete["miniadm.MembersTrack.sitename.php"] = true;
    $toDelete["miniadm.webstats.php"] = true;
    $toDelete["sarg.events.php"] = true;
    $toDelete["squid.blocked.statistics.days.php"] = true;
    $toDelete["squid.blocked.statistics.php"] = true;
    $toDelete["squid.blocked.statistics.week.php"] = true;
    $toDelete["squid.members.statistics.php"] = true;
    $toDelete["squid.statistics.central.php"] = true;
    $toDelete["squid.graphs.php"] = true;
    $toDelete["squid.client-plugins.php"] = true;
    $toDelete["exec.cache.pages.php"] = true;
    while (list($filepath, $table) = each($toDelete)) {
        $filepath = "/usr/share/artica-postfix/{$filepath}";
        if (is_file($filepath)) {
            echo "Remove {$filepath}\n";
            @unlink($filepath);
        }
    }
    $Files["/etc/cron.hourly/SquidHourlyTables.sh"] = true;
    $Files["/bin/artica-firewall.sh"] = true;
    $Files["/etc/init.d/tproxy"] = true;
    $Files["/usr/share/artica-postfix/bin/netdiscover"] = true;
    $Files["/usr/share/artica-postfix/bin/install/rrd/yorel"] = true;
    $Files["/usr/share/artica-postfix/bin/install/rrd/yorel-create"] = true;
    $Files["/usr/share/artica-postfix/bin/install/rrd/yorel_cron"] = true;
    $Files["/usr/share/artica-postfix/bin/install/rrd/yorel-upd"] = true;
    while (list($filepath, $table) = each($Files)) {
        if (is_file($filepath)) {
            echo "Removing {$filepath}\n";
            @unlink($filepath);
        }
    }
    build_progress("Removing old code....", 15);
    $artica_events_delete["dnsperfs"] = true;
    $artica_events_delete["dnsperfs_week"] = true;
    $artica_events_delete["sys_loadvg"] = true;
    $artica_events_delete["sys_mem"] = true;
    $artica_events_delete["sys_loadvg"] = true;
    $artica_events_delete["squid_rqs_days"] = true;
    $artica_events_delete["squid_cache_perfs"] = true;
    $artica_events_delete["cpustats"] = true;
    @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableStreamCache", 0);
    build_progress("List old tables...", 20);
    cleanother();
    $LIST_TABLES_HOURS = LIST_TABLES_HOURS();
    $LIST_TABLES_RTTZ_WORKSHOURS = LIST_TABLES_RTTZ_WORKSHOURS();
    $LIST_TABLES_CACHE_DAY = LIST_TABLES_CACHE_DAY();
    $LIST_TABLES_WORKSHOURS = LIST_TABLES_WORKSHOURS();
    $LIST_TABLES_SIZEHOURS = LIST_TABLES_SIZEHOURS();
    $LIST_TABLES_dansguardian_events = LIST_TABLES_dansguardian_events();
    $LIST_TABLES_RTTD = LIST_TABLES_RTTD();
    $LIST_TABLES_week = LIST_TABLES_week();
    $MQUOTASIZE = LIST_TABLES_gen("%_MQUOTASIZE");
    $WQUOTASIZE = LIST_TABLES_gen("%_WQUOTASIZE");
    $quotaday = LIST_TABLES_gen("quotaday_%");
    $visited = LIST_TABLES_gen("%_visited");
    $quotamonth = LIST_TABLES_gen("quotamonth_%");
    $DAYS = LIST_TABLES_gen("%_day");
    $CATFAM = LIST_TABLES_gen("%_catfam");
    $WWWUSERS = LIST_TABLES_gen("www_%");
    $GCACHES = LIST_TABLES_gen("%_gcache");
    $_not_cached = LIST_TABLES_gen("%_not_cached");
    $members = LIST_TABLES_gen("%_members");
    $dcache = LIST_TABLES_gen("%_dcache");
    $family = LIST_TABLES_gen("%_family");
    $proto = LIST_TABLES_gen("%_proto");
    $_cacheperfs = LIST_TABLES_gen("%_cacheperfs");
    $UserSizeD = LIST_TABLES_gen("UserSizeD_%");
    $blocked_days = LIST_TABLES_gen("%_blocked_days");
    $squidmemory = LIST_TABLES_gen("squidmemory_%");
    $squidmemoryM = LIST_TABLES_gen("squidmemoryM_%");
    $blocked_week = LIST_TABLES_gen("%_blocked_week");
    $hours1 = LIST_TABLES_gen("hour_%");
    $hours2 = LIST_TABLES_gen("squidhour_%");
    $hours3 = LIST_TABLES_gen("sizehour_%");
    $visited = LIST_TABLES_gen("%_visited");
    $squidlogs["UserSizeRTT"] = true;
    $squidlogs["visited_sites"] = true;
    $squidlogs["MySQLStats"] = true;
    while (list($num, $table) = each($LIST_TABLES_HOURS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_RTTZ_WORKSHOURS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_CACHE_DAY)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_WORKSHOURS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_SIZEHOURS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_dansguardian_events)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_RTTD)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($LIST_TABLES_week)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($MQUOTASIZE)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($WQUOTASIZE)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($quotaday)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($visited)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($quotamonth)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($DAYS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($CATFAM)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($WWWUSERS)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($GCACHES)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($_not_cached)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($members)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($family)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($proto)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($_cacheperfs)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($UserSizeD)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($blocked_days)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($squidmemory)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($squidmemoryM)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($blocked_week)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($hours1)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($hours2)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($hours3)) {
        $squidlogs[$num] = true;
    }
    while (list($num, $table) = each($visited)) {
        $squidlogs[$num] = true;
    }
    $q = new mysql_squid_builder();
    while (list($tablename, $none) = each($squidlogs)) {
        if (!$q->TABLE_EXISTS($tablename)) {
            continue;
        }
        if ($q->COUNT_ROWS($table) == 0) {
            $q->QUERY_SQL("DROP TABLE `{$tablename}`");
            continue;
        }
        build_progress("Backup table/remove {$tablename}", 25);
        echo "Backup {$tablename}\n";
        if (!backup_squidlogs($tablename)) {
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    }
    while (list($filename, $none) = each($toDelete)) {
        if (is_file("/share/artica-postfix/{$filename}")) {
            build_progress("Removing {$filename}", 50);
            @unlink("/usr/share/artica-postfix/{$filename}");
        }
    }
    $q = new mysql();
    while (list($tablename, $none) = each($artica_events_delete)) {
        if (!$q->TABLE_EXISTS($tablename, "artica_events")) {
            continue;
        }
        build_progress("Backup table {$tablename}", 60);
        if ($q->COUNT_ROWS($table, "artica_events") == 0) {
            $q->QUERY_SQL("DROP TABLE `{$tablename}`", "artica_events");
            continue;
        }
        $q->QUERY_SQL("DROP TABLE `{$tablename}`", "artica_events");
    }
    $users = new usersMenus();
    if ($users->POSTFIX_INSTALLED) {
        $q = new mysql();
        if ($q->DATABASE_EXISTS("postfixlog")) {
            $q->DELETE_DATABASE("postfixlog");
        }
        if ($q->DATABASE_EXISTS("syslogstore")) {
            $q->DELETE_DATABASE("syslogstore");
        }
    }
    build_progress("{reconfigure_proxy_service}", 70);
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    build_progress("{restarting} BigData Database", 80);
    system("/etc/init.d/influx-db restart --force");
    build_progress("{restarting} Watchdog", 90);
    system("/etc/init.d/artica-status restart --force");
    build_progress("{restarting} Watchdog", 95);
    system("/etc/init.d/squid-tail restart");
    build_progress("{restarting} Watchdog", 98);
    system("/etc/init.d/cache-tail restart");
    @file_put_contents("/etc/artica-postfix/settings/Daemons/UpgradeTov10", 1);
    build_progress("{done}", 100);
}
Esempio n. 14
0
function loadavg_logs()
{
    include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Already running pid {$pid}\n";
        return;
    }
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("artica_events")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Stop !\n";
        }
        events_Loadavg("loadavg_logs:: artica_events database does not exists... try to build one" . __LINE__);
        $q->BuildTables();
    }
    if (!$q->DATABASE_EXISTS("artica_events")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Stop !\n";
        }
        events_Loadavg("loadavg_logs:: artica_events database cannot continue" . __LINE__);
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Scan {$GLOBALS["ARTICALOGDIR"]}/loadavg/*\n";
    }
    $COUNT = $unix->COUNT_FILES("{$GLOBALS["ARTICALOGDIR"]}/loadavg");
    if ($COUNT > 5000) {
        if (!($handle = opendir("{$GLOBALS["ARTICALOGDIR"]}/loadavg"))) {
            return;
        }
        while (false !== ($filename = readdir($handle))) {
            if ($filename == ".") {
                continue;
            }
            if ($filename == "..") {
                continue;
            }
            $filename = "{$GLOBALS["ARTICALOGDIR"]}/loadavg/{$filename}";
            @unlink($filename);
        }
        return;
    }
    if (!($handle = opendir("{$GLOBALS["ARTICALOGDIR"]}/loadavg"))) {
        @mkdir("{$GLOBALS["ARTICALOGDIR"]}/loadavg", 0755, true);
        return;
    }
    while (false !== ($filename = readdir($handle))) {
        if ($filename == ".") {
            continue;
        }
        if ($filename == "..") {
            continue;
        }
        $filename = "{$GLOBALS["ARTICALOGDIR"]}/loadavg/{$filename}";
        if ($unix->file_time_min($filename) > 240) {
            @unlink($filename);
            continue;
        }
        $time = basename($filename);
        $load = @file_get_contents($filename);
        $date = date('Y-m-d H:i:s', $time);
        $sql = "INSERT IGNORE INTO loadavg (`stime`,`load`) VALUES ('{$date}','{$load}');";
        $q->QUERY_SQL($sql, "artica_events");
        if (!$q->ok) {
            events_Loadavg("loadavg_logs:: {$q->mysql_error} line:" . __LINE__);
            continue;
        }
        events_Loadavg("loadavg_logs:: success {$filename}" . __LINE__);
        @unlink($filename);
    }
}
Esempio n. 15
0
function checkdb()
{
    $createtable = false;
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("greyhole")) {
        $createtable = true;
        echo "Starting......: " . date("H:i:s") . " greyhole creating mysql database \"greyhole\"\n";
        $q->CREATE_DATABASE("greyhole");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " greyhole {$q->mysql_error}\n";
            return false;
        }
    }
    if (!$q->TABLE_EXISTS("settings", "greyhole")) {
        echo "Starting......: " . date("H:i:s") . " greyhole create table \"settings\"\n";
        $sql = "CREATE TABLE `settings` (\n\t\t`name` TINYTEXT NOT NULL,\n\t\t`value` TEXT NOT NULL,\n\t\tPRIMARY KEY ( `name`(255) )\n\t\t) ENGINE = MYISAM;";
        $q->QUERY_SQL($sql, "greyhole");
        $sql = "INSERT INTO `settings` (`name`, `value`) VALUES ('last_read_log_smbd_line', '0');";
        $q->QUERY_SQL($sql, "greyhole");
        $sql = "INSERT INTO `settings` (`name`, `value`) VALUES ('last_OOS_notification', '0');";
        $q->QUERY_SQL($sql, "greyhole");
    }
    if (!$q->TABLE_EXISTS("tasks", "greyhole")) {
        echo "Starting......: " . date("H:i:s") . " greyhole create table \"tasks\"\n";
        $sql = "CREATE TABLE `tasks` (\n\t\t`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n\t\t`action` VARCHAR( 10 ) NOT NULL,\n\t\t`share` TINYTEXT NOT NULL,\n\t\t`full_path` TINYTEXT NULL,\n\t\t`additional_info` TINYTEXT NULL,\n\t\t`complete` ENUM( 'yes',  'no', 'frozen', 'thawed', 'idle') NOT NULL,\n\t\t`event_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n\t\t) ENGINE = MYISAM;";
        $q->QUERY_SQL($sql, "greyhole");
        $sql = "ALTER TABLE `tasks` ADD INDEX `find_next_task` ( `complete` , `share` (64) , `id` );";
        $q->QUERY_SQL($sql, "greyhole");
    }
    if (!$q->TABLE_EXISTS("tasks_completed", "greyhole")) {
        echo "Starting......: " . date("H:i:s") . " greyhole create table \"tasks_completed\"\n";
        $sql = "CREATE TABLE `tasks_completed` (\n\t\t`id` BIGINT UNSIGNED NOT NULL,\n\t\t`action` VARCHAR( 10 ) NOT NULL,\n\t\t`share` TINYTEXT NOT NULL,\n\t\t`full_path` TINYTEXT NULL,\n\t\t`additional_info` TINYTEXT NULL,\n\t\t`complete` ENUM( 'yes',  'no' ) NOT NULL,\n\t\t`event_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n\t\t) ENGINE = MYISAM;";
        $q->QUERY_SQL($sql, "greyhole");
        if (!$q->ok) {
            echo "Starting......: " . date("H:i:s") . " greyhole {$q->mysql_error}\n";
        }
    }
    echo "Starting......: " . date("H:i:s") . " greyhole checking database and table done\n";
    return true;
}
Esempio n. 16
0
function remove_host($hostname)
{
    $freeweb = new freeweb($hostname);
    if (is_dir("/var/www/{$hostname}")) {
        shell_exec("/bin/rm -rf /var/www/{$hostname}");
    }
    if ($freeweb->IsGroupWareFromArtica()) {
        $freeweb->delete();
        return;
    }
    if ($freeweb->WebCopyID > 0) {
        $freeweb->delete();
        return;
    }
    $mysql_database = $freeweb->mysql_database;
    $q = new mysql();
    if ($q->DATABASE_EXISTS($mysql_database)) {
        $q->DELETE_DATABASE($mysql_database);
    }
    if ($freeweb->groupware == "POWERADMIN") {
        $freeweb->delete();
        return;
    }
    if ($freeweb->groupware == "ARKEIA") {
        $freeweb->delete();
        return;
    }
    if ($freeweb->groupware == "UPDATEUTILITY") {
        $freeweb->delete();
        return;
    }
    if ($freeweb->groupware == "SARG") {
        $freeweb->delete();
        return;
    }
    if ($hostname == "_default_") {
        $freeweb->delete();
        return;
    }
    if ($freeweb->Forwarder == 0) {
        $freeweb->delete();
        return;
    }
    if (is_dir($freeweb->WORKING_DIRECTORY)) {
        shell_exec("/bin/rm -rf {$freeweb->WORKING_DIRECTORY}");
    }
    $freeweb->delete();
}
Esempio n. 17
0
function updatev2_manu()
{
    $sock = new sockets();
    $unix = new unix();
    $t = time();
    $GLOBALS["TEMP_PATH"] = $unix->TEMP_DIR();
    $ManualArticaDBPath = $sock->GET_INFO("ManualArticaDBPath");
    $ArticaDbReplicate = $sock->GET_INFO("ArticaDbReplicate");
    if ($ManualArticaDBPath == null) {
        $ManualArticaDBPath = "/home/manualupdate/articadb.tar.gz";
    }
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    if (!is_numeric($ArticaDbReplicate)) {
        $ArticaDbReplicate = 0;
    }
    $tar = $unix->find_program("tar");
    updatev2_progress(80, "{installing}...");
    if ($GLOBALS["VERBOSE"]) {
        echo "uncompressing {$ManualArticaDBPath}\n";
    }
    @mkdir($ArticaDBPath, 0755, true);
    updatev2_progress(85, "{stopping_service}...");
    shell_exec("/etc/init.d/artica-postfix stop articadb");
    updatev2_progress(95, "{extracting_package}...");
    shell_exec("{$tar} -xf {$ManualArticaDBPath} -C {$ArticaDBPath}/");
    updatev2_progress(96, "{cleaning}...");
    if ($ArticaDbReplicate == 1) {
        @copy("/usr/share/artica-postfix/ressources/logs/web/cache/CATZ_ARRAY", "/home/articatechdb.version");
        @copy("{$ManualArticaDBPath}", "/home/articadb.tar.gz");
        @chmod("/home/articadb.tar.gz", 0755);
        @chmod("/home/articatechdb.version", 0755);
    }
    @unlink($ManualArticaDBPath);
    updatev2_progress(89, "{starting_service}...");
    if ($GLOBALS["VERBOSE"]) {
        echo "starting Articadb\n";
    }
    shell_exec("/etc/init.d/artica-postfix start articadb");
    updatev2_progress(90, "{checking}");
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("catz")) {
        updatev2_progress(95, "Removing old database catz");
        $q->DELETE_DATABASE("catz");
    }
    updatev2_progress(99, "{finish}");
    $took = $unix->distanceOfTimeInWords($t, time());
    $LOCAL_VERSION = @file_get_contents("{$ArticaDBPath}/VERSION");
    squid_admin_mysql(2, "New Artica Database statistics {$LOCAL_VERSION} updated took:{$took}", "");
    // ufdbguard_admin_events("New Artica Database statistics $LOCAL_VERSION updated took:$took.",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
    updatev2_progress(100, "{done}");
    $q->QUERY_SQL("TRUNCATE TABLE `catztemp`");
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $cmd = trim("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.visited.sites.php --schedule-id={$GLOBALS["SCHEDULE_ID"]} >/dev/null 2>&1 &");
    shell_exec($cmd);
    return true;
}
Esempio n. 18
0
function SearchComputers()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $sock = new sockets();
    $EnableIntelCeleron = intval($sock->GET_INFO("EnableIntelCeleron"));
    $q = new mysql();
    $sock = new sockets();
    $fontsize = "14px";
    $cs = 0;
    $page = 1;
    if (!$q->DATABASE_EXISTS("ocsweb")) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->TABLE_EXISTS("hardware", "ocsweb")) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->TABLE_EXISTS("networks", "ocsweb", true)) {
        $sock->getFrameWork("services.php?mysql-ocs=yes");
    }
    if (!$q->FIELD_EXISTS("networks", "isActive", "ocsweb")) {
        $q->QUERY_SQL("ALTER TABLE `networks` ADD `isActive` SMALLINT( 1 ) NOT NULL DEFAULT '0',ADD INDEX ( `isActive` ) ", "ocsweb");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $table = "(SELECT networks.HARDWARE_ID,networks.MACADDR,networks.STATUS,networks.IPADDRESS,networks.isActive,\n\t\t\thardware.* FROM networks,hardware WHERE networks.HARDWARE_ID=hardware.ID) as t";
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "ocsweb"));
        if (!$q->ok) {
            json_error_show($q->mysql_error . "<br>{$sql}");
        }
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "ocsweb"));
        if (!$q->ok) {
            json_error_show($q->mysql_error . "<br>{$sql}");
        }
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, "ocsweb");
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<hr>{$sql}");
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data");
    }
    $users = new usersMenus();
    $DHC_MAIN = false;
    if ($users->dhcp_installed) {
        $EnableDHCPServer = intval($sock->GET_INFO('EnableDHCPServer'));
        if ($EnableDHCPServer == 1) {
            $DHC_MAIN = true;
        }
    }
    $SQUID_MAIN = false;
    if ($users->SQUID_INSTALLED) {
        $SQUID_MAIN = true;
    }
    $fontsize = "22px";
    $computer = new computers();
    $q2 = new mysql_squid_builder();
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["MACADDR"] == "unknown") {
            continue;
        }
        $ligne["MACADDR"] = strtolower($ligne["MACADDR"]);
        $HARDWARE_ID = $ligne["HARDWARE_ID"];
        $uid = null;
        $OSNAME = null;
        if ($ligne["OSNAME"] == "Unknown") {
            $ligne["OSNAME"] = null;
        }
        $color = "#7D7D7D";
        $md = md5($ligne["MACADDR"]);
        $uri = strtolower($ligne["NAME"]);
        if ($EnableIntelCeleron == 0) {
            $uid = $computer->ComputerIDFromMAC($ligne["MACADDR"]);
        }
        $view = "&nbsp;";
        $jslink = null;
        $jsfiche = null;
        $ISDB = "ok32-grey.png";
        $DHCP = "ok32-none.png";
        $SQUID = "ok32-none.png";
        if ($DHC_MAIN) {
            $DHCP = "ok32-grey.png";
            if ($computer->dhcpfixedFromMac($ligne["MACADDR"])) {
                $DHCP = "ok32.png";
            }
        }
        if ($SQUID_MAIN) {
            $ligne2 = mysql_fetch_array($q2->QUERY_SQL("SELECT enabled FROM computers_time WHERE `MAC`='{$ligne["MACADDR"]}'", "artica_backup"));
            if (intval($ligne2["enabled"]) != 0) {
                $SQUID = "warning24.png";
            }
        }
        if ($uid != null) {
            $ISDB = "ok32.png";
            $jsfiche = MEMBER_JS($uid, 1, 1);
            $view = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>";
            $jslink = "<a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$jsfiche}\" \n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>";
        } else {
            $uid = $ligne["NAME"];
            if (preg_match("#^[0-9]+\\.[0-9]+\\.[0-9]+#", $uid)) {
                $q = new mysql_squid_builder();
                $NAME2 = $q->UID_FROM_MAC($ligne["MACADDR"]);
                if ($NAME2 != null) {
                    $uid = $NAME2;
                }
            }
            if ($uid == null) {
                $uid = "Unknown";
            }
            $jsfiche = "Loadjs('domains.computer.autoadd.php?mac=" . urlencode($ligne["MACADDR"]) . "&ipaddr=" . urlencode($ligne["IPADDRESS"]) . "&computername=" . urlencode($uid) . "&t={$_GET["t"]}')";
            if ($EnableIntelCeleron == 1) {
                $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')";
            }
            $jslink = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>";
            $view = "<a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$jsfiche}\"\n\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>{$uid}</a>";
        }
        $js[] = "LoadAjaxTiny('cmp-{$md}','{$page}?compt-status={$ligne["IPADDRESS"]}');";
        $icon = "<img src='img/{$ISDB}'>";
        if ($ligne["OSNAME"] != null) {
            $OSNAME = "<div style='font-size:9px'><i>{$ligne["OSNAME"]}</i></div>";
        }
        if ($_GET["callback"] != null) {
            $color = "black";
            if ($_GET["fullvalues"] == 1) {
                $viewjs = "{$_GET["callback"]}('{$uid}','{$ligne["IPADDRESS"]}','{$ligne["MACADDR"]}')";
            } else {
                $viewjs = "{$_GET["callback"]}('{$uid}')";
            }
            $view = "<a href=\"javascript:blur();\" \n\t\t\t\t\t\tOnClick=\"javascript:{$viewjs}\" \n\t\t\t\t\t\tstyle='font-size:{$fontsize};text-decoration:underline'>" . str_replace("\$", "", strtolower($uid)) . "</a>";
            $icon = imgtootltip("arrow-blue-left-32.png", null, $viewjs);
        }
        if (!IsPhysicalAddress($ligne["MACADDR"])) {
            if ($_GET["CorrectMac"] == 1) {
                continue;
            }
        }
        $AlreadyMAC[$ligne["MACADDR"]] = true;
        $zdate = null;
        if (isset($ligne["zDate"])) {
            $zdate = "<div style='font-size:11px;color:#7D7D7D'>{$ligne["zDate"]}</div>";
        }
        $macenc = urlencode($ligne["MACADDR"]);
        $ipenc = urlencode($ligne["IPADDRESS"]);
        $jsDelete = "Loadjs('{$MyPage}?delete-computer-js=yes&MAC={$macenc}&t={$_GET["t"]}');";
        $alias = $q2->UID_FROM_MAC($ligne["MACADDR"]);
        if ($alias != null) {
            $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&MAC={$macenc}');";
        }
        if ($alias == null) {
            $alias = $q2->UID_FROM_IP($ligne["IPADDRESS"]);
            if ($alias != null) {
                $alias_uri = "Loadjs('squid.nodes.php?node-infos-js=yes&ipaddr={$ipenc}');";
            }
        }
        if ($alias == null) {
            $alias = "<center><img src='img/32-plus.png'></center>";
            $alias_uri = "Loadjs('squid.nodes.php?link-user-js=yes&MAC={$macenc}&ipaddr={$ipenc}',true)";
        }
        if ($EnableIntelCeleron == 1) {
            $jsfiche = "Loadjs('domains.computer.mysql.php?HARDWARE_ID={$HARDWARE_ID}&t={$_GET["t"]}')";
        }
        $cs++;
        $data['rows'][] = array('id' => md5(serialize($ligne)), 'cell' => array($view . $zdate, "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["IPADDRESS"]}</a></span>", "<span style='font-size:{$fontsize}'>{$jslink}{$ligne["MACADDR"]}</a></span>", "<span style='font-size:{$fontsize}'><a href=\"javascript:blur();\" \n\t\t\tOnClick=\"javascript:{$alias_uri}\" style='text-decoration:underline'>{$alias}</a></span>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\">{$icon}</a></center>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$DHCP}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsfiche}\"><img src='img/{$SQUID}'></center></a>", "<center><a href=\"javascript:blur();\" OnClick=\"javascript:{$jsDelete}\"><img src='img/delete-32.png'></center></a>"));
    }
    if ($cs > $_POST["rp"]) {
        $data['total'] = $cs;
        echo json_encode($data);
        return;
    }
    if ($cs == 0) {
        json_error_show("no item");
    }
    $data['total'] = $cs;
    echo json_encode($data);
}
Esempio n. 19
0
function checkdb()
{
    $unix = new unix();
    $q = new mysql();
    $JAVA_HOME = $unix->JAVA_HOME_GET();
    if (strlen($JAVA_HOME) == 0) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM JAVA_HOME failed\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " OpenEMM JAVA_HOME {$JAVA_HOME}\n";
    if (!is_file("/home/openemm/bin/openemm.sh")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM /home/openemm/bin/openemm.sh no such file\n";
        return;
    }
    if (!is_file("/opt/openemm/tomcat6/bin/startup.sh")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM tomcat 6.x is not installed\n";
        return;
    }
    if (!$q->DATABASE_EXISTS("openemm")) {
        $q->CREATE_DATABASE("openemm");
    }
    if (!$q->DATABASE_EXISTS("openemm")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM failed creating database openemm\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " OpenEMM database openemm OK\n";
    if (!$q->DATABASE_EXISTS("openemm_cms")) {
        $q->CREATE_DATABASE("openemm_cms");
    }
    if (!$q->DATABASE_EXISTS("openemm_cms")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM failed creating database openemm_cms\n";
        return;
    }
    if (!test_cms_tables()) {
        if (is_file("/home/openemm/USR_SHARE/openemm_cms-2011.sql")) {
            $mysql = $unix->find_program("mysql");
            $cmd = "{$mysql} -u {$q->mysql_admin} -p\"{$q->mysql_password}\" --batch --database=openemm_cms < /home/openemm/USR_SHARE/openemm_cms-2011.sql";
            shell_exec($cmd);
        }
    }
    if (!testtables()) {
        $mysql = $unix->find_program("mysql");
        if (is_file("/home/openemm/USR_SHARE/openemm-2011.sql")) {
            $cmd = "{$mysql} -u {$q->mysql_admin} -p\"{$q->mysql_password}\" --batch --database=openemm < /home/openemm/USR_SHARE/openemm-2011.sql";
            shell_exec($cmd);
        }
    }
    if (!testtables()) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM failed creating openemm tables\n";
        return;
    }
    if (!test_cms_tables()) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM failed creating openemm_cms tables\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " OpenEMM tables in openemm base OK\n";
    echo "Starting......: " . date("H:i:s") . " OpenEMM tables in openemm_cms base OK\n";
    if (!$unix->CreateUnixUser("openemm")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM unix user openemm failed\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " OpenEMM unix user openemm OK\n";
    patch_javahome($JAVA_HOME);
    patch_tomcat_dir("/opt/openemm/tomcat6");
    if (!is_dir("/home/openemm/logs")) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM creating /home/openemm/logs directory\n";
        @mkdir("/home/openemm/logs", 0755, true);
    }
    $aa_complain = $unix->find_program("aa-complain");
    if (is_file($aa_complain)) {
        shell_exec("{$aa_complain} {$JAVA_HOME}/bin/java");
    }
    if (!is_file("/home/openemm/webapps/openemm/WEB-INF/classes/messages_en_US.properties")) {
        shell_exec("/bin/cp /home/openemm/webapps/openemm/WEB-INF/classes/messages_en.properties /home/openemm/webapps/openemm/WEB-INF/classes/messages_en_US.properties");
    }
    cms_properties();
    if (!is_dir("/home/openemm/work/Catalina/openemm/_")) {
        @mkdir("/home/openemm/work/Catalina/openemm/_", 0755, true);
    }
    shell_exec("/bin/chown openemm /home/openemm");
    shell_exec("/bin/chown -R openemm /home/openemm");
    if (is_numeric(is_tomcat_running())) {
        echo "Starting......: " . date("H:i:s") . " OpenEMM stopping tomcat first...\n";
        shell_exec("/etc/init.d/artica-postfix stop tomcat");
    }
    @unlink("/home/openemm/logs/catalina.out");
    @unlink("/home/openemm/logs/openemm/openemm_axis.log");
    @unlink("/home/openemm/logs/openemm/openemm_axis.log");
    @unlink("/home/openemm/logs/openemm/openemm_core.log");
    @unlink("/home/openemm/logs/openemm/userlogs.log");
}
Esempio n. 20
0
function mysql_checks()
{
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("ids")) {
        $q->CREATE_DATABASE("ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS database\n";
        }
    }
    if (!$q->TABLE_EXISTS("schema", "ids")) {
        $q->QUERY_SQL("CREATE TABLE `schema` ( vseq        INT      UNSIGNED NOT NULL,\n\tctime       DATETIME NOT NULL,\n\tPRIMARY KEY (vseq));", "ids");
        $q->QUERY_SQL("INSERT INTO `schema`  (vseq, ctime) VALUES ('107', now());", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/schema\n";
        }
    }
    if (!$q->TABLE_EXISTS("event", "ids")) {
        $q->QUERY_SQL("CREATE TABLE event  ( sid \t  INT \t   UNSIGNED NOT NULL,\n\t\tcid \t  INT \t   UNSIGNED NOT NULL,\n\t\tsignature   INT      UNSIGNED NOT NULL,\n\t\ttimestamp \t   DATETIME NOT NULL,\n\t\tPRIMARY KEY (sid,cid),\n\t\tINDEX       sig (signature),\n\t\tINDEX       time (timestamp));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/event\n";
        }
    }
    if (!$q->TABLE_EXISTS("signature", "ids")) {
        $q->QUERY_SQL("CREATE TABLE signature ( sig_id       INT          UNSIGNED NOT NULL AUTO_INCREMENT,\n\tsig_name     VARCHAR(255) NOT NULL,\n\tsig_class_id INT          UNSIGNED NOT NULL,\n\tsig_priority INT          UNSIGNED,\n\tsig_rev      INT          UNSIGNED,\n\tsig_sid      INT          UNSIGNED,\n\tsig_gid      INT          UNSIGNED,\n\tPRIMARY KEY (sig_id),\n\tINDEX   sign_idx (sig_name(20)),\n\tINDEX   sig_class_id_idx (sig_class_id));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/signature\n";
        }
    }
    if (!$q->TABLE_EXISTS("sig_reference", "ids")) {
        $q->QUERY_SQL("CREATE TABLE sig_reference (sig_id  INT    UNSIGNED NOT NULL,\n\t\tref_seq INT    UNSIGNED NOT NULL,\n\t\tref_id  INT    UNSIGNED NOT NULL,\n\t\tPRIMARY KEY(sig_id, ref_seq));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/sig_reference\n";
        }
    }
    if (!$q->TABLE_EXISTS("reference", "ids")) {
        $q->QUERY_SQL("CREATE TABLE reference (  ref_id        INT         UNSIGNED NOT NULL AUTO_INCREMENT,\n\tref_system_id INT         UNSIGNED NOT NULL,\n\tref_tag       TEXT NOT NULL,\n\tPRIMARY KEY (ref_id));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/reference\n";
        }
    }
    if (!$q->TABLE_EXISTS("reference_system", "ids")) {
        $q->QUERY_SQL("CREATE TABLE reference_system ( ref_system_id   INT         UNSIGNED NOT NULL AUTO_INCREMENT,\n\tref_system_name VARCHAR(20),\n\tPRIMARY KEY (ref_system_id));", "ids");
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/reference_system\n";
        }
    }
    if (!$q->TABLE_EXISTS("sig_class", "ids")) {
        $q->QUERY_SQL("CREATE TABLE sig_class ( sig_class_id        INT    UNSIGNED NOT NULL AUTO_INCREMENT,\n\tsig_class_name      VARCHAR(60) NOT NULL,\n\tPRIMARY KEY (sig_class_id),\n\tINDEX       (sig_class_id),\n\tINDEX       (sig_class_name));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/sig_class\n";
        }
    }
    # store info about the sensor supplying data
    if (!$q->TABLE_EXISTS("sensor", "ids")) {
        $q->QUERY_SQL("CREATE TABLE sensor ( sid\t  INT \t   UNSIGNED NOT NULL AUTO_INCREMENT,\n\thostname    TEXT,\n\tinterface   TEXT,\n\tfilter\t  TEXT,\n\tdetail\t  TINYINT,\n\tencoding\t  TINYINT,\n\tlast_cid    INT      UNSIGNED NOT NULL,\n\tPRIMARY KEY (sid));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/sensor\n";
        }
    }
    # All of the fields of an ip header
    if (!$q->TABLE_EXISTS("iphdr", "ids")) {
        $q->QUERY_SQL("CREATE TABLE iphdr  ( sid \t  INT \t   UNSIGNED NOT NULL,\n\tcid \t  INT \t   UNSIGNED NOT NULL,\n\tip_src      INT      UNSIGNED NOT NULL,\n\tip_dst      INT      UNSIGNED NOT NULL,\n\tip_ver      TINYINT  UNSIGNED,\n\tip_hlen     TINYINT  UNSIGNED,\n\tip_tos  \t  TINYINT  UNSIGNED,\n\tip_len \t  SMALLINT UNSIGNED,\n\tip_id    \t  SMALLINT UNSIGNED,\n\tip_flags    TINYINT  UNSIGNED,\n\tip_off      SMALLINT UNSIGNED,\n\tip_ttl   \t  TINYINT  UNSIGNED,\n\tip_proto \t  TINYINT  UNSIGNED NOT NULL,\n\tip_csum \t  SMALLINT UNSIGNED,\n\tPRIMARY KEY (sid,cid),\n\tINDEX ip_src (ip_src),\n\tINDEX ip_dst (ip_dst));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/iphdr\n";
        }
    }
    # All of the fields of a tcp header
    if (!$q->TABLE_EXISTS("tcphdr", "ids")) {
        $q->QUERY_SQL("CREATE TABLE tcphdr(  sid \t  INT \t   UNSIGNED NOT NULL,\n\tcid \t  INT \t   UNSIGNED NOT NULL,\n\ttcp_sport   SMALLINT UNSIGNED NOT NULL,\n\ttcp_dport   SMALLINT UNSIGNED NOT NULL,\n\ttcp_seq     INT      UNSIGNED,\n\ttcp_ack     INT      UNSIGNED,\n\ttcp_off     TINYINT  UNSIGNED,\n\ttcp_res     TINYINT  UNSIGNED,\n\ttcp_flags   TINYINT  UNSIGNED NOT NULL,\n\ttcp_win     SMALLINT UNSIGNED,\n\ttcp_csum    SMALLINT UNSIGNED,\n\ttcp_urp     SMALLINT UNSIGNED,\n\tPRIMARY KEY (sid,cid),\n\tINDEX       tcp_sport (tcp_sport),\n\tINDEX       tcp_dport (tcp_dport),\n\tINDEX       tcp_flags (tcp_flags));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/tcphdr\n";
        }
    }
    # All of the fields of a udp header
    if (!$q->TABLE_EXISTS("udphdr", "ids")) {
        $q->QUERY_SQL("CREATE TABLE udphdr(  sid \t  INT \t   UNSIGNED NOT NULL,\n\tcid \t  INT \t   UNSIGNED NOT NULL,\n\tudp_sport   SMALLINT UNSIGNED NOT NULL,\n\tudp_dport   SMALLINT UNSIGNED NOT NULL,\n\tudp_len     SMALLINT UNSIGNED,\n\tudp_csum    SMALLINT UNSIGNED,\n\tPRIMARY KEY (sid,cid),\n\tINDEX       udp_sport (udp_sport),\n\tINDEX       udp_dport (udp_dport));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/udphdr\n";
        }
    }
    # All of the fields of an icmp header
    if (!$q->TABLE_EXISTS("icmphdr", "ids")) {
        $q->QUERY_SQL("CREATE TABLE icmphdr( sid \t  INT \t   UNSIGNED NOT NULL,\n\tcid \t  INT  \t   UNSIGNED NOT NULL,\n\ticmp_type   TINYINT  UNSIGNED NOT NULL,\n\ticmp_code   TINYINT  UNSIGNED NOT NULL,\n\ticmp_csum   SMALLINT UNSIGNED,\n\ticmp_id     SMALLINT UNSIGNED,\n\ticmp_seq    SMALLINT UNSIGNED,\n\tPRIMARY KEY (sid,cid),\n\tINDEX       icmp_type (icmp_type));", "ids");
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/icmphdr\n";
        }
    }
    # Protocol options
    if (!$q->TABLE_EXISTS("opt", "ids")) {
        $q->QUERY_SQL("CREATE TABLE opt    ( sid         INT      UNSIGNED NOT NULL,\n\tcid         INT      UNSIGNED NOT NULL,\n\toptid       INT      UNSIGNED NOT NULL,\n\topt_proto   TINYINT  UNSIGNED NOT NULL,\n\topt_code    TINYINT  UNSIGNED NOT NULL,\n\topt_len     SMALLINT,\n\topt_data    TEXT,\n\tPRIMARY KEY (sid,cid,optid));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/opt\n";
        }
    }
    # Packet payload
    if (!$q->TABLE_EXISTS("data", "ids")) {
        $q->QUERY_SQL("CREATE TABLE data   ( sid           INT      UNSIGNED NOT NULL,\n\tcid           INT      UNSIGNED NOT NULL,\n\tdata_payload  TEXT,\n\tPRIMARY KEY (sid,cid));", "ids");
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/data\n";
        }
    }
    # encoding is a lookup table for storing encoding types
    if (!$q->TABLE_EXISTS("encoding", "ids")) {
        $q->QUERY_SQL("CREATE TABLE encoding(encoding_type TINYINT UNSIGNED NOT NULL,\n\tencoding_text TEXT NOT NULL,\n\tPRIMARY KEY (encoding_type));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        $q->QUERY_SQL("INSERT INTO encoding (encoding_type, encoding_text) VALUES (0, 'hex');", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        $q->QUERY_SQL("INSERT INTO encoding (encoding_type, encoding_text) VALUES (1, 'base64');", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        $q->QUERY_SQL("INSERT INTO encoding (encoding_type, encoding_text) VALUES (2, 'ascii');", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/encoding\n";
        }
    }
    # detail is a lookup table for storing different detail levels
    if (!$q->TABLE_EXISTS("detail", "ids")) {
        $q->QUERY_SQL("CREATE TABLE detail  (detail_type TINYINT UNSIGNED NOT NULL,\n\tdetail_text TEXT NOT NULL,\n\tPRIMARY KEY (detail_type));", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        $q->QUERY_SQL("INSERT INTO detail (detail_type, detail_text) VALUES (0, 'fast');", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        $q->QUERY_SQL("INSERT INTO detail (detail_type, detail_text) VALUES (1, 'full');", "ids");
        if (!$q->ok) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MySQL Error {$q->mysql_error}\n";
            }
            return;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Setting.......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating IDS/detail\n";
        }
    }
}
Esempio n. 21
0
function rotate()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "TimeFile={$TimeFile}\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $xtime = $unix->file_time_min($TimeFile);
    if (!$GLOBALS['VERBOSE']) {
        if ($xtime < 5) {
            return;
        }
    }
    @unlink($TimeFile, time());
    @file_put_contents($TimeFile, time());
    $q = new mysql();
    $echo = $unix->find_program("echo");
    if (!$q->DATABASE_EXISTS("bwmng")) {
        $q->CREATE_DATABASE("bwmng");
    }
    if (!$q->DATABASE_EXISTS("bwmng", true)) {
        return;
    }
    @copy("/home/artica/bwm-ng/interfaces.csv", "/home/artica/bwm-ng/interfaces.csv." . time());
    @unlink("/home/artica/bwm-ng/interfaces.csv");
    $files = $unix->DirFiles("/home/artica/bwm-ng");
    if (system_is_overloaded(__FILE__)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "OVERLOADED !!!!\n";
        }
        return;
    }
    while (list($filename, $notused) = each($files)) {
        if ($filename == "interfaces.csv") {
            continue;
        }
        $filepath = "/home/artica/bwm-ng/{$filename}";
        $filetime = $unix->file_time_min($filepath);
        if ($filetime > 60) {
            @unlink($filepath);
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Open {$filepath} {$filetime}mn\n";
        }
        $row = 1;
        if (($handle = fopen($filepath, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
                $num = count($data);
                if ($num == 0) {
                    continue;
                }
                $row++;
                $uniq_key = md5(serialize($data));
                $Unix_Timestamp = $data[0];
                if (!is_numeric($Unix_Timestamp)) {
                    continue;
                }
                $Interface_Name = $data[1];
                if (trim($Interface_Name) == null) {
                    print_r($data);
                    continue;
                }
                $BytesOut = intval($data[2]);
                $BytesIn = intval($data[3]);
                $BytesTotal = $data[4];
                $PacketsOut = $data[5];
                $PacketsIn = $data[6];
                $PacketsTotal = $data[7];
                if ($BytesOut == 0 && $BytesIn == 0) {
                    continue;
                }
                $Date = date("Y-m-d H:i:s", $Unix_Timestamp);
                $tableT = date("YmdH", $Unix_Timestamp) . "_bwmrt";
                if ($Interface_Name == "total") {
                    $array_total[$tableT][] = "('{$uniq_key}','{$Date}','{$BytesOut}','{$BytesIn}')";
                    continue;
                }
                $table = date("YmdH", $Unix_Timestamp) . "_bwmrh";
                $array_eths[$table][] = "('{$uniq_key}','{$Interface_Name}','{$Date}','{$BytesOut}','{$BytesIn}')";
            }
            fclose($handle);
            if (system_is_overloaded(__FILE__)) {
                break;
            }
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$filepath} CLOSED: " . count($array_eths) . " eths, " . count($array_total) . " total\n";
        }
        if (array_to_interfaces($array_eths)) {
            if (array_to_total($array_total)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$filepath} > DELETE\n";
                }
                @unlink($filepath);
            }
        } else {
            @unlink($filepath);
        }
        $array_eths = array();
        $array_total = array();
    }
    restart(true);
    if (system_is_overloaded(__FILE__)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "OVERLOADED !!!!\n";
        }
        return;
    }
    build_days();
    build_current_time();
}
Esempio n. 22
0
function build()
{
    $sock = new sockets();
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    if (!is_dir("{$ArticaDBPath}/data/catz")) {
        return;
    }
    $f[] = "[client] ";
    $f[] = "#password\t= your_password ";
    $f[] = "#port\t\t= 3306 ";
    $f[] = "socket\t\t= /var/run/mysqld/articadb.sock ";
    $f[] = " ";
    $f[] = " ";
    $f[] = "[mysqld] ";
    $f[] = "#port\t\t= 3306 ";
    $f[] = "socket\t\t= /var/run/mysqld/articadb.sock ";
    $f[] = "skip-external-locking";
    $f[] = "skip-networking ";
    $f[] = "skip-innodb";
    $f[] = "skip-slave-start";
    $f[] = "default-storage-engine = MYISAM ";
    $f[] = "default_tmp_storage_engine = MYISAM ";
    $f[] = "key_buffer_size = 16M ";
    $f[] = "max_allowed_packet = 1M ";
    $f[] = "query_cache_type = 1";
    $f[] = "query_cache_size = 35M";
    $f[] = "max_heap_table_size=40M";
    $f[] = "tmp_table_size=8M";
    $f[] = "table_open_cache = 180 ";
    $f[] = "sort_buffer_size = 256K ";
    $f[] = "read_buffer_size = 1M ";
    $f[] = "read_rnd_buffer_size = 256K ";
    $f[] = "net_buffer_length = 128K ";
    $f[] = "thread_stack = 128K ";
    $f[] = "thread_cache_size=8";
    $f[] = "table_open_cache=70";
    $f[] = "max_connections=20";
    $f[] = "server-id\t= 1 ";
    $f[] = "#log-bin=mysql-bin ";
    $f[] = "#binlog_format=mixed ";
    $f[] = "#binlog_direct_non_transactional_updates=TRUE ";
    $f[] = "tmpdir={$ArticaDBPath}/tmp";
    $f[] = "open_files_limit=2048";
    $f[] = " ";
    $f[] = " ";
    $f[] = "[mysqldump] ";
    $f[] = "quick ";
    $f[] = "max_allowed_packet = 16M ";
    $f[] = " ";
    $f[] = "[mysql] ";
    $f[] = "no-auto-rehash ";
    $f[] = "#safe-updates ";
    $f[] = " ";
    $f[] = "[myisamchk] ";
    $f[] = "key_buffer_size = 8M ";
    $f[] = "sort_buffer_size = 8M ";
    $f[] = " ";
    $f[] = "[mysqlhotcopy] ";
    $f[] = "interactive-timeout ";
    $f[] = "";
    @file_put_contents("{$ArticaDBPath}/my.cnf", @implode("\n", $f));
    @mkdir("{$ArticaDBPath}/mysql/etc", 0755, true);
    @mkdir("{$ArticaDBPath}/tmp", 0755, true);
    shell_exec("/bin/ln -sf {$ArticaDBPath}/data {$ArticaDBPath}/mysql/data");
    shell_exec("/bin/ln -sf {$ArticaDBPath}/my.cnf {$ArticaDBPath}/mysql/etc/my.cnf");
    @unlink("{$ArticaDBPath}/data/data");
    $q = new mysql();
    if ($q->DATABASE_EXISTS("catz")) {
        $q->DELETE_DATABASE("catz");
    }
    echo "Starting......: " . date("H:i:s") . " ArticaDBst configuration done...\n";
}
Esempio n. 23
0
function Save()
{
    $servername = trim(strtolower($_GET["servername"]));
    if (substr($servername, 0, 1) == '.') {
        echo $servername . " FAILED\n";
        return;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $tpl = new templates();
    $FreewebsStorageDirectory = $sock->GET_INFO("FreewebsStorageDirectory");
    if (!$users->AsWebMaster) {
        return "FALSE";
    }
    $uid = $_GET["uid"];
    $mysql_database = format_mysql_table($_GET["mysql_database"]);
    $mysql_password = $_GET["mysql_password"];
    $mysql_username = $_GET["mysql_username"];
    $lvm_vg = $_GET["lvm_vg"];
    $vg_size = $_GET["vg_size"];
    $ServerIP = $_GET["ServerIP"];
    $ServerPort = 0;
    if (preg_match("#(.+?):([0-9]+)#", $ServerIP, $re)) {
        $ServerIP = $re[1];
        $ServerPort = $re[2];
    }
    if (!is_numeric($vg_size)) {
        $vg_size = 5000;
    }
    $ftpuser = $_GET["ftpuser"];
    $ftppassword = $_GET["ftppassword"];
    $useSSL = $_GET["useSSL"];
    if (!$users->PUREFTP_INSTALLED) {
        $_GET["useFTP"] = 0;
        $ftpuser = null;
        $ftppassword = null;
    }
    $sql = "SELECT servername FROM freeweb WHERE servername='{$_GET["servername"]}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, 'artica_backup'));
    if ($ligne["servername"] != null) {
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if (!$users->AsSystemAdministrator) {
            $ou = $_SESSION["ou"];
        }
        $sql = "UPDATE freeweb SET \n\t\t\tmysql_password='******',\n\t\t\tmysql_username='******',\n\t\t\tmysql_database='{$mysql_database}',\n\t\t\tmysql_instance_id='{$_GET["mysql_instance_id"]}',\n\t\t\tftpuser='******',\n\t\t\tftppassword='******',\n\t\t\tuid='{$uid}',\n\t\t\tgpid='{$_GET["gpid"]}',\n\t\t\tuseMysql='{$_GET["useMysql"]}',\n\t\t\tuseFTP='{$_GET["useFTP"]}',\n\t\t\tlvm_vg='{$_GET["lvm_vg"]}',\n\t\t\tlvm_size='{$_GET["vg_size"]}',\n\t\t\tUseLoopDisk='{$_GET["UseLoopDisk"]}',\n\t\t\tLoopMounts='{$_GET["LoopMounts"]}',\n\t\t\twww_dir='{$_GET["www_dir"]}',\n\t\t\tUseReverseProxy='{$_GET["UseReverseProxy"]}',\n\t\t\tProxyPass='******',\n\t\t\tuseSSL='{$useSSL}',\n\t\t\tServerPort='{$ServerPort}',\n\t\t\tou='{$ou}',\n\t\t\tForwarder='{$_GET["Forwarder"]}',\n\t\t\tForwardTo='{$_GET["ForwardTo"]}',\n\t\t\tServerIP='{$ServerIP}'\n\t\t\tWHERE servername='{$servername}'\n\t\t";
    } else {
        $ApacheServerName = $sock->GET_INFO("ApacheServerName");
        if ($ApacheServerName == null) {
            $ApacheServerName = $users->fqdn;
        }
        if ($uid != null) {
            $u = new user($uid);
            $ou = $u->ou;
        }
        if ($ou != null) {
            if ($FreewebsStorageDirectory != null) {
                $www_dir = "{$FreewebsStorageDirectory}/{$servername}";
            }
        }
        $sock = new sockets();
        $servername = str_replace('..', '.', $servername);
        $servername = str_replace('/', '.', $servername);
        $servername = str_replace('\\', '.', $servername);
        $servername = str_replace(' ', '.', $servername);
        $servername = str_replace('$', '.', $servername);
        $servername = str_replace('#', '.', $servername);
        $servername = str_replace('%', '.', $servername);
        $servername = str_replace('*', '.', $servername);
        if (substr($servername, strlen($servername) - 1, 1) == '.') {
            $servername = substr($servername, 0, strlen($servername) - 1);
        }
        if (substr($servername, 0, 1) == '.') {
            $servername = substr($servername, 1, strlen($servername));
        }
        if ($servername == $ApacheServerName) {
            echo $tpl->javascript_parse_text("{virtual_hostname_cannot_same_main_hostname}", 1);
            return;
        }
        if ($_GET["force-groupware"] != null) {
            $groupware_field = ",groupware";
            $groupware_value = ",'{$_GET["force-groupware"]}'";
        }
        if ($_GET["www_dir"] != null) {
            $www_dir_field = ",www_dir";
            $www_dir_value = ",'{$_GET["www_dir"]}'";
        }
        $sock->getFrameWork("freeweb.php?force-resolv=yes");
        $sql = "INSERT INTO freeweb (mysql_password,mysql_username,ftpuser,ftppassword,useSSL,servername,mysql_database,\n\t\tuid,gpid,useMysql,useFTP,lvm_vg,lvm_size,UseLoopDisk,LoopMounts,ou,domainname,www_dir,ServerPort,UseReverseProxy,\n\t\tProxyPass,Forwarder,ForwardTo,ForceInstanceZarafaID,mysql_instance_id,ServerIP{$groupware_field}{$www_dir_field})\n\t\tVALUES('{$mysql_password}','{$mysql_username}','{$ftpuser}','{$ftppassword}','{$useSSL}','{$servername}','{$mysql_database}',\n\t\t'{$uid}','{$_GET["gpid"]}','{$_GET["useMysql"]}',\n\t\t'{$_GET["useFTP"]}','{$_GET["lvm_vg"]}','{$_GET["vg_size"]}','{$_GET["UseLoopDisk"]}','{$_GET["LoopMounts"]}','{$ou}',\n\t\t'{$_GET["domainname"]}','{$FreewebsStorageDirectory}','{$ServerPort}','{$_GET["UseReverseProxy"]}','{$_GET["ProxyPass"]}',\n\t\t'{$_GET["Forwarder"]}','{$_GET["ForwardTo"]}','{$_GET["ForceInstanceZarafaID"]}','{$_GET["mysql_instance_id"]}','{$ServerIP}'{$groupware_value}{$www_dir_value}\n\t\t)";
    }
    writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $q->BuildTables();
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sock = new sockets();
    $sock->getFrameWork("system.php?dns-linker=yes");
    if ($_GET["useFTP"] == 1) {
        if ($users->PUREFTP_INSTALLED) {
            if (trim($ftpuser) != null) {
                if (trim($ftppassword) != null) {
                    $pure = new pureftpd_user();
                    if (!$pure->CreateUser($ftpuser, $ftppassword, $servername)) {
                        echo "FTP: Failed\n";
                        return;
                    }
                    $sock->getFrameWork("services.php?reload-pure-ftpd=yes");
                }
            }
        }
    }
    if ($_GET["useMysql"] == 1) {
        if (!$q->DATABASE_EXISTS($mysql_database)) {
            $q->CREATE_DATABASE("{$mysql_database}");
        }
        if (!$q->PRIVILEGES($mysql_username, $mysql_password, $mysql_database)) {
            echo "GRANT {$mysql_database} FAILED FOR {$mysql_username}\n{$q->mysql_error}";
        }
    }
    if (isset($_GET["ADD_DNS_ENTRY"])) {
        $dnsDOM = explode(".", $_GET["servername"]);
        $netbiosname = $dnsDOM[0];
        unset($dnsDOM[0]);
        $domainname = implode(".", $dnsDOM);
        include_once dirname(__FILE__) . "/ressources/class.pdns.inc";
        $pdns = new pdns($domainname);
        $pdns->EditIPName($netbiosname, $_GET["ADD_DNS_ENTRY"], "A");
    }
    if ($ligne["servername"] == null) {
        if ($_GET["force-groupware"] != null) {
            $sql = "INSERT INTO drupal_queue_orders(`ORDER`,`servername`) VALUES('INSTALL_GROUPWARE','{$servername}')";
            $q = new mysql();
            $q->QUERY_SQL($sql, "artica_backup");
            $sock->getFrameWork("freeweb.php?rebuild-vhost=yes&servername={$servername}");
        }
    }
    $sock->getFrameWork("services.php?freeweb-start=yes");
    sleep(2);
    $sock->getFrameWork("cmd.php?freeweb-restart=yes");
}
Esempio n. 24
0
function mysql_backup($WordpressBackupParams, $servername)
{
    $unix = new unix();
    $mysqldump = $unix->find_program("mysqldump");
    $q = new mysql();
    $free = new freeweb($servername);
    $password = null;
    $gzip = $unix->find_program("gzip");
    $database = $free->mysql_database;
    echo "Backup database {$database}";
    if (!$q->DATABASE_EXISTS($database)) {
        apache_admin_mysql(0, "{$servername} cannot backup a non-existent database {$database}", null, __FILE__, __LINE__);
        return false;
    }
    $BaseWorkDir = $WordpressBackupParams["DEST"] . "/{$servername}/" . date("Y-m-d-H") . "h";
    @mkdir("{$BaseWorkDir}", 0755, true);
    $nice = $unix->EXEC_NICE();
    $q = new mysql();
    if ($q->mysql_password != null) {
        $password = "******" . $unix->shellEscapeChars($q->mysql_password);
    }
    $t = time();
    $prefix = trim("{$nice} {$mysqldump} --add-drop-table --single-transaction --force --insert-ignore -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$password} {$database}");
    $cmdline = "{$prefix} | {$gzip} > {$BaseWorkDir}/database.gz";
    shell_exec($cmdline);
    $took = $unix->distanceOfTimeInWords($t, time());
    $size = FormatBytes(@filesize("{$BaseWorkDir}/database.gz") / 1024);
    if ($GLOBALS["OUTPUT"]) {
        echo "{$database} MySQL Took {$took} gz = {$size}\n";
    }
    apache_admin_mysql(2, "{$servername} database {$database} backuped {$size} (took {$took})", null, __FILE__, __LINE__);
}
Esempio n. 25
0
 private function autoinstall()
 {
     $q = new mysql();
     writelogs("FREEWEB: running autoinstall()", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
     if (!$q->DATABASE_EXISTS($this->database)) {
         writelogs("[{$this->servername}] DATABASE DOES NOT EXISTS Create e new one", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
         $q->CREATE_DATABASE($this->database);
     }
     global $GO_LANGUAGE, $lang, $GO_EVENTS;
     require "{$this->www_dir}/Group-Office.php";
     require_once "{$this->www_dir}/classes/filesystem.class.inc";
     require_once "{$this->www_dir}/install/gotest.php";
     include_once "{$this->www_dir}/classes/base/events.class.inc.php";
     require "{$this->www_dir}/language/languages.inc.php";
     require "{$this->www_dir}/install/sql/updates.inc.php";
     require_once "{$this->www_dir}/classes/base/users.class.inc.php";
     require_once "{$this->www_dir}/classes/base/groups.class.inc.php";
     require $GO_LANGUAGE->get_base_language_file('countries');
     require_once "{$this->www_dir}/classes/base/theme.class.inc.php";
     $GO_THEME = new GO_THEME();
     $db = new db();
     $GO_EVENTS = new GO_EVENTS();
     $GO_CONFIG->save_setting('version', count($updates));
     $GO_LANGUAGE->set_language($GO_CONFIG->language);
     $GO_USERS = new GO_USERS();
     $user['id'] = $GO_USERS->nextid("go_users");
     echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" userid \"{$user['id']}\"\n";
     $GO_GROUPS = new GO_GROUPS();
     $GO_GROUPS->query("DELETE FROM go_db_sequence WHERE seq_name='groups'");
     $GO_GROUPS->query("DELETE FROM go_groups");
     $admin_group_id = $GO_GROUPS->add_group(1, $lang['common']['group_admins']);
     $everyone_group_id = $GO_GROUPS->add_group(1, $lang['common']['group_everyone']);
     $internal_group_id = $GO_GROUPS->add_group(1, $lang['common']['group_internal']);
     $GO_MODULES->load_modules();
     require_once "{$this->www_dir}/install/upgrade.php";
     $fs = new filesystem();
     $module_folders = $fs->get_folders($GO_CONFIG->root_path . 'modules/');
     $available_modules = array();
     foreach ($module_folders as $folder) {
         if (!file_exists($folder['path'] . '/install/noautoinstall')) {
             echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" checking module {$folder['name']}\n";
             $available_modules[] = $folder['name'];
         }
     }
     $priority_modules = array('summary', 'email', 'calendar', 'tasks', 'addressbook', 'files', 'notes', 'projects', 'ldapauth');
     for ($i = 0; $i < count($priority_modules); $i++) {
         if (in_array($priority_modules[$i], $available_modules)) {
             echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" add module \"{$priority_modules[$i]}\" [" . $i . "/" . count($priority_modules) . "]\n";
             $GO_MODULES->add_module($priority_modules[$i]);
         }
     }
     for ($i = 0; $i < count($available_modules); $i++) {
         if (!in_array($available_modules[$i], $priority_modules)) {
             if ($available_modules[$i] == "mailings") {
                 continue;
             }
             /*
             if($available_modules[$i]=="blacklist"){continue;}
             if($available_modules[$i]=="search"){continue;}
             if($available_modules[$i]=="modules"){continue;}
             //if($available_modules[$i]=="users"){continue;}
             //if($available_modules[$i]=="comments"){continue;}
             //if($available_modules[$i]=="sieve"){continue;}
             //if($available_modules[$i]=="bookmarks"){continue;}
             //if($available_modules[$i]=="links"){continue;}
             */
             echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" add module \"{$available_modules[$i]}\" [" . $i . "/" . count($available_modules) . "]\n";
             try {
                 $GO_MODULES->add_module($available_modules[$i]);
             } catch (Exception $e) {
                 echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" failed adding \"{$available_modules[$i]}\" module\n";
             }
         }
     }
     writelogs("Adding LDAPAUTH Module GO_MODULES->add_module('ldapauth')", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
     $GO_MODULES->add_module('ldapauth');
     echo "Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" save_setting upgrade_mtime\n";
     $GO_CONFIG->save_setting('upgrade_mtime', $GO_CONFIG->mtime);
     if ($this->uid != null) {
         $u = new user($this->uid);
         $password = $u->password;
         $mail = $u->mail;
         $uid = $this->uid;
         writelogs("Adding {$this->uid}/{$u->password}/{$mail} Module GO_USERS->add_user", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
     } else {
         $ldap = new clladp();
         $uid = $ldap->ldap_admin;
         $password = $ldap->ldap_password;
         $mail = "*****@*****.**";
     }
     $GO_USERS->nextid('go_users');
     writelogs("Starting......: " . date("H:i:s") . " Apache \"{$this->servername}\" adding \"{$uid}\" language {$GO_LANGUAGE->language} user {$mail}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
     $user['id'] = 1;
     $user['language'] = $GO_LANGUAGE->language;
     $user['first_name'] = $GO_CONFIG->product_name;
     $user['middle_name'] = '';
     $user['last_name'] = "en";
     $user['username'] = "******";
     $user['password'] = "******";
     $user['email'] = "{$mail}";
     $user['sex'] = 'M';
     $user['enabled'] = '1';
     $user['country'] = $GO_CONFIG->default_country;
     $user['work_country'] = $GO_CONFIG->default_country;
     //$GO_USERS->debug=true;
     $GO_USERS->add_user($user, array(1, 2, 3), array($GO_CONFIG->group_everyone));
     writelogs("Starting......: " . date("H:i:s") . " Apache installtion of group office success", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__);
 }
Esempio n. 26
0
function checkMysql()
{
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("powerdns")) {
        echo "Starting......: PowerDNS creating 'powerdns' database\n";
        if (!$q->CREATE_DATABASE("powerdns")) {
            echo "Starting......: PowerDNS creating 'powerdns' database failed\n";
            return;
        }
    }
    echo "Starting......: PowerDNS 'powerdns' database OK\n";
    if (!$q->TABLE_EXISTS("domains", "powerdns")) {
        echo "Starting......: PowerDNS creating 'domains' table\n";
        $sql = "create table domains (\n\t\t\t id\t\t INT auto_increment,\n\t\t\t name\t\t VARCHAR(255) NOT NULL,\n\t\t\t master\t\t VARCHAR(128) DEFAULT NULL,\n\t\t\t last_check\t INT DEFAULT NULL,\n\t\t\t type\t\t VARCHAR(6) NOT NULL,\n\t\t\t notified_serial INT DEFAULT NULL, \n\t\t\t account         VARCHAR(40) DEFAULT NULL,\n\t\t\t primary key (id)\n\t\t\t) Engine=InnoDB;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'domains' table FAILED\n";
        } else {
            $q->QUERY_SQL("CREATE UNIQUE INDEX name_index ON domains(name);", "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("records", "powerdns")) {
        echo "Starting......: PowerDNS creating 'records' table\n";
        $sql = "CREATE TABLE records (\n\t\t\t  id              INT auto_increment,\n\t\t\t  domain_id       INT DEFAULT NULL,\n\t\t\t  name            VARCHAR(255) DEFAULT NULL,\n\t\t\t  type            VARCHAR(10) DEFAULT NULL,\n\t\t\t  content         VARCHAR(255) DEFAULT NULL,\n\t\t\t  ttl             INT DEFAULT NULL,\n\t\t\t  prio            INT DEFAULT NULL,\n\t\t\t  change_date     INT DEFAULT NULL,\n\t\t\t  primary key(id)\n\t\t\t)Engine=InnoDB;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'records' table FAILED\n";
        }
        $q->QUERY_SQL("CREATE INDEX rec_name_index ON records(name);", "powerdns");
        $q->QUERY_SQL("CREATE INDEX nametype_index ON records(name,type);", "powerdns");
        $q->QUERY_SQL("CREATE INDEX domain_id ON records(domain_id);", "powerdns");
        $q->QUERY_SQL("alter table records add ordername VARCHAR(255);", "powerdns");
        $q->QUERY_SQL("alter table records add auth bool;", "powerdns");
        $q->QUERY_SQL("create index orderindex on records(ordername);", "powerdns");
        $q->QUERY_SQL("alter table records change column type type VARCHAR(10);", "powerdns");
    }
    if (!$q->TABLE_EXISTS("supermasters", "powerdns")) {
        echo "Starting......: PowerDNS creating 'supermasters' table\n";
        $sql = "create table supermasters (\n\t\t\t\t  ip VARCHAR(25) NOT NULL, \n\t\t\t\t  nameserver VARCHAR(255) NOT NULL, \n\t\t\t\t  account VARCHAR(40) DEFAULT NULL\n\t\t\t\t) Engine=InnoDB;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'supermasters' table FAILED\n";
        }
        $q->QUERY_SQL("CREATE INDEX rec_name_index ON records(name);", "powerdns");
        $q->QUERY_SQL("CREATE INDEX nametype_index ON records(name,type);", "powerdns");
        $q->QUERY_SQL("CREATE INDEX domain_id ON records(domain_id);", "powerdns");
    }
    if (!$q->TABLE_EXISTS("domainmetadata", "powerdns")) {
        echo "Starting......: PowerDNS creating 'domainmetadata' table\n";
        $sql = "create table domainmetadata (\n\t\t\t id              INT auto_increment,\n\t\t\t domain_id       INT NOT NULL,\n\t\t\t kind            VARCHAR(16),\n\t\t\t content        TEXT,\n\t\t\t primary key(id)\n\t\t\t);";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'domainmetadata' table FAILED\n";
        } else {
            $q->QUERY_SQL("create index domainmetaidindex on domainmetadata(domain_id);", "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("cryptokeys", "powerdns")) {
        echo "Starting......: PowerDNS creating 'cryptokeys' table\n";
        $sql = "create table cryptokeys (\n\t\t\t id             INT auto_increment,\n\t\t\t domain_id      INT NOT NULL,\n\t\t\t flags          INT NOT NULL,\n\t\t\t active         BOOL,\n\t\t\t content        TEXT,\n\t\t\t primary key(id)\n\t\t\t); ";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'cryptokeys' table FAILED\n";
        } else {
            $q->QUERY_SQL("create index domainidindex on cryptokeys(domain_id);", "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("tsigkeys", "powerdns")) {
        echo "Starting......: PowerDNS creating 'tsigkeys' table\n";
        $sql = "create table tsigkeys (\n\t\t\t id             INT auto_increment,\n\t\t\t name           VARCHAR(255), \n\t\t\t algorithm      VARCHAR(255),\n\t\t\t secret         VARCHAR(255),\n\t\t\t primary key(id)\n\t\t\t);";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'tsigkeys' table FAILED\n";
        } else {
            $q->QUERY_SQL("create unique index namealgoindex on tsigkeys(name, algorithm);", "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("users", "powerdns")) {
        echo "Starting......: PowerDNS creating 'users' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `users` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `username` varchar(16) NOT NULL DEFAULT '0',\n\t\t\t  `password` varchar(34) NOT NULL DEFAULT '0',\n\t\t\t  `fullname` varchar(255) NOT NULL DEFAULT '0',\n\t\t\t  `email` varchar(255) NOT NULL DEFAULT '0',\n\t\t\t  `description` varchar(1024) NOT NULL DEFAULT '0',\n\t\t\t  `perm_templ` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t  `active` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t  PRIMARY KEY (`id`))";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'users' table FAILED\n";
        }
    }
    if (!$q->TABLE_EXISTS("perm_items", "powerdns")) {
        echo "Starting......: PowerDNS creating 'perm_items' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `perm_items` (\n\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `name` varchar(64) NOT NULL DEFAULT '0',\n\t\t  `descr` varchar(1024) NOT NULL DEFAULT '0',\n\t\t  PRIMARY KEY (`id`)\n\t\t) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=62 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'perm_items' table FAILED\n";
        } else {
            $sql = "INSERT INTO `perm_items` (`id`, `name`, `descr`) VALUES\n\t\t\t(41, 'zone_master_add', 'User is allowed to add new master zones.'),\n\t\t\t(42, 'zone_slave_add', 'User is allowed to add new slave zones.'),\n\t\t\t(43, 'zone_content_view_own', 'User is allowed to see the content and meta data of zones he owns.'),\n\t\t\t(44, 'zone_content_edit_own', 'User is allowed to edit the content of zones he owns.'),\n\t\t\t(45, 'zone_meta_edit_own', 'User is allowed to edit the meta data of zones he owns.'),\n\t\t\t(46, 'zone_content_view_others', 'User is allowed to see the content and meta data of zones he does not own.'),\n\t\t\t(47, 'zone_content_edit_others', 'User is allowed to edit the content of zones he does not own.'),\n\t\t\t(48, 'zone_meta_edit_others', 'User is allowed to edit the meta data of zones he does not own.'),\n\t\t\t(49, 'search', 'User is allowed to perform searches.'),\n\t\t\t(50, 'supermaster_view', 'User is allowed to view supermasters.'),\n\t\t\t(51, 'supermaster_add', 'User is allowed to add new supermasters.'),\n\t\t\t(52, 'supermaster_edit', 'User is allowed to edit supermasters.'),\n\t\t\t(53, 'user_is_ueberuser', 'User has full access. God-like. Redeemer.'),\n\t\t\t(54, 'user_view_others', 'User is allowed to see other users and their details.'),\n\t\t\t(55, 'user_add_new', 'User is allowed to add new users.'),\n\t\t\t(56, 'user_edit_own', 'User is allowed to edit their own details.'),\n\t\t\t(57, 'user_edit_others', 'User is allowed to edit other users.'),\n\t\t\t(58, 'user_passwd_edit_others', 'User is allowed to edit the password of other users.'),\n\t\t\t(59, 'user_edit_templ_perm', 'User is allowed to change the permission template that is assigned to a user.'),\n\t\t\t(60, 'templ_perm_add', 'User is allowed to add new permission templates.'),\n\t\t\t(61, 'templ_perm_edit', 'User is allowed to edit existing permission templates.');";
            $q->QUERY_SQL($sql, "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("perm_templ", "powerdns")) {
        echo "Starting......: PowerDNS creating 'perm_templ' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `perm_templ` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(128) NOT NULL DEFAULT '0',\n\t\t\t  `descr` varchar(1024) NOT NULL DEFAULT '0',\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'perm_templ' table FAILED\n";
        } else {
            $sql = "INSERT INTO `perm_templ` (`id`, `name`, `descr`) VALUES (1, 'Administrator', 'Administrator template with full rights.');";
            $q->QUERY_SQL($sql, "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("perm_templ_items", "powerdns")) {
        echo "Starting......: PowerDNS creating 'perm_templ_items' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `perm_templ_items` (\n\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `templ_id` int(11) NOT NULL DEFAULT '0',\n\t\t  `perm_id` int(11) NOT NULL DEFAULT '0',\n\t\t  PRIMARY KEY (`id`)\n\t\t) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=250 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'perm_templ_items' table FAILED\n";
        } else {
            $sql = "INSERT INTO `perm_templ_items` (`id`, `templ_id`, `perm_id`) VALUES (249, 1, 53);";
            $q->QUERY_SQL($sql, "powerdns");
        }
    }
    if (!$q->TABLE_EXISTS("zones", "powerdns")) {
        echo "Starting......: PowerDNS creating 'zones' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `zones` (\n\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t  `domain_id` int(11) NOT NULL DEFAULT '0',\n\t\t  `owner` int(11) NOT NULL DEFAULT '0',\n\t\t  `comment` varchar(1024) DEFAULT '0',\n\t\t  `zone_templ_id` int(11) NOT NULL,\n\t\t  PRIMARY KEY (`id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'zones' table FAILED\n";
        }
    }
    if (!$q->TABLE_EXISTS("zone_templ", "powerdns")) {
        echo "Starting......: PowerDNS creating 'zone_templ' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `zone_templ` (\n\t\t\t  `id` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(128) NOT NULL DEFAULT '0',\n\t\t\t  `descr` varchar(1024) NOT NULL DEFAULT '0',\n\t\t\t  `owner` bigint(20) NOT NULL DEFAULT '0',\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'zone_templ' table FAILED\n";
        }
    }
    if (!$q->TABLE_EXISTS("zone_templ_records", "powerdns")) {
        echo "Starting......: PowerDNS creating 'zone_templ_records' table\n";
        $sql = "CREATE TABLE IF NOT EXISTS `zone_templ_records` (\n\t\t  `id` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t  `zone_templ_id` bigint(20) NOT NULL DEFAULT '0',\n\t\t  `name` varchar(255) NOT NULL DEFAULT '0',\n\t\t  `type` varchar(6) NOT NULL DEFAULT '0',\n\t\t  `content` varchar(255) NOT NULL DEFAULT '0',\n\t\t  `ttl` bigint(20) NOT NULL DEFAULT '0',\n\t\t  `prio` bigint(20) NOT NULL DEFAULT '0',\n\t\t  PRIMARY KEY (`id`)\n\t\t) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
        $q->QUERY_SQL($sql, "powerdns");
        if (!$q->ok) {
            echo "Starting......: PowerDNS creating 'zone_templ_records' table FAILED\n";
        }
    }
    echo "Starting......: PowerDNS Mysql done...\n";
    poweradmin();
}
Esempio n. 27
0
function duplicate_wordpress($servername)
{
    $unix = new unix();
    $q = new mysql();
    $free = new freeweb($servername);
    $WORKING_DIRECTORY = $free->www_dir;
    if ($free->groupware_duplicate == null) {
        build_progress("{$servername}: {duplicate} {$servername} no duplicate set...", 42);
        sleep(2);
        return false;
    }
    $free2 = new freeweb($free->groupware_duplicate);
    if ($free2->mysql_database == null) {
        echo "Fatal: {$free->groupware_duplicate} did not have any such DB set, try to find it..\n";
        $free2->mysql_database = $free2->CreateDatabaseName();
        echo "Fatal: {$free->groupware_duplicate} = {$free2->mysql_database}\n";
    }
    if (!$q->DATABASE_EXISTS($free2->mysql_database, true)) {
        build_progress("{$servername}: {duplicate} {$free->groupware_duplicate} did not have any database...", 42);
        sleep(2);
        return false;
    }
    $srcdir = $free2->www_dir;
    $Mysqlpassword = null;
    $cp = $unix->find_program("cp");
    $rm = $unix->find_program("rm");
    if (@is_link($WORKING_DIRECTORY)) {
        $WORKING_DIRECTORY = @readlink($WORKING_DIRECTORY);
    }
    if (is_dir($WORKING_DIRECTORY)) {
        build_progress("{$servername}: {removing} {$WORKING_DIRECTORY}...", 42);
        sleep(2);
        shell_exec("{$rm} -rf {$WORKING_DIRECTORY}/*");
    }
    @mkdir($WORKING_DIRECTORY, 0755, true);
    build_progress("{$servername}: {installing} {from} {$srcdir}...", 42);
    shell_exec("{$cp} -rf {$srcdir}/* {$WORKING_DIRECTORY}/");
    $wordpressDB = $free->mysql_database;
    if ($wordpressDB == null) {
        $wordpressDB = $free->CreateDatabaseName();
    }
    if ($q->DATABASE_EXISTS($wordpressDB)) {
        build_progress("{$servername}: {remove_database} {$wordpressDB}...", 42);
        sleep(2);
        if (!$q->DELETE_DATABASE($wordpressDB)) {
            build_progress("{$servername}: {remove_database} {$wordpressDB} {failed}...", 42);
            return false;
        }
        if (!$q->CREATE_DATABASE($wordpressDB, true)) {
            build_progress("{$servername}: {create_database} {$wordpressDB} {failed}...", 42);
            return false;
        }
    }
    if (!$q->DATABASE_EXISTS($wordpressDB)) {
        if (!$q->CREATE_DATABASE($wordpressDB, true)) {
            build_progress("{$servername}: {create_database} {$wordpressDB} {failed}...", 42);
            return false;
        }
    }
    build_progress("{$servername}: {backup_database} {from} {$free2->mysql_database}...", 42);
    $mysqldump = $unix->find_program("mysqldump");
    $q = new mysql();
    if ($q->mysql_password != null) {
        $Mysqlpassword = "******" . $unix->shellEscapeChars($q->mysql_password);
    }
    $t = time();
    $TMP_FILE = $unix->FILE_TEMP();
    $cmdline = trim("{$mysqldump} --add-drop-table --single-transaction --force --insert-ignore -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$Mysqlpassword} {$free2->mysql_database} >{$TMP_FILE} 2>&1");
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmdline}\n";
    }
    $results = array();
    exec($cmdline, $results);
    while (list($num, $ligne) = each($results)) {
        echo "{$ligne}\n";
        if (preg_match("#ERROR\\s+([0-9]+)#", $ligne)) {
            build_progress("{$servername}: {restore_database} {to} {$wordpressDB} {failed}..", 42);
            sleep(3);
            return false;
        }
    }
    build_progress("{$servername}: {restore_database} {to} {$wordpressDB}..", 42);
    $mysqlbin = $unix->find_program("mysql");
    $cmd = "{$mysqlbin} --batch --force -S /var/run/mysqld/mysqld.sock -u {$q->mysql_admin}{$Mysqlpassword} --database={$wordpressDB} <{$TMP_FILE} 2>&1";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    exec($cmd, $results);
    while (list($num, $ligne) = each($results)) {
        echo "{$ligne}\n";
        if (preg_match("#ERROR\\s+([0-9]+)#", $ligne)) {
            build_progress("{$servername}: {restore_database} {to} {$wordpressDB} {failed}..", 42);
            sleep(3);
            return false;
        }
    }
    build_progress("{$servername}: {restore_database} {to} {$wordpressDB}..{done}", 42);
    @unlink($TMP_FILE);
    if (!scan($WORKING_DIRECTORY)) {
        build_progress("{$servername}: {install} {failed}", 42);
        sleep(3);
        return false;
    }
    $proto = "http";
    if ($free->useSSL == 1) {
        $proto = "https";
    }
    $sql = "UPDATE `wp_options` SET `option_value`='{$proto}://{$servername}' WHERE `option_name`='siteurl'";
    $q->QUERY_SQL($sql, $wordpressDB);
    if (!$q->ok) {
        echo $q->mysql_error;
        build_progress("{$servername}: {install} {failed}", 42);
        sleep(3);
        return false;
    }
    $sql = "UPDATE `wp_options` SET `option_value`='{$proto}://{$servername}' WHERE `option_name`='home'";
    $q->QUERY_SQL($sql, $wordpressDB);
    if (!$q->ok) {
        echo $q->mysql_error;
        build_progress("{$servername}: {install} {failed}", 42);
        sleep(3);
        return false;
    }
    $free->groupware_duplicate = null;
    $free->CreateSite(true);
    return true;
}
Esempio n. 28
0
function buildMysql()
{
    $q = new mysql();
    if (!$q->DATABASE_EXISTS("pommo")) {
        $q->CREATE_DATABASE("pommo");
    }
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_config` (\n  `config_name` varchar(64) NOT NULL default '',\n  `config_value` text NOT NULL,\n  `config_description` tinytext NOT NULL,\n  `autoload` enum('on','off') NOT NULL default 'on',\n  `user_change` enum('on','off') NOT NULL default 'on',\n  PRIMARY KEY  (`config_name`)\n) ENGINE=MyISAM;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "INSERT INTO `pommo_config` (`config_name`, `config_value`, `config_description`, `autoload`, `user_change`) VALUES\n('admin_username', 'admin', 'Username', 'off', 'on'),\n('admin_password', '9dd3ba637ec2fcaf383415617d39e002', 'Password', 'off', 'on'),\n('admin_email', '*****@*****.**', 'Administrator Email', 'on', 'on'),\n('site_name', 'Artica For poMMo', 'Website Name', 'on', 'on'),\n('site_url', 'http://www.pommo-rocks.com', 'Website URL', 'on', 'on'),\n('site_success', '', 'Signup Success URL', 'off', 'on'),\n('site_confirm', '', '', 'off', 'on'),\n('list_name', 'Artica Mailing List', 'List Name', 'on', 'on'),\n('list_fromname', 'poMMo Administrative Team', 'From Name', 'off', 'on'),\n('list_fromemail', '*****@*****.**', 'From Email', 'off', 'on'),\n('list_frombounce', '*****@*****.**', 'Bounces', 'off', 'on'),\n('list_exchanger', 'sendmail', 'List Exchanger', 'off', 'on'),\n('list_confirm', 'on', 'Confirmation Messages', 'off', 'on'),\n('list_charset', 'ISO-8859-1', '', 'off', 'on'),\n('list_wysiwyg', 'on', '', 'off', 'off'),\n('maxRuntime', '80', '', 'off', 'on'),\n('messages', 'a:6:{s:9:\"subscribe\";a:4:{s:3:\"msg\";s:152:\"Welcome to our mailing list. You can always login to update your records or unsubscribe by visiting: \n  https://192.168.1.12:9000/mailing/user/login.php\";s:3:\"sub\";s:30:\"Welcome to Artica Mailing List\";s:3:\"web\";s:45:\"Welcome to our mailing list. Enjoy your stay.\";s:5:\"email\";b:0;}s:11:\"unsubscribe\";a:4:{s:3:\"sub\";s:33:\"Farewell from Artica Mailing List\";s:3:\"msg\";s:106:\"You have been unsubscribed and will not receive any more mailings from us. Feel free to come back anytime!\";s:3:\"web\";s:55:\"You have successfully unsubscribed. Enjoy your travels.\";s:5:\"email\";b:0;}s:7:\"confirm\";a:2:{s:3:\"msg\";s:253:\"You have requested to subscribe to Artica Mailing List. We would like to validate your email address before adding you as a subscriber. Please click the link below to be added ->\r\n\t[[url]]\r\n\r\nIf you have received this message in error, please ignore it.\";s:3:\"sub\";s:20:\"Subscription request\";}s:8:\"activate\";a:2:{s:3:\"msg\";s:222:\"Someone has requested to access to your records for Artica Mailing List. You may edit your information or unsubscribe by visiting the link below ->\r\n\t[[url]]\r\n\r\nIf you have received this message in error, please ignore it.\";s:3:\"sub\";s:36:\"Artica Mailing List: Account Access.\";}s:8:\"password\";a:2:{s:3:\"msg\";s:201:\"You have requested to change your password for Artica Mailing List. Please validate this request by clicking the link below ->\r\n\t[[url]]\r\n\r\nIf you have received this message in error, please ignore it.\";s:3:\"sub\";s:23:\"Change Password request\";}s:6:\"update\";a:2:{s:3:\"msg\";s:198:\"You have requested to update your records for Artica Mailing List. Please validate this request by clicking the link below ->\n\n\t[[url]]\n\nIf you have received this message in error, please ignore it.\";s:3:\"sub\";s:22:\"Update Records request\";}}', '', 'off', 'off'),\n('notices', '', '', 'off', 'off'),\n('demo_mode', 'off', 'Demonstration Mode', 'on', 'on'),\n('smtp_1', 'a:5:{s:4:\"host\";s:9:\"127.0.0.1\";s:4:\"port\";s:4:\"2525\";s:4:\"auth\";s:3:\"off\";s:4:\"user\";s:0:\"\";s:4:\"pass\";s:0:\"\";}', '', 'off', 'off'),\n('smtp_2', '', '', 'off', 'off'),\n('smtp_3', '', '', 'off', 'off'),\n('smtp_4', '', '', 'off', 'off'),\n('throttle_DBPP', '0', '', 'off', 'on'),\n('throttle_DP', '10', '', 'off', 'on'),\n('throttle_DMPP', '0', '', 'off', 'on'),\n('throttle_BPS', '0', '', 'off', 'on'),\n('throttle_MPS', '3', '', 'off', 'on'),\n('throttle_SMTP', 'individual', '', 'off', 'on'),\n('public_history', 'on', 'Public Mailing History', 'off', 'on'),\n('version', 'Aardvark PR16.1', 'poMMo Version', 'on', 'off'),\n('key', '1e0b60', 'Unique Identifier', 'on', 'off'),\n('revision', '42', 'Internal Revision', 'on', 'off');\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_fields` (\n  `field_id` smallint(5) unsigned NOT NULL auto_increment,\n  `field_active` enum('on','off') NOT NULL default 'off',\n  `field_ordering` smallint(5) unsigned NOT NULL default '0',\n  `field_name` varchar(60) default NULL,\n  `field_prompt` varchar(60) default NULL,\n  `field_normally` varchar(60) default NULL,\n  `field_array` text,\n  `field_required` enum('on','off') NOT NULL default 'off',\n  `field_type` enum('checkbox','multiple','text','date','number','comment') default NULL,\n  PRIMARY KEY  (`field_id`),\n  KEY `active` (`field_active`,`field_ordering`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_groups` (\n  `group_id` smallint(5) unsigned NOT NULL auto_increment,\n  `group_name` tinytext NOT NULL,\n  PRIMARY KEY  (`group_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_group_rules` (\n  `rule_id` int(10) unsigned NOT NULL auto_increment,\n  `group_id` int(10) unsigned NOT NULL default '0',\n  `field_id` tinyint(3) unsigned NOT NULL default '0',\n  `type` tinyint(1) NOT NULL default '0' COMMENT '0: OFF, (and), 1: ON (or)',\n  `logic` enum('is','not','greater','less','true','false','is_in','not_in') NOT NULL,\n  `value` text,\n  PRIMARY KEY  (`rule_id`),\n  KEY `group_id` (`group_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_mailings` (\n  `mailing_id` int(10) unsigned NOT NULL auto_increment,\n  `fromname` varchar(60) NOT NULL default '',\n  `fromemail` varchar(60) NOT NULL default '',\n  `frombounce` varchar(60) NOT NULL default '',\n  `subject` varchar(60) NOT NULL default '',\n  `body` mediumtext NOT NULL,\n  `altbody` mediumtext,\n  `ishtml` enum('on','off') NOT NULL default 'off',\n  `mailgroup` varchar(60) NOT NULL default 'Unknown',\n  `subscriberCount` int(10) unsigned NOT NULL default '0',\n  `started` datetime NOT NULL,\n  `finished` datetime default NULL,\n  `sent` int(10) unsigned NOT NULL default '0',\n  `charset` varchar(15) NOT NULL default 'UTF-8',\n  `status` tinyint(1) NOT NULL default '1' COMMENT '0: finished, 1: processing, 2: cancelled',\n  PRIMARY KEY  (`mailing_id`),\n  KEY `status` (`status`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_mailing_current` (\n  `current_id` int(10) unsigned NOT NULL,\n  `command` enum('none','restart','stop','cancel') NOT NULL default 'none',\n  `serial` int(10) unsigned default NULL,\n  `securityCode` char(32) default NULL,\n  `notices` longtext,\n  `current_status` enum('started','stopped') NOT NULL default 'stopped',\n  `touched` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n  PRIMARY KEY  (`current_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_mailing_notices` (\n  `mailing_id` int(10) unsigned NOT NULL,\n  `notice` varchar(255) NOT NULL,\n  `touched` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n  `id` smallint(5) unsigned NOT NULL,\n  KEY `mailing_id` (`mailing_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_queue` (\n  `subscriber_id` int(10) unsigned NOT NULL,\n  `status` tinyint(1) NOT NULL default '0' COMMENT '0: unsent, 1: sent, 2: failed',\n  `smtp` tinyint(1) NOT NULL default '0' COMMENT '0: none, 1-4: Designated to SMTP relay #',\n  PRIMARY KEY  (`subscriber_id`),\n  KEY `status` (`status`,`smtp`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_scratch` (\n  `scratch_id` int(10) unsigned NOT NULL auto_increment,\n  `time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n  `type` smallint(5) unsigned NOT NULL default '0' COMMENT 'Used to identify row type. 0 = undifined, 1 = ',\n  `int` bigint(20) default NULL,\n  `str` text,\n  PRIMARY KEY  (`scratch_id`),\n  KEY `type` (`type`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='General Purpose Table for caches, counts, etc.' AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_subscribers` (\n  `subscriber_id` int(10) unsigned NOT NULL auto_increment,\n  `email` char(60) NOT NULL default '',\n  `time_touched` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n  `time_registered` datetime NOT NULL,\n  `flag` tinyint(1) NOT NULL default '0' COMMENT '0: NULL, 1-8: REMOVE, 9: UPDATE',\n  `ip` int(10) unsigned default NULL COMMENT 'Stored with INET_ATON(), Fetched with INET_NTOA()',\n  `status` tinyint(1) NOT NULL default '2' COMMENT '0: Inactive, 1: Active, 2: Pending',\n  PRIMARY KEY  (`subscriber_id`),\n  KEY `status` (`status`,`subscriber_id`),\n  KEY `status_2` (`status`,`email`),\n  KEY `status_3` (`status`,`time_touched`),\n  KEY `status_4` (`status`,`time_registered`),\n  KEY `status_5` (`status`,`ip`),\n  KEY `flag` (`flag`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_subscriber_data` (\n  `data_id` bigint(20) unsigned NOT NULL auto_increment,\n  `field_id` int(10) unsigned NOT NULL default '0',\n  `subscriber_id` int(10) unsigned NOT NULL default '0',\n  `value` char(60) NOT NULL default '',\n  PRIMARY KEY  (`data_id`),\n  KEY `subscriber_id` (`subscriber_id`,`field_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_subscriber_pending` (\n  `pending_id` int(10) unsigned NOT NULL auto_increment,\n  `subscriber_id` int(10) unsigned NOT NULL default '0',\n  `pending_code` char(32) NOT NULL,\n  `pending_type` enum('add','del','change','password') default NULL,\n  `pending_array` text,\n  PRIMARY KEY  (`pending_id`),\n  KEY `code` (`pending_code`),\n  KEY `subscriber_id` (`subscriber_id`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_templates` (\n  `template_id` smallint(5) unsigned NOT NULL auto_increment,\n  `name` varchar(60) NOT NULL default 'name',\n  `description` varchar(255) default NULL,\n  `body` mediumtext,\n  `altbody` mediumtext,\n  PRIMARY KEY  (`template_id`)\n) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;\n";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "INSERT INTO `pommo_templates` (`template_id`, `name`, `description`, `body`, `altbody`) VALUES\n(1, 'CSS Example', 'poMMo default, featuring a plain CSS based HTML design. Includes a weblink (to view online) in the header, and a unsubscribe link in the footer.', '<style type=\"text/css\" media=\"all\">\r\n\r\n/* base styling */\r\n\r\ndiv.pommoMailing {\r\n\r\n  background-color: white; /* background color */\r\n  color: #333; /* text color */\r\n  width: 100%;\r\n  padding: 6px;\r\n\r\n}\r\n\r\ndiv.pommoMailing a, div.pommoMailing a:visited {\r\n\r\n  text-decoration: none;\r\n  color: #0067ff; /* link & visited link color */\r\n\r\n}\r\n\r\n/* header styling */\r\n\r\ndiv.pommoMailing div.pommoHeader {\r\n  \r\n  border: 1px solid black;\r\n  padding: 6px;\r\n  background-color: #DDF0BD; /* light green */\r\n  color: green;\r\n  width: 100%;\r\n  text-align: center;\r\n}\r\n\r\n/* footer styling */\r\n\r\ndiv.pommoMailing div.pommoFooter {\r\n  width: 100%;\r\n  padding: 5px 12px;\r\n  background-color: black;\r\n  color: #DDD;\r\n}\r\n\r\ndiv.pommoMailing p.smaller {\r\n  font-size: 80%;\r\n}\r\n\r\n\r\n</style>\r\n\r\n<div class=\"pommoMailing\">\r\n\r\n  <div class=\"pommoHeader\">\r\n    If you are having trouble viewing this email, <a href=\"[[!weblink]]\">click here</a>.\r\n  </div>\r\n\r\n  <h2>Bonjour!</h2>\r\n  <br />\r\n \r\n  <p>\r\n  Aliquam tempor erat eu sapien. Proin nisl lorem, hendrerit ut, venenatis vel, consequat in, est. In hac habitasse platea dictumst. Praesent malesuada tristique massa. Donec nec dui. Nulla at ligula quis diam auctor vulputate. Sed ligula ligula, elementum ac, tincidunt nec, accumsan non, risus. Aliquam convallis blandit tortor. In porta nisi interdum ante. Maecenas sem. Maecenas at felis ac massa dictum malesuada. Maecenas quis lectus. In hac habitasse platea dictumst. Ut sit amet nunc. Donec non lacus. Nulla facilisi. Vestibulum molestie. Aenean at enim sit amet augue auctor bibendum. Duis in ipsum.\r\n  </p>\r\n\r\n  <div class=\"pommoFooter\">\r\n  To unsubscribe or update your records, <a href=\"[[!unsubscribe]]\">Click here</a>.\r\n  </div>\r\n\r\n  <p class=\"smaller\">\r\n    Message sent with <a href=\"http://www.pommo.org/\">poMMo</a>.\r\n  </p>\r\n\r\n</div>', NULL);";
    $q->QUERY_SQL($sql, "pommo");
    $sql = "CREATE TABLE IF NOT EXISTS `pommo_updates` (\n  `serial` int(10) unsigned NOT NULL,\n  PRIMARY KEY  (`serial`)\n) ENGINE=MyISAM DEFAULT CHARSET=latin1;\n";
    $sql = "INSERT INTO `pommo_updates` (`serial`) VALUES (24);";
    $q->QUERY_SQL($sql, "pommo");
}
Esempio n. 29
0
function clean_squid_stats_dbs()
{
    $sock = new sockets();
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    $CleanArticaSquidDatabases = $sock->GET_INFO("CleanArticaSquidDatabases");
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_numeric($CleanArticaSquidDatabases)) {
        $CleanArticaSquidDatabases = 0;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($CleanArticaSquidDatabases == 0) {
            echo "Option is not activated...\n";
            return;
        }
    }
    $q = new mysql_squid_builder();
    $tables = $q->LIST_TABLES_DAYS();
    $rows = 0;
    $count_tables = 0;
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_DAYS_BLOCKED();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_MEMBERS();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_MONTH();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $tables = $q->LIST_TABLES_WEEKS();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $q = new mysql_catz();
    $tables = $q->LIST_TABLES_CATEGORIES();
    while (list($num, $table) = each($tables)) {
        $rows = $rows + $q->COUNT_ROWS($table);
        if ($GLOBALS["VERBOSE"]) {
            echo " Delete table {$table} {$rows} rows \n";
        }
        $count_tables++;
        $q->DELETE_TABLE($table);
    }
    $q = new mysql();
    if ($q->DATABASE_EXISTS("catz")) {
        $q->DELETE_DATABASE("catz");
    }
    if ($count_tables > 0) {
        mysql_admin_mysql(1, "Restarting MySQL service...", null, __FILE__, __LINE__);
        shell_exec("/etc/init.d/mysql restart");
    }
    $sock->TOP_NOTIFY("{$count_tables} statistics tables as been deleted with {$rows} rows", "info");
    //print_r($tables);
}
Esempio n. 30
0
function CreateDatabase($arrayconfig)
{
    $q = new mysql();
    $errors = null;
    $lang = $arrayconfig["LANG"];
    $DBcreated = false;
    $DBtype = 'mysql';
    $DBhostname = $q->mysql_server;
    $DBuserName = $q->mysql_admin;
    $DBpassword = $q->mysql_password;
    $DBname = $arrayconfig["DB"];
    $DBPrefix = 'jos_';
    $DBOld = "bu";
    $DBversion = null;
    if ($q->DATABASE_EXISTS($arrayconfig["DB"])) {
        write_events("Database already exists");
        return true;
    }
    $q->CREATE_DATABASE($arrayconfig["DB"]);
    if (!$q->ok) {
        write_events("Error: {$q->mysql_error}");
    }
    if (!$q->DATABASE_EXISTS($arrayconfig["DB"])) {
        write_events("Failed to create database {$arrayconfig["DB"]} \"{$q->mysql_error}\"");
        set_status("{failed}");
        return false;
    }
    write_events("Database successfully created");
    $dbscheme = '/usr/local/share/artica/joomla_src/installation/sql/mysql/joomla.sql';
    populateDatabase($dbscheme, $arrayconfig["DB"]);
    $dbscheme = '/usr/local/share/artica/joomla_src/installation/sql/mysql/sample_data.sql';
    populateDatabase($dbscheme, $arrayconfig["DB"]);
    WriteAdmin($arrayconfig["uid"], $arrayconfig["DB"]);
    return true;
}