PageRenderTime 55ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/src/plugins/netapp-storage/web/netapp-storage-action.php

https://github.com/qyjohn/openqrm
PHP | 121 lines | 74 code | 17 blank | 30 comment | 8 complexity | 5bc6a40a58e00e8e1163e39984901df9 MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of openQRM.
  4. openQRM is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License version 2
  6. as published by the Free Software Foundation.
  7. openQRM is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with openQRM. If not, see <http://www.gnu.org/licenses/>.
  13. Copyright 2009, Matthias Rechenburg <matt@openqrm.com>
  14. */
  15. $netapp_storage_command = $_REQUEST["netapp_storage_command"];
  16. $RootDir = $_SERVER["DOCUMENT_ROOT"].'/openqrm/base/';
  17. require_once "$RootDir/include/openqrm-database-functions.php";
  18. require_once "$RootDir/include/user.inc.php";
  19. require_once "$RootDir/include/openqrm-server-config.php";
  20. require_once "$RootDir/class/storage.class.php";
  21. require_once "$RootDir/class/resource.class.php";
  22. require_once "$RootDir/class/deployment.class.php";
  23. require_once "$RootDir/class/event.class.php";
  24. require_once "$RootDir/class/authblocker.class.php";
  25. require_once "$RootDir/class/openqrm_server.class.php";
  26. require_once "$RootDir/include/htmlobject.inc.php";
  27. global $IMAGE_INFO_TABLE;
  28. global $DEPLOYMENT_INFO_TABLE;
  29. global $OPENQRM_SERVER_BASE_DIR;
  30. // place for the storage stat files
  31. $StorageDir = $_SERVER["DOCUMENT_ROOT"].'/openqrm/base/plugins/netapp-storage/storage';
  32. $netapp_image_name = htmlobject_request('netapp_image_name');
  33. $event = new event();
  34. $openqrm_server = new openqrm_server();
  35. $OPENQRM_SERVER_IP_ADDRESS=$openqrm_server->get_ip_address();
  36. global $OPENQRM_SERVER_IP_ADDRESS;
  37. // user/role authentication
  38. if ($OPENQRM_USER->role != "administrator") {
  39. $event->log("authorization", $_SERVER['REQUEST_TIME'], 1, "netapp-storage-action", "Un-Authorized access to netapp-storage-actions from $OPENQRM_USER->name", "", "", 0, 0, 0);
  40. exit();
  41. }
  42. $event->log("$netapp_storage_command", $_SERVER['REQUEST_TIME'], 5, "netapp-storage-action", "Processing netapp-storage command $netapp_storage_command", "", "", 0, 0, 0);
  43. if (!file_exists($StorageDir)) {
  44. mkdir($StorageDir);
  45. }
  46. // main actions
  47. switch ($netapp_storage_command) {
  48. case 'init':
  49. // this command creates the following tables
  50. // -> netapp_storage_servers
  51. // na_id INT(5)
  52. // na_storage_id INT(5)
  53. // na_storage_name VARCHAR(20)
  54. // na_storage_user VARCHAR(20)
  55. // na_storage_password VARCHAR(20)
  56. // na_storage_comment VARCHAR(50)
  57. //
  58. $create_netapp_storage_config = "create table netapp_storage_servers(na_id INT(5), na_storage_id INT(5), na_storage_name VARCHAR(20), na_storage_user VARCHAR(20), na_storage_password VARCHAR(20), na_storage_comment VARCHAR(50))";
  59. $db=openqrm_get_db_connection();
  60. $recordSet = &$db->Execute($create_netapp_storage_config);
  61. $event->log("$netapp_storage_command", $_SERVER['REQUEST_TIME'], 5, "netapp-storage-action", "Initialyzed NetApp-storage Server table", "", "", 0, 0, 0);
  62. $db->Close();
  63. break;
  64. case 'uninstall':
  65. $drop_netapp_storage_config = "drop table netapp_storage_servers";
  66. $db=openqrm_get_db_connection();
  67. $recordSet = &$db->Execute($drop_netapp_storage_config);
  68. $event->log("$netapp_storage_command", $_SERVER['REQUEST_TIME'], 5, "netapp-storage-action", "Uninstalled NetApp-storage Server table", "", "", 0, 0, 0);
  69. $db->Close();
  70. break;
  71. case 'get_ident':
  72. if (!file_exists($StorageDir)) {
  73. mkdir($StorageDir);
  74. }
  75. break;
  76. case 'clone_finished':
  77. if (!file_exists($StorageDir)) {
  78. mkdir($StorageDir);
  79. }
  80. $filename = $StorageDir."/".$_POST['filename'];
  81. $filedata = base64_decode($_POST['filedata']);
  82. echo "<h1>$filename</h1>";
  83. $fout = fopen($filename,"wb");
  84. fwrite($fout, $filedata);
  85. fclose($fout);
  86. break;
  87. case 'auth_finished':
  88. // remove storage-auth-blocker if existing
  89. $authblocker = new authblocker();
  90. $authblocker->get_instance_by_image_name($netapp_image_name);
  91. if (strlen($authblocker->id)) {
  92. $event->log('auth_finished', $_SERVER['REQUEST_TIME'], 5, "netapp-storage-action", "Removing authblocker for image $netapp_image_name", "", "", 0, 0, 0);
  93. $authblocker->remove($authblocker->id);
  94. }
  95. break;
  96. default:
  97. $event->log("$netapp_storage_command", $_SERVER['REQUEST_TIME'], 3, "netapp-storage-action", "No such netapp-storage command ($netapp_storage_command)", "", "", 0, 0, 0);
  98. break;
  99. }
  100. ?>