ip_main.php 7.29 KB
Newer Older
Alan Garcia's avatar
Alan Garcia committed
1
2
3
4
5
6
<?php 
require_once("../class/config.php");
include_once("head.php");


$fields = array (
7
8
9
10
11
12
13
  "delete_id"           => array ("get",  "integer", ""),
  "delete_affected_id"  => array ("get",  "integer", ""),
  "id"                  => array ("post", "integer", 0),
  "ipsub"               => array ("post", "string", ""),
  "infos"               => array ("post", "string" ,""),
  "s_ipsub"             => array ("post", "integer", ""),
  "s_protocol"          => array ("post", "string", ""),
Alan Garcia's avatar
Alan Garcia committed
14
15
16
);
getFields($fields);

17
18
19
20
21
22
23
24
25
26
if (!empty($s_protocol)) {
  $val="s_affect_".$s_protocol;
  $fields = array( $val => Array('post','string', '') );
  getFields($fields);

  if (! $authip->ip_affected_save($s_ipsub, $s_protocol, $$val) ) {
    $error="Error during ip_affected_save";
  }
}

27
28
29
30
31
32
if (!empty($delete_affected_id)) {
  if (! $authip->ip_affected_delete($delete_affected_id)) {
    $error="Error during deletion";
  }
}

Alan Garcia's avatar
Alan Garcia committed
33
34
if (!empty($delete_id)) {
  if (! $authip->ip_delete($delete_id)) {
35
    $error="Error during deletion";
Alan Garcia's avatar
Alan Garcia committed
36
37
38
  }
}

39
40
if (!empty($ipsub)) {
  if (! $authip->ip_save($id, $ipsub, $infos)) {
Alan Garcia's avatar
Alan Garcia committed
41
42
43
44
    $error="Error during recording";
  }
}

45
46
47
$list_ip = $authip->list_ip();
$ac  = $authip->get_auth_class();
$lac = $authip->list_affected();
Alan Garcia's avatar
Alan Garcia committed
48
49
50
51
52
53
?>

<h3><?php __("Access security"); ?></h3>
<hr id="topbar"/>
<br />

54
<?php if (isset($error) && $error) { ?>
55
  <p class="alert alert-danger"><?php echo $error ; $error=''; ?></p>
Alan Garcia's avatar
Alan Garcia committed
56
57
<?php } ?>

58
59
<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>

60
61
62
<h3><?php __("Enabled rules"); ?></h3>

<table class="tlist">
63
<tr>
64
65
66
  <th><?php __("Authorised IP address or network");?></th>
  <th><?php __("Access type");?></th>
  <th></th>
67
68
69
</tr>
<?php 
  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
73
    //echo "<br/>".$list_ip[$ll['authorised_ip_id']]['ip_human'];
    echo "</span></td>";
Alan Garcia's avatar
Alan Garcia committed
74
    echo "<td>".@$ac[$ll['protocol']]['name'];
75
76
77
78
    if (isset($ac[$ll['protocol']]['values'][$ll['parameters']]) && $ac[$ll['protocol']]['values'][$ll['parameters']]) {
      echo " "._("for")." ".$ac[$ll['protocol']]['values'][$ll['parameters']];
    }
    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
81
82
83
84
    echo "</tr>";
  }
?>
</table>

85
86
<hr/>
<h3><?php __("Add a new rule"); ?></h3>
Alan Garcia's avatar
Alan Garcia committed
87
88
89
90

