"MYUSERNAME", "pass"=>"MYPASSWORD", "service"=>"MYSERVICE", "auth"=>"MYSECRET"), array("user"=>"MYUSERNAME", "pass"=>"MYPASSWORD", "service"=>"voipstunt"), array("user"=>"MYUSERNAME", "pass"=>"MYPASSWORD", "service"=>"sparvoip.de")); */ // // NO MORE SETTINGS TO EDIT BELOW THIS LINE ***************************************************************************** function usage() { $sOutput = "

\n"; $sOutput .= "usage: ".$_SERVER['PHP_SELF']. "?cmd=[freedays|creditcents|call|sms|tariffwizard|callforward]&usernumber=usernumber&auth=yoursecret [monthsago|daysago|sourcenumber|smstext] [destinationnumber]
\n"; $sOutput .= " Extra options when sending an sms. After [destinationnumber] there is [monthtosend] [daytosend] [hourtosend] [minutetosend] [gmt](difference in hours) and [callerid]
\n"; $sOutput .= " Extra options when using the callforward command. After [destinationnumber] there is " . "fwdtype=[-1|0|1|2|3] for Get current status, Never, Always, When offline and When offline or away.
\n"; $sOutput .= "

\n"; $sOutput .= "

\n"; $sExUsage = $_SERVER['PHP_SELF']."?cmd=creditcents&usernumber=1&auth=yoursecret"; $sOutput .= "eg. ".$sExUsage."\n"; $sOutput .= "

\n"; $sOutput .= "

\n"; $sOutput .= "You can also run this php script as a shell or cron job ...
\n"; $sOutput .= "/pathToPHP/php " . $_SERVER['PHP_SELF']." 'cmd=creditcents&usernumber=1&auth=yoursecret'
\n"; $sOutput .= "

\n"; $sOutput .= "

\n"; $sOutput .= "Use the example form below to get started.\n"; $sOutput .= "

\n"; return $sOutput; } function html_select($sName,$aItems,$sSelected=""){ // Where $aItems is an array of POST VALUE => DISPLAY VALUE $sOutput = ""; $sOutput .= "\n"; return $sOutput; } function num_to_array($iNum,$iStart=1){ $aArray = ""; for ($i = $iStart; $i <= $iNum; $i++) { $aArray[$i] = $i; } return $aArray; } if (! function_exists('array_combine')) { // Exists from PHP5 function array_combine($a1, $a2){ if(count($a1) != count($a2)) return false; if(count($a1) <= 0) return false; $a1 = array_values($a1); $a2 = array_values($a2); $output = array(); for($i = 0; $i < count($a1); $i++) { $output[$a1[$i]] = $a2[$i]; } return $output; } } function print_form() { // TODO Get rid of these globals !!! global $sCommand, $aUsers, $iSourceNum, $iDestNum, $iFwdType, $sMsg, $iUserNumber, $sAuth, $iMonthToSend, $iDayToSend, $iHourToSend, $iMinuteToSend, $iGmtDiff, $iCallerId; $sOutput = "EXAMPLE FORM:
\n"; $sOutput .= "

\n"; $sOutput .= "

\n"; $aCmds = array("","freedays","creditcents","call","sms","tariffwizard", "callforward"); $aCmds = array_combine($aCmds, $aCmds); // Make the keys and values the same. $sOutput .= "CMD: " . html_select("cmd", $aCmds,$sCommand )."
\n"; // List of user numbers. $aNums = ""; $aNums = num_to_array(count($aUsers)); $sOutput .= "USERNUMBER: ". html_select("usernumber", $aNums, $iUserNumber)."
\n"; // $sOutput .= "AUTH:
\n"; // $sOutput .= "MONTHSAGO(creditcents): ". html_select("monthsago", num_to_array(12,0))."
\n"; // $sOutput .= "DAYSAGO(creditcents): ". html_select("daysago", num_to_array(31,0))."
\n"; $sOutput .= "SOURCENUMBER(call):
\n"; $sOutput .= "CALLERID(sms):
\n"; $sOutput .= "SMSTEXT(sms):
\n"; $sOutput .= "DESTINATIONNUMBER(call|sms|tariffwizard|callforward):
\n"; $sOutput .= "
\n"; $sOutput .= "

Leave these at 0 to send SMS NOW.

