Esempio n. 1
0
function new_client_id()
{
    $candidate_id = random_name(6, "client");
    $i = 0;
    while (!is_client_unique($candidate_id) && $i < 10) {
        $candidate_id = random_name(6, "client");
        $i += 1;
    }
    if ($i == 10) {
        echo "failed to find a client id... Maybe system is full";
        return false;
    }
    $ip = $_SERVER['REMOTE_ADDR'];
    $db_link = db_connect();
    $insert_query = "INSERT INTO clients SET client_id='{$candidate_id}'";
    $insert_query .= ", ip='{$ip}';";
    $success = mysqli_query($db_link, $insert_query);
    if (!success) {
        echo 'Error creating client in DB!';
        return false;
    }
    return $candidate_id;
}
Esempio n. 2
0
$q = $db->query("SELECT max(id) FROM colleges");
$max_college_id = $q->fetch()[0];
$q = $db->query("SELECT max(id) FROM standings");
$max_standing_id = $q->fetch()[0];
$q = $db->query("SELECT max(id) FROM courses");
$max_course_id = $q->fetch()[0];
// Remove old random rows
$db->query("DELETE FROM user_courses WHERE user_id > 6");
$db->query("DELETE FROM group_members WHERE user_id > 6");
$db->query("DELETE FROM groups WHERE id > 3");
$db->query("DELETE FROM users WHERE id > 6");
// Create N random users
$userids = array();
$q = $db->prepare("INSERT INTO users (name, email, phone, campus_id, college_id, standing_id) VALUES (:name, :email, :phone, :campus_id, :college_id, :standing_id)");
for ($i = 0; $i < $NUMBER_OF_USERS; $i++) {
    $name = random_name();
    $email = "user{$i}@example.com";
    $phone = sprintf("800555%04d", $i);
    $campus_id = mt_rand(1, $max_campus_id);
    $college_id = mt_rand(1, $max_college_id);
    $standing_id = mt_rand(1, $max_standing_id);
    //echo $name, "\n";
    //echo $email, "\n";
    //echo $phone, "\n";
    //echo $campus_id, "\n";
    //echo $college_id, "\n";
    //echo $standing_id, "\n";
    $q->bindValue(":name", $name);
    $q->bindValue(":email", $email);
    $q->bindValue(":phone", $phone);
    $q->bindValue(":campus_id", $campus_id);
Esempio n. 3
0
function install_step4()
{
    $INTEGRIA_config = "include/config.php";
    global $integria_footertext;
    global $integria_version;
    if (!isset($_POST["user"]) || !isset($_POST["dbname"]) || !isset($_POST["host"]) || !isset($_POST["pass"])) {
        $dbpassword = "";
        $dbuser = "";
        $dbhost = "";
        $dbname = "";
    } else {
        $dbpassword = $_POST["pass"];
        $dbuser = $_POST["user"];
        $dbhost = $_POST["host"];
        if (isset($_POST["demodb"])) {
            $demodb = $_POST["demodb"];
        } else {
            $demodb = 0;
        }
        if (isset($_POST["createdb"])) {
            $createdb = $_POST["createdb"];
        } else {
            $createdb = 0;
        }
        if (isset($_POST["createuser"])) {
            $createuser = $_POST["createuser"];
        } else {
            $createuser = 0;
        }
        $dbname = $_POST["dbname"];
        if (isset($_POST["url"])) {
            $url = $_POST["url"];
        } else {
            $url = '/integria';
        }
    }
    $everything_ok = 0;
    $step1 = 0;
    $step2 = 0;
    $step3 = 0;
    $step4 = 0;
    $step5 = 0;
    $step6 = 0;
    $step7 = 0;
    echo "\n\t<div align='center' class='mt35'>\n\t<div id='wizard' style=''>\n\t\t<div id='install_box' style='float: right;'>\n\t\t\t<h1>Creating database and default configuration file</h1>\n\t\t\t<table style='background: #ffffff;'>";
    if (!mysql_connect($dbhost, $dbuser, $dbpassword)) {
        check_generic(0, "Connection with Database");
    } else {
        check_generic(1, "Connection with Database");
        // Create schema
        if ($createdb == 1) {
            $step1 = mysql_query("CREATE DATABASE {$dbname}");
            check_generic($step1, "Creating database '{$dbname}'");
        } else {
            $step1 = 1;
        }
        if ($step1 == 1) {
            $step2 = mysql_select_db($dbname);
            check_generic($step2, "Opening database '{$dbname}'");
            $step3 = parse_mysql_dump("integria_db.sql");
            check_generic($step3, "Creating schema");
            // Populate the database with basic and optional demo data
            $step4 = parse_mysql_dump("integria_dbdata.sql");
            if ($step4 == 1 && $demodb == 1) {
                $step4 = parse_mysql_dump("integria_demo.sql");
            }
            check_generic($step4, "Populating database");
            $random_password = random_name(8);
            if ($createuser == 1) {
                $query = "GRANT ALL PRIVILEGES ON {$dbname}.* to integria@localhost  IDENTIFIED BY '" . $random_password . "'";
                $step5 = mysql_query($query);
                mysql_query("FLUSH PRIVILEGES");
                check_generic($step5, "Established privileges for user 'integria' on database '{$dbname}', with password <i>'{$random_password}'</i>");
            } else {
                $step5 = 1;
            }
            $step6 = is_writable("include");
            check_generic($step6, "Write permissions to save config file in './include'");
            $cfgin = fopen("include/config.inc.php", "r");
            $cfgout = fopen($INTEGRIA_config, "w");
            $config_contents = fread($cfgin, filesize("include/config.inc.php"));
            //---INIT--- CONFIG FILE
            $config_new = '<?php' . "\n" . '// Begin of automatic config file' . "\n" . '$config["dbuser"]='******'"integria";' . "\n" . '$config["dbpass"]="******";	// DB Password' . "\n";
            } else {
                $config_new = $config_new . '"' . $dbuser . '";' . "\n" . '$config["dbpass"]="******";	// DB Password' . "\n";
            }
            $config_new = $config_new . "\n" . '$config["dbname"]="' . $dbname . '";    // MySQL DataBase name' . "\n" . '$config["dbhost"]="' . $dbhost . '";    // DB Host' . "\n" . "\n" . '$config["baseurl"]="' . $url . '";	// Base URL' . "\n" . '$config["baseurl_static"]="' . $url . '";	// Don\'t  delete' . "\n" . '// End of automatic config file' . "\n" . '?>';
            //---END--- CONFIG FILE
            $step7 = fputs($cfgout, $config_new);
            $step7 = $step7 + fputs($cfgout, $config_contents);
            if ($step7 > 0) {
                $step7 = 1;
            }
            fclose($cfgin);
            fclose($cfgout);
            check_generic($step7, "Created new config file at '" . $INTEGRIA_config . "'");
        }
        mysql_select_db($dbname);
    }
    if ($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1 == 7) {
        $everything_ok = 1;
    }
    echo "</table></div>\n\t\t<div class='box' style='float: left;'>\n\t\t\t<img src='images/integria_white.png' alt=''>\n\t\t\t<br><br>\n\t\t\t<font size=1px>" . $integria_version . "</font>\n\t\t</div>\n\t\t\n\t\t<div class='box' style='float: left;'>\n\t\t\t<img src='images/step3.png' alt=''>\n\t\t</div>\n\t\t\n\t\t<div id='install_box' style='clear: both; margin-bottom: 25px;margin-left: 25px;'>\n\t\t\n\t\t<p>";
    if ($everything_ok == 1) {
        echo "<a href='install.php?step=5'><img align='right' src='images/arrow_next.png' class=''></a>";
    } else {
        echo "<img src='images/info.png'> You get some problems. Installation is not completed. \n\t\t\t<p>Please correct failures before trying again. All database schemes created in this step have been dropped.</p>";
        if (mysql_error() != "") {
            echo "<p><img src='images/info.png'> <b>ERROR:</b> " . mysql_error() . "</p>";
        }
        if ($createdb == 1) {
            mysql_query("DROP DATABASE {$dbname}");
        }
    }
    echo "</div>\n\t\t<div style='clear: both; width: 100%;'></div>\n\t\t</div></div>";
}