Esempio n. 1
0
function drawDataBase($database)
{
    global $conf_mysql_db;
    global $adm_login;
    global $adm_pass;
    global $conf_user_mysql_type;
    global $conf_user_mysql_host;
    global $conf_user_mysql_root_login;
    global $conf_user_mysql_root_pass;
    global $conf_demo_version;
    global $conf_user_mysql_prepend_admin_name;
    global $pro_mysql_admin_table;
    $q = "SELECT * FROM {$pro_mysql_admin_table} WHERE adm_login='******';";
    $r = mysql_query($q) or die("Cannot query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    $n = mysql_num_rows($r);
    if ($n != 1) {
        die("Cannot find user !");
    }
    $admin_param = mysql_fetch_array($r);
    if ($conf_user_mysql_type == "distant") {
        $newid = mysql_connect($conf_user_mysql_host, $conf_user_mysql_root_login, $conf_user_mysql_root_pass) or die("Cannot connect to user SQL host");
    }
    $out = "<br><h3>" . _("Your users") . "</h3>";
    if ($conf_user_mysql_prepend_admin_name == "yes") {
        $out .= "<i>" . _("Your username will be prepended to the database username.") . "</i><br>";
    }
    $q = "SELECT DISTINCT User FROM mysql.user WHERE dtcowner='{$adm_login}' ORDER BY User;";
    $r = mysql_query($q) or die("Cannot query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    $n = mysql_num_rows($r);
    $num_users = $n;
    $out .= "<table><tr><td>" . _("User") . "</td><td>" . _("Password:"******"</td><td>" . _("Action") . "</td><td></td></tr>";
    $hidden = "<input type=\"hidden\" name=\"adm_login\" value=\"{$adm_login}\">\n\t\t<input type=\"hidden\" name=\"addrlink\" value=\"" . $_REQUEST["addrlink"] . "\">\n\t\t<input type=\"hidden\" name=\"adm_pass\" value=\"{$adm_pass}\">";
    $dblist_user = "";
    for ($i = 0; $i < $n; $i++) {
        $a = mysql_fetch_array($r);
        $out .= "<tr><td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t\t<input type=\"hidden\" name=\"action\" value=\"modify_dbuser_pass\">\n\t\t<input type=\"hidden\" name=\"dbuser\" value=\"" . $a["User"] . "\">\n\t\t" . $a["User"] . "</td>\n\t\t<td><input type=\"text\" name=\"db_pass\" value=\"\"></td>\n\t\t<td><input type=\"submit\" value=\"" . _("Save") . "\"></form></td>\n\t\t<td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t\t<input type=\"hidden\" name=\"action\" value=\"del_dbuser\">\n\t\t<input type=\"hidden\" name=\"dbuser\" value=\"" . $a["User"] . "\">\n\t\t<input type=\"submit\" value=\"" . _("Delete") . "\"></form></td></tr>";
        if (!isset($dblist_clause)) {
            $dblist_clause = "User='******'";
        } else {
            $dblist_clause .= " OR User='******'";
        }
        $dblist_user[] = $a["User"];
    }
    $out .= "<tr><td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t<input type=\"hidden\" name=\"action\" value=\"add_dbuser\">\n\t<input type=\"text\" name=\"dbuser\" value=\"\"></td>\n\t<td><input type=\"text\" name=\"db_pass\" value=\"\"></td>\n\t<td><input type=\"submit\" value=\"" . _("Create") . "\"></form></td><td></td></tr>";
    $out .= "</table>";
    $out .= "<br><h3>" . _("List of your databases:") . "</h3><br>";
    if ($conf_user_mysql_prepend_admin_name == "yes") {
        $out .= "<i>" . _("Your username will be prepended to the database name.") . "</i><br>";
    }
    if ($conf_demo_version == "no" && $num_users > 0) {
        mysql_select_db("mysql") or die("Cannot select db mysql for account management !!!");
        $query = "SELECT DISTINCT Db,User FROM db WHERE {$dblist_clause};";
        $result = mysql_query($query) or die("Cannot query \"{$query}\" !!!" . mysql_error());
        $num_rows = mysql_num_rows($result);
        $dblist = "<table cellpadding=\"2\" cellspacing=\"2\">";
        $dblist .= "<tr><td>" . _("Database name") . "</td><td>" . _("User") . "</td><td>" . _("Action") . "</td><td></td></tr>";
        for ($i = 0; $i < $num_rows; $i++) {
            $row = mysql_fetch_array($result);
            if ($i != 0) {
                //				$out .= " - ";
            }
            $dblist_user_popup = "";
            for ($j = 0; $j < $num_users; $j++) {
                if ($row["User"] == $dblist_user[$j]) {
                    $dblist_user_popup .= "<option value=\"" . $dblist_user[$j] . "\" selected>" . $dblist_user[$j] . "</option>";
                } else {
                    $dblist_user_popup .= "<option value=\"" . $dblist_user[$j] . "\">" . $dblist_user[$j] . "</option>";
                }
            }
            $dblist .= "<tr><td>" . $row["Db"] . "</td>";
            $dblist .= "<td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t\t\t<input type=\"hidden\" name=\"action\" value=\"change_db_owner\">\n\t\t\t<input type=\"hidden\" name=\"dbname\" value=\"" . $row["Db"] . "\">\n\t\t\t<select name=\"dbuser\">{$dblist_user_popup}</select></td>";
            $dblist .= "<td><input type=\"submit\" value=\"" . _("Save") . "\"></form></td>\n\t\t\t<td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t\t\t<input type=\"hidden\" name=\"action\" value=\"delete_user_db\">\n\t\t\t<input type=\"hidden\" name=\"dbname\" value=\"" . $row["Db"] . "\">\n\t\t\t<input type=\"submit\" value=\"" . _("Delete") . "\"></form></td></tr>";
            //			$out .= $row["Db"];
        }
        if ($num_rows < $admin_param["nbrdb"]) {
            $dblist_user_popup = "";
            for ($j = 0; $j < $num_users; $j++) {
                $dblist_user_popup .= "<option value=\"" . $dblist_user[$j] . "\">" . $dblist_user[$j] . "</option>";
            }
            $dblist .= "<tr><td><form action=\"" . $_SERVER["PHP_SELF"] . "\">{$hidden}\n\t\t<input type=\"hidden\" name=\"action\" value=\"add_dbuser_db\">\n\t\t<input type=\"text\" name=\"newdb_name\"></td>\n\t\t\t\t<td><select name=\"dbuser\">{$dblist_user_popup}</select></td>\n\t\t\t\t<td><input type=\"submit\" value=\"" . _("Create") . "\"></form></td><td></td></tr>";
        }
        $dblist .= "</table>";
        $out .= $dblist;
        $out .= "<br>" . _("Total database number:") . " {$num_rows}/" . $admin_param["nbrdb"] . "<br>";
        if ($conf_user_mysql_type == "distant") {
            mysql_close($newid) or die("Cannot disconnect to user database");
            connect2base();
        }
        mysql_select_db($conf_mysql_db) or die("Cannot select db \"{$conf_mysql_db}\" !!!");
        return $out;
    } else {
        $out .= _("Please create a MySQL user in order to be able to create a database.");
        return $out;
    }
}
Esempio n. 2
0
function drawAdminTools_PackageInstaller($domain, $adm_path)
{
    global $adm_login;
    global $adm_pass;
    global $edit_domain;
    global $addrlink;
    global $dtcshared_path;
    global $pro_mysql_subdomain_table;
    global $conf_mysql_db;
    global $conf_user_mysql_type;
    global $conf_user_mysql_host;
    global $conf_user_mysql_root_login;
    global $conf_user_mysql_root_pass;
    global $package_installer_console;
    global $dtcpkg_db_login;
    global $pkg_info;
    $txt = "";
    $dir = $dtcshared_path . "/package-installer";
    if (isset($_REQUEST["action"]) && ($_REQUEST["action"] == "do_install" || $_REQUEST["action"] == "prepareinstall")) {
        $pkg_path = $dir . "/" . $_REQUEST["pkg"];
        $dtc_pkg_info = $pkg_path . "/dtc-pkg-info.php";
        if (!file_exists($dtc_pkg_info)) {
            die("Package {$dtc_pkg_info} not found line " . __LINE__ . " file " . __FILE__);
        }
        include $dtc_pkg_info;
    }
    if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "do_install") {
        $pkg_path = $dir . "/" . $_REQUEST["pkg"];
        $dtc_pkg_install = $pkg_path . "/dtc-pkg-install.php";
        if (file_exists($dtc_pkg_install)) {
            include $dtc_pkg_install;
        }
        // Check if user has enough rights
        checkLoginPassAndDomain($adm_login, $adm_pass, $edit_domain);
        checkSubdomainFormat($_REQUEST["subdomain"]);
        $admin_path = getAdminPath($adm_login);
        $target = "{$admin_path}/{$edit_domain}/subdomains/" . $_REQUEST["subdomain"] . "/html";
        if (!is_dir($target)) {
            die("Destination directory does not exists line " . __LINE__ . " file " . __FILE__);
        }
        // Unpack the distribution package in target folder
        if ($pkg_info["unpack_type"] == "tar.gz") {
            $cmd = "tar -C {$target} -xvzf {$pkg_path}/" . $pkg_info["file"];
            $x = "=> tar -C {$target} -xvzf {$pkg_path}/" . $pkg_info["file"] . "\n";
            exec($cmd, $exec_out, $return_val);
        } else {
            if ($pkg_info["unpack_type"] == "tar.bz2") {
                $cmd = "tar -C {$target} -xvjf {$pkg_path}/" . $pkg_info["file"];
                $x = "=> tar -xvjf " . $pkg_info["file"] . "\n";
                exec($cmd, $exec_out, $return_val);
            } else {
                die("Package methode not supported yet");
            }
        }
        // Rename folder to the destination folder name (eg remove version out of package.X.X.X folder name if exists)
        if (isset($pkg_info["renamedir_to"]) && isset($pkg_info["resulting_dir"]) && $pkg_info["resulting_dir"] != $pkg_info["renamedir_to"]) {
            $cmd = "mv {$target}/" . $pkg_info["resulting_dir"] . " {$target}/" . $pkg_info["renamedir_to"];
            $x .= "=> Moving " . $pkg_info["resulting_dir"] . " to " . $pkg_info["renamedir_to"] . "<br>";
            exec($cmd, $exec_out, $return_val);
        }
        // https://dtc.gpl-host.com/dtc/index.php?adm_login=zigo&adm_pass=toto&addrlink=gpl-host.com/package-installer&action=prepareinstall&pkg=phpbb
        // Move the folder to the requested name dtcpkg_directory=bla
        if ($pkg_info["can_select_directory"] == "yes") {
            if ($_REQUEST["dtcpkg_directory"] == "") {
                $cmd = "mv {$target}/" . $pkg_info["renamedir_to"] . "/* {$target}/";
                $x .= "=> Moving " . $pkg_info["renamedir_to"] . " to folder /<br>";
                exec($cmd, $exec_out, $return_val);
                $realtarget = "{$target}";
            } else {
                $cmd = "mv {$target}/" . $pkg_info["renamedir_to"] . " {$target}/" . $_REQUEST["dtcpkg_directory"];
                $x .= "=> Moving " . $pkg_info["renamedir_to"] . " to " . $_REQUEST["dtcpkg_directory"] . "<br>";
                exec($cmd, $exec_out, $return_val);
                $realtarget = "{$target}/" . $_REQUEST["dtcpkg_directory"];
            }
        }
        if ($conf_user_mysql_type == "distant") {
            $newid = mysql_connect($conf_user_mysql_host, $conf_user_mysql_root_login, $conf_user_mysql_root_pass) or die("Cannot connect to user host");
        }
        // Get the database infos beffore calling the custom package installer
        $q = "SELECT DISTINCT db.Db,db.User FROM mysql.user,mysql.db WHERE user.dtcowner='{$adm_login}' AND db.User=user.User AND db.Db='" . $_REQUEST["database_name"] . "';";
        $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
        $n = mysql_num_rows($r);
        if ($n != 1) {
            die("Cannot find database line " . __LINE__ . " file " . __FILE__);
        }
        $a = mysql_fetch_array($r);
        $dtcpkg_db_login = $a["User"];
        if ($conf_user_mysql_type == "distant") {
            mysql_close($newid) or die("Cannot disconnect to user database");
            connect2base();
        }
        // Call the package specific installer php script
        $install_ret = do_package_install();
        // reselect the current dtc db in case another have been set
        mysql_select_db($conf_mysql_db);
        if ($install_ret == 0) {
            $package_installer_console .= "Install successful !<br>";
        }
        $nbr_remove = sizeof($pkg_info["remove_folder_path"]);
        if ($nbr_remove > 0) {
            //	print_r($pkg_info["remove_folder_path"]);
            $nbr_remove = sizeof($pkg_info["remove_folder_path"]);
            $package_installer_console .= "Removing install folders...<br>";
            for ($i = 0; $i < $nbr_remove; $i++) {
                $cmd = "rm -r {$realtarget}/" . $pkg_info["remove_folder_path"][$i];
                //	$package_installer_console .= $cmd."<br>";
                exec($cmd, $exec_out, $return_val);
            }
        }
        // Print the results
        $txt .= "<h3>Installation of " . $pkg_info["name"] . ":</h3><br><pre>" . $x . $package_installer_console . "</pre>";
        return $txt;
    }
    if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "prepareinstall") {
        $txt = "<h3>You are about to install " . $pkg_info["name"] . ":</h3><br>\n\t\t<u>Description:</u> " . $pkg_info["long_desc"] . "<br>\n\t\t<u>Version:</u> " . $pkg_info["version"] . "<br><br>";
        $txt .= "<form action=\"" . $_SERVER["PHP_SELF"] . "\">\n\t\t<input type=\"hidden\" name=\"adm_login\" value=\"{$adm_login}\">\n\t\t<input type=\"hidden\" name=\"adm_pass\" value=\"{$adm_pass}\">\n\t\t<input type=\"hidden\" name=\"addrlink\" value=\"{$addrlink}\">";
        if ($pkg_info["need_database"] == "yes") {
            $txt .= "<h3>Choose a database name for setup:</h3><br>";
            if ($conf_user_mysql_type == "distant") {
                $newid = mysql_connect($conf_user_mysql_host, $conf_user_mysql_root_login, $conf_user_mysql_root_pass) or die("Cannot connect to user SQL host");
            }
            mysql_select_db("mysql") or die("Cannot select db: mysql");
            $q = "SELECT db.Db,db.User FROM user,db\n\t\t\tWHERE user.dtcowner='{$adm_login}'\n\t\t\tAND db.User=user.User";
            $r = mysql_query($q) or die("Cannot query {$q} line " . __LINE__ . " file " . __FILE__ . " sql said: " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $txt .= "You don't have any database yet. Please create one using the database tool\n\t\t\t\t(click database in the menu, then create a user and a database for this user).";
                if ($conf_user_mysql_type == "distant") {
                    mysql_close($newid) or die("Cannot disconnect to user database");
                    connect2base();
                }
                mysql_select_db($conf_mysql_db);
                return $txt;
            }
            $txt .= "Database name: <select name=\"database_name\">";
            for ($i = 0; $i < $n; $i++) {
                $a = mysql_fetch_array($r);
                $txt .= "<option value=\"" . $a["Db"] . "\">" . $a["Db"] . " (login: "******"User"] . ")" . "</option>";
            }
            $txt .= "</select><br>\n\t\t\t\tDatabase password: <input type=\"password\" name=\"dtcpkg_db_pass\" value=\"\"><br><br>";
            if ($conf_user_mysql_type == "distant") {
                mysql_close($newid) or die("Cannot disconnect to user database");
                connect2base();
            }
            mysql_select_db($conf_mysql_db) or die("Cannot select db: {$conf_mysql_db} line " . __LINE__ . " file " . __FILE__);
        }
        if ($pkg_info["need_admin_email"] == "yes") {
            $txt .= "<h3>Enter email for the admin of this package:</h3><br>";
            $txt .= "Email: <input type=\"text\" name=\"dtcpkg_email\" value=\"\"><br><br>";
        }
        if ($pkg_info["need_admin_login"] == "yes") {
            $txt .= "<h3>Enter login informations for the admin of this package:</h3><br>";
            $txt .= "Login: <input type=\"text\" name=\"dtcpkg_login\" value=\"\"><br>";
            if ($pkg_info["need_admin_pass"] == "yes") {
                $txt .= "Pass: <input type=\"text\" name=\"dtcpkg_pass\" value=\"\"><br>";
            }
            $txt .= "<br>";
        }
        $txt .= "<h3>Choose the subdomain and install :</h3><br>";
        $txt .= "<input type=\"hidden\" name=\"action\" value=\"do_install\">\n\t\t<input type=\"hidden\" name=\"pkg\" value=\"" . $_REQUEST["pkg"] . "\">\n\t\tSubdomain: <select name=\"subdomain\">";
        //		echo "<pre>";
        //		print_r($domain);
        //		echo "</pre>";
        $n = sizeof($domain["subdomains"]);
        for ($i = 0; $i < $n; $i++) {
            $txt .= "<option value=\"" . $domain["subdomains"][$i]["name"] . "\">" . $domain["subdomains"][$i]["name"] . "</option>";
        }
        $txt .= "</select><br><br>";
        if ($pkg_info["can_select_directory"] == "yes") {
            $txt .= "<h3>Enter the directory where you want to install this package:</h3><br>";
            $txt .= "Directory (blank for /): <input type=\"text\" name=\"dtcpkg_directory\" value=\"\"><br><br>";
        }
        $txt .= "<input type=\"submit\" value=\"Install\">";
        $txt .= "</form>";
        return $txt;
    }
    $txt = "<h3>" . _("Choose a package to install") . ":</h3>";
    $txt .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\">";
    $txt .= "<tr><td>" . _("Package name") . "</td><td>" . _("Description") . "</td><td>" . _("Package version") . "</td><td>" . _("Need a database") . "</td><td>" . _("Unpack size") . "</td><td>" . _("Install") . "</td></tr>";
    $packages = array();
    if (is_dir($dir) && ($dh = opendir($dir))) {
        while (($file = readdir($dh)) !== false) {
            if (is_dir($dir . "/" . $file) && $file != "." && $file != "..") {
                $packages[] = $file;
            }
        }
        closedir($dh);
    }
    sort($packages);
    foreach ($packages as $package) {
        if (file_exists($dir . "/" . $package . "/dtc-pkg-info.php")) {
            include $dir . "/" . $package . "/dtc-pkg-info.php";
            $txt .= "<tr><td>" . $pkg_info["name"] . "</td>\n\t\t\t\t<td>" . $pkg_info["short_desc"] . "</td>\n\t\t\t\t<td>" . $pkg_info["version"] . "</td>\n\t\t\t\t<td>" . $pkg_info["need_database"] . "</td>\n\t\t\t\t<td style=\"white-space:nowrap;text-align=right\" nowrap>" . smartByte($pkg_info["unpack_disk_usage"]) . "</td>\n\t\t\t\t<td><a href=\"" . $_SERVER["PHP_SELF"] . "?adm_login={$adm_login}&adm_pass={$adm_pass}&addrlink={$addrlink}&action=prepareinstall&pkg={$package}\">" . _("Install") . "</a></td></tr>";
        }
    }
    $txt .= "</table>";
    return $txt;
}
Esempio n. 3
0
        $submit_err .= _("Incorrect MySQL db name format: please enter another and try again.") . "<br>\n";
        $commit_flag = "no";
    } else {
        $q = "SELECT User FROM mysql.db WHERE Db='" . $_REQUEST["dbname"] . "';";
        $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
        $n = mysql_num_rows($r);
        if ($n < 1) {
            $submit_err .= "Cannot reselect MySQL db name: please enter another and try again.<br>\n";
            $commit_flag = "no";
        } else {
            $a = mysql_fetch_array($r);
            $q = "SELECT User FROM mysql.user WHERE User='******' AND dtcowner='{$adm_login}';";
            $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
            $n = mysql_num_rows($r);
            if ($n < 1) {
                $submit_err .= _("MySql database ownership not valid: I will not let you change owner of this database because it doesn't seems to be owned by you.") . "<br>\n";
                $commit_flag = "no";
            }
        }
    }
    if ($commit_flag == "yes") {
        $q = "UPDATE mysql.db SET User='******' WHERE Db='" . $_REQUEST["dbname"] . "';";
        $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
        $q = "FLUSH PRIVILEGES;";
        $r = mysql_query($q) or die("Cannot execute query \"{$q}\" line " . __LINE__ . " file " . __FILE__ . " sql said " . mysql_error());
    }
    if ($conf_user_mysql_type == "distant") {
        mysql_close($newid) or die("Cannot disconnect to user database");
        connect2base();
    }
}
Esempio n. 4
0
        $field_name = mysql_field_name($fields, $i);
        $toto = "conf_" . $field_name;
        global ${$toto};
        ${$toto} = $row["{$field_name}"];
    }
}
//////////////////////////////////////
//////////////////////////////////////
////                              ////
////   AUTOCONF STARTS HERE !!!   ////
////                              ////
//////////////////////////////////////
//////////////////////////////////////
// Include the config file, create it if not found
require "{$dtcshared_path}/{$autoconf_configfile}";
if (connect2base() == false) {
    die("Cannot connect to database !!!");
}
getConfig();
// Do all the updates according to upgrade_sql.php
if (!isset($conf_db_version)) {
    $conf_db_version = 0;
}
if ($conf_demo_version == 'yes') {
    session_register("demo_version_has_started");
    if (!isset($_SESSION["demo_version_has_started"]) || $_SESSION["demo_version_has_started"] != "started") {
        $_SESSION["demo_version_has_started"] = "started";
        $query = "DELETE FROM admin;";
        $result = mysql_query($query) or die("Cannot query {$query} !!!" . mysql_error());
        $query = "DELETE FROM clients;";
        $result = mysql_query($query) or die("Cannot query {$query} !!!" . mysql_error());