PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/pulse2/web/modules/msc/msc/launch_bundle.php

https://github.com/vmasilva/mmc
PHP | 211 lines | 153 code | 14 blank | 44 comment | 34 complexity | 9420c9aa2460b87cbbd18b7a3e602ad4 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?
  2. /*
  3. * (c) 2004-2007 Linbox / Free&ALter Soft, http://linbox.com
  4. * (c) 2007 Mandriva, http://www.mandriva.com
  5. *
  6. * $Id$
  7. *
  8. * This file is part of Mandriva Management Console (MMC).
  9. *
  10. * MMC is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * MMC is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with MMC; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. require_once('modules/msc/includes/widgets.inc.php');
  25. require_once('modules/msc/includes/utilities.php');
  26. require_once('modules/msc/includes/qactions.inc.php');
  27. require_once('modules/msc/includes/mirror_api.php');
  28. require_once('modules/msc/includes/commands_xmlrpc.inc.php');
  29. require_once('modules/msc/includes/package_api.php');
  30. require_once('modules/msc/includes/scheduler_xmlrpc.php');
  31. require_once('modules/msc/includes/mscoptions_xmlrpc.php');
  32. require_once('modules/msc/includes/bundle_widgets.php');
  33. function launch_bundle($cible, $orders, $gid = null, $proxy = array()) {
  34. $params = array();
  35. foreach (array('start_date', 'end_date', 'create_directory', 'start_script', 'delete_file_after_execute_successful', 'wake_on_lan', 'next_connection_delay', 'max_connection_attempt', 'start_inventory', 'maxbw', 'deployment_intervals', 'copy_mode', 'clean_on_success', 'do_wol', 'do_inventory', 'do_reboot', 'bundle_title') as $param) {
  36. $params[$param] = $_POST[$param];
  37. }
  38. $halt_to = array();
  39. foreach ($_POST as $p=>$v) {
  40. if (preg_match('/^issue_halt_to_/', $p)) {
  41. $p = preg_replace('/^issue_halt_to_/', '', $p);
  42. $halt_to[] = $p;
  43. }
  44. }
  45. $params['issue_halt_to'] = $halt_to;
  46. // given a proxy list and a proxy style, we now have to build or proxy chain
  47. // target structure is an dict using the following stucture: "priority" => array(proxies)
  48. $ordered_proxies = array();
  49. if ($_POST['proxy_mode'] == 'multiple') { // first case: split mode; every proxy got the same priority (1 in our case)
  50. foreach ($proxy as $p) {
  51. array_push($ordered_proxies, array('uuid' => $p, 'priority' => 1, 'max_clients' => $_POST['max_clients_per_proxy']));
  52. }
  53. $params['proxy_mode'] = 'split';
  54. } elseif ($_POST['proxy_mode'] == 'single') { // second case: queue mode; one priority level per proxy, starting at 1
  55. $current_priority = 1;
  56. foreach ($proxy as $p) {
  57. array_push($ordered_proxies, array('uuid' => $p, 'priority' => $current_priority, 'max_clients' => $_POST['max_clients_per_proxy']));
  58. $current_priority += 1;
  59. }
  60. $params['proxy_mode'] = 'queue';
  61. }
  62. // TODO: activate this : msc_command_set_pause($cmd_id);
  63. $ret = add_bundle_api($orders, $cible, $params, $params['copy_mode'], $gid, $ordered_proxies);
  64. if (is_array($ret) && !empty($ret)) {
  65. $commands = $ret[1];
  66. scheduler_start_these_commands('', $commands);
  67. }
  68. return $ret;
  69. }
  70. if (isset($_POST["bconfirmproxy"])) {
  71. /* Start bundle using local proxies */
  72. $proxy = array();
  73. if (isset($_POST["lpmembers"])) {
  74. if ($_POST["local_proxy_selection_mode"] == "semi_auto") {
  75. $members = unserialize(base64_decode($_POST["lpmachines"]));
  76. foreach($members as $member => $name) {
  77. $computer = preg_split("/##/", $member);
  78. $proxy[] = $computer[1];
  79. }
  80. shuffle($proxy);
  81. $proxy = array_splice($proxy, 0, $_POST['proxy_number']);
  82. } elseif ($_POST["local_proxy_selection_mode"] == "manual") {
  83. $members = unserialize(base64_decode($_POST["lpmembers"]));
  84. foreach($members as $member => $name) {
  85. $computer = preg_split("/##/", $member);
  86. $proxy[] = $computer[1];
  87. }
  88. }
  89. }
  90. $gid = $_POST["gid"];
  91. /* package order in bundle */
  92. $members = unserialize(base64_decode($_POST["lmembers"]));
  93. $sort = new RenderedMSCBundleSortG($group, $members);
  94. $orders = $sort->get_sort_order();
  95. $bundle_id = launch_bundle(array(), $orders, $gid, $proxy);
  96. header("Location: ".urlStrRedirect("base/computers/groupmsctabs", array('tab'=>'grouptablogs', 'gid'=>$gid, 'bundle_id'=>$id_bundle[0])));}
  97. if (isset($_POST["local_proxy"]) && isset($_POST["blaunch_bundle"])) {
  98. require('modules/msc/msc/local_proxy.php');
  99. /* Unset this so that bundle is not launched */
  100. unset($_POST["blaunch_bundle"]);
  101. }
  102. /* single target handling */
  103. if (isset($_GET['uuid']) and !isset($_GET['badvanced']) and !isset($_POST['launchAction'])) {
  104. $machine = getMachine(array('uuid'=>$_GET['uuid']));
  105. if ($machine->uuid != $_GET['uuid']) { // Not matching computer found, show error
  106. $msc_host = new RenderedMSCHostDontExists($_GET['hostname']);
  107. $msc_host->headerDisplay();
  108. } else { // We found a matching computer
  109. // stage 2: order bundle
  110. if (isset($_POST["bsort_bundle"])) { // propose to reorder the bundles
  111. $members = unserialize(base64_decode($_POST["lmembers"]));
  112. $sort = new RenderedMSCBundleSortM($machine, $members);
  113. $sort->display();
  114. // stage 4a: user choosed to run the bundle without going to advanced mode
  115. } elseif (isset($_POST["blaunch_bundle"])) { // send the cmd to msc plugin, launch all commands, and then goes on the logs page
  116. $members = unserialize(base64_decode($_POST["lmembers"]));
  117. $sort = new RenderedMSCBundleSortM($machine, $members);
  118. $orders = $sort->get_sort_order();
  119. // check bundle order
  120. if (!$sort->check_sort_order($orders)) {
  121. $sort->display_ordered($orders);
  122. } else {
  123. $cible = array($machine->uuid);
  124. $id_bundle = launch_bundle($cible, $orders);
  125. header("Location: " . urlStrRedirect("base/computers/msctabs", array('tab'=>'tablogs', 'uuid'=>$machine->uuid, 'hostname'=>$machine->hostname, 'bundle_id'=>$id_bundle[0])));
  126. }
  127. // stage 3: user choosed to go into advanced mode
  128. } elseif (isset($_POST["badvanced_bundle"])) {
  129. $members = unserialize(base64_decode($_POST["lmembers"]));
  130. $sort = new RenderedMSCBundleSortAdvM($machine, $members);
  131. $sort->display();
  132. // stage 4b: user choosed to run the bundle while in advanced mode
  133. } elseif (isset($_POST["badvanced_bundle_valid"])) {
  134. $members = unserialize(base64_decode($_POST["lmembers"]));
  135. $sort = new RenderedMSCBundleSortAdvM($machine, $members);
  136. $orders = $sort->get_sort_order();
  137. // check bundle order
  138. if (!$sort->check_sort_order($orders)) {
  139. $sort->display_ordered($orders);
  140. } else {
  141. $cible = array($machine->uuid);
  142. $id_bundle = launch_bundle($cible, $orders);
  143. header("Location: ".urlStrRedirect("base/computers/groupmsctabs", array('tab'=>'grouptablogs', 'uuid'=>$machine->uuid, 'hostname'=>$machine->hostname, 'bundle_id'=>$id_bundle[0])));
  144. }
  145. // stage 1: packages selection
  146. } else {
  147. // display packages which may be put in the bundle
  148. $list = new RenderedMSCBundleChoiceM($machine);
  149. $list->display();
  150. }
  151. }
  152. }
  153. /* group display */
  154. if (!isset($_GET['badvanced']) && isset($_GET['gid']) && !isset($_POST['launchAction']) && !isset($_GET['uuid']) && !isset($_POST["local_proxy"])) {
  155. $group = new Group($_GET['gid'], true);
  156. // stage 2: order bundle
  157. if (isset($_POST["bsort_bundle"])) {
  158. $members = unserialize(base64_decode($_POST["lmembers"]));
  159. $sort = new RenderedMSCBundleSortG($group, $members);
  160. $sort->display();
  161. // stage 4a: user choosed to run the bundle without going to advanced mode
  162. } elseif (isset($_POST["blaunch_bundle"])) {
  163. $members = unserialize(base64_decode($_POST["lmembers"]));
  164. $sort = new RenderedMSCBundleSortG($group, $members);
  165. $orders = $sort->get_sort_order();
  166. if (!$sort->check_sort_order($orders)) {
  167. $sort->display_ordered($orders);
  168. } else {
  169. $cible = array_map("onlyValues", $group->getResult(0, -1));
  170. $id_bundle = launch_bundle($cible, $orders, $group->id);
  171. header("Location: ".urlStrRedirect("base/computers/groupmsctabs", array('tab'=>'grouptablogs', 'gid'=>$group->id, 'bundle_id'=>$id_bundle[0])));
  172. }
  173. // stage 3: user choosed to go into advanced mode
  174. } elseif (isset($_POST["badvanced_bundle"])) {
  175. $members = unserialize(base64_decode($_POST["lmembers"]));
  176. $sort = new RenderedMSCBundleSortAdvG($group, $members);
  177. $sort->display();
  178. // stage 4b: user choosed to run the bundle while in advanced mode
  179. } elseif (isset($_POST["badvanced_bundle_valid"])) {
  180. $members = unserialize(base64_decode($_POST["lmembers"]));
  181. $sort = new RenderedMSCBundleSortAdvG($group, $members);
  182. $orders = $sort->get_sort_order();
  183. // check bundle order
  184. if (!$sort->check_sort_order($orders)) {
  185. $sort->display_ordered($orders);
  186. } else {
  187. $cible = array_map("onlyValues", $group->getResult(0, -1));
  188. $id_bundle = launch_bundle($cible, $orders, $group->id);
  189. header("Location: ".urlStrRedirect("base/computers/groupmsctabs", array('tab'=>'grouptablogs', 'gid'=>$group->id, 'bundle_id'=>$id_bundle[0])));
  190. }
  191. // stage 1: packages selection
  192. } else {
  193. $list = new RenderedMSCBundleChoiceG($group);
  194. $list->display();
  195. }
  196. }
  197. ?>