예제 #1
0
 public function createAdmin()
 {
     $this->view = false;
     /*
      * email
      * first name
      * last name
      * country
      * city
      * password
      * password repeat
      */
     createUser:
     $this->cadre("create administrator user");
     $email_is_valid = false;
     do {
         $rl = new Hoa\Console\Readline\Readline();
         $email = $rl->readLine('Your email [will be used as login] : ');
         if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $this->displayResult("This email considered as valid !", "KO");
         } else {
             $this->displayResult("This email considered as valid !", "OK");
             $domain = explode('@', $email)[1];
             if (checkdnsrr($domain, 'MX')) {
                 $this->displayResult("This MX records exists !", "OK");
                 $email_is_valid = true;
             } else {
                 $this->displayResult("This MX records exists !", "KO");
             }
         }
     } while ($email_is_valid === false);
     //first name
     $firstname = $rl->readLine('Your firstname : ');
     //last name
     $lastname = $rl->readLine('Your lastname : ');
     //country
     $sql = "SELECT libelle FROM geolocalisation_country where libelle != '' ORDER BY libelle";
     $DB = $this->di['db']->sql(DB_DEFAULT);
     $res = $DB->sql_query($sql);
     $country = [];
     while ($ob = $DB->sql_fetch_object($res)) {
         $country[] = $ob->libelle;
     }
     do {
         $rl = new Hoa\Console\Readline\Readline();
         $rl->setAutocompleter(new Hoa\Console\Readline\Autocompleter\Word($country));
         $country2 = $rl->readLine('Your country [First letter in upper case, then tab for help] : ');
         $sql = "select id from geolocalisation_country where libelle = '" . $DB->sql_real_escape_string($country2) . "'";
         $res = $DB->sql_query($sql);
         if ($DB->sql_num_rows($res) == 1) {
             $ob = $DB->sql_fetch_object($res);
             $id_country = $ob->id;
             $this->displayResult("Country found in database !", "OK");
         } else {
             $this->displayResult("Country found in database !", "KO");
         }
     } while ($DB->sql_num_rows($res) != 1);
     //city
     $sql = "SELECT libelle FROM geolocalisation_city where id_geolocalisation_country = '" . $id_country . "' ORDER BY libelle";
     $DB = $this->di['db']->sql(DB_DEFAULT);
     $res = $DB->sql_query($sql);
     $city = [];
     while ($ob = $DB->sql_fetch_object($res)) {
         $city[] = $ob->libelle;
     }
     do {
         $rl = new Hoa\Console\Readline\Readline();
         $rl->setAutocompleter(new Hoa\Console\Readline\Autocompleter\Word($city));
         $city2 = $rl->readLine('Your city [First letter in upper case, then tab for help] : ');
         $sql = "select id from geolocalisation_city where libelle = '" . $DB->sql_real_escape_string($city2) . "'";
         $res = $DB->sql_query($sql);
         if ($DB->sql_num_rows($res) == 1) {
             $ob = $DB->sql_fetch_object($res);
             $id_city = $ob->id;
             $this->displayResult("City found in database !", "OK");
         } else {
             $this->displayResult("City found in database !", "KO");
         }
     } while ($DB->sql_num_rows($res) != 1);
     //password
     $rl = new Hoa\Console\Readline\Password();
     $good = false;
     do {
         $pwd = $rl->readLine('Password : '******'Password (repeat) : ');
         if (!empty($pwd) && $pwd === $pwd2) {
             $good = true;
             $this->displayResult("The passwords must be the same & not empty", "OK");
         } else {
             $this->displayResult("The passwords must be the same & not empty", "KO");
         }
     } while ($good !== true);
     $ip = trim(@file_get_contents("http://icanhazip.com"));
     if (empty($ip) || !filter_var($ip, FILTER_VALIDATE_IP)) {
         $ip = "127.0.0.1";
     }
     $data['user_main']['is_valid'] = 1;
     $data['user_main']['email'] = $email;
     $data['user_main']['login'] = $email;
     $data['user_main']['password'] = \Glial\Auth\Auth::hashPassword($email, $pwd);
     //to set uppercase to composed name like 'Jean-Louis'
     $firstname = str_replace("-", " - ", $firstname);
     $firstname = mb_convert_case($firstname, MB_CASE_TITLE, "UTF-8");
     $data['user_main']['firstname'] = str_replace(" - ", "-", $firstname);
     $data['user_main']['name'] = mb_convert_case($lastname, MB_CASE_UPPER, "UTF-8");
     $data['user_main']['ip'] = $ip;
     $data['user_main']['date_created'] = date('Y-m-d H:i:s');
     $data['user_main']['id_group'] = 4;
     // 4 = super admin
     $data['user_main']['id_geolocalisation_country'] = $id_country;
     $data['user_main']['id_geolocalisation_city'] = $id_city;
     $data['user_main']['id_client'] = 1;
     $id_user = $DB->sql_save($data);
     if ($id_user) {
         $this->displayResult("Admin account successfully created", "OK");
     } else {
         print_r($data);
         $error = $DB->sql_error();
         print_r($error);
         $this->displayResult("Admin account successfully created", "KO");
         goto createUser;
     }
     echo Color::getColoredString("\nAdministrator successfully created !\n", "green");
     $ip_list = shell_exec('ifconfig -a | grep "inet ad" | cut -d ":" -f 2 | cut -d " " -f 1');
     $ips = explode("\n", $ip_list);
     foreach ($ips as $ip) {
         if (empty($ip)) {
             continue;
         }
         echo "You can connect to the application on this url : " . Color::getColoredString("http://" . $ip . WWW_ROOT, "yellow") . "\n";
     }
     echo "You can connect to the application on this url : " . Color::getColoredString("http://" . gethostname() . WWW_ROOT, "yellow") . "\n";
 }
예제 #2
0
파일: Bootstrap.php 프로젝트: glial/glial
            $params = array();
            for ($i = 3; $i < $_SERVER["argc"]; $i++) {
                $params[] = $_SERVER["argv"][$i];
            }
            $_SYSTEM['param'] = $params;
        }
        //cli_set_process_title("glial-" . $_SYSTEM['controller'] . "-" . $_SYSTEM['action']." (".$name.")");
    } else {
        throw new InvalidArgumentException('usage : gial <controlleur> <action> [params]');
    }
    define('LINK', WWW_ROOT . "en" . "/");
} else {
    //mode with apache
    define('LINK', WWW_ROOT . I18n::Get() . "/");
    if (AUTH_ACTIVE) {
        $auth = new Auth();
        $auth->setInstance($_DB->sql(DB_DEFAULT), "user_main", array("login", "password"));
        $auth->setFctToHashCookie(function ($password) {
            return password_hash($password . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'], PASSWORD_DEFAULT);
        });
        $auth->authenticate(false);
        FactoryController::addDi("auth", $auth);
    }
    ENVIRONEMENT ? $_DEBUG->save("User connexion") : "";
    $_SYSTEM['controller'] = \Glial\Utility\Inflector::camelize($url['controller']);
    $_SYSTEM['action'] = $url['action'];
    $_SYSTEM['param'] = $url['param'];
    $acl = new Acl(CONFIG . "acl.config.ini");
    FactoryController::addDi("acl", $acl);
    $js = new Javascript();
    FactoryController::addDi("js", $js);