Example #1
0
 public function dbactionAdd()
 {
     global $gbl, $sgbl, $login, $ghtml;
     self::checkIfXenOK();
     $ret = lxshell_return('xm', '--help');
     if ($ret == 127) {
         throw new lxException('no_xen_at_all');
     }
     $main = $this->main;
     $privilege = isset($main->priv) ? $main->priv : NULL;
     $diskusage = $privilege->disk_usage;
     // If unlimited put 3 GB, if not get use the normal disk usage (@todo checks if it's a bug)
     if ($this->isUnlimited($privilege->disk_usage)) {
         $diskusage = 3 * 1024;
         // Put 3 GB (@todo: no byte counted, is bad done on resource backend instead)
     }
     if ($main->isWindows() && $diskusage < 2 * 1024) {
         //throw new lxException("windows_needs_more_than_2GB");
     }
     $freediskspace = $this->getFreeDiskSpace();
     if ($freediskspace - $diskusage < 20) {
         throw new lxException('not_enough_space');
     }
     $user_name = $main->username;
     $password = $main->password;
     $virtual_machine_name = $main->nname;
     if ($main->dbaction === 'syncadd') {
         $vps_username_created = vps::create_user($user_name, $password, $virtual_machine_name, self::XEN_CONSOLE_BINARY);
         return NULL;
     }
     if (self::getStatus($virtual_machine_name, self::XEN_HOME) !== 'deleted') {
         throw new lxException('a_virtual_machine_with_the_same_id_exists');
     }
     // Check if the template begins with "windows-lxblank"
     if ($main->isBlankWindows()) {
         if (!lxfile_exists('/home/wincd.img')) {
             throw new lxException('windows_installation_image_missing');
         }
     }
     /*
     if (!lxfile_exists("__path_program_home/xen/template/{$main->ostemplate}.tar.gz")) {
     	throw new lxException("could_not_find_the_osimage", '', $main->ostemplate);
     }
     */
     $vps_username_created = vps::create_user($user_name, $password, $virtual_machine_name, self::XEN_CONSOLE_BINARY);
     $this->createRootPath();
     lxfile_mkdir($main->configrootdir);
     $this->setMemoryUsage();
     $this->setCpuUsage();
     $this->setSwapUsage();
     $this->setDiskUsage();
     if ($sgbl->isDebug()) {
         $this->doRealCreate();
     } else {
         callObjectInBackground($this, 'doRealCreate');
     }
     $result = array('__syncv_username' => $vps_username_created);
     return $result;
 }
Example #2
0
 function createExtraVariables()
 {
     if (csb($this->subaction, 'graph_')) {
         $res = vps::findVpsGraph($this->nname, strfrom($this->subaction, "graph_"));
         $this->__var_graph_list = $res;
     }
 }
Example #3
0
function getResourceOstemplate(&$vlist, $ttype = 'all')
{
    $olist = vps::getVpsOsimage(null, "openvz");
    $olist = array_keys($olist);
    $xlist = vps::getVpsOsimage(null, "xen");
    $xlist = array_keys($xlist);
    if ($ttype === 'openvz' || $ttype === 'all') {
        $vlist['openvzostemplate_list'] = array('U', $olist);
    }
    if ($ttype === 'xen' || $ttype === 'all') {
        $vlist['xenostemplate_list'] = array('U', $xlist);
    }
}
Example #4
0
 function createShowPropertyList(&$alist)
 {
     global $gbl, $sgbl, $login, $ghtml;
     if ($ghtml->frm_subaction === 'forcedeletepserver') {
         $alist['property'] = pserver::createListAlist($this, 'pserver');
         return;
     }
     if ($ghtml->frm_subaction === 'deleteorphanedvps') {
         $alist['property'] = vps::createListAlist($this, 'pserver');
         return;
     }
     if ($ghtml->frm_subaction === 'ippool') {
         $alist['property'] = ippool::createListAlist($this, 'ippool');
     } else {
         $alist['property'][] = "a=show";
         $alist['property'][] = "o=sp_specialplay&a=updateform&sa=skin";
     }
 }
