Exemple #1
0
 public function index(HttpRequestEx $request)
 {
     $params = $request->getParameters();
     if (!empty($params['plugins'])) {
         $plugins = json_decode($params['plugins'], true);
         foreach ($plugins as $plugin => $tick) {
             if ($tick) {
                 $enabled[] = $plugin;
             }
         }
         if (!empty($enabled)) {
             echo "<pre>Starting composer..\n";
             //chdir($this->bootLoader->getBaseDir());
             //$output = $this->shell->run('composer -vv require %s', array_map(function ($f) { return "minutephp/$f:dev-master"; }, $enabled));
             $plugins = array_map(function ($f) {
                 return "minutephp/{$f}";
             }, $enabled);
             $success = $this->installer->install($plugins);
             if ($success) {
                 //--prefer-source
                 echo '<h3>All done!</h3>';
                 echo '<script>top.location.href = "/first-run/apache";</script>';
             } else {
                 echo "<h3>Something didn't go as expected.</h3>";
             }
         }
     }
 }
Exemple #2
0
 public function index($name, $mode)
 {
     echo '<html><title>Plugin installer</title><head><script>var interval = setInterval(function(){window.scrollTo(0,document.body.scrollHeight);}, 1000);</script></head><body>';
     echo '<pre>';
     $pass = $this->installer->install([$name], $mode == 'remove' ? 'remove' : 'require', false);
     echo '</pre>';
     echo '<script>clearInterval(interval);</script>';
     echo $pass ? printf('<scrip' . 't>self.opener.location.reload(); self.close();</script>') : '<h3>Sorry, could not install plugin at this time.</h3>';
     echo '</body></html>';
 }
Exemple #3
0
 public function setup(HttpRequestEx $request)
 {
     $params = $request->getParameters();
     try {
         if (!empty($params['db']['database']) && !empty($params['db']['username']) && !empty($params['db']['password'])) {
             try {
                 $conn = $this->database->connect($params['db']);
                 if ($pdo = $conn->getPdo()) {
                     $conf = sprintf('%s/app/Config/db-config', $this->bootLoader->getBaseDir());
                     if (file_put_contents($conf, sprintf('mysql://%s:%s@%s/%s', $params['db']['username'], $params['db']['password'], $params['db']['host'], $params['db']['database']))) {
                         if ($this->installer->install(['minutephp/site'], 'require', true)) {
                             $sth = $pdo->prepare('REPLACE INTO users SET email = :email, password = :password, ip_addr = :ip, created_at = NOW(), updated_at = NOW(), first_name = "Admin", verified = "true"');
                             $sth->execute(['email' => sprintf('admin@%s', $params['site']['domain'] ?? 'localhost'), 'password' => password_hash(Str::random(), PASSWORD_DEFAULT), 'ip' => $this->sniffer->getUserIP()]);
                             if ($admin_id = $pdo->lastInsertId()) {
                                 $sth = $pdo->prepare('REPLACE INTO m_user_groups set user_id = :user_id, group_name = "admin", created_at = NOW(), updated_at = NOW(), 
                                                                        expires_at = "20200101", credits = 999, comments = "First run"');
                                 $sth->execute(['user_id' => $admin_id]);
                                 $types = ['public' => $params['site'] ?? [], 'private' => []];
                                 foreach ($types as $type => $data) {
                                     $sth = $pdo->prepare('REPLACE INTO m_configs set type = :type, data_json = :data');
                                     $sth->execute(['type' => $type, 'data' => json_encode($data)]);
                                 }
                                 $this->session->startSession($admin_id);
                                 return 'pass';
                             }
                         } else {
                             throw new FirstRunError($this->lang->getText("Unable to run composer"));
                         }
                     }
                 }
             } catch (\Throwable $e) {
                 throw new FirstRunError($this->lang->getText("Unable to connect to database.\n") . $e->getMessage());
             }
         }
         throw new FirstRunError($this->lang->getText('All connection parameters are required. Please check connection details'));
     } catch (\Throwable $e) {
         if (!empty($conf) && file_exists($conf)) {
             @unlink($conf);
         }
         throw new FirstRunError("Error: " . $e->getMessage());
     }
 }