/** * send mail */ function _sendmail($cp) { //$mail->SMTPDebug = 3; // Enable verbose debug output $to = $cp->email_domain ? $cp->email_domain : ADMIN_EMAIL; $res = send_mail1($to, _post('subject'), _post('body')); ajax_output(strip_tags($res)); }
/** * chmod dir(755) & all files in folder (644) * @param $data */ function _chmod($data) { $dir = _post('dir'); $str = exec('start cmd.exe /c "cd ' . WHM_CPANEL_SHELL_APP . '\\x_ssh/&&__chmod.bat ' . $data->acc_id . ' ' . $dir . '"'); ajax_output($str); }
//Export the database and output the status to the page $command = 'mysql -h ' . $mysqlHostName . ' -u ' . $mysqlUserName . ' "-p' . $mysqlPassword . '" ' . $mysqlDatabaseName . ' < ' . $mysqlImportFilename; exec($command, $output = array(), $worked); switch ($worked) { case 0: $msg = 'Import file <b>' . $mysqlImportFilename . '</b> successfully imported to database <b>' . $mysqlDatabaseName . '</b>'; break; case 1: $msg = 'There was an error during import. Please make sure the import file is saved in the same folder as this script and check your values:<br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' . $mysqlDatabaseName . '</b></td></tr><tr><td>MySQL User Name:</td><td><b>' . $mysqlUserName . '</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' . $mysqlHostName . '</b></td></tr><tr><td>MySQL Import Filename:</td><td><b>' . $mysqlImportFilename . '</b></td></tr></table>'; break; default: $msg = ''; } unlink($mysqlImportFilename); //remove file after executing ajax_output(array('result' => $msg)); } elseif ($task == 'maintenance_mode') { $htaccess_file = $doc_root . '/.htaccess'; $url = hwt_post('redirect_url', 'http://hoangweb.com'); #$begin_locksite_comment ='# BEGIN HOANGWEB LOCKSITE'; #$end_locksite_comment ='# END HOANGWEB LOCKSITE'; //default htaccess content $htaccess = file_get_contents($htaccess_file); //lock site if (strpos($htaccess, "ErrorDocument 403 {$url}") === false) { //block code $append = "# BEGIN HOANGWEB LOCKSITE\nErrorDocument 403 {$url}\r\nOrder deny,allow\r\nDeny from all\n# END HOANGWEB LOCKSITE"; $htaccess .= "\n\n{$append}"; } //modify .htaccess file_put_contents($htaccess_file, $htaccess);
/** * run sql to fixed url base in wordpress that stored in wp_posts, wp_postmeta,wp_options * @param $cp */ function wp_sql_fixedbaseurl($cp) { $db = _post('db'); $dbuser = _post('dbuser'); $where = ''; if ($db) { $where .= " and db='{$db}' "; } if ($dbuser) { $where .= " and dbuser='******' "; } $dbs = get_acct_dbs($cp->acc_id, $where); if ($dbs) { $dbs = $dbs->FetchRow(); } if (is_array($dbs) && count($dbs)) { $cmd = _post('cmd'); //contain command file $find = _post('findstr'); //what to find? $repl = _post('replacestr'); //replace with ? $save = WHM_CPANEL_SHELL_APP . "/x_ssh/commands"; //modify cmd file, do not put -D param before dbname //https://my.bluehost.com/cgi/help/112 $txt = "mysql -p -u {$cp->cpaneluser}_{$dbs['dbuser']} {$cp->cpaneluser}_{$dbs['db']} < wp_fixedbaseurl_mysql.sql\r\nread -n1 -r -p 'Press any key to continue...' key"; file_put_contents($save . '/' . $cmd, $txt); //create sql file $sql = 'update wp_options set option_value=REPLACE(option_value,"' . $find . '","' . $repl . '");' . PHP_EOL; $sql .= 'update wp_posts set post_content=REPLACE(post_content,"' . $find . '","' . $repl . '");' . PHP_EOL; $sql .= 'update wp_posts set guid=REPLACE(guid,"' . $find . '","' . $repl . '");' . PHP_EOL; $sql .= 'update wp_postmeta set meta_value=REPLACE(meta_value,"' . $find . '","' . $repl . '");' . PHP_EOL; file_put_contents($save . '/wp_fixedbaseurl_mysql.sql', $sql); //upload .sql file to server $cpanel_file = $cp->get_instance('fileman_no_auth'); $res = $cpanel_file->uploadfiles(array('fullpath' => "{$save}/wp_fixedbaseurl_mysql.sql", 'type' => '', 'name' => 'wp_fixedbaseurl_mysql.sql'), '/'); ajax_output($res); //run batch file $cp->run_command(); } }
/** * open ssh terminal for root account (refer to whm) * @param $cp */ function openssh_rootaccess($cp) { $root_pass = HW_WHM_ROOT_PASS; $str = exec('start cmd.exe /c "cd ' . WHM_CPANEL_SHELL_APP . '\\x_ssh/&&__open-ssh-root.bat ' . HW_WHM_IP . ' ' . $root_pass . '"'); #$str = exec('start cmd.exe /c "cd '.WHM_CPANEL_SHELL_APP.'\x_uploader/&&__open-ssh-root.bat"'); ajax_output($str); }
/** * list all svn users from `svn_wp_users` on server * @param $acc_id * @param string $subdomain * @return array */ function wptool_list_svn_users($acc_id = '', $subdomain = '') { if (!$acc_id) { $acc_id = $this->acc_id; } $acc = get_cpanel_acc($acc_id); $domain = isset($acc['cpanel_domain']) ? $acc['cpanel_domain'] : ''; if (empty($domain)) { return; } //update wp tool $res = $this->upload_wptool($acc_id, $subdomain); ajax_output($res); //run this file $url = rtrim($domain, '/') . '/' . HW_WP_TOOL_FILE . '?do=list_svn_users&json=1&acc=' . $acc_id; $res = curl_post($url, array('subdomain' => $subdomain)); return (array) json_decode($res); }
/** * del ftp account * @param $data */ function delftp_acct($data) { $ftpuser = _post('user'); /*$query = "json-api/cpanel?cpanel_jsonapi_user={$cpaneluser}&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=delftp&user={$ftpuser}&destroy=1"; $cpanel = HW_CPanel::loadacct_instance($acc_id, false); $result = $cpanel->cpanelapi($query);*/ //authorize $cpanel_ftp = HW_CPanel_Ftp::loadacct($data->acc_id); $result = $cpanel_ftp->delftp($ftpuser); ajax_output($result); }
/** * export db from localhost used by this application * @param $cp */ function export_localdb($cp) { include 'libs/dumper.php'; $name = _post('file', DB_NAME); $include_tables = _post('include_tables'); $savepath = _post('savepath', 'tmp/'); try { $arg = array('host' => DB_HOST, 'username' => DB_USER, 'password' => DB_PASS, 'db_name' => DB_NAME); if ($include_tables) { $arg['include_tables'] = preg_split('#[,\\s]+#', $include_tables); } $world_dumper = Shuttle_Dumper::create($arg); // dump the database to gzipped file #$world_dumper->dump($savepath.$name. '.sql.gz'); //.sql.gz not allow to import by mysql command // dump the database to plain text file $world_dumper->dump($savepath . $name . '.sql'); echo 'Export database ' . DB_NAME . ' successfull !'; } catch (Shuttle_Exception $e) { ajax_output(array('result' => "Couldn't dump database: " . $e->getMessage())); } }
/** * list all repositories * @param $cp */ function svn_list_repositories($cp) { $subdomain = _post('subdomain'); $update_repo_db = _post('update_repo_db'); //upload hw wp tool $res = $cp->upload_wptool(0, $subdomain); ajax_output($res); //run this file $url = rtrim(_domain($cp->domain, $subdomain), '/') . '/' . HW_WP_TOOL_FILE . '?do=svn_list_repositories&acc=' . $cp->acc_id; $data = array('update_repo_db' => $update_repo_db); $res = curl_post($url, $data); ajax_output($res); }
/** * restore cpbackup file * @param $data */ function restore_cpbackup($data) { $str = exec('start cmd.exe /c "cd ' . WHM_CPANEL_SHELL_APP . '\\x_ssh/&&__cpbackup-restore.bat ' . $data->acc_id . '"'); ajax_output($str); }