Example #1
0
 public function import()
 {
     # Imports or displays. Whatever really..
     global $style;
     global $db;
     global $main;
     global $type;
     if (!$_POST) {
         $query = $db->query("SELECT * FROM `<PRE>servers` WHERE `type` = 'whm'");
         while ($data = $db->fetch_array($query)) {
             $values[] = array($data['name'], $data['id']);
         }
         $array['DROPDOWN'] = $main->dropdown("server", $values);
         echo $style->replaceVar("tpl/whmimport/step1.tpl", $array);
     } elseif ($_POST) {
         foreach ($main->postvar as $key => $value) {
             if ($value == "" && !$n) {
                 $main->errors("Please fill in all the fields!");
                 $n++;
             }
         }
         if (!$n) {
             include LINK . "servers/whm.php";
             $whm = new whm();
             $userdata = $whm->listaccs($main->postvar['server']);
             foreach ($userdata as $data) {
                 $pselect = $db->query("SELECT * FROM `<PRE>packages` WHERE `backend` = '{$data['package']}'");
                 $usercheck = $db->query("SELECT * FROM `<PRE>users` WHERE `user` = '{$data['user']}'");
                 if ($db->num_rows($usercheck) == 0) {
                     if ($db->num_rows($pselect) == 0) {
                         echo "hey!";
                         $db->query("INSERT INTO `<PRE>packages` (name,backend,description,type,server,admin) \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   VALUES('{$data['package']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$data['package']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  'Description Here',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  'free',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '{$main->postvar['server']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  '0')");
                     }
                     $pidquery = $db->query("SELECT * FROM `<PRE>packages` WHERE `backend` = '{$data['package']}'");
                     $piddata = $db->fetch_array($pidquery);
                     $finalpackid = $piddata['id'];
                     $checkquery = $db->query("SELECT * FROM `<PRE>users` WHERE `user` = '{$data['user']}'");
                     if ($db->num_rows($checkquery) == 0) {
                         $db->query("INSERT INTO `<PRE>users` (user,email,password,salt,signup,ip) \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$data['user']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$data['email']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'saltme',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$data['start_date']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'')");
                         $checkquery = $db->query("SELECT * FROM `<PRE>users` WHERE `user` = '{$data['user']}'");
                         $datanewuser = $db->fetch_array($checkquery);
                         $db->query("INSERT INTO `<PRE>user_packs` (userid,domain,pid,signup,status,additional) \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t VALUES(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$datanewuser['id']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$data['domain']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$finalpackid}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$data['start_date']}',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'1',\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$additional}')");
                         $n++;
                     }
                 }
             }
         }
         echo $n . " Accounts have been imported!";
     }
 }
Example #2
0
 public function import()
 {
     global $dbh, $postvar, $getvar, $instance;
     if (!$_POST) {
         $servers_query = $dbh->select("servers", array("type", "=", "whm"), 0, 0, 1);
         while ($servers_data = $dbh->fetch_array($servers_query)) {
             $values[] = array($servers_data['name'], $servers_data['id']);
         }
         $whm_array['DROPDOWN'] = main::dropdown("server", $values);
         echo style::replaceVar("tpl/admin/import/whm.tpl", $whm_array);
     } elseif ($_POST) {
         $postvar['server'] = $postvar['server'];
         //Hack to make sure we post the 'server' field as it doesn't post if it's empty.
         check::empty_fields();
         if (main::errors()) {
             echo "<ERRORS>";
         } else {
             include INC . "/servers/whm.php";
             $whm = new whm();
             $whm_accounts = $whm->listaccs($postvar['server']);
             foreach ($whm_accounts as $whm_data) {
                 $packages_data = $dbh->select("packages", array("backend", "=", $whm_data['package']));
                 $users_data = $dbh->select("users", array("user", "=", $whm_data['user']));
                 if (!$users_data['id']) {
                     if (!$packages_data['id']) {
                         $packages_insert = array("name" => $whm_data['package'], "backend" => $whm_data['package'], "description" => "Inported from WHM: " . $whm_data['package'], "type" => "free", "server" => $postvar['server'], "admin" => "1");
                         $dbh->insert("packages", $packages_insert);
                     }
                     $new_packages_data = $dbh->select("packages", array("backend", "=", $whm_data['package']));
                     $salt = crypto::salt();
                     $newpass = crypto::passhash(rand(), $salt);
                     $users_insert = array("user" => $whm_data['user'], "email" => $whm_data['email'], "password" => $newpass, "salt" => $salt, "signup" => $whm_data['start_date'], "status" => "1", "domain" => $whm_data['domain'], "pid" => $new_packages_data['id']);
                     $dbh->insert("users", $users_insert);
                     $dbh->insert("users_bak", $users_insert);
                     $n++;
                 }
             }
             echo $n . " Accounts have been imported!";
         }
     }
 }