Alternc  3.2
Alternc logiel libre pour l'hébergement
 All Data Structures Namespaces Files Functions Variables Pages
ip_main.php
Go to the documentation of this file.
1 <?php
2 require_once("../class/config.php");
3 include_once("head.php");
4 
5 
6 $fields = array (
7  "delete_id" => array ("get", "integer", ""),
8  "delete_affected_id" => array ("get", "integer", ""),
9  "id" => array ("post", "integer", 0),
10  "ipsub" => array ("post", "string", ""),
11  "infos" => array ("post", "string" ,""),
12  "s_ipsub" => array ("post", "integer", ""),
13  "s_protocol" => array ("post", "string", ""),
14 );
16 
17 if (!empty($s_protocol)) {
18  $val="s_affect_".$s_protocol;
19  $fields = array( $val => Array('post','string', '') );
21 
22  if (! $authip->ip_affected_save($s_ipsub, $s_protocol, $$val) ) {
23  $error="Error during ip_affected_save";
24  }
25 }
26 
27 if (!empty($delete_affected_id)) {
28  if (! $authip->ip_affected_delete($delete_affected_id)) {
29  $error="Error during deletion";
30  }
31 }
32 
33 if (!empty($delete_id)) {
34  if (! $authip->ip_delete($delete_id)) {
35  $error="Error during deletion";
36  }
37 }
38 
39 if (!empty($ipsub)) {
40  if (! $authip->ip_save($id, $ipsub, $infos)) {
41  $error="Error during recording";
42  }
43 }
44 
45 $list_ip = $authip->list_ip();
46 $ac = $authip->get_auth_class();
47 $lac = $authip->list_affected();
48 ?>
49 
50 <h3><?php __("Access security"); ?></h3>
51 <hr id="topbar"/>
52 <br />
53 
54 <?php if (isset($error) && $error) { ?>
55  <p class="alert alert-danger"><?php echo $error ; $error=''; ?></p>
56 <?php } ?>
57 
58 <p><?php __("Here you can add rules to restrict access to AlternC's services, filtered by IP. First, add trusted IPs in the 'Known IP and networks' list. Then, add rules to grant access on services to the chosen IPs from this list.") ?></p>
59 
60 <h3><?php __("Enabled rules"); ?></h3>
61 
62 <table class="tlist">
63 <tr>
64  <th><?php __("Authorised IP address or network");?></th>
65  <th><?php __("Access type");?></th>
66  <th></th>
67 </tr>
68 <?php
69  foreach ($lac as $ll) {
70  echo "<tr class='lst' >";
71  echo "<td><span title=\"{$list_ip[$ll['authorised_ip_id']]['ip_human']}\">".$list_ip[$ll['authorised_ip_id']]['infos'];
72  //echo "<br/>".$list_ip[$ll['authorised_ip_id']]['ip_human'];
73  echo "</span></td>";
74  echo "<td>".@$ac[$ll['protocol']]['name'];
75  if (isset($ac[$ll['protocol']]['values'][$ll['parameters']]) && $ac[$ll['protocol']]['values'][$ll['parameters']]) {
76  echo " "._("for")." ".$ac[$ll['protocol']]['values'][$ll['parameters']];
77  }
78  echo "</td>";
79  echo '<td><div class="ina delete"><a href="ip_main.php?delete_affected_id='.urlencode($ll["id"]).'">'._("Delete").'</a></div></td>';
80  echo "</tr>";
81  }
82 ?>
83 </table>
84 
85 <hr/>
86 <h3><?php __("Add a new rule"); ?></h3>
87 
88 <?php if (empty($list_ip)) { ?>
89  <p><?php __("You need to have some 'Known IP and networks' defined below to define a new rule.") ?></p>
90 <?php } else { ?>
91 <form method="post" action="ip_main.php" name="main" id="main">
92 <table class="tlistb">
93  <tbody>
94  <tr valign="top">
95  <th><?php __("Access type"); ?></th>
96  <td class="lst2">
97  <?php foreach ($ac as $a) { ?>
98  <p>
99  <input type="radio" name="s_protocol" id="s_protocol_<?php echo htmlentities($a['protocol']);?>" value="<?php echo htmlentities($a['protocol']);?>" />
100  <label for="s_protocol_<?php echo htmlentities($a['protocol']);?>"><?php echo htmlentities($a['name']); ?></label>
101 
102  <?php if ( sizeof($a['values']) > 1 ) { ?>
103  <select name="s_affect_<?php echo htmlentities($a['protocol']);?>" id="s_affect_<?php echo htmlentities($a['protocol']);?>">
104  <?php foreach ($a['values'] as $k => $v) { ?>
105  <option value="<?php echo htmlentities($k); ?>"><?php echo htmlentities($v); ?></option>
106  <?php } ?>
107  </select>
108  <?php } else { ?>
109  <?php foreach ($a['values'] as $k => $v) { ?>
110  <label><b><?php echo htmlentities($v); ?></b></label>
111  <input type=hidden name="s_affect_<?php echo htmlentities($a['protocol']);?>" id="s_affect_<?php echo htmlentities($a['protocol']);?>" value="<?php echo htmlentities($k); ?>" readonly />
112  <?php } ?>
113  <?php } ?>
114  </p>
115  <?php } ?>
116  </td>
117  </tr>
118  <tr>
119  <th><?php __("Authorized IP address or network"); ?></th>
120  <td valign="middle" class="lst2">
121  <p>
122  <select name="s_ipsub">
123  <?php foreach ($list_ip as $li) { ?>
124  <option value="<?php echo $li['id']; ?>"><?php echo htmlentities($li['infos']);
125  //echo " - ".$li['ip'] ; if (!($li['subnet']==32 || $li['subnet'] == 128)) echo "/".$li['subnet'];
126  ?></option>
127  <?php } ?>
128  </select>
129  </p>
130  </td>
131  </tr>
132  <tr>
133  <th>&nbsp;</th>
134  <td valign='middle' class="lst2">
135  <input type="submit" class="inb ok" value="<?php __("Save")?>" onclick='return check_accesstype_selected();' />
136  </td>
137  </tr>
138  </tbody>
139 </table>
140 </form>
141 <?php } // empty $list_ip ?>
142 <br/>
143 <hr/>
144 <h3><?php __("Known IP and networks");?></h3>
145 <table class="tlist">
146 <tr><th><?php __("Name"); ?></th><th><?php __("IP or network"); ?></th><th><?php __("Type"); ?></th><th colspan='2'></th></tr>
147 <?php
148 foreach($list_ip as $i) {
149  if (checkip($i['ip'])) {
150  if ($i['subnet']==32) {
151  $txt=_("Address IPv4");
152  } else {
153  $txt=_("Subnet IPv4");
154  }
155  } elseif (checkipv6($i['ip'])) {
156  if ($i['subnet']==128) {
157  $txt=_("Address IPv6");
158  } else {
159  $txt=_("Subnet IPv6");
160  }
161  } else {
162  $txt=_("Error with this IP");
163  }
164  echo "<tr class='lst' ><td>{$i['infos']}</td><td>{$i['ip_human']}</td><td>$txt</td>";
165  ?>
166  <td><div class="ina edit"><a href="javascript:edit_ip(<?php echo "'".htmlentities($i['id'])."','".htmlentities($i['ip_human'])."','".htmlentities($i['infos'])."'"; ?>);"><?php __("Edit"); ?></a></div></td>
167  <td><div class="ina delete"><a href="ip_main.php?delete_id=<?php echo urlencode($i["id"]) ?>"><?php __("Delete"); ?></a></div></td>
168  </tr>
169 
170 <?php } ?>
171 </table>
172 <br/>
173 <hr/>
174 <h3><?php __("Add an IP or a networks");?></h3>
175 
176 <p><a href="javascript:edit_ip('','<?php echo htmlentities(get_remote_ip())."','Home IP'";?>);" ><?php echo __("Add my current IP"); ?></a></p>
177 <span id="form_add_ip">
178 <form method="post" action="ip_main.php" name="main" >
179  <p id="reset_edit_ip" style="display:none;"><a href="javascript:reset_edit_ip();"><?php __("Cancel edit")?></a></p>
180 
181  <input type="hidden" name="id" value="" id="edit_id" />
182  <table class="tlistb">
183  <tr><th><?php __("Name"); ?></th><th><?php __("IP or network. <i>IPv4, IPv6 and subnet allowed</i>"); ?></th><th></th></tr>
184 
185  <tr class="lst2">
186  <td><input type="text" size='20' maxlength='39' name="ipsub" id="edit_ip" /></td>
187  <td><input type="text" size='25' maxlength='200' name="infos" id="edit_infos" /></td>
188  <td><input type="submit" class="inb ok" value="<?php __("Save")?>" /></td>
189  </tr>
190  </table>
191 </form>
192 </span>
193 
194 <script type="text/javascript">
195  function reset_edit_ip() {
196  $("#reset_edit_ip").hide();
197  $("#edit_id").val('');
198  $("#edit_ip").val('');
199  $("#edit_infos").val('');
200  }
201 
202  function edit_ip(id, iph, infos) {
203  if ( id != '' ) {
204  $("#reset_edit_ip").show();
205  }
206  $("#edit_id").val(id);
207  $("#edit_infos").val(infos);
208  $("#edit_ip").val(iph);
209  }
210 
211 function check_accesstype_selected() {
212  if ( $('input[name=s_protocol]:radio:checked').val() ) {
213  // there is a value
214  return true;
215  }
216  alert("<?php __("Please select an access type"); ?>");
217  return false;
218 }
219 
220 </script>
221 <?php include_once("foot.php"); ?>