(BSD 2 clause) * Copyright (c) 2007 Jonathan Watt (BSD 2 clause) * Copyright (c) 2007 Scott Dale (BSD 2 clause) * All rights reserved. * * originally part of m0n0wall (http://m0n0.ch/wall) * Copyright (c) 2003-2004 Manuel Kasper . * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ $nocsrf = true; require_once("auth_check.inc"); require_once("functions.inc"); require_once("ipsec.inc"); // Compose the table contents and pass it back to the ajax caller if ($_REQUEST && $_REQUEST['ajax']) { if (isset($config['ipsec']['phase1'])) { $spd = ipsec_dump_spd(); $sad = ipsec_dump_sad(); $mobile = ipsec_dump_mobile(); $ipsec_status = ipsec_list_sa(); $activecounter = 0; $inactivecounter = 0; $ipsec_detail_array = array(); $ikenum = array(); if (isset($config['ipsec']['phase2'])) { foreach ($config['ipsec']['phase2'] as $ph2ent) { if (!ipsec_lookup_phase1($ph2ent,$ph1ent)) { continue; } if ($ph2ent['remoteid']['type'] == "mobile" || isset($ph1ent['mobile'])) { continue; } if (isset($ph1ent['disabled']) || isset($ph2ent['disabled'])) { continue; } if (empty($ph1ent['iketype']) || $ph1ent['iketype'] == 'ikev1') { if (!isset($ikenum[$ph1ent['ikeid']])) { $ikenum[$ph1ent['ikeid']] = 0; } else { $ikenum[$ph1ent['ikeid']]++; } $ikeid = "con{$ph1ent['ikeid']}00" . $ikenum[$ph1ent['ikeid']]; } else { if (isset($ikenum[$ph1ent['ikeid']])) { continue; } $ikeid = "con{$ph1ent['ikeid']}"; $ikenum[$ph1ent['ikeid']] = true; } $found = false; foreach ($ipsec_status as $id => $ikesa) { if (isset($ikesa['child-sas'])) { foreach ($ikesa['child-sas'] as $childid => $childsa) { list($childcid, $childsid) = explode('-', $childid, 2); if ($ikeid == $childcid) { $found = true; break; } } } else if ($ikeid == $id) { $found = true; } if ($found === true) { if ($ikesa['state'] == 'ESTABLISHED') { /* tunnel is up */ $iconfn = "true"; $activecounter++; } else { /* tunnel is down */ $iconfn = "false"; $inactivecounter++; } break; } } if ($found === false) { /* tunnel is down */ $iconfn = "false"; $inactivecounter++; } $ipsec_detail_array[] = array('src' => convert_friendly_interface_to_friendly_descr($ph1ent['interface']), 'dest' => $ph1ent['remote-gateway'], 'remote-subnet' => ipsec_idinfo_to_text($ph2ent['remoteid']), 'descr' => $ph2ent['descr'], 'status' => $iconfn); } } unset($ikenum); } // Generate JSON formatted data for the widget to update from $jsondata = "{"; $jsondata .= "\"overview\":\""; $jsondata .= ""; $jsondata .= "" . $activecounter . ""; $jsondata .= "" . $inactivecounter . ""; $jsondata .= "" . (is_array($mobile['pool']) ? htmlspecialchars($mobile['pool'][0]['usage']) : '0') . ""; $jsondata .= ""; $jsondata .= "\",\n"; $jsondata .= "\"tunnel\":\""; foreach ($ipsec_detail_array as $ipsec) { $jsondata .= ""; $jsondata .= "" . htmlspecialchars($ipsec['src']) . ""; $jsondata .= "" . $ipsec['remote-subnet'] . "
(" . htmlspecialchars($ipsec['dest']) . ")"; $jsondata .= "" . htmlspecialchars($ipsec['descr']) . ""; if ($ipsec['status'] == "true") { $jsondata .= ''; } else { $jsondata .= ''; } $jsondata .= ""; } $jsondata .= "\",\n"; $jsondata .= "\"mobile\":\""; if (is_array($mobile['pool'])) { foreach ($mobile['pool'] as $pool) { if (!is_array($pool['lease'])) { continue; } foreach ($pool['lease'] as $muser) { $jsondata .= ""; $jsondata .= "" . htmlspecialchars($muser['id']) . ""; $jsondata .= "" . htmlspecialchars($muser['host']) . ""; $jsondata .= "" . htmlspecialchars($muser['status']) . ""; $jsondata .= ""; } } } else { $jsondata .= "\"}"; } print($jsondata); exit; } $widgetkey_nodash = str_replace("-", "", $widgetkey); if (isset($config['ipsec']['phase1'])) { $tab_array = array(); $tab_array[] = array(gettext("Overview"), true, $widgetkey_nodash . "-Overview"); $tab_array[] = array(gettext("Tunnels"), false, $widgetkey_nodash . "-tunnel"); $tab_array[] = array(gettext("Mobile"), false, $widgetkey_nodash . "-mobile"); display_widget_tabs($tab_array); } $mobile = ipsec_dump_mobile(); $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; if (isset($config['ipsec']['phase2'])): ?>

here.')?>