/src/www/exec_cmd.inc
PHP | 590 lines | 588 code | 2 blank | 0 comment | 148 complexity | 27ae2998bd58744a4a3aaedd647d98c2 MD5 | raw file
- <?php
- require_once("find_int.inc");
- require_once 'Net/IPv4.php';
- function exec_int_config_cmd($postrointprint, $rointconfig) {
- $name = $postrointprint[$rointconfig]['name'];
- $ipaddressvalue = $postrointprint[$rointconfig]['ipaddressvalue'];
- $ipsubnetvalue = $postrointprint[$rointconfig]['ipsubnetvalue'];
- if (($ipaddressvalue != "") && ($ipsubnetvalue != "")) {
- $tmp = shell_exec("sudo ifconfig $name $ipaddressvalue netmask $ipsubnetvalue");
- }
- return 0;
- }
- function restart_network() {
- $tmp = shell_exec("sudo /etc/init.d/networking restart");
- return 0;
- }
- function flush_route() {
- $tmp = shell_exec("sudo route del default");
- return 0;
- }
- function check_emuromode() {
- if (file_exists("/root/alm/switch")) {
- $tmp = shell_exec("sudo rm -rf /root/alm/switch");
- }
- restore_router_mode_lite();
- if (!file_exists("/root/alm/router")) {
- $tmp = shell_exec("sudo mkdir /root/alm/router");
- }
- }
- function check_emuswmode() {
- if (file_exists("/root/alm/router")) {
- $tmp = shell_exec("sudo rm -rf /root/alm/router");
- }
- restore_switch_mode_lite();
- if (!file_exists("/root/alm/switch")) {
- $tmp = shell_exec("sudo mkdir /root/alm/switch");
- }
- }
- function startupmag() {
- find_all_int($all_int);
- $tmp = shell_exec("sudo /usr/sbin/brctl addbr br0");
- $tmp = shell_exec("ifconfig br0 up");
- startup_all_int($all_int);
- }
- function restore_switch_mode() {
- find_all_int($all_int);
- $tmp = shell_exec("ifconfig br0 up");
- startup_all_int($all_int);
- set_router_mode($all_int);
- set_switch_mode($all_int);
- }
- function restore_router_mode() {
- find_all_int($all_int);
- $tmp = shell_exec("ifconfig br0 up");
- startup_all_int($all_int);
- set_switch_mode($all_int);
- set_router_mode($all_int);
- }
- function set_switch_mode($all_int) {
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /usr/sbin/brctl addif br0 $int");
- }
- $tmp = shell_exec("sudo /sbin/ifconfig br0 192.168.250.1 netmask 255.255.255.0");
- }
- function set_router_mode($all_int) {
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /usr/sbin/brctl delif br0 $int");
- }
- $k = 200;
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /sbin/ifconfig $int 192.168." . "$k" . ".1 netmask 255.255.255.0");
- $k++;
- }
- $tmp = shell_exec("sudo echo 1 > /proc/sys/net/ipv4/ip_forward");
- }
- function restore_switch_mode_lite() {
- find_all_int($all_int);
- $tmp = shell_exec("ifconfig br0 up");
- startup_all_int($all_int);
- set_router_mode_lite($all_int);
- set_switch_mode_lite($all_int);
- }
- function restore_router_mode_lite() {
- find_all_int($all_int);
- $tmp = shell_exec("ifconfig br0 up");
- startup_all_int($all_int);
- set_switch_mode_lite($all_int);
- set_router_mode_lite($all_int);
- }
- function set_switch_mode_lite($all_int) {
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /usr/sbin/brctl addif br0 $int");
- }
- }
- function set_router_mode_lite($all_int) {
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /usr/sbin/brctl delif br0 $int");
- }
- $tmp = shell_exec("sudo echo 1 > /proc/sys/net/ipv4/ip_forward");
- }
- function startup_all_int($all_int) {
- foreach ($all_int as $startint) {
- $tmp = shell_exec("sudo ifconfig $startint up");
- }
- }
- function reset_magnolia() {
- find_all_int($all_int);
- foreach ($all_int as $int) {
- $tmp = shell_exec("sudo /sbin/tc qdisc del dev $int root");
- }
- }
- function check_speed($emurointconfig, &$ethspeednum) {
- $ethspeedinfo = shell_exec("sudo ethtool $emurointconfig | grep -i speed");
- if (isset($ethspeedmatch)) { unset($ethspeedmatch); }
- preg_match_all('/Speed: (.*)Mb\/s/i', $ethspeedinfo, $ethspeedmatch);
- if (isset($ethspeedmatch[1][0])) {
- $ethspeed = $ethspeedmatch[1][0];
- $ethspeednum = ((int)$ethspeed) * 1000;
- } else {
- $ethspeednum = 100000;
- }
- }
- function exec_emuroint_cmd($postemurointprint, $emurointconfig, $ethspeednum, $x) {
- $name = $postemurointprint[$emurointconfig]['name'];
- $bandwidth = $postemurointprint[$emurointconfig]['bandwidth'];
- $delay = $postemurointprint[$emurointconfig]['delay'];
- $jitter = $postemurointprint[$emurointconfig]['jitter'];
- $delaycorr = $postemurointprint[$emurointconfig]['delaycorr'];
- $delaydist = $postemurointprint[$emurointconfig]['delaydist'];
- $packetloss = $postemurointprint[$emurointconfig]['packetloss'];
- $packetlosscorr = $postemurointprint[$emurointconfig]['packetlosscorr'];
- $packetdup = $postemurointprint[$emurointconfig]['packetdup'];
- $packetdupcorr = $postemurointprint[$emurointconfig]['packetdupcorr'];
- $packetreord = $postemurointprint[$emurointconfig]['packetreord'];
- $packetreordcorr = $postemurointprint[$emurointconfig]['packetreordcorr'];
- $packetreordgap = $postemurointprint[$emurointconfig]['packetreordgap'];
- $sourceipsubnet = $postemurointprint[$emurointconfig]['sourceipsubnet'];
- $destipsubnet = $postemurointprint[$emurointconfig]['destipsubnet'];
- $portnum = $postemurointprint[$emurointconfig]['portnum'];
- $emulationtag = FALSE;
-
- if ($bandwidth!="" && ($delay!="" || $packetloss!="" || $packetdup!="" || $packetreord!="" || $packetreordgap!="")) {
- $emulationtag = TRUE;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent root handle 1:0 htb default 11";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:11 htb rate ".(strval($ethspeednum/10))."kbit";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:11 handle 11:0 sfq perturb 10";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:".$x." htb rate ".$bandwidth."kbit";
- $final_cmd[] = $cmd;
- $netem_cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:".$x." handle ".$x.":0 netem";
- if ($delay!="") {
- $netem_cmd = $netem_cmd . " " . "delay " . $delay . "ms";
- if ($jitter!="") {
- $netem_cmd = $netem_cmd . " " . $jitter . "ms";
- }
- if ($delaycorr!="") {
- $netem_cmd = $netem_cmd . " " . $delaycorr . "%";
- }
- if ($delaydist!="") {
- $netem_cmd = $netem_cmd . " " . "distribution " . $delaydist;
- }
- if ($packetreord!="") {
- $netem_cmd = $netem_cmd . " " . "reorder " . $packetreord . "%";
- if ($packetreordcorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetreordcorr . "%";
- }
- }
- if ($packetreord=="" && $packetreordgap!="") {
- $netem_cmd = $netem_cmd . " " . "gap " . $packetreordgap;
- }
- }
- if ($packetloss!="") {
- $netem_cmd = $netem_cmd . " " . "loss " . $packetloss . "%";
- if ($packetlosscorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetlosscorr . "%";
- }
- }
- if ($packetdup!="") {
- $netem_cmd = $netem_cmd . " " . "duplicate " . $packetdup . "%";
- if ($packetdupcorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetdupcorr . "%";
- }
- }
- $final_cmd[] = $netem_cmd;
- } else if ($bandwidth!="" && ($delay=="" && $packetloss=="" && $packetdup=="" && $packetreord=="" && $packetreordgap=="")) {
- $emulationtag = TRUE;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent root handle 1:0 htb default 11";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:11 htb rate ".(strval($ethspeednum/10))."kbit";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:11 handle 11:0 sfq perturb 10";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:".$x." htb rate ".$bandwidth."kbit";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:".$x." handle ".$x.":0 sfq perturb 10";
- $final_cmd[] = $cmd;
- } else if ($bandwidth=="" && ($delay!="" || $packetloss!="" || $packetdup!="" || $packetreord!="" || $packetreordgap!="")) {
- $emulationtag = TRUE;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent root handle 1:0 htb default 11";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:11 htb rate ".(strval($ethspeednum/10))."kbit";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:11 handle 11:0 sfq perturb 10";
- $final_cmd[] = $cmd;
- $cmd = "sudo /sbin/tc class add dev $emurointconfig parent 1:0 classid 1:".$x." htb rate ".(strval($ethspeednum/2))."kbit";
- $final_cmd[] = $cmd;
- $netem_cmd = "sudo /sbin/tc qdisc add dev $emurointconfig parent 1:".$x." handle ".$x.":0 netem";
- if ($delay!="") {
- $netem_cmd = $netem_cmd . " " . "delay " . $delay . "ms";
- if ($jitter!="") {
- $netem_cmd = $netem_cmd . " " . $jitter . "ms";
- }
- if ($delaycorr!="") {
- $netem_cmd = $netem_cmd . " " . $delaycorr . "%";
- }
- if ($delaydist!="") {
- $netem_cmd = $netem_cmd . " " . "distribution " . $delaydist;
- }
- if ($packetreord!="") {
- $netem_cmd = $netem_cmd . " " . "reorder " . $packetreord . "%";
- if ($packetreordcorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetreordcorr . "%";
- }
- }
- if ($packetreord=="" && $packetreordgap!="") {
- $netem_cmd = $netem_cmd . " " . "gap " . $packetreordgap;
- }
- }
- if ($packetloss!="") {
- $netem_cmd = $netem_cmd . " " . "loss " . $packetloss . "%";
- if ($packetlosscorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetlosscorr . "%";
- }
- }
- if ($packetdup!="") {
- $netem_cmd = $netem_cmd . " " . "duplicate " . $packetdup . "%";
- if ($packetdupcorr!="") {
- $netem_cmd = $netem_cmd . " " . $packetdupcorr . "%";
- }
- }
- $final_cmd[] = $netem_cmd;
- } else {
- }
- if ($emulationtag == TRUE) {
- $filter_cmd = "sudo /sbin/tc filter add dev $emurointconfig protocol ip parent 1:0 prio 1 u32";
- if ($sourceipsubnet!="") {
- $filter_cmd = $filter_cmd . " " . "match ip src $sourceipsubnet";
- } else {
- $filter_cmd = $filter_cmd . " " . "match ip src 0.0.0.0/0";
- }
- if ($destipsubnet!="") {
- $filter_cmd = $filter_cmd . " " . "match ip dst $destipsubnet";
- } else {
- $filter_cmd = $filter_cmd . " " . "match ip dst 0.0.0.0/0";
- }
- if ($portnum!="") {
- $filter_cmd = $filter_cmd . " " . "match ip dport $portnum 0xffff";
- }
- $filter_cmd = $filter_cmd . " " . "flowid 1:" . $x;
- $final_cmd[] = $filter_cmd;
- }
- if ($emulationtag == TRUE) {
- foreach ($final_cmd as $magcommand) {
- $tmp = shell_exec($magcommand);
- }
- }
- }
- function get_emurovalue(&$emurointprint, $emurointconfig, $y) {
- $emurointprint[$emurointconfig]['name'] = $emurointconfig;
- $tcqdiscinfo = shell_exec("tc qdisc show dev $emurointconfig");
- $emutag = FALSE;
- if (strstr($tcqdiscinfo, 'qdisc htb 1: root')!=FALSE) {
- $tcclassinfo = shell_exec("tc class show dev $emurointconfig");
- if (strstr($tcclassinfo, ("class htb 1:".$y." root leaf ".$y.":"))!=FALSE) {
- preg_match_all(("/class htb 1:".$y."(.*) rate (.*)bit ceil/U"), $tcclassinfo, $tcclassmatch);
- if (isset($tcclassmatch[2][0])) {
- $emutag = TRUE;
- $tcclassmatchtext = $tcclassmatch[2][0];
- if (strstr($tcclassmatchtext, 'K')!=FALSE) {
- $speednumtxt = strstr($tcclassmatchtext, 'K', true);
- } else if (strstr($tcclassmatchtext, 'M')!=FALSE) {
- $tmpspeednumtxt = strstr($tcclassmatchtext, 'M', true);
- $tmpspeednum = (int)$tmpspeednumtxt;
- $tmpspeednumtxt = $tmpspeednum * 1000;
- $speednumtxt = strval($tmpspeednumtxt);
- } else {
- $tmpspeednum=(int)$tcclassmatchtext;
- $tmpspeednumtxt=$tmpspeednum/1000;
- $speednumtxt=strval($tmpspeednumtxt);
- }
- $emurointprint[$emurointconfig]['bandwidth'] = $speednumtxt;
- } else {
- $emurointprint[$emurointconfig]['bandwidth'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['bandwidth'] = "";
- }
- if (strstr($tcqdiscinfo, ("netem ".$y.": parent 1:".$y))!=FALSE) {
- $emutag = TRUE;
- $tcqdiscinfonetem = strstr($tcqdiscinfo, ("netem ".$y.": parent 1:".$y));
- preg_match_all(("/delay\s(([\d][\w\.%]*\s+)*)/"), $tcqdiscinfonetem, $tcqdiscmatchdelay);
- if (isset($tcqdiscmatchdelay[1][0])) {
- $tcqdiscmatchdelaytrim = trim($tcqdiscmatchdelay[1][0]);
- $tcqdiscmatchdelaytrim = preg_replace("/\s{2,}/", " ", $tcqdiscmatchdelaytrim);
- $tcqdiscmatchdelayarray = explode(" ", $tcqdiscmatchdelaytrim);
- if (isset($tcqdiscmatchdelayarray[0])) {
- if ((strstr($tcqdiscmatchdelayarray[0], 's')!=FALSE) && (strstr($tcqdiscmatchdelayarray[0], 'ms')==FALSE) && (strstr($tcqdiscmatchdelayarray[0], 'us')==FALSE)) {
- $tmpdelaynumtxt = strstr($tcqdiscmatchdelayarray[0], 's', true);
- $tmpdelaynum = (int)$tmpdelaynumtxt;
- $tmpdelaynumtxt = $tmpdelaynum * 1000;
- $delaynumtxt = strval($tmpdelaynumtxt);
- } elseif (strstr($tcqdiscmatchdelayarray[0], 'ms')!=FALSE) {
- $delaynumtxt = strstr($tcqdiscmatchdelayarray[0], 'ms', true);
- } else {
- $delaynumtxt = "";
- }
- $emurointprint[$emurointconfig]['delay'] = $delaynumtxt;
- } else {
- $emurointprint[$emurointconfig]['delay'] = "";
- }
- if (isset($tcqdiscmatchdelayarray[1])) {
- if ((strstr($tcqdiscmatchdelayarray[1], 's')!=FALSE) && (strstr($tcqdiscmatchdelayarray[1], 'ms')==FALSE) && (strstr($tcqdiscmatchdelayarray[1], 'us')==FALSE)) {
- $tmpjitternumtxt = strstr($tcqdiscmatchdelayarray[1], 's', true);
- $tmpjitternum = (int)$tmpjitternumtxt;
- $tmpjitternumtxt = $tmpjitternum * 1000;
- $jitternumtxt = strval($tmpjitternumtxt);
- } elseif (strstr($tcqdiscmatchdelayarray[1], 'ms')!=FALSE) {
- $jitternumtxt = strstr($tcqdiscmatchdelayarray[1], 'ms', true);
- } else {
- $jitternumtxt = "";
- }
- $emurointprint[$emurointconfig]['jitter'] = $jitternumtxt;
- } else {
- $emurointprint[$emurointconfig]['jitter'] = "";
- }
- if (isset($tcqdiscmatchdelayarray[2])) {
- $emurointprint[$emurointconfig]['delaycorr'] = strstr($tcqdiscmatchdelayarray[2], '%', true);
- } else {
- $emurointprint[$emurointconfig]['delaycorr'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['delay'] = "";
- $emurointprint[$emurointconfig]['jitter'] = "";
- $emurointprint[$emurointconfig]['delaycorr'] = "";
- }
- $emurointprint[$emurointconfig]['delaydist'] = "";
- preg_match_all(("/loss\s(([\d][\w\.%]*\s+)*)/"), $tcqdiscinfonetem, $tcqdiscmatchloss);
- if (isset($tcqdiscmatchloss[1][0])) {
- $tcqdiscmatchlosstrim = trim($tcqdiscmatchloss[1][0]);
- $tcqdiscmatchlosstrim = preg_replace("/\s{2,}/", " ", $tcqdiscmatchlosstrim);
- $tcqdiscmatchlossarray = explode(" ", $tcqdiscmatchlosstrim);
- if (isset($tcqdiscmatchlossarray[0])) {
- $emurointprint[$emurointconfig]['packetloss'] = strstr($tcqdiscmatchlossarray[0], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetloss'] = "";
- }
- if (isset($tcqdiscmatchlossarray[1])) {
- $emurointprint[$emurointconfig]['packetlosscorr'] = strstr($tcqdiscmatchlossarray[1], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetlosscorr'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['packetloss'] = "";
- $emurointprint[$emurointconfig]['packetlosscorr'] = "";
- }
- preg_match_all(("/duplicate\s(([\d][\w\.%]*\s+)*)/"), $tcqdiscinfonetem, $tcqdiscmatchduplicate);
- if (isset($tcqdiscmatchduplicate[1][0])) {
- $tcqdiscmatchduplicatetrim = trim($tcqdiscmatchduplicate[1][0]);
- $tcqdiscmatchduplicatetrim = preg_replace("/\s{2,}/", " ", $tcqdiscmatchduplicatetrim);
- $tcqdiscmatchduplicatearray = explode(" ", $tcqdiscmatchduplicatetrim);
- if (isset($tcqdiscmatchduplicatearray[0])) {
- $emurointprint[$emurointconfig]['packetdup'] = strstr($tcqdiscmatchduplicatearray[0], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetdup'] = "";
- }
- if (isset($tcqdiscmatchduplicatearray[1])) {
- $emurointprint[$emurointconfig]['packetdupcorr'] = strstr($tcqdiscmatchduplicatearray[1], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetdupcorr'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['packetdup'] = "";
- $emurointprint[$emurointconfig]['packetdupcorr'] = "";
- }
- preg_match_all(("/reorder\s(([\d][\w\.%]*\s+)*)/"), $tcqdiscinfonetem, $tcqdiscmatchreord);
- if (isset($tcqdiscmatchreord[1][0])) {
- $tcqdiscmatchreordtrim = trim($tcqdiscmatchreord[1][0]);
- $tcqdiscmatchreordtrim = preg_replace("/\s{2,}/", " ", $tcqdiscmatchreordtrim);
- $tcqdiscmatchreordarray = explode(" ", $tcqdiscmatchreordtrim);
- if (isset($tcqdiscmatchreordarray[0])) {
- $emurointprint[$emurointconfig]['packetreord'] = strstr($tcqdiscmatchreordarray[0], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetreord'] = "";
- }
- if (isset($tcqdiscmatchreordarray[1])) {
- $emurointprint[$emurointconfig]['packetreordcorr'] = strstr($tcqdiscmatchreordarray[1], '%', true);
- } else {
- $emurointprint[$emurointconfig]['packetreordcorr'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['packetreord'] = "";
- $emurointprint[$emurointconfig]['packetreordcorr'] = "";
- }
- preg_match_all(("/gap\s(([\d][\w\.%]*\s+)*)/"), $tcqdiscinfonetem, $tcqdiscmatchgap);
- if (isset($tcqdiscmatchgap[1][0])) {
- $tcqdiscmatchgaptrim = trim($tcqdiscmatchgap[1][0]);
- $tcqdiscmatchgaptrim = preg_replace("/\s{2,}/", " ", $tcqdiscmatchgaptrim);
- if (isset($tcqdiscmatchgaptrim)) {
- $emurointprint[$emurointconfig]['packetreordgap'] = $tcqdiscmatchgaptrim;
- } else {
- $emurointprint[$emurointconfig]['packetreordgap'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['packetreordgap'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['delay'] = "";
- $emurointprint[$emurointconfig]['jitter'] = "";
- $emurointprint[$emurointconfig]['delaycorr'] = "";
- $emurointprint[$emurointconfig]['delaydist'] = "";
- $emurointprint[$emurointconfig]['packetloss'] = "";
- $emurointprint[$emurointconfig]['packetlosscorr'] = "";
- $emurointprint[$emurointconfig]['packetdup'] = "";
- $emurointprint[$emurointconfig]['packetdupcorr'] = "";
- $emurointprint[$emurointconfig]['packetreord'] = "";
- $emurointprint[$emurointconfig]['packetreordcorr'] = "";
- $emurointprint[$emurointconfig]['packetreordgap'] = "";
- }
- if ($emutag == TRUE) {
- $ip_calc = new Net_IPv4();
- $tcfilterinfo = shell_exec("tc filter show dev $emurointconfig");
- if (strstr($tcfilterinfo, ("flowid 1:".$y))!=FALSE) {
- $tcfilterinfoflowid = strstr($tcfilterinfo, ("flowid 1:".$y));
- preg_match_all(("/match\s(\w*)\/(\w*)\sat\s12/U"), $tcfilterinfoflowid, $tcfilterinfomatchsrcip);
- preg_match_all(("/match\s(\w*)\/(\w*)\sat\s16/U"), $tcfilterinfoflowid, $tcfilterinfomatchdstip);
- preg_match_all(("/match\s(\w*)\/(\w*)\sat\s20/U"), $tcfilterinfoflowid, $tcfilterinfomatchdport);
- if (isset($tcfilterinfomatchsrcip[1][0]) && isset($tcfilterinfomatchsrcip[2][0])) {
- $tcfiltersrciptrim = trim($tcfilterinfomatchsrcip[1][0]);
- $tcfiltersrcsubnettrim = trim($tcfilterinfomatchsrcip[2][0]);
- $tcfiltersrcip = $ip_calc->htoa($tcfiltersrciptrim);
- $tcfiltersrcsubnetmask = $ip_calc->htoa($tcfiltersrcsubnettrim);
- $tcfiltersrcsubnetCIDR = mask2cidr($tcfiltersrcsubnetmask);
- $emurointprint[$emurointconfig]['sourceip'] = $tcfiltersrcip;
- $emurointprint[$emurointconfig]['sourceCIDR'] = $tcfiltersrcsubnetCIDR;
- } else {
- $emurointprint[$emurointconfig]['sourceip'] = "";
- $emurointprint[$emurointconfig]['sourceCIDR'] = "";
- }
- if (isset($tcfilterinfomatchdstip[1][0]) && isset($tcfilterinfomatchdstip[2][0])) {
- $tcfilterdstiptrim = trim($tcfilterinfomatchdstip[1][0]);
- $tcfilterdstsubnettrim = trim($tcfilterinfomatchdstip[2][0]);
- $tcfilterdstip = $ip_calc->htoa($tcfilterdstiptrim);
- $tcfilterdstsubnetmask = $ip_calc->htoa($tcfilterdstsubnettrim);
- $tcfilterdstsubnetCIDR = mask2cidr($tcfilterdstsubnetmask);
- $emurointprint[$emurointconfig]['destip'] = $tcfilterdstip;
- $emurointprint[$emurointconfig]['destCIDR'] = $tcfilterdstsubnetCIDR;
- } else {
- $emurointprint[$emurointconfig]['destip'] = "";
- $emurointprint[$emurointconfig]['destCIDR'] = "";
- }
- if (isset($tcfilterinfomatchdport[1][0])) {
- $tcfilterdporttrim = trim($tcfilterinfomatchdport[1][0]);
- $tcfilterdport = hexdec($tcfilterdporttrim);
- $emurointprint[$emurointconfig]['portnum'] = strval($tcfilterdport);
- } else {
- $emurointprint[$emurointconfig]['portnum'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['sourceip'] = "";
- $emurointprint[$emurointconfig]['sourceCIDR'] = "";
- $emurointprint[$emurointconfig]['destip'] = "";
- $emurointprint[$emurointconfig]['destCIDR'] = "";
- $emurointprint[$emurointconfig]['portnum'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['sourceip'] = "";
- $emurointprint[$emurointconfig]['sourceCIDR'] = "";
- $emurointprint[$emurointconfig]['destip'] = "";
- $emurointprint[$emurointconfig]['destCIDR'] = "";
- $emurointprint[$emurointconfig]['portnum'] = "";
- }
- } else {
- $emurointprint[$emurointconfig]['bandwidth'] = "";
- $emurointprint[$emurointconfig]['delay'] = "";
- $emurointprint[$emurointconfig]['jitter'] = "";
- $emurointprint[$emurointconfig]['delaycorr'] = "";
- $emurointprint[$emurointconfig]['delaydist'] = "";
- $emurointprint[$emurointconfig]['packetloss'] = "";
- $emurointprint[$emurointconfig]['packetlosscorr'] = "";
- $emurointprint[$emurointconfig]['packetdup'] = "";
- $emurointprint[$emurointconfig]['packetdupcorr'] = "";
- $emurointprint[$emurointconfig]['packetreord'] = "";
- $emurointprint[$emurointconfig]['packetreordcorr'] = "";
- $emurointprint[$emurointconfig]['packetreordgap'] = "";
- $emurointprint[$emurointconfig]['sourceip'] = "";
- $emurointprint[$emurointconfig]['sourceCIDR'] = "";
- $emurointprint[$emurointconfig]['destip'] = "";
- $emurointprint[$emurointconfig]['destCIDR'] = "";
- $emurointprint[$emurointconfig]['portnum'] = "";
- }
- }
- function mask2cidr($mask) {
- if ($mask == "0.0.0.0") {
- return 0;
- } else {
- $long = ip2long($mask);
- $base = ip2long('255.255.255.255');
- return 32-log(($long ^ $base)+1,2);
- }
- }
- function validate_input(&$postemurointprint, $emurointconfig) {
- $postemurointprint[$emurointconfig]['bandwidth'] = trim($postemurointprint[$emurointconfig]['bandwidth']);
- $postemurointprint[$emurointconfig]['delay'] = trim($postemurointprint[$emurointconfig]['delay']);
- $postemurointprint[$emurointconfig]['jitter'] = trim($postemurointprint[$emurointconfig]['jitter']);
- $postemurointprint[$emurointconfig]['delaycorr'] = trim($postemurointprint[$emurointconfig]['delaycorr']);
- $postemurointprint[$emurointconfig]['delaydist'] = trim($postemurointprint[$emurointconfig]['delaydist']);
- $postemurointprint[$emurointconfig]['packetloss'] = trim($postemurointprint[$emurointconfig]['packetloss']);
- $postemurointprint[$emurointconfig]['packetlosscorr'] = trim($postemurointprint[$emurointconfig]['packetlosscorr']);
- $postemurointprint[$emurointconfig]['packetdup'] = trim($postemurointprint[$emurointconfig]['packetdup']);
- $postemurointprint[$emurointconfig]['packetdupcorr'] = trim($postemurointprint[$emurointconfig]['packetdupcorr']);
- $postemurointprint[$emurointconfig]['packetreord'] = trim($postemurointprint[$emurointconfig]['packetreord']);
- $postemurointprint[$emurointconfig]['packetreordcorr'] = trim($postemurointprint[$emurointconfig]['packetreordcorr']);
- $postemurointprint[$emurointconfig]['packetreordgap'] = trim($postemurointprint[$emurointconfig]['packetreordgap']);
- $postemurointprint[$emurointconfig]['sourceip'] = trim($postemurointprint[$emurointconfig]['sourceip']);
- $postemurointprint[$emurointconfig]['sourcesubnet'] = trim($postemurointprint[$emurointconfig]['sourcesubnet']);
- $postemurointprint[$emurointconfig]['destip'] = trim($postemurointprint[$emurointconfig]['destip']);
- $postemurointprint[$emurointconfig]['destsubnet'] = trim($postemurointprint[$emurointconfig]['destsubnet']);
- $postemurointprint[$emurointconfig]['sourceipsubnet'] = $postemurointprint[$emurointconfig]['sourceip'] . "/" . $postemurointprint[$emurointconfig]['sourcesubnet'];
- $postemurointprint[$emurointconfig]['destipsubnet'] = $postemurointprint[$emurointconfig]['destip'] . "/" . $postemurointprint[$emurointconfig]['destsubnet'];
- $postemurointprint[$emurointconfig]['portnum'] = trim($postemurointprint[$emurointconfig]['portnum']);
- if (!preg_match("/^((\d){1,6})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['bandwidth'])) {
- $postemurointprint[$emurointconfig]['bandwidth'] = "";
- }
- if (!preg_match("/^((\d){1,6})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['delay'])) {
- $postemurointprint[$emurointconfig]['delay'] = "";
- }
- if (!preg_match("/^((\d){1,6})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['jitter'])) {
- $postemurointprint[$emurointconfig]['jitter'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['delaycorr'])) {
- $postemurointprint[$emurointconfig]['delaycorr'] = "";
- }
- if (!preg_match("/^[a-z]{1,12}$/", $postemurointprint[$emurointconfig]['delaydist'])) {
- $postemurointprint[$emurointconfig]['delaydist'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetloss'])) {
- $postemurointprint[$emurointconfig]['packetloss'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetlosscorr'])) {
- $postemurointprint[$emurointconfig]['packetlosscorr'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetdup'])) {
- $postemurointprint[$emurointconfig]['packetdup'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetdupcorr'])) {
- $postemurointprint[$emurointconfig]['packetdupcorr'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetreord'])) {
- $postemurointprint[$emurointconfig]['packetreord'] = "";
- }
- if (!preg_match("/^((\d){1,3})(\.[\d]{1,2})?$/", $postemurointprint[$emurointconfig]['packetreordcorr'])) {
- $postemurointprint[$emurointconfig]['packetreordcorr'] = "";
- }
- if (!preg_match("/^(\d){1,3}$/", $postemurointprint[$emurointconfig]['packetreordgap'])) {
- $postemurointprint[$emurointconfig]['packetreordgap'] = "";
- }
- if (!preg_match("/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([1-2]?[0-9]|3[0-2])$/", $postemurointprint[$emurointconfig]['sourceipsubnet'])) {
- $postemurointprint[$emurointconfig]['sourceipsubnet'] = "";
- }
- if (!preg_match("/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([1-2]?[0-9]|3[0-2])$/", $postemurointprint[$emurointconfig]['destipsubnet'])) {
- $postemurointprint[$emurointconfig]['destipsubnet'] = "";
- }
- if (!preg_match("/^(\d){1,5}$/", $postemurointprint[$emurointconfig]['portnum'])) {
- $postemurointprint[$emurointconfig]['portnum'] = "";
- }
- }
- function validate_intconfig(&$postrointprint, $rointconfig) {
- $postrointprint[$rointconfig]['ipaddressvalue'] = trim($postrointprint[$rointconfig]['ipaddressvalue']);
- $postrointprint[$rointconfig]['ipsubnetvalue'] = trim($postrointprint[$rointconfig]['ipsubnetvalue']);
- if (!preg_match("/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/", $postrointprint[$rointconfig]['ipaddressvalue'])) {
- $postrointprint[$rointconfig]['ipaddressvalue'] = "";
- }
- if (!preg_match("/^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/", $postrointprint[$rointconfig]['ipsubnetvalue'])) {
- $postrointprint[$rointconfig]['ipsubnetvalue'] = "";
- }
- }
- ?>