Example #5
0
 function getCommandResource($resource)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $ret = null;
     switch ($resource) {
         case "ostemplate_xen":
             return vps::getVpsOsimage($login, "xen");
         case "ostemplate_openvz":
             return vps::getVpsOsimage($login, "openvz");
         case "vpspserver":
             $lx = $this->getVpsServers('xen');
             $lo = $this->getVpsServers('openvz');
             $ret = lx_merge_good($lx, $lo);
             $ret = convert_to_associate($ret);
             break;
         case "vpspserver_xen":
             $ret = $this->getVpsServers("xen");
             $ret = convert_to_associate($ret);
             break;
         case "vpspserver_openvz":
             $ret = $this->getVpsServers("openvz");
             $ret = convert_to_associate($ret);
             break;
         case "dnstemplate":
             $ret = domainBase::getDnsTemplateList($this);
             $ret = convert_to_associate($ret);
             break;
         case "resourceplan":
             $list = $this->getList('resourceplan');
             $ret = get_namelist_from_objectlist($list, 'nname', 'realname');
             break;
     }
     return $ret;
 }
Example #6
0
 function createShowAlist(&$alist, $subaction = null)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $revc = $login->getObject('general')->reversedns_b;
     $hackbutton = $login->getObject('general')->hackbuttonconfig_b;
     static $status;
     static $reason;
     if (isUpdating()) {
         $ghtml->print_redirect_back('system_is_updating_itself', '');
     }
     if ($ghtml->frm_action === 'show') {
     } else {
         $status = $this->status;
     }
     $this->setIId();
     if (!$status) {
         try {
             $status = $this->getStatusForThis();
             dprint($status);
         } catch (Exception $e) {
             if (if_demo()) {
                 $status = 'on';
             } else {
                 print "Could not get Status: Reason: {$e->getMessage()}";
                 exit;
             }
         }
     }
     if (csa($status, ":")) {
         $st = explode(":", $status);
         $status = array_shift($st);
         $reason = implode(" ", $st);
         $reason = str_replace("\n", " ", $reason);
     }
     if ($status !== $this->status) {
         dprint("Status in Db not the same as Status of the system, resetting db");
         $this->status = $status;
         $this->setUpdateSubaction();
     }
     if ($this->status === 'create') {
         $alist['__v_message'] = "<b> VM is being Created... Please Wait.. </b> \n";
         $alist['__v_refresh'] = true;
         return;
     }
     if ($this->status === 'createfailed') {
         $alist['__v_message'] = "<b> VM creation has failed. Reason: {$reason} </b>\n";
         $alist['__v_refresh'] = true;
         return;
     }
     if ($this->checkIfLockedForAction('restore')) {
         $alist['__v_message'] = 'The VM is getting restored, please wait...';
         $alist['__v_refresh'] = true;
         return $alist;
     }
     if ($this->checkIfLockedForAction('rebuild')) {
         $alist['__v_message'] = 'The VM is getting rebuilt, please wait...';
         $alist['__v_refresh'] = true;
         return $alist;
     }
     if ($this->checkIfLockedForAction('switchserver')) {
         $alist['__v_message'] = 'The VM is being migrated, please wait...';
         $alist['__v_refresh'] = true;
         return $alist;
     }
     if ($this->checkIfLockedForAction('livemigrate')) {
         $alist['__v_message'] = 'The VPS is being Migrated Live. The CP is inactive, but your VPS is running Normally.';
         $alist['__v_refresh'] = true;
         return $alist;
     }
     if ($this->status === 'deleted') {
         $alist['__v_message'] = "The VM {$this->getIid}() Doesn't Exist on {$this->syncserver}. If you have migrated the vps, you can manually change the server in the database using the below, Or restore from backup. </b>";
         $alist['__v_refresh'] = true;
         $alist['__title_main'] = $login->getKeywordUc('resource');
         $alist['__v_dialog_csync'] = "a=updateform&sa=changesyncserver";
         $alist['__var_backup_flag'] = "a=show&o=lxbackup";
         $alist[] = "a=updateform&sa=rebuild";
         return null;
     }
     /*
     	if ($this->getObject('lxbackup')->backupstage === 'doing') { 
     		$alist['__v_message'] = 'The VM is getting backed up, please wait...';
     		$alist['__v_refresh'] = true;
     		return $alist;
     	}
     */
     $this->makeSureTheUserExists();
     $this->makeSureTheMacAddressExists();
     $this->makeSureVifExists();
     if ($subaction === 'config') {
         return $this->createShowAlistConfig($alist);
     }
     if ($subaction === 'graph') {
         $alist['__title_graph'] = $login->getKeywordUc('graph');
         return $alist;
     }
     $alist['__title_administer'] = $login->getKeywordUc('administration');
     if ($this->getParentO()->isClass('client')) {
         if (!$this->isLogin()) {
             if ($login->priv->isOn('vps_limit_flag')) {
                 $alist['__v_dialog_limit'] = "a=updateForm&sa=limit";
                 $alist['__v_dialog_plan'] = "a=updateForm&sa=change_plan";
             }
         }
     }
     $alist['__v_dialog_info'] = "a=updateForm&sa=information";
     $alist['__v_dialog_pass'] = "******";
     if (!$this->isWindows()) {
         //$alist[] = "a=show&n=browsebackup&l[class]=ffile&l[nname]=/";
         $bslave = $this->getBackupServer();
         if (!is_disabled_or_null($bslave) && $this->priv->isOn('centralbackup_flag')) {
             $alist[] = "a=show&n=browsebackup";
         }
     }
     if (!$this->isLogin()) {
         $alist[] = "a=update&sa=dologin";
     }
     $alist['__title_console'] = $login->getKeywordUc('console');
     //$alist[] = "a=show&o=sshclient";
     if ($this->isWindows()) {
         $alist[] = "a=show&o=vncviewer";
     } else {
         $alist[] = "a=show&o=consolessh";
         $alist[] = "a=list&c=sshauthorizedkey";
     }
     if (!$this->isXen()) {
         $alist[] = "a=updateform&sa=commandcenter";
     }
     $alist[] = "a=list&c=blockedip";
     $alist['__v_dialog_netw'] = "a=updateform&sa=network";
     $alist[] = "a=list&c=traceroute";
     if (!$this->isWindows()) {
         $alist['__v_dialog_main'] = "a=updateform&sa=mainipaddress";
     }
     if (!$this->isXen()) {
         $alist['__v_dialog_fixdev'] = "a=updateform&sa=fixdev";
     }
     if ($hackbutton && $hackbutton->isOn('nobackup') && !$this->isWindows()) {
         vps::$__desc_backup_num = array("", "", "backup:number_of_backups", "number_of_backups");
     } else {
         if ($this->priv->isOn('backup_flag')) {
             $alist[] = "a=show&o=lxbackup";
         }
     }
     if ($login->isAdmin()) {
         $alist['__title_action'] = $login->getKeywordUc('action');
     }
     if ($login->priv->isOn("rebuildvps_flag")) {
         $alist['__v_dialog_rebuild'] = "a=updateform&sa=rebuild";
     }
     if (!$this->isWindows()) {
         $alist[] = "a=updateform&sa=recovervps";
     }
     if (!$this->isWindows()) {
         if ($login->isAdmin()) {
             $alist['__v_dialog_sw'] = "a=updateform&sa=switchserver";
         }
         if ($login->isAdmin() && !$this->isXen()) {
             $alist['__v_dialog_live'] = "a=updateform&sa=livemigrate";
         }
     }
     if ($login->isAdmin()) {
         $alist['__v_dialog_tem'] = "a=updateform&sa=createtemplate";
         $alist['__v_dialog_clone'] = "a=updateform&sa=clonevps";
     }
     if (!$this->isWindows()) {
         $alist['__title_resource'] = $login->getKeywordUc('resource');
     }
     if (!$this->isLogin() && $login->priv->isOn('ip_manage_flag')) {
         $alist[] = "a=list&c=vmipaddress_a";
     }
     if (!$this->isWindows()) {
         $alist['__v_dialog_root'] = "a=updateform&sa=rootpassword";
         $alist[] = "a=show&l[class]=ffile&l[nname]=/";
         $alist['__v_dialog_time'] = "a=updateform&sa=timezone";
         if ($this->isOn('kloxo_flag') && $login->priv->isOn('rebuildvps_flag')) {
             $alist['__v_dialog_inst'] = "a=updateform&sa=installkloxo";
         }
     }
     $alist['__title_power'] = $login->getKeywordUc('power');
     $alist[] = "a=update&sa=boot";
     $alist[] = "a=update&sa=poweroff";
     $alist[] = "a=update&sa=reboot";
     if ($this->isXen()) {
         $alist[] = "a=updateform&sa=mount";
     }
     if ($this->isXen()) {
         $alist[] = "a=updateform&sa=hardpoweroff";
     }
     $alist[] = "a=list&c=emailalert";
     if (!$this->isXen()) {
         $alist[] = "a=list&c=openvzqos";
     }
     //$this->getLxclientActions($alist);
     /*
     if ($this->priv->isOn('backup_flag')) {
     	$alist[] = "a=show&o=lxbackup";
     }
     */
     $alist['__title_misc'] = "Extra";
     $this->getListActions($alist, 'vpstraffichistory');
     $this->getListActions($alist, 'utmp');
     $this->getTicketMessageUrl($alist);
     if ($hackbutton && $hackbutton->isOn('nomonitor')) {
     } else {
         if (is_unlimited($this->priv->monitorport_num) || $this->priv->monitorport_num) {
             $alist[] = "a=list&c=monitorserver";
         }
     }
     if ($this->priv->isOn('managereversedns_flag')) {
         if ($revc && $revc->isOn('enableflag')) {
             $alist[] = "a=list&c=reversedns";
         }
     }
     if ($this->priv->isOn('managedns_flag')) {
         if ($revc && $revc->isOn('forwardenableflag')) {
             $alist[] = "a=list&c=dns";
         }
     }
     $alist['__title_advanced'] = "Advanced";
     if (!$this->isLogin()) {
         $alist[] = "a=updateform&sa=disable_per";
     }
     if ($login->isAdmin() && !$this->isXen()) {
         $alist[] = "a=updateForm&sa=changenname";
     }
     if (!$this->isLogin()) {
         $alist[] = "a=updateform&sa=resendwelcome";
     }
     if ($login->isAdmin()) {
         $alist[] = "a=updateForm&sa=changelocation";
         $alist[] = "a=updateform&sa=createuser";
     }
     if ($this->isXen() && !$this->isLogin()) {
         $alist[] = "a=updateform&sa=append_xen_config";
     }
     $alist[] = "a=updateform&sa=append_inittab";
     if ($login->isAdmin()) {
         $alist[] = "a=updateform&sa=ostemplatelist";
     }
     //if ($this->isXen() && $this->ostemplate === 'unknown') {
     if ($this->isXen() && $login->isAdmin()) {
         $alist[] = "a=updateForm&sa=changeosimagename";
     }
     if (!$this->isLogin()) {
         if ($login->isNotCustomer()) {
             // Disabling change owner for the present.
             $alist[] = "a=updateForm&sa=changeowner";
         }
     }
     if ($this->isXen()) {
         $alist[] = "a=updateform&sa=macaddress";
     }
     $alist[] = "a=show&o=notification";
     $alist[] = "a=updateform&sa=miscinfo";
     if ($this->isLogin()) {
         $alist[] = "o=sp_specialplay&a=updateform&sa=login_options";
     }
     $this->getCustomButton($alist);
     return $alist;
 }
