PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/hypervm/httpdocs/lib/vps/vpsbaselib.php

https://github.com/lxcenter/hypervm
PHP | 420 lines | 313 code | 85 blank | 22 comment | 40 complexity | aa74cd00253b2d6d5d194a79e3749021 MD5 | raw file
  1. <?php
  2. abstract class vpsbase extends vpsCore {
  3. static $__desc_newlocation = array("n", "", "new Location");
  4. static $__desc_username = array("n", "", "username");
  5. static $__desc_networknetmask = array("n", "", "NetMask");
  6. //static $__desc_vmipaddress_a_num = array("q", "", "ip:number_of_ipaddresses");
  7. static $__desc_centralbackup_server = array("", "", "central_backup_server");
  8. static $__desc_secondlevelquota_flag = array("q", "", "second_level_quota_(only_for_openvz)");
  9. static $__desc_text_inittab = array("", "", "append_to_inittab");
  10. static $__desc_kloxo_flag = array("f", "", "show_kloxo_buttons");
  11. static $__desc_text_xen_config = array("", "", "append_to_xen_config");
  12. static $__desc_fixdev_confirm_f = array("f", "", "confirm_fix_dev");
  13. static $__desc_recover_ostemplate = array("", "", "could_not_find_your_ostemplate_please_supply_one");
  14. static $__acdesc_update_changeosimagename = array("", "", "change_os_template_name");
  15. static $__acdesc_update_createuser = array("", "", "create_console_user");
  16. static $__acdesc_update_append_inittab = array("", "", "append_to_inttab");
  17. static $__acdesc_update_append_xen_config = array("", "", "append_to_xen_config");
  18. static $__acdesc_update_network = array("", "", "network");
  19. static $__acdesc_update_mount = array("", "", "mount");
  20. static $__acdesc_update_changesyncserver = array("", "", "change_server_in_db");
  21. static $__acdesc_update_fixdev = array("", "", "fix_centos_dev");
  22. static $__desc_vcpu_number = array("", "", "number_of_virtual_cpu");
  23. static $__desc_networkbridge = array("", "", "network_bridge");
  24. function isRightParent()
  25. {
  26. return ($this->getParentO()->getClName() === $this->parent_clname) ;
  27. }
  28. static function continueFormlistpriv($parent, $class, $param, $continueaction)
  29. {
  30. $listpriv = $parent->listpriv;
  31. $more = false;
  32. if (count($listpriv->vpspserver_list) > 1) {
  33. $more = true;
  34. }
  35. if ($more) {
  36. $vlist['server_detail_f'] = array('M', pserver::createServerInfo($listpriv->vpspserver_list, "vps"));
  37. $vlist["vpspserver_sing"] = "";
  38. $ret["param"] = $param;
  39. $ret["variable"] = $vlist;
  40. $ret["action"] = "continue";
  41. $ret["continueaction"] = "finish";
  42. } else {
  43. //$param['listpriv_s_dbtype_list'] = implode($parent->listpriv->dbtype_list);
  44. $param["listpriv_s_vpspserver_sing"] = implode("", $parent->listpriv->vpspserver_list);
  45. $ret = exec_class_method($class, 'continueFormFinish', $parent, $class, $param, $continueaction);
  46. }
  47. return $ret;
  48. }
  49. function updateInformation($param)
  50. {
  51. if (isset($param['networkgateway'])) {
  52. $param['networkgateway'] = trim($param['networkgateway']);
  53. if ($param['networkgateway']) {
  54. validate_ipaddress($param['networkgateway'], 'networkgateway');
  55. }
  56. }
  57. return $param;
  58. }
  59. function updateCreateUser($param)
  60. {
  61. $param['username'] = str_replace(".", "", $this->nname);
  62. return $param;
  63. }
  64. function updateCreateTemplate($param)
  65. {
  66. global $gbl, $sgbl, $login, $ghtml;
  67. if (!$login->isAdmin()) {
  68. throw new lxexception('only_for_admin', 'parent');
  69. }
  70. return $param;
  71. }
  72. function updateChangeLocation($param)
  73. {
  74. if ($param['newlocation'] === $this->corerootdir) {
  75. throw new lxexception('no_change', 'newlocation');
  76. }
  77. return $param;
  78. }
  79. function formChangeLocationOpenvz()
  80. {
  81. $location = $this->getLocationlist();
  82. $llist = get_namelist_from_objectlist($location);
  83. $nlist = $llist;
  84. if (!$nlist) {
  85. throw new lxexception('need_locations');
  86. }
  87. $this->newlocation = $this->corerootdir;
  88. $nlist = array_push_unique($nlist, $this->corerootdir);
  89. $vlist['newlocation'] = array('s', $nlist);
  90. return $vlist;
  91. }
  92. function updateRootpassword($param)
  93. {
  94. $this->rootpassword_changed = 'on';
  95. return $param;
  96. }
  97. function formChangeLocationXen()
  98. {
  99. /*
  100. if ($this->isXenLvm()) {
  101. $vlist['newlocation'] = array('M', 'Already on LVM');
  102. $vlist['__v_button'] = array();
  103. return $vlist;
  104. }
  105. */
  106. $location = $this->getLocationlist();
  107. $llist = get_namelist_from_objectlist($location);
  108. dprintr($location);
  109. $nlist = null;
  110. foreach($llist as $l) {
  111. if (csb($l, "lvm:")) {
  112. $nlist[] = $l;
  113. }
  114. }
  115. if (!$nlist) {
  116. throw new lxexception('need_lvm_location');
  117. }
  118. $vlist['newlocation'] = array('s', $nlist);
  119. return $vlist;
  120. }
  121. function updateMacaddress($param)
  122. {
  123. $list = explode(":", $param['macaddress']);
  124. if (count($list) > 5) {
  125. throw new lxexception('macaddress_only_five');
  126. }
  127. return $param;
  128. }
  129. function updateform($subaction, $param)
  130. {
  131. global $gbl, $sgbl, $login, $ghtml;
  132. $parent = $this->getParentO();
  133. $gen = $login->getObject('general')->generalmisc_b;
  134. switch($subaction) {
  135. case "recovervps":
  136. /*
  137. if (!lxfile_exists("{$this->getOstemplatePath()}/{$this->ostemplate}.tar.gz")) {
  138. $list = exec_class_method("vps__{$this->ttype}", "getOsTemplatelist");
  139. $vlist['recover_ostemplate'] = array('A', $list);
  140. }
  141. */
  142. $vlist['recover_confirm_f'] = null;
  143. return $vlist;
  144. case "mount":
  145. $vlist['confirm_f'] = array('M', "confirm");
  146. return $vlist;
  147. case "macaddress":
  148. $vlist['macaddress'] = null;
  149. return $vlist;
  150. case "ostemplatelist":
  151. getResourceOstemplate($vlist, $this->ttype);
  152. $vlist['__v_updateall_button'] = array();
  153. return $vlist;
  154. case "hardpoweroff":
  155. $vlist['confirm_f'] = array("M", "Confirm");
  156. return $vlist;
  157. case "reboot":
  158. $vlist['confirm_f'] = array("M", "Confirm");
  159. return $vlist;
  160. case "shutdown":
  161. $vlist['confirm_f'] = array("M", "Confirm");
  162. return $vlist;
  163. case "mainipaddress":
  164. $vlist['mainipaddress'] = array('s', get_namelist_from_objectlist($this->vmipaddress_a));
  165. return $vlist;
  166. case "livemigrate":
  167. $serverlist = $login->getServerList($this->get__table());
  168. $rs = null;
  169. foreach($serverlist as $l) {
  170. $driverapp = $gbl->getSyncClass(null, $l, 'vps');
  171. if ($driverapp === 'openvz') {
  172. $rs[] = $l;
  173. }
  174. }
  175. $serverlist = $rs;
  176. if (!$this->checkIfLockedForAction('livemigrate')) {
  177. if ($this->olddeleteflag === 'doing') {
  178. $this->olddeleteflag = 'program_interrupted';
  179. $this->setUpdateSubaction();
  180. }
  181. }
  182. $vlist['olddeleteflag'] = array('M', null);
  183. $vlist['server_detail_f'] = array('M', pserver::createServerInfo($serverlist, $this->get__table()));
  184. $vlist['syncserver'] = array('s', $serverlist);
  185. return $vlist;
  186. case "append_inittab":
  187. $vlist['text_inittab'] = array('t', $this->text_inittab);
  188. return $vlist;
  189. case "append_xen_config":
  190. $vlist['text_xen_config'] = array('t', $this->text_xen_config);
  191. return $vlist;
  192. case "changelocation":
  193. if ($this->isXen()) {
  194. return $this->formChangeLocationXen();
  195. } else {
  196. return $this->formChangeLocationOpenvz();
  197. }
  198. break;
  199. case "createuser":
  200. $this->username = str_replace(".", "", $this->nname);
  201. $vlist['username'] = array('M', null);
  202. return $vlist;
  203. case "changeosimagename":
  204. $vlist['ostemplate'] = null;
  205. return $vlist;
  206. case "clonevps":
  207. $vlist['__v_button'] = array();
  208. return $vlist;
  209. case "createtemplate":
  210. $stem = explode("-", $this->ostemplate);
  211. if ($this->isWindows()) {
  212. $name = "{$stem[0]}-";
  213. } else {
  214. $name = "{$stem[0]}-{$stem[1]}-{$stem[2]}-";
  215. }
  216. $vlist['newostemplate_name_f'] = array("m", array("pretext" => $name));
  217. $vlist['__v_button'] = 'Create';
  218. return $vlist;
  219. case "rebuild":
  220. if ($this->isWindows()) {
  221. $type = "img";
  222. } else {
  223. $type = "tar.gz";
  224. }
  225. $ostlist = vps::getVpsOsimage($this, $this->ttype, $type);
  226. $vlist['ostemplate'] = array('A', $ostlist);
  227. if ($this->isNotWindows() && $this->priv->isOn('backup_flag')) {
  228. //$vlist['rebuild_backup_f'] = null;
  229. }
  230. $vlist['rebuild_confirm_f'] = null;
  231. return $vlist;
  232. case "installkloxo":
  233. $this->kloxo_type = 'master';
  234. $vlist['rebuild_confirm_f'] = null;
  235. $vlist['__v_button'] = 'Install';
  236. return $vlist;
  237. case "commandcenter":
  238. return $this->commandCenter($param);
  239. case "fixdev":
  240. $vlist['fixdev_confirm_f'] = null;
  241. return $vlist;
  242. case "rootpassword":
  243. if ($this->isXen()) { $vlist['__m_message_pre'] = 'xen_restart_message'; }
  244. $vlist['rootpassword'] = null;
  245. return $vlist;
  246. //ONly for Template...
  247. case "description":
  248. $vlist['description'] = null;
  249. //$vlist['share_status'] = null;
  250. if (!$this->isRightParent()) {
  251. $this->convertToUnmodifiable($vlist);
  252. }
  253. return $vlist;
  254. case "timezone":
  255. $vlist['timezone'] = array('s', pserver::getTimeZoneList());
  256. return $vlist;
  257. case "information":
  258. $vlist['nname'] = array('M', $this->nname);
  259. $vlist['corerootdir'] = array('M', $this->corerootdir);
  260. $vlist['ddate']= array('M', @ date('d-m-Y', $this->ddate));
  261. $vlist['kloxo_flag'] = null;
  262. if ($login->isAdmin() && $this->isXen()) {
  263. $vlist['nosaveconfig_flag'] = null;
  264. }
  265. if (!$this->isXen()) {
  266. $vlist['vpsid']= array('M', $this->vpsid);
  267. }
  268. if ($this->isXen() && $login->isAdmin()) {
  269. $vlist['vcpu_number'] = array('s', range(1, 10));
  270. }
  271. if ($login->isAdmin()) {
  272. $use_slaves = "--use-slaves-backup-server--";
  273. if (!$this->centralbackup_server) {
  274. $this->centralbackup_server = $use_slaves;
  275. }
  276. $sq = new Sqlite(null, "centralbackupserver");
  277. $list = get_namelist_from_arraylist($sq->getTable(array('nname')));
  278. $list = lx_merge_good(array($use_slaves), $list);
  279. //$vlist['centralbackup_flag'] = null;
  280. $vlist['centralbackup_server'] = array('s', $list);
  281. }
  282. $vlist['ostemplate']= array('M', null);
  283. $vlist['parent_name_f'] = array('M', $this->getParentName());
  284. //$vlist['dbtype_list'] = array('M', $this->listpriv->dbtype_list);
  285. $vlist['contactemail'] = "";
  286. if (!$this->isLogin()) {
  287. $vlist['text_comment'] = null;
  288. }
  289. return $vlist;
  290. // Only for template. For the main guy, it comes as 'rebuild'
  291. case "network":
  292. if ($this->isXen()) { $vlist['__m_message_pre'] = 'xen_restart_message'; }
  293. if (!$this->isLogin() || !$gen->isOn('disable_hostname_change')) {
  294. $vlist['hostname'] = null;
  295. }
  296. if ($this->isXen()) {
  297. if (!$this->networknetmask) { $this->networknetmask = "255.255.255.0"; }
  298. $vlist['networkgateway'] = null;
  299. $vlist['networknetmask'] = null;
  300. if ($login->priv->isOn('ip_manage_flag') || $login->isAdmin()) {
  301. $vlist['networkbridge'] = array('s', array("--automatic--", "xenbr0", "xenbr1", "xenbr2", "xenbr3", "xenbr4"));
  302. }
  303. }
  304. $iplist = $this->vmipaddress_a;
  305. $iplist = implode(", ", get_namelist_from_objectlist($iplist, 'nname'));
  306. $vlist['one_ipaddress_f']= array('M', $iplist);
  307. $vlist['nameserver'] = null;
  308. return $vlist;
  309. case "ostemplate":
  310. $driverapp = $gbl->getSyncClass($this->__masterserver, $this->listpriv->vpspserver_sing, 'vps');
  311. $ostlist = rl_exec_get(null, $this->listpriv->vpspserver_sing, array("vps__$driverapp", "getOsTemplatelist"));
  312. $ostlist = lx_merge_good(array('--defer-osimage--' => '--defer-osimage--'), $ostlist);
  313. $vlist['ostemplate'] = array('A', $ostlist);
  314. return $vlist;
  315. case "changesyncserver":
  316. $sq = new Sqlite(null, 'pserver');
  317. $list = $sq->getTable(array('nname'));
  318. $list = get_namelist_from_arraylist($list);
  319. $vlist['syncserver'] = array('s', $list);
  320. $gbl->__ajax_refresh = true;
  321. return $vlist;
  322. // Only for template...
  323. case "vpspserver_s":
  324. $listpriv = $parent->listpriv;
  325. $vlist['server_detail_f'] = array('M', pserver::createServerInfo($listpriv->vpspserver_list, "vps"));
  326. $parent = $this->getParentO();
  327. $vlist['vpspserver_sing'] = null;
  328. if (!$this->isRightParent()) {
  329. $this->convertToUnmodifiable($vlist);
  330. }
  331. return $vlist;
  332. }
  333. return parent::updateform($subaction, $param);
  334. }
  335. }