<?php if (empty($list_ip)) { ?>
  <p><?php __("You need to have some 'Known IP and networks' defined below to define a new rule.") ?></p>
<?php } else { ?>
91
<form method="post" action="ip_main.php" name="main" id="main">
92
<table class="tlistb">
93
94
  <tbody>
    <tr valign="top">
95
96
    <th><?php __("Access type"); ?></th>
    <td class="lst2">
97
98
      <?php foreach ($ac as $a) { ?>
        <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
103
104
105
106
107
108

        <?php if ( sizeof($a['values']) > 1 ) { ?>
           <select name="s_affect_<?php echo htmlentities($a['protocol']);?>" id="s_affect_<?php echo htmlentities($a['protocol']);?>">
             <?php foreach ($a['values'] as $k => $v) { ?>
               <option value="<?php echo htmlentities($k); ?>"><?php echo htmlentities($v); ?></option>
             <?php  } ?>
           </select>
        <?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
115
        </p>
      <?php } ?>
116
117
118
119
120
    </td>
    </tr>
    <tr>
    <th><?php __("Authorized IP address or network"); ?></th>
    <td valign="middle" class="lst2">
121
122
      <p>
      <select name="s_ipsub">
123
        <?php foreach ($list_ip as $li) { ?>
124
125
126
          <option value="<?php echo $li['id']; ?>"><?php echo htmlentities($li['infos']); 
            //echo " - ".$li['ip'] ; if (!($li['subnet']==32 || $li['subnet'] == 128)) echo "/".$li['subnet'];
            ?></option>
127
128
129
130
        <?php } ?>
      </select>
      </p>
    </td>
131
132
133
    </tr>
    <tr>
    <th>&nbsp;</th>
134
    <td valign='middle' class="lst2">
Alan Garcia's avatar
Alan Garcia committed
135
      <input type="submit" class="inb ok" value="<?php __("Save")?>" onclick='return check_accesstype_selected();' />
136
137
138
139
140
    </td>
    </tr>
  </tbody>
</table>
</form>
Alan Garcia's avatar
Alan Garcia committed
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
148
149
150
<?php 
foreach($list_ip as $i) {
  if (checkip($i['ip'])) {
    if ($i['subnet']==32) {
151
      $txt=_("Address IPv4");
152
    } else {
153
      $txt=_("Subnet IPv4");
154
155
156
    }
  } elseif (checkipv6($i['ip'])) {
    if ($i['subnet']==128) {
157
      $txt=_("Address IPv6");
158
    } else {
159
      $txt=_("Subnet IPv6");
160
    }
161
162
163
  } else {
    $txt=_("Error with this IP");
  }
164
  echo "<tr class='lst' ><td>{$i['infos']}</td><td>{$i['ip_human']}</td><td>$txt</td>";
165
  ?>
166
167
  <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>
  <td><div class="ina delete"><a href="ip_main.php?delete_id=<?php echo urlencode($i["id"]) ?>"><?php __("Delete"); ?></a></div></td>
Alan Garcia's avatar
Alan Garcia committed
168
  </tr>
169
170

<?php } ?>
Alan Garcia's avatar
Alan Garcia committed
171
</table>
172
173
174
175
176
177
<br/>
<hr/>
<h3><?php __("Add an IP or a networks");?></h3>

<p><a href="javascript:edit_ip('','<?php echo htmlentities(get_remote_ip())."','Home IP'";?>);" ><?php echo __("Add my current IP"); ?></a></p>
<span id="form_add_ip">
178
<form method="post" action="ip_main.php" name="main" >
179
180
  <p id="reset_edit_ip" style="display:none;"><a href="javascript:reset_edit_ip();"><?php __("Cancel edit")?></a></p>

181
  <input type="hidden" name="id" value="" id="edit_id" />
182
183
184
185
  <table class="tlistb">
  <tr><th><?php __("Name"); ?></th><th><?php __("IP or network. <i>IPv4, IPv6 and subnet allowed</i>"); ?></th><th></th></tr>
  
  <tr class="lst2">
186
187
    <td><input type="text" size='20' maxlength='39' name="ipsub" id="edit_ip" /></td>
    <td><input type="text" size='25' maxlength='200' name="infos" id="edit_infos" /></td>
Alan Garcia's avatar
Alan Garcia committed
188
    <td><input type="submit" class="inb ok" value="<?php __("Save")?>" /></td>
189
  </tr>
190
  </table>
191
192
</form>
</span>
Alan Garcia's avatar
Alan Garcia committed
193
194

<script type="text/javascript">
195
196
197
198
199
  function reset_edit_ip() {
    $("#reset_edit_ip").hide();
    $("#edit_id").val('');
    $("#edit_ip").val('');
    $("#edit_infos").val('');
Alan Garcia's avatar
Alan Garcia committed
200
201
  }

202
203
204
205
  function edit_ip(id, iph, infos) {
    if ( id != '' ) { 
      $("#reset_edit_ip").show();
    }
Alan Garcia's avatar
Alan Garcia committed
206
207
    $("#edit_id").val(id);
    $("#edit_infos").val(infos);
208
    $("#edit_ip").val(iph);
Alan Garcia's avatar
Alan Garcia committed
209
210
  }

211
212
213
214
215
216
217
218
219
function check_accesstype_selected() {
  if ( $('input[name=s_protocol]:radio:checked').val() ) {
    // there is a value
    return true;
  }
  alert("<?php __("Please select an access type"); ?>");
  return false;
}

Alan Garcia's avatar
Alan Garcia committed
220
221
</script>
<?php include_once("foot.php"); ?>