control.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. <?php
  2. /**
  3. * The control file of system module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL (http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Jianhua Wang <wangjianhua@easycorp.ltd>
  8. * @package system
  9. * @version $Id$
  10. * @link https://www.zentao.net
  11. * @property systemModel $system
  12. * @property cneModel $cne
  13. */
  14. class system extends control
  15. {
  16. /**
  17. * 服务仪表盘。
  18. * Dashboard page.
  19. *
  20. * @param int $total
  21. * @param int $recPerPage
  22. * @param int $pageID
  23. * @access public
  24. * @return void
  25. */
  26. public function dashboard($total = 0, $recPerPage = 20, $pageID = 1)
  27. {
  28. $this->loadModel('cne');
  29. $this->app->loadClass('pager', true);
  30. $pager = new pager($total, $recPerPage, $pageID);
  31. $instances = $this->loadModel('instance')->getList($pager, '', '', 'running', false);
  32. $instancesMetrics = $this->cne->instancesMetrics($instances, false);
  33. foreach($instances as &$instance)
  34. {
  35. $metrics = zget($instancesMetrics, $instance->id);
  36. $instance->cpu = is_object($metrics) ? $this->instance->printCpuUsage($instance, $metrics->cpu) : new stdClass();
  37. $instance->mem = is_object($metrics) ? $this->instance->printStorageUsage($instance, $metrics->memory) : new stdClass();
  38. }
  39. $actions = $this->loadModel('action')->getDynamic('all', 'today');
  40. $this->view->title = $this->lang->my->common;
  41. $this->view->instances = $instances;
  42. $this->view->actions = $actions;
  43. $this->view->pager = $pager;
  44. $this->view->instanceTotal = $this->instance->getInstanceCount();
  45. $this->display();
  46. }
  47. /**
  48. * 数据库列表。
  49. * Show database list.
  50. *
  51. * @access public
  52. * @return void
  53. */
  54. public function dbList()
  55. {
  56. $this->app->loadLang('instance');
  57. $this->view->title = $this->lang->system->dbManagement;
  58. $this->view->dbList = $this->loadModel('cne')->allDBList();
  59. $this->display();
  60. }
  61. /**
  62. * 对象存储视图。
  63. * OSS view.
  64. *
  65. * @access public
  66. * @return void
  67. */
  68. public function ossView()
  69. {
  70. $this->loadModel('cne');
  71. $minioInstance = new stdclass;
  72. $minioInstance->k8name = 'cne-operator';
  73. $minioInstance->spaceData = new stdclass;
  74. $minioInstance->spaceData->k8space = $this->config->k8space;
  75. $ossAccount = $this->cne->getDefaultAccount($minioInstance, 'minio');
  76. $ossDomain = $this->cne->getDomain($minioInstance, 'minio');
  77. $this->view->title = $this->lang->system->oss->common;
  78. $this->view->ossAccount = $ossAccount ? $ossAccount : new stdclass();
  79. $this->view->ossDomain = $ossDomain;
  80. $this->display();
  81. }
  82. /**
  83. * 自定义域名配置。
  84. * Config customer's domain.
  85. *
  86. * @access public
  87. * @return void
  88. */
  89. public function configDomain()
  90. {
  91. $domainSettings = $this->system->getDomainSettings();
  92. if($domainSettings->customDomain) $this->locate($this->inLink('domainView'));
  93. $this->locate($this->inLink('editDomain'));
  94. }
  95. /**
  96. * 编辑自定义域名。
  97. * Edit customer's domain.
  98. *
  99. * @access public
  100. * @return void
  101. */
  102. public function editDomain()
  103. {
  104. if(!commonModel::hasPriv('system', 'configDomain')) $this->loadModel('common')->deny('system', 'configDomain', false);
  105. $this->loadModel('instance');
  106. if($_POST)
  107. {
  108. session_write_close();
  109. $settings = form::data($this->config->system->form->editDomain)
  110. ->setDefault('https', 'false')
  111. ->setIf(is_array($this->post->https) && in_array('true', $this->post->https), 'https', 'true')
  112. ->get();
  113. $this->system->saveDomainSettings($settings);
  114. if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError(true)));
  115. return $this->send(array('result' => 'success', 'message' => $this->lang->system->notices->updateDomainSuccess, 'locate' => $this->inlink('domainView')));
  116. }
  117. $this->view->title = $this->lang->system->domain->common;
  118. $this->view->domainSettings = $this->system->getDomainSettings();
  119. $this->display();
  120. }
  121. /**
  122. * 校验证书。
  123. * Ajax valid cert.
  124. *
  125. * @access public
  126. * @return void
  127. */
  128. public function ajaxValidateCert()
  129. {
  130. $certData = fixer::input('post')->get();
  131. if(!validater::checkREG($certData->customDomain, '/^((?!-)[a-z0-9-]{1,63}(?<!-)\\.)+[a-z]{2,6}$/'))
  132. {
  133. return $this->send(array('result' => 'fail', 'message' => $this->lang->system->errors->invalidDomain));
  134. }
  135. $certName = 'tls-' . str_replace('.', '-',$certData->customDomain);
  136. $result = $this->loadModel('cne')->validateCert($certName, $certData->certPem, $certData->certKey, $certData->customDomain);
  137. if($result->code == 200) return $this->send(array('result' => 'success', 'message' => $this->lang->system->notices->validCert));
  138. return $this->send(array('result' => 'fail', 'message' => $result->message));
  139. }
  140. /**
  141. * 更新域名的进度。
  142. * Show progress of updating domains.
  143. *
  144. * @access public
  145. * @return void
  146. */
  147. public function ajaxUpdatingDomainProgress()
  148. {
  149. session_write_close();
  150. $oldDomainQty = $this->loadModel('instance')->countOldDomain();
  151. return print(sprintf($this->lang->system->domain->updatingProgress, $oldDomainQty));
  152. }
  153. /**
  154. * 域名设置视图。
  155. * Domain settings view.
  156. *
  157. * @access public
  158. * @return void
  159. */
  160. public function domainView()
  161. {
  162. $domainSettings = $this->system->getDomainSettings();
  163. $certName = 'tls-' . str_replace('.', '-', $domainSettings->customDomain);
  164. $cert = $this->loadModel('cne')->certInfo($certName);
  165. $notAfter = zget($cert, 'not_after', '');
  166. if($notAfter) $cert->expiredDate = date('Y-m-d H:i:s', $notAfter);
  167. $this->view->title = $this->lang->system->domain->common;
  168. $this->view->domainSettings = $domainSettings;
  169. $this->view->cert = $cert;
  170. $this->display();
  171. }
  172. /**
  173. * 创建一个禅道DevOps平台版的备份。
  174. * Backup the system.
  175. *
  176. * @param string $reload yes|no
  177. * @param string $mode |manual|system|upgrade|downgrade
  178. * @access public
  179. * @return void
  180. */
  181. public function backup($reload = 'no', $mode = 'manual')
  182. {
  183. if($reload == 'yes') session_write_close();
  184. set_time_limit(0);
  185. if(!$this->config->inQuickon) $this->sendError($this->lang->system->cneStatus);
  186. $this->loadModel('instance');
  187. $instance = $this->config->instance->zentaopaas;
  188. $result = $this->system->backup($instance, $mode);
  189. $this->loadModel('action')->create('system', 0, 'createBackup');
  190. if($result['result'] == 'success')
  191. {
  192. $backupName = $result['data']->backup_name;
  193. $this->send($result + array('callback' => "backupInProgress('$backupName')"));
  194. }
  195. else
  196. {
  197. $this->send($result);
  198. }
  199. }
  200. /**
  201. * 恢复一个备份。
  202. * Restore the backup.
  203. *
  204. * @param string $backupName
  205. * @return void
  206. */
  207. public function restoreBackup($backupName)
  208. {
  209. session_write_close();
  210. set_time_limit(0);
  211. $this->loadModel('cne');
  212. if(empty($this->config->system->noBackupBeforeRestore))
  213. {
  214. $instance = $this->config->instance->zentaopaas;
  215. $backupResult = $this->cne->backup($instance, null, 'restore');
  216. if($backupResult->code != 200) $this->sendError($backupResult->message);
  217. while(true)
  218. {
  219. $backupStatus = $this->cne->getBackupStatus($instance, $backupResult->data->backup_name);
  220. if($backupStatus->code != 200) $this->sendError($backupStatus->message);
  221. if(strtolower($backupStatus->data->status) == 'completed') break;
  222. sleep(1);
  223. }
  224. }
  225. $backupName = str_replace('_', '-', $backupName);
  226. $result = $this->system->restore($instance, $backupName);
  227. $this->loadModel('action')->create('system', 0, 'restoreBackup', '', $backupName);
  228. $this->send($result + array('load' => true, 'callback' => "restoreInProgress('$backupName')"));
  229. }
  230. /**
  231. * 删除一个备份。
  232. * Delete the backup.
  233. *
  234. * @param string $backupName
  235. * @return void
  236. */
  237. public function deleteBackup($backupName)
  238. {
  239. $backupName = str_replace('_', '-', $backupName);
  240. $instance = $this->config->instance->zentaopaas;
  241. $result = $this->system->deleteBackup($instance, $backupName);
  242. $this->loadModel('action')->create('system', 0, 'deleteBackup', '', $backupName);
  243. $this->send($result + array('load' => true, 'callback' => "deleteInProgress('$backupName')"));
  244. }
  245. /**
  246. * 执行系统升级。
  247. * Upgrade ths quickon system.
  248. *
  249. * @param string $edition
  250. * @return void
  251. */
  252. public function upgrade($backup = 'yes', $edition = 'open')
  253. {
  254. session_write_close();
  255. set_time_limit(0);
  256. $this->loadModel('cne');
  257. if(!$this->system->isUpgradeable()) $this->sendError($this->lang->system->backup->error->beenLatestVersion);
  258. $this->loadModel('action')->create('system', 0, 'upgradeSystem');
  259. if($backup == 'yes' && empty($this->config->system->noBackupBeforeUpgrade))
  260. {
  261. $this->loadModel('instance');
  262. $instance = $this->config->instance->zentaopaas;
  263. $backupResult = $this->cne->backup($instance, null, 'upgrade');
  264. if($backupResult->code != 200) $this->sendError($backupResult->message);
  265. while(true)
  266. {
  267. $backupStatus = $this->cne->getBackupStatus($instance, $backupResult->data->backup_name);
  268. if($backupStatus->code != 200) $this->sendError($backupStatus->message);
  269. if(strtolower($backupStatus->data->status) == 'completed') break;
  270. sleep(1);
  271. }
  272. }
  273. $rawResult = $this->cne->upgrade($edition);
  274. if($rawResult)
  275. {
  276. if($rawResult->code == 200)
  277. $this->sendSuccess(array('message' => $this->lang->system->backup->success->upgrade, 'callback' => 'upgradeInProgress'));
  278. else
  279. $this->sendError($rawResult->message);
  280. }
  281. $this->sendError($this->lang->CNE->serverError);
  282. }
  283. /**
  284. * AJAX: 获取备份列表。
  285. * AJAX: Get the backup list.
  286. *
  287. * @return void
  288. */
  289. public function ajaxGetBackups()
  290. {
  291. $result = $this->system->getBackupList($this->config->instance->zentaopaas);
  292. $this->send($result);
  293. }
  294. /**
  295. * 获取备份的进度。
  296. * AJAX: Get the progress of the backup.
  297. *
  298. * @access public
  299. * @param string $backupName
  300. * @return void
  301. */
  302. public function ajaxGetBackupProgress($backupName)
  303. {
  304. session_write_close();
  305. $this->loadModel('cne');
  306. if(strpos($backupName, '_') !== false) $backupName = str_replace('_', '-', $backupName);
  307. $this->app->loadConfig('instance');
  308. $instance = $this->config->instance->zentaopaas;
  309. $result = $this->cne->getBackupStatus($instance, $backupName);
  310. if($result && $result->code == 200)
  311. {
  312. $status = strtolower($result->data->status);
  313. if($status == 'completed') return $this->send(array('result' => 'success', 'message' => $this->lang->system->backup->backupSucceed, 'status' => 'completed', 'closeModal' => true, 'load' => helper::createLink('backup', 'index')));
  314. if($status == 'pending' || $status == 'inprogress') return $this->send(array('result' => 'progress', 'status' => 'inprogress', 'text' => sprintf($this->lang->system->backup->progress, $result->data->completed, $result->data->total)));
  315. if($status == 'failed') return $this->send(array('result' => 'failed', 'message' => $this->lang->system->backup->error->backupFail, 'closeModal' => true));
  316. }
  317. else
  318. {
  319. return $this->send(array('result' => 'failed', 'message' => $result->message, 'closeModal' => true));
  320. }
  321. }
  322. /**
  323. * 获取还原的进度。
  324. * AJAX: Get the progress of the restore.
  325. *
  326. * @access public
  327. * @param string $backupName
  328. * @return void
  329. */
  330. public function ajaxGetRestoreProgress($backupName)
  331. {
  332. session_write_close();
  333. $this->loadModel('cne');
  334. $backupName = str_replace('_', '-', $backupName);
  335. $result = $this->cne->getRestoreStatus($this->config->instance->zentaopaas, $backupName);
  336. if($result && $result->code == 200)
  337. {
  338. $status = $result->data->status;
  339. if($status == 'completed') return $this->send(array('result' => 'success', 'message' => $this->lang->system->backup->restoreSucceed, 'status' => 'completed', 'load' => helper::createLink('backup', 'index')));
  340. if($status == 'pending' || $status == 'inprogress') return $this->send(array('result' => 'progress', 'status' => 'inprogress', 'text' => sprintf($this->lang->system->backup->progressStore, $result->data->completed, $result->data->total)));
  341. if($status == 'failed') return $this->send(array('result' => 'failed', 'message' => $this->lang->system->backup->error->backupFail, 'load' => helper::createLink('backup', 'index')));
  342. }
  343. else
  344. {
  345. return $this->send(array('result' => 'failed', 'message' => $result->message, 'load' => helper::createLink('backup', 'index')));
  346. }
  347. }
  348. /**
  349. * 获取升级的进度。(当前没有进度,但可以通过获取是否可以升级来检查)
  350. * AJAX: Get upgrade progress.
  351. *
  352. * @return void
  353. */
  354. public function ajaxGetUpgradeProgress()
  355. {
  356. $isUpgradeable = $this->system->isUpgradeable();
  357. if($isUpgradeable) return $this->send(array('result' => 'fail', 'message' => $this->lang->system->backup->upgrading));
  358. return $this->send(array('result' => 'success', 'message' => $this->lang->system->backup->success->upgrade, 'load' => true));
  359. }
  360. /**
  361. * 获取删除的进度。
  362. * AJAX: Get delete progress.
  363. *
  364. * @param string $backupName
  365. * @return void
  366. */
  367. public function ajaxGetDeleteProgress($backupName)
  368. {
  369. session_write_close();
  370. $this->loadModel('cne');
  371. if(strpos($backupName, '_') !== false) $backupName = str_replace('_', '-', $backupName);
  372. $rawResult = $this->cne->getBackupList($this->config->instance->zentaopaas);
  373. if($rawResult && $rawResult->code == 200)
  374. {
  375. foreach($rawResult->data as $backup)
  376. {
  377. if($backup->name == $backupName) return $this->sendSuccess(array('status' => 'inprogress', 'message' => $rawResult->message));
  378. }
  379. $this->sendSuccess(array('status' => 'completed', 'message' => $rawResult->message));
  380. }
  381. $this->sendError(isset($rawResult->message) ? $rawResult->message : 'fail');
  382. }
  383. /**
  384. * 生成数据库授权链接。
  385. * Generate database auth parameters and jump to login page.
  386. *
  387. * @access public
  388. * @return void
  389. */
  390. public function ajaxDBAuthUrl()
  391. {
  392. $post = fixer::input('post')
  393. ->setDefault('namespace', 'default')
  394. ->get();
  395. if(empty($post->dbName)) return $this->send(array('result' => 'fail', 'message' => $this->lang->system->errors->dbNameIsEmpty));
  396. $detail = $this->loadModel('cne')->dbDetail($post->dbName, $post->namespace);
  397. if(empty($detail)) return $this->send(array('result' => 'fail', 'message' => $this->lang->system->errors->notFoundDB));
  398. $this->app->loadConfig('instance');
  399. $dbAuth = array();
  400. $dbAuth['driver'] = zget($this->config->instance->adminer->dbTypes, $post->dbType, '');
  401. $dbAuth['server'] = $detail->host . ':' . $detail->port;
  402. $dbAuth['username'] = $detail->username;
  403. $dbAuth['db'] = $detail->database;
  404. $dbAuth['password'] = $detail->password;
  405. $url = '/adminer?'. http_build_query($dbAuth);
  406. $this->send(array('result' => 'success', 'message' => '', 'data' => array('url' => $url)));
  407. }
  408. /**
  409. * 获取对象存储信息。
  410. * Get oss account and domain by ajax.
  411. *
  412. * @access public
  413. * @return void
  414. */
  415. public function ajaxOssInfo()
  416. {
  417. $minioInstance = new stdclass;
  418. $minioInstance->k8name = 'cne-operator';
  419. $minioInstance->spaceData = new stdclass;
  420. $minioInstance->spaceData->k8space = $this->config->k8space;
  421. $ossAccount = $this->loadModel('cne')->getDefaultAccount($minioInstance, 'minio');
  422. $ossDomain = $this->cne->getDomain($minioInstance, 'minio');
  423. $ossDomain->domain = $ossDomain->access_host;
  424. $url = $this->loadModel('instance')->url($ossDomain);
  425. if($ossAccount and $ossDomain) return $this->send(array('result' => 'success', 'message' => '', 'data' => array('account' => $ossAccount, 'url' => $url)));
  426. $this->send(array('result' => 'fail', 'message' => $this->lang->system->errors->failGetOssAccount));
  427. }
  428. /**
  429. * 公共函数,设置产品菜单及页面基础数据。
  430. * Common action, set the menu and basic data.
  431. *
  432. * @param int $productID
  433. * @param string $branch
  434. * @access public
  435. * @return void
  436. */
  437. public function commonAction($productID, $branch = '')
  438. {
  439. $this->loadModel('product')->setMenu($productID, $branch);
  440. $product = $this->product->getById($productID);
  441. $products = $this->product->getPairs('all', 0, '', 'all');
  442. if(empty($product)) $this->locate($this->createLink('product', 'create'));
  443. $this->product->checkAccess($productID, $products);
  444. $this->view->product = $product;
  445. $this->view->branch = $branch;
  446. $this->view->branches = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($product->id);
  447. }
  448. /**
  449. * 获取应用列表。
  450. * Get application list.
  451. *
  452. * @param int $productID
  453. * @param string $branch
  454. * @param string $orderBy
  455. * @param int $recTotal
  456. * @param int $recPerPage
  457. * @param int $pageID
  458. * @access public
  459. * @return void
  460. * @param int $projectID
  461. */
  462. public function browse($productID, $projectID = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
  463. {
  464. if($projectID)
  465. {
  466. $this->loadModel('project')->setMenu($projectID);
  467. $productID = $this->loadModel('product')->getProductIDByProject($projectID);
  468. }
  469. else
  470. {
  471. $this->commonAction($productID);
  472. }
  473. $this->app->loadClass('pager', true);
  474. $pager = pager::init($recTotal, $recPerPage, $pageID);
  475. $systems = $this->system->getList($productID, 'all', $orderBy, $pager);
  476. foreach($systems as &$system)
  477. {
  478. $system->latestRelease = $system->latestRelease ? $system->latestRelease : '';
  479. }
  480. $this->view->title = $this->lang->system->browse;
  481. $this->view->productID = $productID;
  482. $this->view->projectID = $projectID;
  483. $this->view->appList = $systems;
  484. $this->view->releases = $this->loadModel('release')->getPairs();
  485. $this->view->appPairs = $this->system->getPairs();
  486. $this->view->orderBy = $orderBy;
  487. $this->view->pager = $pager;
  488. $this->display();
  489. }
  490. /**
  491. * 创建应用。
  492. * Create application.
  493. *
  494. * @param int $productID
  495. * @access public
  496. * @return void
  497. */
  498. public function create($productID)
  499. {
  500. if($_POST)
  501. {
  502. $integrated = $this->post->integrated;
  503. if($integrated) $this->config->system->create->requiredFields .= ',children';
  504. $formData = form::data($this->config->system->form->create)
  505. ->setDefault('product', $productID)
  506. ->setDefault('status', 'active')
  507. ->setDefault('createdBy', $this->app->user->account)
  508. ->setIF($integrated == '0', 'children', '')
  509. ->get();
  510. $this->system->create($formData);
  511. if(dao::isError()) return $this->sendError(dao::getError());
  512. $this->sendSuccess(array('load' => true));
  513. }
  514. $this->view->title = $this->lang->system->create;
  515. $this->view->systemList = $this->system->getPairs(0, '0');
  516. $this->display();
  517. }
  518. /**
  519. * 编辑应用。
  520. * Edit application.
  521. *
  522. * @param int $id
  523. * @access public
  524. * @return void
  525. */
  526. public function edit($id)
  527. {
  528. $system = $this->system->fetchByID($id);
  529. if($_POST)
  530. {
  531. $integrated = $system->integrated;
  532. if($integrated) $this->config->system->edit->requiredFields .= ',children';
  533. $formData = form::data($this->config->system->form->edit)
  534. ->setDefault('editedBy', $this->app->user->account)
  535. ->setDefault('integrated', $integrated)
  536. ->setDefault('editedBy', $this->app->user->account)
  537. ->get();
  538. $this->system->update($id, $formData);
  539. if(dao::isError()) return $this->sendError(dao::getError());
  540. $this->sendSuccess(array('load' => true));
  541. }
  542. $this->view->title = $this->lang->system->edit;
  543. $this->view->system = $system;
  544. $this->view->systemList = $this->system->getPairs(0, '0');
  545. $this->display();
  546. }
  547. /**
  548. * 上架应用。
  549. * Active application.
  550. *
  551. * @param int $id
  552. * @access public
  553. * @return void
  554. */
  555. public function active($id)
  556. {
  557. $system = new stdclass();
  558. $system->status = 'active';
  559. $this->system->update($id, $system, 'active');
  560. if(dao::isError()) return $this->sendError(dao::getError());
  561. $this->sendSuccess(array('load' => true));
  562. }
  563. /**
  564. * 下架应用。
  565. * Inactive application.
  566. *
  567. * @param int $id
  568. * @access public
  569. * @return void
  570. */
  571. public function inactive($id)
  572. {
  573. $system = new stdclass();
  574. $system->status = 'inactive';
  575. $this->system->update($id, $system, 'inactive');
  576. if(dao::isError()) return $this->sendError(dao::getError());
  577. $this->sendSuccess(array('load' => true));
  578. }
  579. /**
  580. * 删除应用。
  581. * Delete application.
  582. *
  583. * @param int $id
  584. * @access public
  585. * @return void
  586. */
  587. public function delete($id)
  588. {
  589. $releases = $this->system->getReleasesByID($id);
  590. if(!empty($releases)) return $this->sendError($this->lang->system->releaseExist);
  591. $builds = $this->system->getBuildsByID($id);
  592. if(!empty($builds)) return $this->sendError($this->lang->system->buildExist);
  593. $this->system->delete(TABLE_SYSTEM, $id);
  594. if(dao::isError()) return $this->sendError(dao::getError());
  595. $this->sendSuccess(array('load' => true));
  596. }
  597. /**
  598. * 初始化产品下的应用数据(仅用于第一次安装)。
  599. * Init the application data of the product.
  600. *
  601. * @access public
  602. * @return void
  603. */
  604. public function initSystem()
  605. {
  606. return $this->system->initSystem();
  607. }
  608. /**
  609. * 获取CNE平台的集群度量。
  610. * Get cluster metrics of CNE platform.
  611. *
  612. * @access public
  613. * @return void
  614. */
  615. public function ajaxCneMetrics()
  616. {
  617. $cneMetrics = $this->loadModel('cne')->cneMetrics();
  618. $result = array(
  619. 'status' => $cneMetrics->status,
  620. 'node_count' => $cneMetrics->node_count,
  621. 'ready_count' => zget($cneMetrics, 'ready_count', 0),
  622. 'nodeError' => zget($cneMetrics, 'nodeError', ''),
  623. 'cpuInfo' => $this->systemZen->getCpuUsage($cneMetrics->metrics->cpu),
  624. 'memoryInfo' => $this->systemZen->getMemUsage($cneMetrics->metrics->memory)
  625. );
  626. return $this->send(array('result' => 'success', 'data' => $result));
  627. }
  628. /**
  629. * 备份详情。
  630. * Backup detail.
  631. *
  632. * @param string $name
  633. * @access public
  634. * @return void
  635. */
  636. public function backupView($name)
  637. {
  638. if(!$this->config->inQuickon) $this->sendError($this->lang->system->cneStatus);
  639. if(strpos($name, '_') !== false) $name = str_replace('_', '-', $name);
  640. $this->loadModel('instance');
  641. $instance = $this->config->instance->zentaopaas;
  642. $this->view->title = $this->lang->system->backupView;
  643. $this->view->backup = $this->loadModel('cne')->backupDetail($instance, $name);
  644. $this->display();
  645. }
  646. }