list_db.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. [$http_host, $port] = explode(":", $_SERVER["HTTP_HOST"] . ":");
  3. $db_myadmin_link = "//" . $http_host . "/phpmyadmin/";
  4. $db_pgadmin_link = "//" . $http_host . "/phppgadmin/";
  5. if (!empty($_SESSION["DB_PMA_ALIAS"])) {
  6. $db_myadmin_link = "//" . $http_host . "/" . $_SESSION["DB_PMA_ALIAS"] . "/";
  7. }
  8. if (!empty($_SESSION["DB_PGA_ALIAS"])) {
  9. $db_pgadmin_link = "//" . $http_host . "/" . $_SESSION["DB_PGA_ALIAS"] . "/";
  10. }
  11. ?>
  12. <!-- Begin toolbar -->
  13. <div class="toolbar">
  14. <div class="toolbar-inner">
  15. <div class="toolbar-buttons">
  16. <?php if ($read_only !== "true") { ?>
  17. <a href="/add/db/" class="button button-secondary js-button-create">
  18. <i class="fas fa-circle-plus icon-green"></i><?= tohtml( _("Add Database")) ?>
  19. </a>
  20. <?php if ($_SESSION["DB_SYSTEM"] === "mysql" || $_SESSION["DB_SYSTEM"] === "mysql,pgsql" || $_SESSION["DB_SYSTEM"] === "pgsql,mysql") { ?>
  21. <a class="button button-secondary <?= tohtml(ipUsed() ? "button-suspended" : "") ?>" href="<?= tohtml($db_myadmin_link) ?>" target="_blank">
  22. <i class="fas fa-database icon-orange"></i>phpMyAdmin
  23. </a>
  24. <?php } ?>
  25. <?php if ($_SESSION["DB_SYSTEM"] === "pgsql" || $_SESSION["DB_SYSTEM"] === "mysql,pgsql" || $_SESSION["DB_SYSTEM"] === "pgsql,mysql") { ?>
  26. <a class="button button-secondary <?= tohtml(ipUsed() ? "button-suspended" : "") ?>" href="<?= tohtml($db_pgadmin_link) ?>" target="_blank">
  27. <i class="fas fa-database icon-orange"></i>phpPgAdmin
  28. </a>
  29. <?php } ?>
  30. <?php if (ipUsed()) { ?>
  31. <a target="_blank" href="https://hestiacp.com/docs/server-administration/databases.html#why-i-can-t-use-http-ip-phpmyadmin">
  32. <i class="fas fa-circle-question"></i>
  33. </a>
  34. <?php } ?>
  35. <?php } ?>
  36. </div>
  37. <div class="toolbar-right">
  38. <div class="toolbar-sorting">
  39. <button class="toolbar-sorting-toggle js-toggle-sorting-menu" type="button" title="<?= tohtml( _("Sort items")) ?>">
  40. <?= tohtml( _("Sort by")) ?>:
  41. <span class="u-text-bold">
  42. <?php if ($_SESSION['userSortOrder'] === 'name') { $label = _('Name'); } else { $label = _('Date'); } ?>
  43. <?= tohtml($label) ?> <i class="fas fa-arrow-down-a-z"></i>
  44. </span>
  45. </button>
  46. <ul class="toolbar-sorting-menu js-sorting-menu u-hidden">
  47. <li data-entity="sort-charset">
  48. <span class="name"><?= tohtml( _("Charset")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  49. </li>
  50. <li data-entity="sort-date" data-sort-as-int="1">
  51. <span class="name <?php if ($_SESSION['userSortOrder'] === 'date') { echo 'active'; } ?>"><?= tohtml( _("Date")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  52. </li>
  53. <li data-entity="sort-disk" data-sort-as-int="1">
  54. <span class="name"><?= tohtml( _("Disk")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  55. </li>
  56. <li data-entity="sort-name">
  57. <span class="name <?php if ($_SESSION['userSortOrder'] === 'name') { echo 'active'; } ?>"><?= tohtml( _("Name")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  58. </li>
  59. <li data-entity="sort-server">
  60. <span class="name"><?= tohtml( _("Host")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  61. </li>
  62. <li data-entity="sort-user">
  63. <span class="name"><?= tohtml( _("Username")) ?> <i class="fas fa-arrow-down-a-z"></i></span><span class="up"><i class="fas fa-arrow-up-a-z"></i></span>
  64. </li>
  65. </ul>
  66. <?php if ($read_only !== "true") { ?>
  67. <form x-data x-bind="BulkEdit" action="/bulk/db/" method="post">
  68. <input type="hidden" name="token" value="<?= tohtml($_SESSION["token"]) ?>">
  69. <select class="form-select" name="action">
  70. <option value=""><?= tohtml( _("Apply to selected")) ?></option>
  71. <?php if ($_SESSION["userContext"] === "admin") { ?>
  72. <option value="rebuild"><?= tohtml( _("Rebuild All")) ?></option>
  73. <option value="suspend"><?= tohtml( _("Suspend All")) ?></option>
  74. <option value="unsuspend"><?= tohtml( _("Unsuspend All")) ?></option>
  75. <?php } ?>
  76. <option value="delete"><?= tohtml( _("Delete")) ?></option>
  77. </select>
  78. <button type="submit" class="toolbar-input-submit" title="<?= tohtml( _("Apply to selected")) ?>">
  79. <i class="fas fa-arrow-right"></i>
  80. </button>
  81. </form>
  82. <?php } ?>
  83. </div>
  84. <div class="toolbar-search">
  85. <form action="/search/" method="get">
  86. <input type="hidden" name="token" value="<?= tohtml($_SESSION["token"]) ?>">
  87. <input type="search" class="form-control js-search-input" name="q" value="<?= tohtml($_POST['q'] ?? '') ?>" title="<?= tohtml( _("Search")) ?>">
  88. <button type="submit" class="toolbar-input-submit" title="<?= tohtml( _("Search")) ?>">
  89. <i class="fas fa-magnifying-glass"></i>
  90. </button>
  91. </form>
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. <!-- End toolbar -->
  97. <div class="container">
  98. <h1 class="u-text-center u-hide-desktop u-mt20 u-pr30 u-mb20 u-pl30"><?= tohtml( _("Databases")) ?></h1>
  99. <div class="units-table js-units-container">
  100. <div class="units-table-header">
  101. <div class="units-table-cell">
  102. <input type="checkbox" class="js-toggle-all-checkbox" title="<?= tohtml( _("Select all")) ?>" <?= tohtml($display_mode) ?>>
  103. </div>
  104. <div class="units-table-cell"><?= tohtml( _("Name")) ?></div>
  105. <div class="units-table-cell"></div>
  106. <div class="units-table-cell u-text-center"><?= tohtml( _("Disk")) ?></div>
  107. <div class="units-table-cell u-text-center"><?= tohtml( _("Type")) ?></div>
  108. <div class="units-table-cell u-text-center"><?= tohtml( _("Username")) ?></div>
  109. <div class="units-table-cell u-text-center"><?= tohtml( _("Hostname")) ?></div>
  110. <div class="units-table-cell u-text-center"><?= tohtml( _("Charset")) ?></div>
  111. </div>
  112. <!-- Begin database list item loop -->
  113. <?php
  114. list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
  115. foreach ($data as $key => $value) {
  116. ++$i;
  117. if ($data[$key]['SUSPENDED'] == 'yes') {
  118. $status = 'suspended';
  119. $spnd_action = 'unsuspend';
  120. $spnd_action_title = _('Unsuspend');
  121. $spnd_icon = 'fa-play';
  122. $spnd_icon_class = 'icon-green';
  123. $spnd_confirmation = _('Are you sure you want to unsuspend database %s?') ;
  124. } else {
  125. $status = 'active';
  126. $spnd_action = 'suspend';
  127. $spnd_action_title = _('Suspend');
  128. $spnd_icon = 'fa-pause';
  129. $spnd_icon_class = 'icon-highlight';
  130. $spnd_confirmation = _('Are you sure you want to suspend database %s?') ;
  131. }
  132. if ($data[$key]['HOST'] != 'localhost' ) $http_host = $data[$key]['HOST'];
  133. if ($data[$key]['TYPE'] == 'mysql') $db_admin = "phpMyAdmin";
  134. if ($data[$key]['TYPE'] == 'mysql') $db_admin_link = "https://".$http_host."/phpmyadmin/";
  135. if (($data[$key]['TYPE'] == 'mysql') && (!empty($_SESSION['DB_PMA_ALIAS']))) $db_admin_link = $_SESSION['DB_PMA_ALIAS'];
  136. if ($data[$key]['TYPE'] == 'pgsql') $db_admin = "phpPgAdmin";
  137. if ($data[$key]['TYPE'] == 'pgsql') $db_admin_link = "https://".$http_host."/phppgadmin/";
  138. if (($data[$key]['TYPE'] == 'pgsql') && (!empty($_SESSION['DB_PGA_ALIAS']))) $db_admin_link = $_SESSION['DB_PGA_ALIAS'];
  139. ?>
  140. <div class="units-table-row <?php if ($data[$key]['SUSPENDED'] == 'yes') echo 'disabled'; ?> js-unit"
  141. data-sort-date="<?= tohtml(strtotime($data[$key]['DATE'].' '.$data[$key]['TIME'])) ?>"
  142. data-sort-name="<?= tohtml($key) ?>"
  143. data-sort-disk="<?= tohtml($data[$key]["U_DISK"]) ?>"
  144. data-sort-user="<?= tohtml($data[$key]["DBUSER"]) ?>"
  145. data-sort-server="<?= tohtml($data[$key]["HOST"]) ?>"
  146. data-sort-charset="<?= tohtml($data[$key]["CHARSET"]) ?>">
  147. <div class="units-table-cell">
  148. <div>
  149. <input id="check<?= tohtml($i) ?>" class="js-unit-checkbox" type="checkbox" title="<?= tohtml( _("Select")) ?>" name="database[]" value="<?= tohtml($key) ?>" <?= tohtml($display_mode) ?>>
  150. <label for="check<?= tohtml($i) ?>" class="u-hide-desktop"><?= tohtml( _("Select")) ?></label>
  151. </div>
  152. </div>
  153. <div class="units-table-cell units-table-heading-cell u-text-bold">
  154. <span class="u-hide-desktop"><?= tohtml( _("Name")) ?>:</span>
  155. <?php if ($read_only === "true" || $data[$key]["SUSPENDED"] == "yes") { ?>
  156. <?= tohtml($key) ?>
  157. <?php } else { ?>
  158. <a href="/edit/db/?<?= tohtml(http_build_query(["database" => $key, "token" => $_SESSION["token"]])) ?>" title="<?= tohtml( _("Edit Database")) ?>: <?= tohtml($key) ?>">
  159. <?= tohtml($key) ?>
  160. </a>
  161. <?php } ?>
  162. </div>
  163. <div class="units-table-cell">
  164. <?php if (!$read_only) { ?>
  165. <ul class="units-table-row-actions">
  166. <?php if ($data[$key]["SUSPENDED"] == "no") { ?>
  167. <li class="units-table-row-action shortcut-enter" data-key-action="href">
  168. <a
  169. class="units-table-row-action-link"
  170. href="/edit/db/?<?= tohtml(http_build_query(["database" => $key, "token" => $_SESSION["token"]])) ?>"
  171. title="<?= tohtml( _("Edit Database")) ?>"
  172. >
  173. <i class="fas fa-pencil icon-orange"></i>
  174. <span class="u-hide-desktop"><?= tohtml( _("Edit Database")) ?></span>
  175. </a>
  176. </li>
  177. <?php } ?>
  178. <?php if ($data[$key]['TYPE'] == 'mysql' && isset($_SESSION['PHPMYADMIN_KEY']) && $_SESSION['PHPMYADMIN_KEY'] != '' && !ipUsed()) { $time = time(); ?>
  179. <?php
  180. $hestia_sso_token = password_hash(
  181. $key . $user_plain . $_SESSION['user_combined_ip'] . $time . $_SESSION['PHPMYADMIN_KEY'],
  182. PASSWORD_DEFAULT,
  183. );
  184. $hestia_sso_url = $db_myadmin_link . "hestia-sso.php?" . http_build_query([
  185. "database" => $key,
  186. "user" => $user_plain,
  187. "exp" => $time,
  188. "hestia_token" => $hestia_sso_token,
  189. ]);
  190. ?>
  191. <li class="units-table-row-action shortcut-enter" data-key-action="href">
  192. <a
  193. class="units-table-row-action-link"
  194. href="<?= tohtml($hestia_sso_url) ?>"
  195. title="phpMyAdmin" target="_blank"
  196. >
  197. <i class="fas fa-right-to-bracket icon-orange"></i>
  198. <span class="u-hide-desktop">phpMyAdmin</span>
  199. </a>
  200. </li>
  201. <?php } ?>
  202. <li class="units-table-row-action shortcut-enter" data-key-action="href">
  203. <a
  204. class="units-table-row-action-link"
  205. href="/download/database/?<?= tohtml(http_build_query(["database" => $key, "token" => $_SESSION["token"]])) ?>"
  206. title="<?= tohtml( _("Download Database")) ?>"
  207. >
  208. <i class="fas fa-download icon-orange"></i>
  209. <span class="u-hide-desktop"><?= tohtml( _("Download Database")) ?></span>
  210. </a>
  211. </li>
  212. <li class="units-table-row-action shortcut-s" data-key-action="js">
  213. <a
  214. class="units-table-row-action-link data-controls js-confirm-action"
  215. href="/<?= tohtml($spnd_action) ?>/db/?<?= tohtml(http_build_query(["database" => $key, "token" => $_SESSION["token"]])) ?>"
  216. title="<?= tohtml($spnd_action_title) ?>"
  217. data-confirm-title="<?= tohtml($spnd_action_title) ?>"
  218. data-confirm-message="<?= tohtml(sprintf($spnd_confirmation, $key)) ?>"
  219. >
  220. <i class="fas <?= tohtml($spnd_icon) ?> <?= tohtml($spnd_icon_class) ?>"></i>
  221. <span class="u-hide-desktop"><?= tohtml($spnd_action_title) ?></span>
  222. </a>
  223. </li>
  224. <li class="units-table-row-action shortcut-delete" data-key-action="js">
  225. <a
  226. class="units-table-row-action-link data-controls js-confirm-action"
  227. href="/delete/db/?<?= tohtml(http_build_query(["database" => $key, "token" => $_SESSION["token"]])) ?>"
  228. title="<?= tohtml( _("Delete")) ?>"
  229. data-confirm-title="<?= tohtml( _("Delete")) ?>"
  230. data-confirm-message="<?= tohtml(sprintf(_("Are you sure you want to delete database %s?"), $key)) ?>"
  231. >
  232. <i class="fas fa-trash icon-red"></i>
  233. <span class="u-hide-desktop"><?= tohtml( _("Delete")) ?></span>
  234. </a>
  235. </li>
  236. </ul>
  237. <?php } ?>
  238. </div>
  239. <div class="units-table-cell u-text-center-desktop">
  240. <span class="u-hide-desktop u-text-bold"><?= tohtml( _("Disk")) ?>:</span>
  241. <span class="u-text-bold">
  242. <?= tohtml(humanize_usage_size($data[$key]["U_DISK"])) ?>
  243. </span>
  244. <span class="u-text-small">
  245. <?= tohtml(humanize_usage_measure($data[$key]["U_DISK"])) ?>
  246. </span>
  247. </div>
  248. <div class="units-table-cell u-text-center-desktop">
  249. <span class="u-hide-desktop u-text-bold"><?= tohtml( _("Type")) ?>:</span>
  250. <?= tohtml($data[$key]["TYPE"]) ?>
  251. </div>
  252. <div class="units-table-cell u-text-bold u-text-center-desktop">
  253. <span class="u-hide-desktop"><?= tohtml( _("Username")) ?>:</span>
  254. <?= tohtml($data[$key]["DBUSER"]) ?>
  255. </div>
  256. <div class="units-table-cell u-text-bold u-text-center-desktop">
  257. <span class="u-hide-desktop"><?= tohtml( _("Hostname")) ?>:</span>
  258. <?= tohtml($data[$key]["HOST"]) ?>
  259. </div>
  260. <div class="units-table-cell u-text-center-desktop">
  261. <span class="u-hide-desktop u-text-bold"><?= tohtml( _("Charset")) ?>:</span>
  262. <?= tohtml($data[$key]["CHARSET"]) ?>
  263. </div>
  264. </div>
  265. <?php } ?>
  266. </div>
  267. <div class="units-table-footer">
  268. <p>
  269. <?php printf(ngettext("%d database", "%d databases", $i), $i); ?>
  270. </p>
  271. </div>
  272. </div>