\n"; $sOutput .= "MONTHTOSEND(sms): ". html_select("monthtosend", num_to_array(12,0),$iMonthToSend)."
\n"; $sOutput .= "DAYTOSEND(sms): ". html_select("daytosend", num_to_array(31,0),$iDayToSend)."
\n"; $sOutput .= "HOURTOSEND(sms): ". html_select("hourtosend", num_to_array(24,0),$iHourToSend)."
\n"; $sOutput .= "MINUTETOSEND(sms): ". html_select("minutetosend", num_to_array(60,0),$iMinuteToSend)."
\n"; $sOutput .= "GMTDIFF(sms): ". html_select("gmt", num_to_array(12,-12),$iGmtDiff)."
\n"; $sOutput .= "
\n"; $sOutput .= "

Call Forward:

\n"; // "fwdtype=[0|1|2|3] for Never, Always, When offline and When offline or away.
\n"; $sOutput .= "Type: " . html_select("fwdtype", array(-1 => "Check", 0 => "Never", 1 => "Always", 2 => "When offline", 3 => "When offline or away"),$iFwdType)."
\n"; $sOutput .= "
\n"; $sOutput .= "\n"; $sOutput .= "
\n"; $sOutput .= "

\n"; return $sOutput; } // Here we set all the required GETs $iUserNumber = (isset($_GET['usernumber'])) ? $_GET['usernumber'] : 1; // If unspecified then use the 1st user $sCommand = (isset($_GET['cmd'])) ? $_GET['cmd'] : ""; // Check for a command. $sAuth = (isset($_GET['auth'])) ? $_GET['auth'] : ""; // Auth if set. $iSourceNum = $_GET['sourcenumber']; $iDestNum = $_GET['destinationnumber']; $sMsg = $_GET['smstext']; // The optional sms vars. [monthtosend] [daytosend] [hourtosend] [minutetosend] [gmt difference in hours] $iMonthToSend = $_GET['monthtosend']; $iDayToSend = $_GET['daytosend']; $iHourToSend = $_GET['hourtosend']; $iMinuteToSend = $_GET['minutetosend']; $iGmtDiff = $_GET['gmt']; $iCallerId = $_GET['callerid']; // // The optional callforward vars. [fwdtype] $iFwdType = $_GET['fwdtype']; // // If there is an auth for this user check it if (isset($aUsers[($iUserNumber - 1)]['auth'])){ // iUserNumber - 1 because arrays start at 0 NOT 1 $sDebugAuth = ""; if ($sAuth <> ""){ if ( $aUsers[($iUserNumber - 1)]['auth'] <> $sAuth){ $bAuth = FALSE; // Auth required but did NOT match. $sDebugAuth .= " Auth required but did NOT match. You used auth=\"".$sAuth."\" for user number ".$iUserNumber."."; } else { $bAuth = TRUE; // Auth required and was correct. $sDebugAuth .= " Auth required and was correct."; } } else { $bAuth = FALSE; // Auth required but was not specified. ($_GET['auth'] NOT set) $sDebugAuth .= " Auth required but was not specified."; } } else { $bAuth = TRUE; // Auth NOT required. $sDebugAuth .= " Auth NOT required."; } if ( $bAuth === TRUE ){ // All ok then set-up the finarea account details. $USER = $aUsers[($iUserNumber - 1)]['user']; // iUserNumber - 1 because arrays start at 0 NOT 1 $PASS = $aUsers[($iUserNumber - 1)]['pass']; $SERVICE = $aUsers[($iUserNumber - 1)]['service']; $iMatchNonDotCom = preg_match('/\./', $SERVICE, $aMatches); // Look for a dot. if ( $iMatchNonDotCom == 0 ) { // .com Betamax service $iMatchURLType = preg_match('/intervoip/', $SERVICE, $aMatches); // Look for intervoip service print_r($aMatches); if ( $iMatchURLType == 0 ){ // Normal .com Betamax service // echo "Betamax .com type 1
\n"; // $BASEURL = "https://myaccount.".$SERVICE.".com/clx"; $BASEURL = "https://www.".$SERVICE.".com/myaccount"; // Where $SERVICE is intervoip } else { // New Betamax service // echo "Betamax .com type 2
\n"; $BASEURL = "https://www.".$SERVICE.".com/myaccount"; // Where $SERVICE is intervoip } } else { // Non .com service eg. someservice.de $BASEURL = "https://myaccount.".$SERVICE."/clx"; } } // ************************************** PRG STARTS HERE *************************************************************** header('Content-Type: text/html; charset=utf-8'); if (empty($sCommand)){ // Then nothing to do !! echo usage(); // Show the usage / help. echo print_form(); // The demo html form. exit; } // DEBUG echo "DEBUG: Auth [".$sDebugAuth."]
\n"; // if ( $bAuth === FALSE ){ // Then auth was required and failed echo "ERROR: auth is required and FAILED!!
\n"; echo print_form(); // The demo html form. exit; } // Check that USER PASS and SERVICE are set if ((empty($USER))||(empty($PASS))||(empty($SERVICE))){ echo "ERROR: USER PASS or SERVICE is NOT set!!
\n"; echo print_form(); // The demo html form. exit; } // Try to login list ($bResult, $iResult, $sDebug) = login($USER, $PASS); if ($bResult == 0){ echo "ERROR: Login Failed!!
\n"; echo $sDebug; echo "
\n"; echo print_form(); // The demo html form. exit; } // #### go to index page as required by META Refresh . list($sMainPage, $iTSPtime, $iResult, $sDebug) = gomainpage(); echo $sDebug; // Lets print the debug here. // Now do something as requested or not. switch ($sCommand){ case "creditcents": list($iCents, $iResult, $sDebug) = creditcents($sMainPage); echo "Credit cents is [".$iCents."] or €".($iCents / 100)."
\n"; break; case "freedays": // Freedays remaining: list($iFreeDays, $iResult, $sDebug) = freedays($sMainPage); echo "Free days remaining is [".$iFreeDays."]
\n"; break; case "call": list($sResult, $iResult, $sDebug) = call($iSourceNum, $iDestNum); if ($iResult > 0){ echo "ERROR:". $sResult."
\n"; } else { echo "Call setup from [".$iSourceNum."] to [".$iDestNum."]
\n"; // echo $sDebug ; } break; case "sms": //OLD Function /* list($sResult,$iCents) = sms($iDestNum,$sMsg,$iMonthToSend,$iDayToSend,$iHourToSend, $iMinuteToSend,$iGmtDiff,$iCallerId,$iTSPtime); */ if ((!empty($iMonthToSend))||(!empty($iDayToSend))||(!empty($iHourToSend))||(!empty($iMinuteToSend))){ // Timed SMS echo "DEBUG : Timed SMS example.
\n"; $iTime = gmmktime($iHourToSend, $iMinuteToSend,0,$iMonthToSend, $iDayToSend); } else { // NOW SMS echo "DEBUG : Now SMS example.
\n"; $iTime = $iTSPtime; // Use the TSPtime (Service providers current time) $iGmtDiff = 0; // $iTSPtime should be GMT } list($sResult, $iCents, $iResult, $sDebug) = sms($iDestNum,$sMsg,$iTime,$iGmtDiff,$iCallerId); if ($iResult > 0){ echo "ERROR:". $sResult."
\n"; echo "
\n"; echo $sDebug; } else { echo "Message sent to service provider.
\n"; echo "Credit cents is [".$iCents."] or €[".($iCents / 100)."]
\n"; } break; case "tariffwizard": list($sUrl, $iRatePerMinute, $iCallSetup, $iResult, $sDebug) = tariffwizard($iDestNum); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Destination number: ".$iDestNum."
Service provider URL: ".$sUrl."
Rate per Min.: ".$iRatePerMinute."
Call setup cost: ".$iCallSetup."
\n"; break; case "callforward": list($iCurrentType, $iCurrentNumber, $iResult, $sDebug) = callforward($iFwdType, $iDestNum); $aCallFwdTypes = array (0 => "Never", 1 => "Always" , 2 => "When offline", 3 => "When offline or away"); if ( $iResult == 0 ) { $sCurrentType = $aCallFwdTypes[$iCurrentType]; echo "CallForwarding is now set as Type[".$sCurrentType."(".$iCurrentType.")] Number[".$iCurrentNumber."]
\n"; // echo "

Debug

\n". $sDebug; // DEBUG } else { echo "Oops something went wrong ...
\n"; echo $sDebug; } break; default: echo "ERROR: UNKNOWN cmd [".$sCommand."]
\n"; echo usage(); } list ($sContent,$iThisResult, $sThisDebug) = logoff(); //$sContent = $sMainPage; //echo "CONTENT [".htmlentities ($sContent)."]
\n"; echo print_form(); // The demo html form. ?> END OF EXAMPLE