view.html.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <?php
  2. /**
  3. * The view view file of zanode module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Zeng Gang<zenggang@easycorp.ltd>
  7. * @package zanode
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. jsVar('nodeID', $zanode->id);
  12. jsVar('zanodeLang', $lang->zanode);
  13. jsVar('nodeStatus', $zanode->status);
  14. jsVar('hostType', $zanode->hostType);
  15. jsVar('webRoot', getWebRoot());
  16. $account = strpos(strtolower($zanode->osName), "windows") !== false ? $config->zanode->defaultWinAccount : $config->zanode->defaultAccount;
  17. $ssh = $zanode->hostType == 'physics' ? ('ssh ' . $zanode->extranet) : ($zanode->ssh ? 'ssh ' . $account . '@' . $zanode->ip . ' -p ' . $zanode->ssh : '');
  18. $snapshotUrl = helper::createLink('zanode', 'browseSnapshot', "nodeID={$zanode->id}");
  19. $mainActions = array();
  20. $commonActions = array();
  21. foreach($config->zanode->view->operateList as $operate)
  22. {
  23. if(strpos($operate, '|') !== false)
  24. {
  25. $operates = explode('|', $operate);
  26. foreach($operates as $operate)
  27. {
  28. if($this->zanode->isClickable($zanode, $operate)) break;
  29. }
  30. }
  31. if(!common::hasPriv('zanode', $operate)) continue;
  32. $action = $config->zanode->dtable->fieldList['actions']['list'][$operate];
  33. if(!$this->zanode->isClickable($zanode, $operate))
  34. {
  35. unset($action);
  36. continue;
  37. }
  38. if($operate === 'edit' || $operate === 'destroy')
  39. {
  40. $commonActions[] = $action;
  41. continue;
  42. }
  43. $mainActions[] = $action;
  44. }
  45. $baseInfo = array();
  46. if($zanode->hostType == 'physics')
  47. {
  48. $baseInfo[] = div
  49. (
  50. setClass('w-1/3'),
  51. span
  52. (
  53. setClass('text-gray'),
  54. $lang->zanode->osName
  55. ),
  56. span
  57. (
  58. setClass('ml-2'),
  59. zget($config->zanode->linuxList, $zanode->osName, zget($config->zanode->windowsList, $zanode->osName))
  60. )
  61. );
  62. $baseInfo[] = div
  63. (
  64. setClass('w-1/2'),
  65. span
  66. (
  67. setClass('text-gray'),
  68. $lang->zanode->sshAddress
  69. ),
  70. span
  71. (
  72. setClass('ml-2'),
  73. $ssh,
  74. $ssh ? h::button
  75. (
  76. setClass('ghost btn btn-info size-sm btn-ssh-copy'),
  77. icon
  78. (
  79. setClass('icon-common-copy icon-copy'),
  80. set::title($lang->zanode->copy),
  81. set::name('')
  82. ),
  83. on::click('sshCopy')
  84. ) : null,
  85. h::input
  86. (
  87. set::type('hidden'),
  88. setID('ssh-copy'),
  89. set::value($ssh)
  90. )
  91. )
  92. );
  93. $hiddenHost || $zanode->cpuCores == 0 ? null : $baseInfo[] = div
  94. (
  95. setClass('w-1/6'),
  96. span
  97. (
  98. setClass('text-gray'),
  99. $lang->zanode->cpuCores
  100. ),
  101. span
  102. (
  103. setClass('ml-2'),
  104. $zanode->cpuCores . ' ' . $lang->zanode->cpuUnit
  105. )
  106. );
  107. $baseInfo[] = div
  108. (
  109. $hiddenHost || $zanode->cpuCores == 0 ? setClass('w-1/6') : setClass('w-1/3 mt-2'),
  110. span
  111. (
  112. setClass('text-gray'),
  113. $lang->zanode->status
  114. ),
  115. span
  116. (
  117. setClass('ml-2'),
  118. zget($lang->zanode->statusList, $zanode->status)
  119. )
  120. );
  121. $hiddenHost || $zanode->memory == 0 ? null : $baseInfo[] = div
  122. (
  123. setClass('w-1/2 mt-4'),
  124. span
  125. (
  126. setClass('text-gray'),
  127. $lang->zanode->memory
  128. ),
  129. span
  130. (
  131. setClass('ml-2'),
  132. $zanode->memory . 'GB'
  133. )
  134. );
  135. $hiddenHost || $zanode->diskSize == 0 ? null : $baseInfo[] = div
  136. (
  137. setClass('w-1/6 mt-4'),
  138. span
  139. (
  140. setClass('text-gray'),
  141. $lang->zanode->diskSize
  142. ),
  143. span
  144. (
  145. setClass('ml-2'),
  146. $zanode->diskSize . 'GB'
  147. )
  148. );
  149. }
  150. else
  151. {
  152. $baseInfo[] = div
  153. (
  154. setClass('w-1/3'),
  155. span
  156. (
  157. setClass('text-gray'),
  158. $lang->zanode->osName
  159. ),
  160. span
  161. (
  162. setClass('ml-2'),
  163. $zanode->osName
  164. )
  165. );
  166. $baseInfo[] = div
  167. (
  168. setClass('w-1/2'),
  169. span
  170. (
  171. setClass('text-gray'),
  172. $lang->zanode->sshCommand
  173. ),
  174. span
  175. (
  176. setClass('ml-2'),
  177. $ssh,
  178. $ssh ? h::button
  179. (
  180. setClass('ghost btn btn-info size-sm btn-ssh-copy'),
  181. icon
  182. (
  183. setClass('icon-common-copy icon-copy'),
  184. set::title($lang->zanode->copy),
  185. set::name('')
  186. ),
  187. on::click('sshCopy')
  188. ) : null,
  189. h::textarea
  190. (
  191. setClass('hidden'),
  192. setID('ssh-copy'),
  193. $ssh
  194. )
  195. )
  196. );
  197. $baseInfo[] = div
  198. (
  199. setClass('w-1/6'),
  200. span
  201. (
  202. setClass('text-gray'),
  203. $lang->zanode->cpuCores
  204. ),
  205. span
  206. (
  207. setClass('ml-2'),
  208. $zanode->cpuCores . '' . $lang->zanode->cpuUnit
  209. )
  210. );
  211. $baseInfo[] = div
  212. (
  213. setClass('w-1/3 mt-4'),
  214. span
  215. (
  216. setClass('text-gray'),
  217. $lang->zanode->status
  218. ),
  219. span
  220. (
  221. setClass('ml-2'),
  222. zget($lang->zanode->statusList, $zanode->status)
  223. )
  224. );
  225. $baseInfo[] = div
  226. (
  227. setClass('w-1/2 mt-4'),
  228. span
  229. (
  230. setClass('text-gray'),
  231. $lang->zanode->defaultUser
  232. ),
  233. span
  234. (
  235. setClass('ml-2'),
  236. $account
  237. )
  238. );
  239. $baseInfo[] = div
  240. (
  241. setClass('w-1/6 mt-4'),
  242. span
  243. (
  244. setClass('text-gray'),
  245. $lang->zanode->memory
  246. ),
  247. span
  248. (
  249. setClass('ml-2'),
  250. $zanode->memory . ' GB'
  251. )
  252. );
  253. $baseInfo[] = div
  254. (
  255. setClass('w-1/3 mt-4'),
  256. span
  257. (
  258. setClass('text-gray'),
  259. $lang->zanode->hostName
  260. ),
  261. span
  262. (
  263. setClass('ml-2 clip w-36 inline-flex'),
  264. set::title($zanode->hostName),
  265. $zanode->hostName
  266. )
  267. );
  268. $baseInfo[] = div
  269. (
  270. setClass('w-1/2 mt-4'),
  271. span
  272. (
  273. setClass('text-gray'),
  274. $lang->zanode->defaultPwd
  275. ),
  276. span
  277. (
  278. setClass('ml-2'),
  279. span
  280. (
  281. setID('pwd-text'),
  282. str_repeat('*', strlen($config->zanode->defaultPwd))
  283. ),
  284. h::button
  285. (
  286. setClass('ghost btn btn-info size-sm btn-pwd-copy'),
  287. icon
  288. (
  289. setClass('icon-common-copy icon-copy'),
  290. set::title($lang->zanode->copy),
  291. set::name('')
  292. ),
  293. on::click('pwdCopy')
  294. ),
  295. h::button
  296. (
  297. setClass('ghost btn btn-info size-sm btn-pwd-show'),
  298. icon
  299. (
  300. setClass('icon-common-eye icon-eye'),
  301. set::title($lang->zanode->showPwd),
  302. set::name('')
  303. ),
  304. on::click('pwdShow')
  305. ),
  306. h::input
  307. (
  308. setID('pwd-copy'),
  309. set::type('hidden'),
  310. set::value($config->zanode->defaultPwd)
  311. )
  312. )
  313. );
  314. }
  315. detailHeader
  316. (
  317. to::title
  318. (
  319. entityLabel
  320. (
  321. set::entityID($zanode->id),
  322. set::level(1),
  323. set::text($zanode->name)
  324. ),
  325. $zanode->deleted ? span(setClass('label danger'), $lang->zanode->deleted) : null
  326. )
  327. );
  328. detailBody
  329. (
  330. sectionList
  331. (
  332. setID('baseInfoContent'),
  333. section
  334. (
  335. set::title($lang->zanode->baseInfo),
  336. h::table
  337. (
  338. setClass('w-full'),
  339. h::tr
  340. (
  341. h::td
  342. (
  343. div
  344. (
  345. setClass('flex flex-wrap pt-2 mx-4'),
  346. $baseInfo
  347. )
  348. )
  349. )
  350. )
  351. ),
  352. section
  353. (
  354. set::title($lang->zanode->desc),
  355. !empty($zanode->desc) ? html(htmlspecialchars_decode($zanode->desc)) : $lang->noData
  356. )
  357. ),
  358. sectionList
  359. (
  360. setID('serviceContent'),
  361. div
  362. (
  363. setClass('text-lg font-bold'),
  364. $lang->zanode->init->statusTitle,
  365. button
  366. (
  367. setClass('ghost btn'),
  368. icon('refresh', setClass('text-primary')),
  369. $lang->zanode->init->checkStatus,
  370. on::click()->call('window.checkServiceStatus')
  371. )
  372. ),
  373. div
  374. (
  375. setClass('service-status hidden'),
  376. span
  377. (
  378. setClass('dot-symbol dot-zenagent text-danger'),
  379. '●'
  380. ),
  381. span
  382. (
  383. ' ZAgent ',
  384. span
  385. (
  386. setClass('zenagent-status'),
  387. $lang->zanode->initializing
  388. )
  389. )
  390. ),
  391. div
  392. (
  393. setClass('service-status hidden'),
  394. span
  395. (
  396. setClass('dot-symbol dot-ztf text-danger'),
  397. '●'
  398. ),
  399. span
  400. (
  401. ' ZTF ',
  402. span
  403. (
  404. setClass('ztf-status'),
  405. $lang->zanode->initializing
  406. )
  407. )
  408. ),
  409. div
  410. (
  411. setID('statusContainer')
  412. ),
  413. div
  414. (
  415. setClass('status-notice'),
  416. span
  417. (
  418. setClass('init-success hidden'),
  419. html(sprintf($lang->zanode->init->initSuccessNoticeTitle, "<a href='https://www.zentao.net/book/zentaopms/974.html?fullScreen=zentao'>{$lang->zanode->manual}</a>", html::a(createLink('testcase', 'automation'), $lang->zanode->automation, '', "data-toggle='modal'")))
  420. ),
  421. $zanode->hostType == 'physics' ? div
  422. (
  423. setClass('init-fail hidden'),
  424. html($lang->zanode->init->initFailNoticeOnPhysics),
  425. textarea
  426. (
  427. setID('initBash'),
  428. setClass('hidden'),
  429. $initBash
  430. ),
  431. div
  432. (
  433. setClass('zanode-init'),
  434. $initBash,
  435. h::button
  436. (
  437. setClass('ghost btn btn-info size-sm btn-init-copy text-primary'),
  438. icon
  439. (
  440. setClass('icon-common-copy icon-copy'),
  441. set::title($lang->zanode->copy),
  442. set::name('')
  443. ),
  444. on::click('onCopy')
  445. )
  446. )
  447. ) : null
  448. )
  449. ),
  450. common::hasPriv('zanode', 'browseSnapshot') && $zanode->hostType == '' ? sectionList
  451. (
  452. section
  453. (
  454. set::title($lang->zanode->browseSnapshot),
  455. to::actions
  456. (
  457. div
  458. (
  459. setClass('ml-auto'),
  460. btn
  461. (
  462. setClass('btn primary'),
  463. $lang->zanode->createSnapshot,
  464. set::url(createLink('zanode', 'createSnapshot', "zanodeID={$zanode->id}")),
  465. set::icon('plus'),
  466. setData(array('toggle' => 'modal')),
  467. set::disabled($zanode->status != 'running' ? true : false)
  468. )
  469. )
  470. )
  471. ),
  472. !empty($snapshotList) ? div(setID('snapshotList'), on::init()->do("$('#snapshotList').load('{$snapshotUrl}');")) : $lang->noData
  473. ) : null,
  474. floatToolbar
  475. (
  476. to::prefix(backBtn(set::icon('back'), $lang->goback)),
  477. set::main($mainActions),
  478. set::suffix($commonActions),
  479. set::object($zanode)
  480. ),
  481. detailSide
  482. (
  483. history()
  484. )
  485. );
  486. render();