$dns\n " . trim( $portLine[1] ) . "\n"; } else { //echo "Master: " . trim( $addressLine[1] ) . ":" . trim( $portLine[1] ); echo "" . trim( $addressLine[1] ) . "\n " . trim( $portLine[1] ) . "\n"; } echo "$rpt_id\n"; } function getIPSCInfo() { $iniFile = IPSC_INI; $logline = `grep "DMR Network" $iniFile -A 10 | egrep "^Address"`; $addressLine = explode( "=", $logline ); // $logline = `grep "DMR Network" $iniFile -A 10 | egrep "^Port"`; // $portLine = explode( "=", $logline ); $logline = `egrep "^\[DMR]$" $iniFile -A 30 | egrep "^Id="`; $idLine = explode( "=", $logline ); $rpt_id = $idLine[1]; echo "$rpt_id\n"; // if( `command -v nslookup` ) { // $address = strstr( `nslookup $addressLine[1]`, "=" ); // $dns = substr( $address, 2, strrpos( $address, "." ) - 2); // //echo "Master: $dns on Port: " . trim( $portLine[1] ); // echo "$dns\n " . trim( $portLine[1] ) . "\n"; // } else { //echo "Master: " . trim( $addressLine[1] ) . ":" . trim( $portLine[1] ); echo "" . trim( $addressLine[1] ) . "\n"; // echo " " . trim( $portLine[1] ) . "\n"; // } $logline = `egrep -h "^Options=\"" $iniFile | tail -n 1`; if( !empty( $logline )) { $optionsLine = explode( "\"", $logline ); $options = explode( ";", $optionsLine[1] ); echo ""; foreach( $options as $option ) { echo "$option "; } } else { echo "N/A"; } echo "\n"; } function countDGIDs( $iniFile = YSFGW_INI ) { $logline = `grep "[Network]" $iniFile -A 10 | egrep "^Options"`; $optionsLine = explode( "=", $logline ); $DGIDs = explode( ",", $optionsLine[1] ); return count( $DGIDs ); } function getYSFInfo() { $iniFile = YSFGW_INI; $logline = `grep "[General]" $iniFile -A 10 | egrep "^Id"`; $idLine = explode( "=", $logline ); $logline = `grep "[Network]" $iniFile -A 10 | egrep "^Startup"`; $startupLine = explode( "=", $logline ); $logline = `grep "[Network]" $iniFile -A 10 | egrep "^Options"`; $optionsLine = explode( "=", $logline ); $DGIDs = explode( ",", $optionsLine[1] ); echo "" . trim( $idLine[1] ) . "\n"; echo "" . trim( $startupLine[1] ) . "\n"; foreach( $DGIDs as $DGID ) { echo "$DGID "; } echo "\n"; } function getUptime() { $uptime = intval( `cat /proc/uptime | awk '{ print $1 }'` ); if( $uptime >= 60 ) { // in minutes $minutes = intval( $uptime / 60 ); $seconds = $uptime % 60; if( $minutes >= 60 ) { $hours = intval( $minutes / 60 ); $minutes = $minutes % 60; if( $hours >= 24 ) { $days = intval( $hours / 24 ); $hours = $hours % 24; $out = "${days}d ${hours}h ${minutes}m and ${seconds}s"; } else { // no days, only hours minutes and seconds $out = "${hours}h ${minutes}m and ${seconds}s"; } } else { // mintes < 60 only minuts, hours $out = "${minutes}m and ${seconds}s"; } } else { // only seconds $out = "${uptime}s"; } return $out; } function ImportDB() { $contents = array(); if( $file = fopen( DMRID_DAT, 'r' )) { if( !defined("NONAMES")) { while( !feof( $file )) { $line = fgetss( $file, 64 ); $elem = explode( ";", $line ); array_push( $contents, $elem ); } } fclose( $file ); } return $contents; } function CallsignLookupDB( $id ) { // $call = "$call"; global $mem; if( !empty( $mem )) { foreach( $mem as $key => $val ) { if( $val[0] === $id ) { $call = $mem[$key]; $callsign = $call[1]; $call_code = "$callsign"; return $call_code; } } } $call_code = "$id"; return $call_code; } function linkCallsign( $callsign ) { $tmp = explode( "-", $callsign ); $call = trim( $tmp[0] ); $suffix = ( !empty( $tmp[1] )) ? "-$tmp[1]" : ""; if( !empty( $suffix )) { $suffix="-$suffix"; } if( !is_numeric( $call )) { $call = "$call" . "$suffix"; } elseif( strlen( $call ) == 7 ) { // old version linked to ham-digital which now is fusioned into radioid.net //$call = "$call"; $call = CallsignLookupDB( $call ); } elseif( strlen( $call ) == 6 ) { $call = "$call"; } elseif( strlen( $call ) == 4 ) { //$call = "Reflector $call"; } return $call; } function linkTG( $tg, $linktg ) { if( !is_numeric( $tg ) && $linktg == "bm") { $tmp = explode( " ", $tg ); $tg_id = trim( $tmp[1] ); $tg_new = "$tg"; return $tg_new; } return $tg; } function rssiCalcImg( $val ) { if( $val > -53 ) $rssi = "\"S9"; else if( $val > -63 ) $rssi = "\"S9"; else if( $val > -73 ) $rssi = "\"S9"; else if( $val > -83 ) $rssi = "\"S9"; else if( $val > -93 ) $rssi = "\"S9\""; else if( $val > -99 ) $rssi = "\"S8\""; else if( $val > -105 ) $rssi = "\"S7\""; else if( $val > -111 ) $rssi = "\"S6\""; else if( $val > -117 ) $rssi = "\"S5\""; else if( $val > -123 ) $rssi = "\"S4\""; else if( $val > -129 ) $rssi = "\"S3\""; else if( $val > -135 ) $rssi = "\"S2\""; else if( $val > -141 ) $rssi = "\"S1\""; return "$rssi"; } function rssiCalc( $val ) { if( $val > -53 ) $rssi = "S9+40dB"; else if( $val > -63 ) $rssi = "S9+30dB"; else if( $val > -73 ) $rssi = "S9+20dB"; else if( $val > -83 ) $rssi = "S9+10dB"; else if( $val > -93 ) $rssi = "S9"; else if( $val > -99 ) $rssi = "S8"; else if( $val > -105 ) $rssi = "S7"; else if( $val > -111 ) $rssi = "S6"; else if( $val > -117 ) $rssi = "S5"; else if( $val > -123 ) $rssi = "S4"; else if( $val > -129 ) $rssi = "S3"; else if( $val > -135 ) $rssi = "S2"; else if( $val > -141 ) $rssi = "S1"; return "$rssi ($val dBm)"; } function printTable( $id=0, $linktg, $time, $callsign, $slot, $tg, $duration, $loss = "---", $ber = "---" ) { if( $duration >= 60 ) { $min = str_pad( intval( $duration / 60 ), 2, "0", STR_PAD_LEFT ); $sec = str_pad( $duration % 60, 2, "0", STR_PAD_LEFT ); $duration = "$min:$sec"; } else { $duration = "00:" . str_pad( $duration, 2, "0", STR_PAD_LEFT ); } echo " \n" . "$id\n" . "$time\n" . "" . linkCallsign( $callsign ) ."\n" . "$slot\n" . "" . linkTG( $tg, $linktg ) . "\n" . "$duration\n" . "$loss\n" . "$ber\n" . "\n"; } // $linktg should be "bm" or false function getLastHeard($logpath = BM_LOGPATH, $prefix = BM_PREFIX, $linktg = false, $limit = MAXENTRIES) { $logPath = "$logpath/$prefix-*.log"; $logLines = explode( "\n", `egrep -h "DMR Slot" $logPath` ); $oldline = ""; $time = ""; $loss = ""; $ber = ""; $rssi = ""; $call = ""; $duration = ""; $repeater = ""; $printLines = []; foreach( $logLines as $line ) { if( empty( $oldline ) && strpos( $line, "network watchdog has expired" )) { // $oldine=$line; continue; } if( strpos( $line, "RF end of voice transmission" )) { $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 24 )." UTC" )); $callsign = substr( $line, 82, strpos( $line, "to" ) - 82 ); $slot = substr( $line, 36, strpos( $line, ",") -36); $tg = substr( $line, 93, strpos( $line, ",", 93 ) - 93 ); $duration = round( trim( substr( $line, 103, strpos( $line, "seconds,", 103 ) - 103 ), " ," )); $rssi_values = explode( "/", substr( $line, 133, strpos( $line, "dBm", 133 ) - 133 )); $loss = rssiCalcImg( round( array_sum( $rssi_values ) / count( $rssi_values ))); $ber = substr( $line, 120, strpos( $line, ",", 120 ) - 120 ); if( empty( $ber )) $ber = "---"; } elseif( strpos( $line, "received network voice header" )) { if( strpos( $oldline, "received network voice header" )) { $oldline = $line; continue; } else { $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 24 )." UTC" )); $old_time = strtotime( $time ); $oldline=$line; continue; } } elseif( strpos( $line, "received network end of voice" )) { $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 24 )." UTC" )); $callsign = substr( $line, 87, strpos( $line, "to ") - 87 ); $slot = substr( $line, 36, strpos( $line, ",") - 36); $tg = substr( $line, strpos( $line, "to " ) + 3, strpos( $line, ",", strpos( $line, "to " ) + 3 ) - strpos( $line, "to " ) - 3 ); $duration = substr( $line, strpos( $line, "to " ) + strlen( $tg ) + 5, strpos( $line, " seconds," ) - strpos( $line, "to " ) - strlen( $tg ) - 5 ); $loss = substr( $line, strpos( $line, "seconds, " ) + 9, strpos( $line, " packet loss" ) - strpos( $line, "seconds, " ) - 9 ); /*if( $loss == "0%" ) { $loss = "-x-"; }*/ $ber = substr( $line, strpos( $line, "BER: " ) + 5, strpos( $line, "%", strpos( $line, "BER: ")) - strpos( $line, "BER: " ) ); //if( $ber == "0.0%" ) $ber = "-x-"; $rssi = ""; } else { continue; } // echo "
\$callsign: $callsign at \$dgid: $dgid\n\$old_time: ".date("Y-m-d H:i:s", $old_time ).
      //   "\n\$new_time: ".date("Y-m-d H:i:s", $new_time )."
\n"; // echo "
OLD LINE: $oldline\nLINE: $line\n
\n"; $tmp = []; $tmp['linktg'] = $linktg; $tmp['time'] = $time; $tmp['callsign'] = $callsign; $tmp['slot'] = $slot; $tmp['tg'] = $tg; $tmp['duration'] = round( $duration, 0, PHP_ROUND_HALF_UP ); $tmp['loss'] = $loss; $tmp['ber'] = $ber; array_unshift( $printLines, $tmp ); unset( $tmp ); // Lastly we set $oldline as the actual line $oldline = $line; } $c = 0; foreach( $printLines as $key=>$line ) { printTable( $c + 1, $line['linktg'], $line['time'], $line['callsign'], $line['slot'], $line['tg'], $line['duration'], $line['loss'], $line['ber'] ); if( ++$c >= MAXENTRIES ) break; } // end foreach $printLines } // end function function qrzRepeater( $rpt ) { /* $pos = strpos( $rpt, "OE" ); if( $pos !== false) { $rpt = "$rpt"; } */ if( preg_match( '/[A-Z]{1,2}\d[A-Z]{1,3}/', $rpt )) { $rpt = "$rpt"; } return $rpt; } function printTableYSF( $id=0, $time, $callsign, $dgid, $duration, $repeater, $loss = "---", $ber = "---" ) { if( $duration >= 60 ) { $min = str_pad( intval( $duration / 60 ), 2, "0", STR_PAD_LEFT ); $sec = str_pad( $duration % 60, 2, "0", STR_PAD_LEFT ); $duration = "$min:$sec"; } else { $duration = "00:" . str_pad( $duration, 2, "0", STR_PAD_LEFT ); } echo " \n" . "$id\n" . "$time\n" . "" . linkCallsign( $callsign ) ."\n" . "$dgid\n" . "$repeater\n" . "$duration\n" . "$loss\n" . "$ber\n" . "\n"; } // function getLastHeard($logpath = BM_LOGPATH, $prefix = BM_PREFIX, $linktg = false, $limit = MAXENTRIES) { // $logPath = "$logpath/$prefix-*.log"; // $logLines = explode( "\n", `egrep -h "DMR Slot" $logPath` ); function getLastHeardYSF($logpath = MMDVMHOST_LOGPATH, $prefix = MMDVMHOST_PREFIX, $limit = MAXENTRIES) { $logPath = "$logpath/$prefix-*.log"; $logLines = explode( "\n", `egrep -h "YSF," $logPath` ); $oldline = ""; $time = ""; $loss = ""; $ber = ""; $rssi = ""; $call = ""; $duration = ""; $repeater = ""; $printLines = []; foreach( $logLines as $line ) { if( empty( $oldline ) && strpos( $line, "network watchdog" )) { // $oldine=$line; continue; } if( strpos( $line, "RF end of transmission" )) { $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 23 )." UTC" )); $callsign = substr( $line, 69, strpos( $line, "to" ) - 69 ); //$dgid = substr( $line, 83, strpos( $line, ",", 83 ) - 83 ); $dgid = substr( $line, strpos( $line, "to " ) + 3, strpos( $line, " ", strpos( $line, "to " ) + 3) - strpos( $line, "to " ) + 3 ); //$repeater = substr( $oldline, strpos( $oldline, "at " ) + 3, strpos( $oldline, " ", strpos( $oldline, "at " ) + 3) - strpos( $oldline, "at " ) + 3 ); $duration = round( trim( substr( $line, 92, strpos( $line, "seconds,", 92 ) - 92 ), " ," )); $rssi_values = explode( "/", substr( $line, 113, strpos( $line, "dBm", 113 ) - 113 )); $rssi = rssiCalc( round( array_sum( $rssi_values ) / count( $rssi_values ))); $loss = "---"; $ber = substr( $line, 111, strpos( $line, ",", 111 ) - 111 ); if( empty( $ber )) $ber = "---"; $repeater = $rssi; // use this testwise, debug } elseif( strpos( $line, "network data" )) { if( strpos( $oldline, "network data" )) { $oldline = $line; continue; } else { $time = date( "Y-m-d H:i:s", strtotime( substr( $line, 3, 23 )." UTC" )); $old_time = strtotime( $time ); $oldline=$line; continue; } } elseif( strpos( $line, "network watchdog" )) { if( strpos( $oldline, "network watchdog" )) { $line = $oldline; continue; } $time = date( "Y-m-d H:i:s", strtotime( substr( $oldline, 3, 23 )." UTC" )); $callsign = trim( substr( $oldline, 59, strpos( $oldline, "to" ) - 59 )); if( strpos( $oldline, "DG-ID" )) { $dgid = substr( $oldline, 79, strpos( $oldline, "at " ) - 79 ); } else { $dgid = substr( $oldline, 73, strpos( $oldline, "at " ) - 73 ); } //$dgid = substr( $oldline, strpos( $oldline, "to " ) + 3, strpos( $oldline, " ", strpos( $oldline, "to " ) + 3) - strpos( $oldline, "to " ) + 3 ); $new_time = strtotime( date( "Y-m-d H:i:s", strtotime( substr( $oldline, 3, 23 )." UTC" ))); $duration = intval(( $new_time - $old_time )); $rpt = substr( $oldline, strpos( $oldline, "at " ) + 3, strpos( $oldline, " ", strpos( $oldline, "at " ) + 3) - strpos( $oldline, "at " ) + 3 ); $repeater = qrzRepeater( trim( $rpt )); $loss = substr( $line, 75, strpos( $line, "%", 75 ) - 74 ); if( $loss == "0%" ) { $loss = "-x-"; } $ber = substr( $line, 96, strpos( $line, "%", 96 ) - 95 ); if( $ber == "0.0%" ) $ber = "-x-"; } else { continue; } $tmp = []; $tmp['time'] = $time; $tmp['callsign'] = $callsign; $tmp['dgid'] = $dgid; $tmp['duration'] = $duration; $tmp['repeater'] = $repeater; $tmp['loss'] = $loss; $tmp['ber'] = $ber; array_unshift( $printLines, $tmp ); unset( $tmp ); // Lastly we set $oldline as the actual line $oldline = $line; } $c = 0; foreach( $printLines as $key=>$line ) { printTableYSF( $c + 1, $line['time'], $line['callsign'], $line['dgid'], $line['duration'], $line['repeater'], $line['loss'], $line['ber'] ); if( ++$c >= MAXENTRIES ) break; } // end foreach $printLines } // end function function printLogs($logpath, $limit = MAXLOGENTRIES) { $logPath = "$logpath/*-".gmdate("Y-m-d").".log"; $logLines = explode("\n", `tail -n $limit $logPath`); echo "\n\n

DEBUG LOGFILES OUTPUT

\n"; echo "
\n";

  foreach( $logLines as $line ) {
    if ( substr( $line, 0, 4) == "==> " ) {
      echo "$line\n";
    } else {
      echo "$line\n";
    }
  }

  echo "\n
\n\n\n"; return 0; }