Menu="NetworkSettings"
Title="Routing Table"
Tag="share-alt"
---
<?PHP
/* Copyright 2005-2017, Lime Technology
 * Copyright 2012-2017, Bergware International.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 */
?>

<?
exec("ls --indicator-style=none /sys/class/net|grep -P '^(eth|br|bond)[0-9]'",$list);
?>
<style>
input.fixed{width:200px;}
</style>
<script>
function deleteRoute(button,gateway,route) {
  swal({title:"Are you sure?",text:"This will delete route "+route+" on gateway "+gateway,type:"warning",showCancelButton:true},function(){
    $.post('/webGui/include/RoutingTable.php',{gateway:gateway,route:route,task:'delete'},function(){resetTable();});
  });
}
function routeTable() {
  $.post('/webGui/include/RoutingTable.php',{task:'update'},function(data){
    if (data) $('#route_list').html(data);
    timers.routeTable = setTimeout(routeTable,10000);
  });
}
function resetTable() {
  document.add_routes.route.value = '';
  document.add_routes.gateway.value = '';
  document.add_routes.metric.value = '';
  clearTimeout(timers.routeTable);
  routeTable();
}
$(routeTable);
</script>
<table class="share_status">
<thead><tr><td>Protocol</td><td>Route</td><td>Gateway</td><td>Metric</td><td style="width:8%;text-align:center">Delete</td></tr></thead>
<tbody id="route_list"></tbody>
</table>

<div class="shade-<?=$display['theme']?>" style="margin-top:12px;padding:12px 4px;">
<form markdown="1" name="add_routes" method="POST" action="/webGui/include/RoutingTable.php" target="progressFrame" onsubmit="setTimeout(resetTable,500)">
Enter route + gateway + metric:
: <input type="text" name="route" maxlength="39" value="" class="fixed" placeholder="IPv4/nn or IPv6/nn route" required>
  <input type="text" name="gateway" class="fixed" value="" list="device" placeholder="gateway name or address" required>
  <datalist id="device"><?foreach ($list as $port):?><?echo "<option value='$port'>"?><?endforeach;?></datalist>
  <input type="text" name="metric" min="1" max="9999" value="" class="trim" placeholder="1"><em><i class="fa fa-sort-numeric-asc"></i> optional metric (lowest is preferred)</em>

> Enter a valid IPv4 route in the format *nnn.nnn.nnn.nnn/xx*, e.g. *192.168.1.0/24*<br>
> or enter a valid IPv6 route in the format *nnnn:nnnn:nnnn::nnnn/xxx*, e.g. *fe80::3ad8:2fff:fe25:9709/64*
>
> Select the gateway from the dropdown list or enter a valid IPv4/IPv6 address as gateway value.
>
> The metric value is optional, it defaults to 1. Use it to select the prefered gateway when more than one entry of the same route exist.

&nbsp;
: <input type="submit" name="task" value="Add Route"><input type="button" value=" Done " onclick="done()">
</form>
</div>
