<?php require_once 'lib/init.php'; $norender = false; initVars('domain', 'docroot'); $error_documents = array(401, 403, 404, 500); header('Cache-Control: private'); switch ($task) { case 'add': if (!checkPackage('site')) { setmsg(t('The package limitation reached.'), 'warning'); } $dirs = ZFile::getUserDirs($me); if (checktoken()) { $domain = $_REQUEST['domain']; $docroot = $_REQUEST['docroot']; // check domain $break = false; if (true !== ($res = ZVhosts::chkDomain($domain))) { $err['domain'] = t('Domain Invalid.'); if ($res == 'occupied') { $err['domain'] = t('Domain Occupied.'); } $break = true; } // check docroot if (!in_array($docroot, $dirs)) { $err['docroot'] = t('Please select a valid document root.'); $break = true; } $docroot = str_replace('~/', "/home/{$me}/", $docroot);
$result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_row($result); if ($row) $databases[] = $row[0];*/ sort($databases); $op = $_REQUEST['op']; if (checktoken() && 'createdb' == $op) { if (!checkPackage('sql')) { setmsg(t('The package limitation reached.'), 'warning', 'self'); } $dbname = $prefix . $_REQUEST['dbname']; // check password if ($prefix == $dbname) { $err['dbname'] = t('Database name can not be empty.'); setmsg($err['dbname'], 'error', 'self'); } if (!checkPackage('sql')) { setmsg(t('The package limitation reached.'), 'warning'); } if ($break) { break; } $sql = "CREATE DATABASE `{$dbname}`"; $res = mysql_query($sql); $dbname_escaped = str_replace('_', '\\_', $dbname); $sql = "GRANT ALL PRIVILEGES ON `{$dbname_escaped}` . * TO '{$user}'@'{$dbhost}' WITH GRANT OPTION "; $res2 = mysql_query($sql); if ($res && $res2) { setmsg(t("Database created."), 'notice', 'self'); } else { setmsg(mysql_error(), 'error', 'self'); }
<?php require_once 'lib/init.php'; $norender = false; initVars('name', 'password', 'docroot', 'writable', 'upload_bandwidth', 'download_bandwidth', 'upload_ratio', 'download_ratio', 'max_conn', 'files_quota', 'size_quota', 'auth_local_ips', 'refused_local_ips', 'auth_client_ips', 'refused_client_ips', 'time_restrictions'); switch ($task) { case 'add': header('Cache-Control: private'); $token = token(); $prefix = $me . '_'; $accounts = ZFtp::getFtpAccounts(); if (!checkPackage()) { setmsg(t('The package limitation reached.'), 'warning'); } $dirs = ZFile::getUserDirs($me); $users = ZUser::getUsers(); if (checktoken()) { $username = $_REQUEST['name']; $owner = $me; $passwd = $_REQUEST['password']; $docroot = $_REQUEST['docroot']; $ftpuser = $owner . '_' . $username; $writable = isset($_REQUEST['writable']); $break = false; // check username if (true !== ($res = ZUser::chkUsername($username))) { if ($res == 'invalid') { $err['name'] = t('Username Invalid. No uppercase, not starting with number, less than 7 chars.'); $break = true; } }
#!/usr/bin/php -q <?php require_once '/usr/local/nimbusec/lib/WHMAPIClient.php'; require_once '/usr/local/nimbusec/lib/Provision.php'; require_once '/usr/local/nimbusec/lib/Logger.php'; // Read input from STDIN $input = get_passed_data(); list($result_status, $result_msg) = checkPackage($input); // Write response to STDOUT echo "{$result_status} {$result_msg}"; function checkPackage($input = array()) { $logger = new Logger("/usr/local/nimbusec/logs", "changePackage.log", true); $data = $input['data']; $logger->info("Triggered change_package hook"); try { $logger->info("Check bundles"); // Get access data for WHM API $hash = file_get_contents("/root/.accesshash"); $host = gethostname(); $serverAddr = gethostbyname($host); $whmApi = new WHMAPIClient($hash, $serverAddr); $oldPkgName = $data['cur_pkg']; $newPkgName = $data['new_pkg']; $userName = $data['user']; $logger->debug("Get input data [cur/old_pkg] '{$oldPkgName}' [new_pkg] '{$newPkgName}' and [user] '{$userName}'"); $oldPkgRes = $whmApi->sendRequest('getpkginfo', array("pkg" => $oldPkgName)); $newPkgRes = $whmApi->sendRequest('getpkginfo', array("pkg" => $newPkgName)); $logger->info("Read infomation for both packages"); // Isset is much faster than array_key_exists $old_hasNimbusec = isset($oldPkgRes['data']['pkg']['nimbusec_bundles']);