PageRenderTime 28ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/plugins/nfs-storage/web/nfs-storage-config.php

https://github.com/qyjohn/openqrm
PHP | 336 lines | 250 code | 62 blank | 24 comment | 27 complexity | 10f60651d806807dc165547d9f1eb4c1 MD5 | raw file
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>NFS manual Storage configuration</title>
  5. <link rel="stylesheet" type="text/css" href="../../css/htmlobject.css" />
  6. <link rel="stylesheet" type="text/css" href="nfs-storage.css" />
  7. <link type="text/css" href="/openqrm/base/js/jquery/development-bundle/themes/smoothness/ui.all.css" rel="stylesheet" />
  8. <script type="text/javascript" src="/openqrm/base/js/jquery/js/jquery-1.3.2.min.js"></script>
  9. <script type="text/javascript" src="/openqrm/base/js/jquery/js/jquery-ui-1.7.1.custom.min.js"></script>
  10. <style type="text/css">
  11. .ui-progressbar-value {
  12. background-image: url(/openqrm/base/img/progress.gif);
  13. }
  14. #progressbar {
  15. position: absolute;
  16. left: 150px;
  17. top: 250px;
  18. width: 400px;
  19. height: 20px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="progressbar">
  25. </div>
  26. <?php
  27. /*
  28. This file is part of openQRM.
  29. openQRM is free software: you can redistribute it and/or modify
  30. it under the terms of the GNU General Public License version 2
  31. as published by the Free Software Foundation.
  32. openQRM is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. GNU General Public License for more details.
  36. You should have received a copy of the GNU General Public License
  37. along with openQRM. If not, see <http://www.gnu.org/licenses/>.
  38. Copyright 2009, Matthias Rechenburg <matt@openqrm.com>
  39. */
  40. // error_reporting(E_ALL);
  41. $thisfile = basename($_SERVER['PHP_SELF']);
  42. $RootDir = $_SERVER["DOCUMENT_ROOT"].'/openqrm/base/';
  43. $BaseDir = $_SERVER["DOCUMENT_ROOT"].'/openqrm/';
  44. require_once "$RootDir/include/user.inc.php";
  45. require_once "$RootDir/class/image.class.php";
  46. require_once "$RootDir/class/storage.class.php";
  47. require_once "$RootDir/class/resource.class.php";
  48. require_once "$RootDir/class/deployment.class.php";
  49. require_once "$RootDir/include/htmlobject.inc.php";
  50. $action=htmlobject_request('action');
  51. $nfs_storage_id = htmlobject_request('nfs_storage_id');
  52. $nfs_storage_name = htmlobject_request('nfs_storage_id');
  53. $nfs_lun_name = htmlobject_request('nfs_lun_name');
  54. $nfs_lun_snap_name = htmlobject_request('nfs_lun_snap_name');
  55. $exports_list_update = htmlobject_request('exports_list_update');
  56. global $nfs_storage_id;
  57. global $nfs_storage_name;
  58. global $nfs_lun_name;
  59. global $nfs_lun_snap_name;
  60. global $exports_list_update;
  61. $nfs_storage_fields = array();
  62. foreach ($_REQUEST as $key => $value) {
  63. if (strncmp($key, "nfs_storage_", 11) == 0) {
  64. $nfs_storage_fields[$key] = $value;
  65. }
  66. }
  67. $refresh_delay=1;
  68. $refresh_loop_max=20;
  69. $openqrm = new openqrm_server();
  70. $OPENQRM_SERVER_IP_ADDRESS=$openqrm->get_ip_address();
  71. global $OPENQRM_SERVER_IP_ADDRESS;
  72. global $OPENQRM_SERVER_BASE_DIR;
  73. function redirect_nfs($strMsg, $nfs_storage_id) {
  74. global $thisfile;
  75. global $action;
  76. $url = $thisfile.'?strMsg='.urlencode($strMsg).'&currenttab=tab0&redirect=yes&action='.$action.'&nfs_storage_id='.$nfs_storage_id;
  77. echo "<meta http-equiv=\"refresh\" content=\"0; URL=$url\">";
  78. exit;
  79. }
  80. function wait_for_statfile($sfile) {
  81. global $refresh_delay;
  82. global $refresh_loop_max;
  83. $refresh_loop=0;
  84. while (!file_exists($sfile)) {
  85. sleep($refresh_delay);
  86. $refresh_loop++;
  87. flush();
  88. if ($refresh_loop > $refresh_loop_max) {
  89. return false;
  90. }
  91. }
  92. return true;
  93. }
  94. function show_progressbar() {
  95. ?>
  96. <script type="text/javascript">
  97. $("#progressbar").progressbar({
  98. value: 100
  99. });
  100. var options = {};
  101. $("#progressbar").effect("shake",options,2000,null);
  102. </script>
  103. <?php
  104. flush();
  105. }
  106. // running the actions
  107. if(htmlobject_request('redirect') != 'yes') {
  108. if(htmlobject_request('action') != '') {
  109. switch (htmlobject_request('action')) {
  110. case 'update':
  111. if (strlen($nfs_storage_id)) {
  112. show_progressbar();
  113. if (!strlen($exports_list_update)) {
  114. $redir_msg = "Got emtpy export-list ! Not updating ...";
  115. redirect_nfs($redir_msg, $nfs_storage_id);
  116. }
  117. $storage = new storage();
  118. $storage->get_instance_by_id($nfs_storage_id);
  119. $storage_resource = new resource();
  120. $storage_resource->get_instance_by_id($storage->resource_id);
  121. $storage_resource_id = $storage_resource->id;
  122. $statfile="storage/".$storage_resource_id.".nfs.stat.manual";
  123. if (!file_exists($statfile)) {
  124. $full_path_to_statfile = "$OPENQRM_SERVER_BASE_DIR/openqrm/plugins/nfs-storage/web/$statfile";
  125. $openqrm->send_command("touch $full_path_to_statfile && chmod 777 $full_path_to_statfile");
  126. }
  127. if (!wait_for_statfile($statfile)) {
  128. $redir_msg = "Error creating file ($statfile)";
  129. redirect_nfs($redir_msg, $nfs_storage_id);
  130. exit(0);
  131. }
  132. if (is_writable($statfile)) {
  133. if (!$handle = fopen($statfile, 'w')) {
  134. $redir_msg = "Cannot open file ($statfile)";
  135. redirect_nfs($redir_msg, $nfs_storage_id);
  136. exit(0);
  137. }
  138. if (fwrite($handle, $exports_list_update) === FALSE) {
  139. $redir_msg = "Cannot write to file ($statfile)";
  140. redirect_nfs($redir_msg, $nfs_storage_id);
  141. exit(0);
  142. }
  143. fclose($handle);
  144. } else {
  145. $redir_msg = "$statfile is not writeable !";
  146. redirect_nfs($redir_msg, $nfs_storage_id);
  147. exit(0);
  148. }
  149. $redir_msg = "Updated export-list for NFS storage $nfs_storage_id";
  150. redirect_nfs($redir_msg, $nfs_storage_id);
  151. }
  152. break;
  153. case 'remove':
  154. if (strlen($nfs_storage_id)) {
  155. show_progressbar();
  156. $storage = new storage();
  157. $storage->get_instance_by_id($nfs_storage_id);
  158. $storage_resource = new resource();
  159. $storage_resource->get_instance_by_id($storage->resource_id);
  160. $storage_resource_id = $storage_resource->id;
  161. $statfile="storage/".$storage_resource_id.".nfs.stat.manual";
  162. if (!unlink($statfile)) {
  163. $redir_msg = "Cannot remove file ($statfile)";
  164. redirect_nfs($redir_msg, $nfs_storage_id);
  165. }
  166. $redir_msg = "Removed export-list for NFS storage $nfs_storage_id";
  167. redirect_nfs($redir_msg, $nfs_storage_id);
  168. }
  169. break;
  170. }
  171. }
  172. }
  173. function nfs_storage_config($nfs_storage_id) {
  174. global $OPENQRM_USER;
  175. global $thisfile;
  176. $storage = new storage();
  177. $storage->get_instance_by_id($nfs_storage_id);
  178. $storage_resource = new resource();
  179. $storage_resource->get_instance_by_id($storage->resource_id);
  180. $deployment = new deployment();
  181. $deployment->get_instance_by_id($storage->type);
  182. $table0 = new htmlobject_db_table('storage_id');
  183. $arHead0 = array();
  184. $arHead0['storage_state'] = array();
  185. $arHead0['storage_state']['title'] ='';
  186. $arHead0['storage_icon'] = array();
  187. $arHead0['storage_icon']['title'] ='';
  188. $arHead0['storage_id'] = array();
  189. $arHead0['storage_id']['title'] ='ID';
  190. $arHead0['storage_name'] = array();
  191. $arHead0['storage_name']['title'] ='Name';
  192. $arHead0['storage_ip'] = array();
  193. $arHead0['storage_ip']['title'] ='Ip';
  194. $arHead0['storage_config'] = array();
  195. $arHead0['storage_config']['title'] ='Manual Config.';
  196. $storage_icon="/openqrm/base/plugins/nfs-storage/img/storage.png";
  197. $state_icon="/openqrm/base/img/$storage_resource->state.png";
  198. if (!file_exists($_SERVER["DOCUMENT_ROOT"]."/".$state_icon)) {
  199. $state_icon="/openqrm/base/img/unknown.png";
  200. }
  201. if (file_exists($_SERVER["DOCUMENT_ROOT"]."/".$storage_icon)) {
  202. $resource_icon_default=$storage_icon;
  203. }
  204. $storage_configuration="<img src=\"/openqrm/base/img/storage.png\" width=\"24\" height=\"24\" border=\"0\" alt=\"manual config.\"/>";
  205. $arBody0 = array();
  206. $arBody0[] = array(
  207. 'storage_state' => "<img src=$state_icon>",
  208. 'storage_icon' => "<img width=24 height=24 src=$resource_icon_default>",
  209. 'storage_id' => $storage->id,
  210. 'storage_name' => $storage->name,
  211. 'storage_ip' => $storage_resource->ip,
  212. 'storage_config' => $storage_configuration,
  213. );
  214. $table0->id = 'Tabelle';
  215. $table0->css = 'htmlobject_table';
  216. $table0->border = 1;
  217. $table0->cellspacing = 0;
  218. $table0->cellpadding = 3;
  219. $table0->form_action = $thisfile;
  220. $table0->head = $arHead0;
  221. $table0->body = $arBody0;
  222. $table0->max = 1;
  223. // manual export file existing ?
  224. $storage_resource_id = $storage_resource->id;
  225. $statfile="storage/".$storage_resource_id.".nfs.stat.manual";
  226. if (file_exists($statfile)) {
  227. $exports_list = "<ul type=\"disc\">";
  228. $storage_content=file($statfile);
  229. foreach ($storage_content as $index => $nfs) {
  230. // find export name
  231. $nfs_line = trim($nfs);
  232. if (strlen($nfs_line)) {
  233. $exports_list .= "<li>$nfs_line</li>";
  234. }
  235. }
  236. $exports_list .= "</ul>";
  237. } else {
  238. $exports_list = "no statfile $statfile exists so far <br>";
  239. }
  240. // textarea for adding/updating export file
  241. $exports_list_update_input = "<strong>Put in your updated exported paths in here </strong><br>";
  242. $exports_list_update_input .= "<textarea name=\"exports_list_update\" rows=\"8\" cols=\"40\"></textarea>";
  243. $back_link = "<a href=nfs-storage-manager.php?action=reload&nfs_storage_id=$nfs_storage_id><strong>Back</strong></a>";
  244. // set template
  245. $t = new Template_PHPLIB();
  246. $t->debug = false;
  247. $t->setFile('tplfile', './tpl/' . 'nfs-storage-config.tpl.php');
  248. $t->setVar(array(
  249. 'formaction' => $thisfile,
  250. 'storage_name' => $storage->name,
  251. 'storage_table' => $table0->get_string(),
  252. 'export_list' => $exports_list,
  253. 'exports_list_update_input' => $exports_list_update_input,
  254. 'hidden_nfs_storage_id' => "<input type='hidden' name='nfs_storage_id' value=$nfs_storage_id>",
  255. 'remove' => htmlobject_input('action', array("value" => 'remove', "label" => 'Remove'), 'submit'),
  256. 'submit' => htmlobject_input('action', array("value" => 'update', "label" => 'Update'), 'submit'),
  257. 'back_link' => $back_link,
  258. ));
  259. $disp = $t->parse('out', 'tplfile');
  260. return $disp;
  261. }
  262. $output = array();
  263. $output[] = array('label' => 'Nfs Storage Config', 'value' => nfs_storage_config($nfs_storage_id));
  264. ?>
  265. <script type="text/javascript">
  266. $("#progressbar").remove();
  267. </script>
  268. <?php
  269. echo htmlobject_tabmenu($output);
  270. ?>