Пример #1
0
 static function connect($name, $elem)
 {
     if (!in_array($elem['driver'], self::$driver)) {
         throw new \Exception("GLI-023 : This driver isn't supported : " . $elem['driver']);
     }
     $driver = '\\Glial\\Sgbd\\Sql\\' . ucwords(strtolower($elem['driver'])) . '\\' . ucwords(strtolower($elem['driver']));
     $addr = $elem['hostname'];
     $dbname = $elem['database'];
     if (!empty($elem['port']) && is_numeric($elem['port'])) {
         $port = $elem['port'];
     } else {
         $port = null;
     }
     self::$db[$name] = new $driver($name, $elem);
     if (!self::$db[$name]) {
         return false;
     }
     self::$db[$name]->setLogger(self::$logger);
     if (!empty($elem['crypted']) && $elem['crypted'] === "1") {
         Crypt::$key = CRYPT_KEY;
         $elem['password'] = Crypt::decrypt($elem['password']);
     }
     self::$db[$name]->sql_connect($addr, $elem['user'], $elem['password'], $dbname, $port);
     return self::$db[$name];
 }
Пример #2
0
 function uncrypt()
 {
     $this->view = false;
     Crypt::$key = CRYPT_KEY;
     $sql = "SELECT * from mysql_server";
     $db = $this->di['db']->sql(DB_DEFAULT);
     $res = $db->sql_query($sql);
     while ($ob = $db->sql_fetch_object($res)) {
         debug(Crypt::decrypt($ob->passwd));
     }
 }
Пример #3
0
 private function importData($server)
 {
     //$path = ROOT."/sql/*.sql";
     $path = ROOT . "/sql/full/pmacontrol.sql";
     Crypt::$key = CRYPT_KEY;
     $server['password'] = Crypt::decrypt($server['password']);
     foreach (glob($path) as $filename) {
         //echo "$filename size ".filesize($filename)."\n";
         $cmd = "mysql -h " . $server["hostname"] . " -u " . $server['user'] . " -P " . $server['port'] . " -p" . $server['password'] . " " . $server['database'] . " < " . $filename . "";
         $this->cmd($cmd, "Loading " . pathinfo($filename)['basename']);
     }
 }
Пример #4
0
 public function addUserPmaControl()
 {
     $this->layout_name = false;
     $this->view = false;
     fwrite(STDOUT, str_repeat("#", 80) . "\n");
     $text = "Create user pmacontrol, Generating SSH keys and install it !";
     fwrite(STDOUT, "#" . str_repeat(" ", (80 - strlen($text) - 2) / 2) . $text . str_repeat(" ", (80 - strlen($text) - 2) / 2) . "#\n");
     fwrite(STDOUT, str_repeat("#", 80) . "\n");
     $passwdpma = $this->setPasswdPmaControl();
     fwrite(STDOUT, str_repeat("-", 80) . "\n");
     $db = $this->di['db']->sql(DB_DEFAULT);
     $sql = "SELECT * FROM mysql_server";
     $servers = $db->sql_fetch_yield($sql);
     Crypt::$key = CRYPT_KEY;
     $account_valided = [];
     foreach ($servers as $server) {
         fwrite(STDOUT, "try to connect in ssh to " . $server['ip'] . " \n");
         $login = Crypt::decrypt($server['ssh_login']);
         $password = Crypt::decrypt($server['ssh_password']);
         $failed = true;
         $run = 1;
         reset($account_valided);
         /*
          * Try credntial in mysql_server (from db.config.ini)
          * else try last credentials successfully worked
          * to finish set your login // password
          */
         do {
             echo "Trying credential (" . $server['ip'] . " login : "******" - password : "******")- run n°" . $run . "\n";
             $ssh = new Ssh($server['ip'], 22, $login, $password);
             if ($ssh->connect(Ssh::DEBUG_ON)) {
                 fwrite(STDOUT, "Successfully connected\n");
                 $tmp = [];
                 $tmp['login'] = $login;
                 $tmp['password'] = $password;
                 $account_valided[md5($tmp['login'] . $tmp['password'])] = $tmp;
                 // create account pmacontrol
                 $ssh->openShell();
                 $ssh->waitPrompt($buffer);
                 $ssh->shellCmd("sudo su -");
                 $ret = $ssh->waitPrompt($buffer, 'password\\sfor\\s[a-z]+\\:');
                 if ($ret) {
                     $ssh->shellCmd($password);
                     $ssh->waitPrompt($buffer);
                 }
                 $ssh->shellCmd("getent passwd pmacontrol");
                 $ret = $ssh->waitPrompt($buffer, 'pmacontrol\\:');
                 if ($ret !== false) {
                     $ssh->shellCmd("useradd -ou 0 -g 0 pmacontrol");
                     $ssh->waitPrompt($buffer);
                 }
                 $ssh->shellCmd("passwd pmacontrol");
                 $ssh->waitPrompt($buffer, ":");
                 $ssh->shellCmd($passwdpma);
                 $ssh->waitPrompt($buffer, ":");
                 $ssh->shellCmd($passwdpma);
                 $ssh->waitPrompt($buffer);
                 $failed = false;
             } else {
                 fwrite(STDOUT, "Failed to connect\n");
                 list($elem) = each($account_valided);
                 if (isset($elem)) {
                     $login = $account_valided[$elem]['login'];
                     $password = $account_valided[$elem]['password'];
                 } else {
                     $user = $this->getLoginPassword();
                     $login = $user['login'];
                     $password = $user['passwd'];
                 }
             }
             $run++;
         } while ($failed);
         //fwrite(STDOUT, "useradd -ou 0 -g 0 pmacontrol\n");
         fwrite(STDOUT, str_repeat("-", 80) . "\n");
         unset($ssh);
     }
 }