= 200 ) { $bmAPIkeyV2 = $bmAPIkey; unset($bmAPIkey); } } //Load the dmrgateway config file $dmrGatewayConfigFile = '/etc/dmrgateway'; if (fopen($dmrGatewayConfigFile,'r')) { $configdmrgateway = parse_ini_file($dmrGatewayConfigFile, true); } // Get the current DMR Master from the config $dmrMasterHost = getConfigItem("DMR Network", "Address", $mmdvmconfigs); if ( $dmrMasterHost == '127.0.0.1' ) { $dmrMasterHost = $configdmrgateway['DMR Network 1']['Address']; if (isset($configdmrgateway['DMR Network 1']['Id'])) { $dmrID = $configdmrgateway['DMR Network 1']['Id']; } } elseif (getConfigItem("DMR", "Id", $mmdvmconfigs)) { $dmrID = getConfigItem("DMR", "Id", $mmdvmconfigs); } else { $dmrID = getConfigItem("General", "Id", $mmdvmconfigs); } // Store the DMR Master IP, we will need this for the JSON lookup $dmrMasterHostIP = $dmrMasterHost; // Make sure the master is a BrandMeister Master $dmrMasterFile = fopen("/usr/local/etc/DMR_Hosts.txt", "r"); while (!feof($dmrMasterFile)) { $dmrMasterLine = fgets($dmrMasterFile); $dmrMasterHostF = preg_split('/\s+/', $dmrMasterLine); if ((strpos($dmrMasterHostF[0], '#') === FALSE) && ($dmrMasterHostF[0] != '')) { if ($dmrMasterHost == $dmrMasterHostF[2]) { $dmrMasterHost = str_replace('_', ' ', $dmrMasterHostF[0]); } } } if (substr($dmrMasterHost, 0, 2) == "BM") { if (isset($bmAPIkeyV2) && !empty($_POST) && (isset($_POST["dropDyn"]) || isset($_POST["dropQso"]) || isset($_POST["tgSubmit"]))) : // Data has been posted for this page $bmAPIurl = 'https://api.brandmeister.network/v2/device/'; // Are we a repeater if ( getConfigItem("DMR Network", "Slot1", $mmdvmconfigs) == "0" ) { unset($_POST["TS"]); $targetSlot = "0"; } else { $targetSlot = $_POST["TS"]; } // Set the API URLs if (isset($_POST["dropDyn"])) { $bmAPIurl = $bmAPIurl.$dmrID."/action/dropDynamicGroups/".$targetSlot; $method = "GET"; } if (isset($_POST["dropQso"])) { $bmAPIurl = $bmAPIurl.$dmrID."/action/dropCallRoute/".$targetSlot; $method = "GET"; } if ( (isset($_POST["tgNr"])) && (isset($_POST["tgSubmit"])) ) { $targetTG = preg_replace("/[^0-9]/", "", $_POST["tgNr"]); } if ( ($_POST["TGmgr"] == "ADD") && (isset($_POST["tgSubmit"])) ) { $bmAPIurl = $bmAPIurl.$dmrID."/talkgroup/"; $method = "POST"; } if ( ($_POST["TGmgr"] == "DEL") && (isset($_POST["tgSubmit"])) ) { $bmAPIurl = $bmAPIurl.$dmrID."/talkgroup/".$targetSlot."/".$targetTG; $method = "DELETE"; } // Build the Data $postHeaders = array( 'Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer '.$bmAPIkeyV2, 'User-Agent: Pi-Star Dashboard for '.$dmrID, ); $opts = array( 'http' => array( 'method' => $method, //'header' => $postHeaders, 'header' => implode("\r\n", $postHeaders), 'password' => '', 'success' => '', 'timeout' => 2, ), ); // If we are adding a TG if ( (!isset($_POST["dropDyn"])) && (!isset($_POST["dropQso"])) && isset($targetTG) && $_POST["TGmgr"] == "ADD" ) { $postDataTG = array( 'slot' => $targetSlot, 'group' => $targetTG ); $postData = json_encode($postDataTG); $postHeaders[] = 'Content-Length: '.strlen($postData); $opts['http']['content'] = $postData; } // Make the request $context = stream_context_create($opts); $result = @file_get_contents($bmAPIurl, false, $context); $feeback=json_decode($result); // Output to the browser echo 'BrandMeister Manager'."\n"; echo "\n\n\n
Command Output
"; if (isset($feeback)) { print "BrandMeister APIv2: OK"; } else { print "BrandMeister APIv2: No Response"; } echo "
\n"; echo "
\n"; // Clean up... unset($_POST); echo ''; else: // Do this when we are not handling post data // If there is a BM API Key if (isset($bmAPIkeyV2)) { echo 'BrandMeister Manager'."\n"; echo '
'."\n"; echo csrf_field_html()."\n"; echo ''."\n"; echo ''."\n"; echo ' '; echo ''; echo ''; echo ''; echo ''; echo ''."\n"; echo ' '; echo ''; echo ''."\n"; echo '
ActionTake Action
'."\n"; echo '
'."\n"; } endif; } } }