Example #7
0
 function updateform($subaction, $param)
 {
     global $gbl, $sgbl, $login, $ghtml;
     $parent = $this->getParentO();
     $gen = $login->getObject('general')->generalmisc_b;
     switch ($subaction) {
         case "recovervps":
             /*
             		if (!lxfile_exists("{$this->getOstemplatePath()}/{$this->ostemplate}.tar.gz")) {
             			$list = exec_class_method("vps__{$this->ttype}", "getOsTemplatelist");
             			$vlist['recover_ostemplate'] = array('A', $list);
             		}
             */
             $vlist['recover_confirm_f'] = null;
             return $vlist;
         case "mount":
             $vlist['confirm_f'] = array('M', "confirm");
             return $vlist;
         case "macaddress":
             $vlist['macaddress'] = null;
             return $vlist;
         case "ostemplatelist":
             getResourceOstemplate($vlist, $this->ttype);
             $vlist['__v_updateall_button'] = array();
             return $vlist;
         case "hardpoweroff":
             $vlist['confirm_f'] = array("M", "Confirm");
             return $vlist;
         case "reboot":
             $vlist['reboot_confirm_f'] = null;
             //  array("f", "Confirm");
             $vlist['__v_button'] = 'Reboot';
             return $vlist;
         case "shutdown":
             $vlist['poweroff_confirm_f'] = null;
             //  array("f", "Confirm");
             $vlist['__v_button'] = 'Power OFF';
             return $vlist;
         case "mainipaddress":
             $vlist['mainipaddress'] = array('s', get_namelist_from_objectlist($this->vmipaddress_a));
             return $vlist;
         case "livemigrate":
             $serverlist = $login->getServerList($this->get__table());
             $rs = null;
             foreach ($serverlist as $l) {
                 $driverapp = $gbl->getSyncClass(null, $l, 'vps');
                 if ($driverapp === 'openvz') {
                     $rs[] = $l;
                 }
             }
             $serverlist = $rs;
             if (!$this->checkIfLockedForAction('livemigrate')) {
                 if ($this->olddeleteflag === 'doing') {
                     $this->olddeleteflag = 'program_interrupted';
                     $this->setUpdateSubaction();
                 }
             }
             $vlist['olddeleteflag'] = array('M', null);
             $vlist['server_detail_f'] = array('M', pserver::createServerInfo($serverlist, $this->get__table()));
             $vlist['syncserver'] = array('s', $serverlist);
             return $vlist;
         case "append_inittab":
             $vlist['text_inittab'] = array('t', $this->text_inittab);
             return $vlist;
         case "append_xen_config":
             $vlist['text_xen_config'] = array('t', $this->text_xen_config);
             return $vlist;
         case "changelocation":
             if ($this->isXen()) {
                 return $this->formChangeLocationXen();
             } else {
                 return $this->formChangeLocationOpenvz();
             }
             break;
         case "createuser":
             $this->username = str_replace(".", "", $this->nname);
             $vlist['username'] = array('M', null);
             return $vlist;
         case "changeosimagename":
             $vlist['ostemplate'] = null;
             return $vlist;
         case "clonevps":
             $vlist['__v_button'] = array();
             return $vlist;
         case "createtemplate":
             $stem = explode("-", $this->ostemplate);
             if ($this->isWindows()) {
                 $name = "{$stem[0]}-";
             } else {
                 $name = "{$stem[0]}-{$stem[1]}-{$stem[2]}-";
             }
             $vlist['newostemplate_name_f'] = array("m", array("pretext" => $name));
             $vlist['__v_button'] = 'Create';
             return $vlist;
         case "rebuild":
             if ($this->isWindows()) {
                 $type = "img";
             } else {
                 $type = "tar.gz";
             }
             $ostlist = vps::getVpsOsimage($this, $this->ttype, $type);
             $vlist['ostemplate'] = array('A', $ostlist);
             if ($this->isNotWindows() && $this->priv->isOn('backup_flag')) {
                 //$vlist['rebuild_backup_f'] = null;
             }
             $vlist['rebuild_confirm_f'] = null;
             return $vlist;
             /*		case "installkloxo":
             			$this->kloxo_type = 'master';
             			$vlist['rebuild_confirm_f'] = null;
             			$vlist['__v_button'] = 'Install';
             			return $vlist;
             */
         /*		case "installkloxo":
         			$this->kloxo_type = 'master';
         			$vlist['rebuild_confirm_f'] = null;
         			$vlist['__v_button'] = 'Install';
         			return $vlist;
         */
         case "commandcenter":
             return $this->commandCenter($param);
         case "fixdev":
             $vlist['fixdev_confirm_f'] = null;
             return $vlist;
         case "rootpassword":
             if ($this->isXen()) {
                 $vlist['__m_message_pre'] = 'xen_restart_message';
             }
             $vlist['rootpassword'] = null;
             return $vlist;
             //ONly for Template...
         //ONly for Template...
         case "description":
             $vlist['description'] = null;
             //$vlist['share_status'] = null;
             if (!$this->isRightParent()) {
                 $this->convertToUnmodifiable($vlist);
             }
             return $vlist;
         case "timezone":
             $vlist['timezone'] = array('s', pserver::getTimeZoneList());
             return $vlist;
         case "information":
             $vlist['nname'] = array('M', $this->nname);
             $vlist['corerootdir'] = array('M', $this->corerootdir);
             $vlist['ddate'] = array('M', @date('d-m-Y', $this->ddate));
             //			$vlist['kloxo_flag'] = null;
             if ($login->isAdmin() && $this->isXen()) {
                 $vlist['nosaveconfig_flag'] = null;
             }
             if (!$this->isXen()) {
                 $vlist['vpsid'] = array('M', $this->vpsid);
             }
             if ($this->isXen() && $login->isAdmin()) {
                 $vlist['vcpu_number'] = array('s', range(1, 10));
             }
             if ($login->isAdmin()) {
                 $use_slaves = "__use-slaves-backup-server__";
                 if (!$this->centralbackup_server) {
                     $this->centralbackup_server = $use_slaves;
                 }
                 $sq = new Sqlite(null, "centralbackupserver");
                 $list = get_namelist_from_arraylist($sq->getTable(array('nname')));
                 $list = lx_merge_good(array($use_slaves), $list);
                 //$vlist['centralbackup_flag'] = null;
                 $vlist['centralbackup_server'] = array('s', $list);
             }
             $vlist['ostemplate'] = array('M', null);
             $vlist['parent_name_f'] = array('M', $this->getParentName());
             //$vlist['dbtype_list'] = array('M', $this->listpriv->dbtype_list);
             $vlist['contactemail'] = "";
             if (!$this->isLogin()) {
                 $vlist['text_comment'] = null;
             }
             return $vlist;
             // Only for template. For the main guy, it comes as 'rebuild'
         // Only for template. For the main guy, it comes as 'rebuild'
         case "network":
             if ($this->isXen()) {
                 $vlist['__m_message_pre'] = 'xen_restart_message';
             }
             if (!$this->isLogin() || !$gen->isOn('disable_hostname_change')) {
                 $vlist['hostname'] = null;
             }
             if ($this->isXen()) {
                 if (!$this->networknetmask) {
                     $this->networknetmask = "255.255.255.0";
                 }
                 $vlist['networkgateway'] = null;
                 $vlist['networknetmask'] = null;
                 if ($login->priv->isOn('ip_manage_flag') || $login->isAdmin()) {
                     $vlist['networkbridge'] = array('s', array("__automatic__", "xenbr0", "xenbr1", "xenbr2", "xenbr3", "xenbr4"));
                 }
             }
             $iplist = $this->vmipaddress_a;
             $iplist = implode(", ", get_namelist_from_objectlist($iplist, 'nname'));
             $vlist['one_ipaddress_f'] = array('M', $iplist);
             $vlist['nameserver'] = null;
             return $vlist;
         case "ostemplate":
             $driverapp = $gbl->getSyncClass($this->__masterserver, $this->listpriv->vpspserver_sing, 'vps');
             $ostlist = rl_exec_get(null, $this->listpriv->vpspserver_sing, array("vps__{$driverapp}", "getOsTemplatelist"));
             $ostlist = lx_merge_good(array('--defer-osimage--' => '--defer-osimage--'), $ostlist);
             $vlist['ostemplate'] = array('A', $ostlist);
             return $vlist;
         case "changesyncserver":
             $sq = new Sqlite(null, 'pserver');
             $list = $sq->getTable(array('nname'));
             $list = get_namelist_from_arraylist($list);
             $vlist['syncserver'] = array('s', $list);
             $gbl->__ajax_refresh = true;
             return $vlist;
             // Only for template...
         // Only for template...
         case "vpspserver_s":
             $listpriv = $parent->listpriv;
             $vlist['server_detail_f'] = array('M', pserver::createServerInfo($listpriv->vpspserver_list, "vps"));
             $parent = $this->getParentO();
             $vlist['vpspserver_sing'] = null;
             if (!$this->isRightParent()) {
                 $this->convertToUnmodifiable($vlist);
             }
             return $vlist;
     }
     return parent::updateform($subaction, $param);
 }