PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/local/www/load_balancer_virtual_server_edit.php

https://github.com/vongrippen/pfsense
PHP | 291 lines | 219 code | 28 blank | 44 comment | 47 complexity | bc332de2145ce7048efaa35814b9203d MD5 | raw file
  1. <?php
  2. /* $Id$ */
  3. /*
  4. load_balancer_virtual_server_edit.php
  5. part of pfSense (http://www.pfsense.com/)
  6. Copyright (C) 2005-2008 Bill Marquette <bill.marquette@gmail.com>.
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice,
  11. this list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  18. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  19. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /*
  27. pfSense_MODULE: routing
  28. */
  29. ##|+PRIV
  30. ##|*IDENT=page-loadbalancer-virtualserver-edit
  31. ##|*NAME=Load Balancer: Virtual Server: Edit page
  32. ##|*DESCR=Allow access to the 'Load Balancer: Virtual Server: Edit' page.
  33. ##|*MATCH=load_balancer_virtual_server_edit.php*
  34. ##|-PRIV
  35. require("guiconfig.inc");
  36. if (!is_array($config['load_balancer']['virtual_server'])) {
  37. $config['load_balancer']['virtual_server'] = array();
  38. }
  39. $a_vs = &$config['load_balancer']['virtual_server'];
  40. if (isset($_POST['id']))
  41. $id = $_POST['id'];
  42. else
  43. $id = $_GET['id'];
  44. if (isset($id) && $a_vs[$id]) {
  45. $pconfig = $a_vs[$id];
  46. } else {
  47. // Sane defaults
  48. $pconfig['mode'] = 'redirect';
  49. }
  50. $changedesc = gettext("Load Balancer: Virtual Server:") . " ";
  51. $changecount = 0;
  52. if ($_POST) {
  53. unset($input_errors);
  54. $pconfig = $_POST;
  55. /* input validation */
  56. switch($pconfig['mode']) {
  57. case "redirect": {
  58. $reqdfields = explode(" ", "ipaddr name port mode");
  59. $reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Port"),gettext("Mode"));
  60. break;
  61. }
  62. case "relay": {
  63. $reqdfields = explode(" ", "ipaddr name port mode relay_protocol");
  64. $reqdfieldsn = array(gettext("IP Address"),gettext("Name"),gettext("Port"),gettext("Relay Protocol"));
  65. break;
  66. }
  67. }
  68. do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
  69. for ($i=0; isset($config['load_balancer']['virtual_server'][$i]); $i++)
  70. if (($_POST['name'] == $config['load_balancer']['virtual_server'][$i]['name']) && ($i != $id))
  71. $input_errors[] = gettext("This virtual server name has already been used. Virtual server names must be unique.");
  72. if (strpos($_POST['name'], " ") !== false)
  73. $input_errors[] = gettext("You cannot use spaces in the 'name' field.");
  74. if (!is_port($_POST['port']))
  75. $input_errors[] = gettext("The port must be an integer between 1 and 65535.");
  76. if(!is_ipaddr($_POST['ipaddr']))
  77. $input_errors[] = sprintf(gettext("%s is not a valid IP address."), $_POST['ipaddr']);
  78. if (!$input_errors) {
  79. $vsent = array();
  80. if(isset($id) && $a_vs[$id])
  81. $vsent = $a_vs[$id];
  82. if($vsent['name'] != "")
  83. $changedesc .= " " . sprintf(gettext("modified '%s' vs:"), $vsent['name']);
  84. else
  85. $changedesc .= " " . sprintf(gettext("created '%s' vs:"), $_POST['name']);
  86. update_if_changed("name", $vsent['name'], $_POST['name']);
  87. update_if_changed("descr", $vsent['descr'], $_POST['descr']);
  88. update_if_changed("pool", $vsent['pool'], $_POST['pool']);
  89. update_if_changed("port", $vsent['port'], $_POST['port']);
  90. update_if_changed("sitedown", $vsent['sitedown'], $_POST['sitedown']);
  91. update_if_changed("ipaddr", $vsent['ipaddr'], $_POST['ipaddr']);
  92. update_if_changed("mode", $vsent['mode'], $_POST['mode']);
  93. update_if_changed("relay protocol", $vsent['relay_protocol'], $_POST['relay_protocol']);
  94. if($_POST['sitedown'] == "")
  95. unset($vsent['sitedown']);
  96. if (isset($id) && $a_vs[$id])
  97. $a_vs[$id] = $vsent;
  98. else
  99. $a_vs[] = $vsent;
  100. if ($changecount > 0) {
  101. /* Mark virtual server dirty */
  102. mark_subsystem_dirty('loadbalancer');
  103. write_config($changedesc);
  104. }
  105. header("Location: load_balancer_virtual_server.php");
  106. exit;
  107. }
  108. }
  109. $pgtitle = array(gettext("Services"),gettext("Load Balancer"),gettext("Virtual Server"),gettext("Edit"));
  110. $statusurl = "status_lb_vs.php";
  111. #$statusurl = "status_lb_pool.php";
  112. $logurl = "diag_logs_relayd.php";
  113. include("head.inc");
  114. ?>
  115. <body link="#0000CC" vlink="#0000CC" alink="#0000CC">
  116. <script language="javascript" type="text/javascript">
  117. function updateRelay(m) {
  118. switch (m) {
  119. case "relay": {
  120. $('relay_protocol').enable();
  121. $('relay').appear();
  122. break;
  123. }
  124. case "redirect": {
  125. $('relay_protocol').disable();
  126. $('relay').hide();
  127. break;
  128. }
  129. }
  130. }
  131. document.observe("dom:loaded", function() {
  132. // Setup some observers
  133. $('redirect_mode').observe('click', function(){
  134. updateRelay('redirect');
  135. });
  136. $('relay_mode').observe('click', function(){
  137. updateRelay('relay');
  138. });
  139. // Go ahead and disable the relay stuff, we'll trigger
  140. updateRelay("<?=htmlspecialchars($pconfig['mode']);?>");
  141. });
  142. </script>
  143. <?php include("fbegin.inc"); ?>
  144. <?php if ($input_errors) print_input_errors($input_errors); ?>
  145. <form action="load_balancer_virtual_server_edit.php" method="post" name="iform" id="iform">
  146. <table width="100%" border="0" cellpadding="6" cellspacing="0">
  147. <tr>
  148. <td colspan="3" valign="top" class="listtopic"><?=gettext("Edit Load Balancer - Virtual Server entry"); ?></td>
  149. </tr>
  150. <tr align="left">
  151. <td width="22%" valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
  152. <td width="78%" class="vtable" colspan="2">
  153. <input name="name" type="text" <?if(isset($pconfig['name'])) echo "value=\"{$pconfig['name']}\"";?>size="32" maxlength="32">
  154. </td>
  155. </tr>
  156. <tr align="left">
  157. <td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td>
  158. <td width="78%" class="vtable" colspan="2">
  159. <input name="descr" type="text" <?if(isset($pconfig['descr'])) echo "value=\"{$pconfig['descr']}\"";?>size="64">
  160. </td>
  161. </tr>
  162. <tr align="left">
  163. <td width="22%" valign="top" class="vncellreq"><?=gettext("IP Address"); ?></td>
  164. <td width="78%" class="vtable" colspan="2">
  165. <input name="ipaddr" type="text" <?if(isset($pconfig['ipaddr'])) echo "value=\"{$pconfig['ipaddr']}\"";?> size="16" maxlength="16">
  166. <br><?=gettext("This is normally the WAN IP address that you would like the server to listen on. All connections to this IP and port will be forwarded to the pool cluster."); ?>
  167. </td>
  168. </tr>
  169. <tr align="left">
  170. <td width="22%" valign="top" class="vncellreq"><?=gettext("Port"); ?></td>
  171. <td width="78%" class="vtable" colspan="2">
  172. <input name="port" type="text" <?if(isset($pconfig['port'])) echo "value=\"{$pconfig['port']}\"";?> size="16" maxlength="16">
  173. <br><?=gettext("This is the port that the clients will connect to. All connections to this port will be forwarded to the pool cluster."); ?>
  174. </td>
  175. </tr>
  176. <tr align="left">
  177. <td width="22%" valign="top" class="vncellreq"><?=gettext("Virtual Server Pool"); ?></td>
  178. <td width="78%" class="vtable" colspan="2">
  179. <?php if(count($config['load_balancer']['lbpool']) == 0): ?>
  180. <b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
  181. <?php else: ?>
  182. <select id="pool" name="pool">
  183. <?php
  184. for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
  185. $selected = "";
  186. if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['pool'] )
  187. $selected = " SELECTED";
  188. echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>";
  189. }
  190. ?>
  191. <?php endif; ?>
  192. </select>
  193. </td>
  194. </tr>
  195. <tr align="left">
  196. <td width="22%" valign="top" class="vncellreq"><?=gettext("Fall Back Pool"); ?></td>
  197. <td width="78%" class="vtable" colspan="2">
  198. <?php if(count($config['load_balancer']['lbpool']) == 0): ?>
  199. <b><?=gettext("NOTE:"); ?></b> <?=gettext("Please add a pool on the Pools tab to use this feature."); ?>
  200. <?php else: ?>
  201. <select id="sitedown" name="sitedown">
  202. <option value=""<?=htmlspecialchars($pconfig['sitedown']) == '' ? ' selected' : ''?>><?=gettext("none"); ?></option>
  203. <?php
  204. for ($i = 0; isset($config['load_balancer']['lbpool'][$i]); $i++) {
  205. $selected = "";
  206. if ( $config['load_balancer']['lbpool'][$i]['name'] == $pconfig['sitedown'] )
  207. $selected = " SELECTED";
  208. echo "<option value=\"{$config['load_balancer']['lbpool'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbpool'][$i]['name']}</option>";
  209. }
  210. ?>
  211. </select>
  212. <br><b><?=gettext("NOTE:"); ?></b> <?=gettext("This is the server that clients will be redirected to if *ALL* servers in the pool are offline."); ?>
  213. <?php endif; ?>
  214. </td>
  215. </tr>
  216. <input type="hidden" name="mode" value="redirect_mode">
  217. <!--
  218. <tr align="left">
  219. <td width="22%" valign="top" class="vncellreq">Mode</td>
  220. <td width="78%" class="vtable" colspan="2">
  221. <input id="redirect_mode" type="radio" name="mode" value="redirect"<?=htmlspecialchars($pconfig['mode']) == 'redirect' ? ' checked="checked"': ''?>> Redirect
  222. <input id="relay_mode" type="radio" name="mode" value="relay"<?=htmlspecialchars($pconfig['mode']) == 'relay' ? ' checked="checked"': ''?>> Relay
  223. <br>
  224. </td>
  225. </tr>
  226. -->
  227. <tr id="relay" align="left" style="display:none;">
  228. <td width="22%" valign="top" class="vncellreq"><?=gettext("Relay Protocol"); ?></td>
  229. <td width="78%" class="vtable" colspan="2">
  230. <select id="relay_protocol" name="relay_protocol">
  231. <?php
  232. for ($i = 0; isset($config['load_balancer']['lbprotocol'][$i]); $i++) {
  233. $selected = "";
  234. if ( $config['load_balancer']['lbprotocol'][$i]['name'] == $pconfig['lbprotocol'] )
  235. $selected = " SELECTED";
  236. echo "<option value=\"{$config['load_balancer']['lbprotocol'][$i]['name']}\"{$selected}>{$config['load_balancer']['lbprotocol'][$i]['name']}</option>";
  237. }
  238. ?>
  239. </select>
  240. <br>
  241. </td>
  242. </tr>
  243. <tr align="left">
  244. <td align="left" valign="bottom">
  245. <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Submit"); ?>">
  246. <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
  247. <?php if (isset($id) && $a_vs[$id] && $_GET['act'] != 'dup'): ?>
  248. <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
  249. <?php endif; ?>
  250. </td>
  251. </tr>
  252. </table>
  253. </form>
  254. <br/>
  255. <span class="red"><strong><?=gettext("Note:"); ?></strong></span> <?=gettext("Don't forget to add a firewall rule for the virtual server/pool after you're finished setting it up."); ?>
  256. <?php include("fend.inc"); ?>
  257. </body>
  258. </html>