No output from php script.

henkoegema

Joined
Jul 12, 2007
Messages
37
Likes
0
Points
0
#1
The following php script is suppose to give me the balance of Voipbuster, by dialing extension 3000

Code:
exten => 3000,1,Wait(1)
exten => 3000,n,Playback(astcc-account-balance-is)
exten => 3000,n,Set(status=${CURL(https://192.168.1.100:8888/credit/credit_voipbuster.php)})
exten => 3000,n,NoOP(${status})
exten => 3000,n,SayDigits(${status})
exten => 3000,n,Playback(vm-goodbye)
exten => 3000,n,Hangup()
//This php script is in /var/www/html/credit/
<?php
function encryptString($string) {
for($i=0; $i < strlen($string); $i++) {
if(is_numeric($string[$i])) {
if($string[$i] < "5")
$string[$i]= $string[$i] + 5;
else
$string[$i]= $string[$i] - 5;
}
}
return str_rot13($string);
}

// Set username and password:
$username = encryptString('henkoegema');
$password = encryptString('xxxxxx');

$loginurl = ('https://myaccount.voipbuster.com/clx/index.php?part=plogin&username=' . $username . '&password=' . $password);
$mainmenuurl = ('https://myaccount.voipbuster.com/clx/index.php?part=menu&justloggedin=true');

//========== FIRST PART (LOGIN): ============

$cookiejar = tempnam("", "");
if ($cookiejar) {
$ch = curl_init(); // curl initialization

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar); //connecting cookie input and output to
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar); //this curl session

curl_setopt ($ch, CURLOPT_URL, $loginurl); //set URL to use in GET/POST action

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //return received data (instead of curl result code)

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); //DISABLE HTTPS AUTHENTICATION CHECKING:

curl_exec ($ch); //EXECUTE 1st REQUEST (FORM LOGIN):
//will give a redirect to: /index.php?part=menu&justloggedin=true


//========== SECOND PART: ==========

// FOLLOWING REDIRECT TO /index.php?....:
curl_setopt($ch, CURLOPT_URL, $mainmenuurl);

$content = curl_exec ($ch); //EXECUTE 2nd REQUEST (load 'main menu'), saving data in $content:

curl_close ($ch); //close curl session

// We gaan evenetje knippen in de ruwe source code van de returnwaarde
// bestudeer de html source (print $content) en alles wordt duidelijk.
$start = strpos($content,'balanceid'); //bepaal start van balanceid
$deelstring = substr($content,$start+26,10); //kopieer het begin van het bedrag de string naar een tussen waarde
//print $deelstring;
$einde = strpos($deelstring,'<'); //einde van het bedrag is waar de afsluit tag begint
$bedrag = substr($deelstring,0,$einde);
print "Remaining credit: $bedrag\n"; //gebruik dit als je wil testen
// print "$bedrag"; //gebruik dit als je het als AGI script gaat gebruiken in Asterisk

}
else { print "error creating cookie file"; }
When I dial extension 3000, the ${status} remains empty.

Executing [3000@from-internal:3] Set("SIP/1206-090883c0", "status=") in new stack
-- Executing [3000@from-internal:4] NoOp("SIP/1206-090883c0", "") in new stack
When I run
https://192.168.1.100:8888/credit/credit_voipbuster.php
directly in a web browser, it gives me the correct output. (8888 is the port number for the browser)

This script worked correctly in Asterisk 1.4.14 with SuSE10.2, but I can't get it working in Elastix. Evenso I just copied and pasted the script. :(
 

henkoegema

Joined
Jul 12, 2007
Messages
37
Likes
0
Points
0
#2
For a while I was thinking it was a SSL certificate problem.

When I execute onElastix server:

Code:
[root@elastix ~]# curl https://localhost:8888/credit/credit_dialnow.php
I get:

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086 SSL routines SL3_GET_SERVER_CERTIFICATE:certificate verify failed
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.



I do get output with (by switching off verification with -k option)

Code:
[root@elastix ~]# curl -k https://localhost:8888/credit/credit_dialnow.php
6.14    <----------- OK !
root@elastix ~]#
I tried to change

exten => 3000,n,Set(Status=${curl https://192.168.1.100:8888/credit/credit_dialnow.php)})

into

exten => 3000,n,Set(Status=${curl -k (https://192.168.1.100:8888/credit/credit_dialnow.php)})

but variable ${Status} remains empty. :(<br><br>Post edited by: henkoegema, at: 2007/08/13 18:09
 

henkoegema

Joined
Jul 12, 2007
Messages
37
Likes
0
Points
0
#3
This works: :)

Code:
[root@elastix ~]# status=$(curl -k https://192.168.1.100:8888/credit/credit_dialnow.php)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     4    0     4    0     0      2      0 --:--:--  0:00:01 --:--:--    18
[root@elastix ~]# echo $status
4.46

This doesn't: :(

......
exten => 3000,n,Set(Status=${curl -k (https://192.168.1.100:8888/credit/credit_dialnow.php)})
exten => 3000,n,NoOP(${Status})
exten => 3000,n,SayDigits(${Status})
 

henkoegema

Joined
Jul 12, 2007
Messages
37
Likes
0
Points
0
#4
Is the CURL function from Elastix a different one then the curl function from the operating system?

(because the php script runs nicely from the os, but NOT from the dialplan in Elastix)
 

henkoegema

Joined
Jul 12, 2007
Messages
37
Likes
0
Points
0
#5
I even tried to do a system call:

Code:
exten => 3000,1,Wait(1)
exten => 3000,n,Playback(astcc-account-balance-is)
exten => 3000,n,System(status=$(curl -k https://192.168.1.100:8888/credit/credit_dialnow.php))
exten => 3000,n,System(echo ${status})
exten => 3000,n,NoOP(${status})
exten => 3000,n,SayDigits(${status})
exten => 3000,n,Playback(vm-goodbye)
exten => 3000,n,Hangup()
But that gives me:


-- Executing [3000@from-internal:2] Playback("Zap/1-1", "astcc-account-balance-is") in new stack
-- <Zap/1-1> Playing 'astcc-account-balance-is' (language 'en')
-- Executing [3000@from-internal:3] System("Zap/1-1", "status=$(curl -k https://192.168.1.100:8888/credit/credit_dialnow.php)") in new stack
-- Executing [3000@from-internal:4] System("Zap/1-1", "echo ") in new stack
-- Executing [3000@from-internal:5] NoOp("Zap/1-1", "") in new stack
-- Executing [3000@from-internal:6] SayDigits("Zap/1-1", "") in new stack


So it looks like that the variable ${status} gets lost. :blink:
 

Members online

No members online now.

Forum statistics

Threads
30,951
Messages
130,979
Members
17,652
Latest member
joeljag_19
Top