PHP Radius client - Access-Accept response is blank - php

I am sending a RADIUS request from PHP, I can see in the RADIUS proxy (FreeRadius) that the response is Access-Accept but the php code does not get a response. This is the Free Radius log sending the Access-Accept to the php code:
Sending Access-Accept Id 78 from 127.0.0.1:1812 to 127.0.0.1:47830
Framed-Protocol = PPP
Service-Type = Framed-User
Class = 0xc54b0a250000013700010200c0a8325c00000000a02e06f58ef1f00101d16804df7acf010000000000000152
MS-RNAP-Not-Quarantine-Capable = SoH-Not-Sent
MS-MPPE-Recv-Key = 0x3c0b83999598f3a5e3d58b13b69520c5
MS-MPPE-Send-Key = 0x37077455d6468f9058b91cdbbb6c2115
MS-CHAP2-Success = 0x01533d37343536414541393038434244433033464630373630333039394343453334433834384138333243
MS-CHAP-Domain = '\001DOMAIN'
MS-MPPE-Encryption-Policy = Encryption-Required
MS-MPPE-Encryption-Types = 14
MS-Quarantine-State = Full-Access
MS-Extended-Quarantine-State = 0
(0) Finished request
However, the code that gets the response:
$req = radius_send_request($res);
if (!$req) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
Spits out the line RadiusError:No valid RADIUS responses received
Any ideas?

Related

Google maps API key causing issue with file_get_contents() in php

I have a pho script that takes an address and returns the lat/lon. Works fine until I put the google api key at the end of the url. I tested the url in the browser and it works fine there.
This works fine:
$geo = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
This causes an error:
$geo = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'+&sensor=false+CA&key=[MyAPIKeyHere]');
It causes the error: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
I've seen consulted similar posts such as,
Warning while using file_get_contents for google api , but they weren't much help.
Here is the complete code:
<?php
// Address
$address = '1451 Broadway New York, NY 10036';
// Address from command line
// $address = readline("Enter an address: ");
// $address = str_replace(' ','+',$address);
// Get JSON results from this request
// This url works
$geo = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');
// This url creates an error
//$geo = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'+&sensor=false+CA&key=[MyAPIKeyHere]');
// Convert the JSON to an array
$geo = json_decode($geo, true);
if ($geo['status'] == 'OK') {
// Get Lat & Long
$latitude = $geo['results'][0]['geometry']['location']['lat'];
$longitude = $geo['results'][0]['geometry']['location']['lng'];
}
// $address = str_replace('+',' ',$address);
echo "The address ". $address. " has the following coordinates:\n" ;
echo "Lat: ". $latitude. " Lon: ". $longitude. "\n";
?>
Try using this API. It worked for me.
https://maps.googleapis.com/maps/api/geocode/json?address='.$address.'&key=YOUR_API_KEY'

How to get LINE user mid using PHP SDK?

I use the LINE BOT API Trial SDK PHP (https://github.com/line/line-bot-sdk-php).
But, for this method:
$res = $bot->sendText(['TARGET_MID'], 'Message');
How to get the user's MID to send them a message?
Thanks for help.
1) A very quick way to get the mid of an interactive user (more of a fun hack, really) is to register a callback URL as per the API instructions, then capture the POST data to that URL like so:
// /callback/index.php
<?php
$postdata = file_get_contents("php://input");
#file_get_contents('https://'.$_SERVER['SERVER_NAME'].'/LINE/' . json_encode($postdata));
Next, scan the QR code in the channel console and add your trial bot to your LINE account. After that is done, send it a quick "Hello!" text.
You could then save the POST data to a text file if you wish, or you could check the server logs. For example, you might see something like this:
163.128.118.223 - - [03/Sep/2016:07:25:25 -0700] "POST /line/callback/ HTTP/1.1" 200 - "-" "ChannelEventDispatcher/1.0"
106.152.218.107 - - [03/Sep/2016:07:25:25 -0700] "GET /LINE/{\"result\":[{\"content\":{\"toType\":1,\"createdTime\":1472114754839,\"from\":\"ub7dbd4a12c322f6c0117773d739c55a4\",\"location\":null,\"id\":\"4357194057879\",\"to\":[\"u2b6a4ba287028dee7291122094dac827\"],\"text\":\"Hello!\",\"contentMetadata\":{\"AT_RECV_MODE\":\"2\",\"SKIP_BADGE_COUNT\":\"true\"},\"deliveredTime\":0,\"contentType\":1,\"seq\":null},\"createdTime\":1472912724868,\"eventType\":\"138311609000106301\",\"from\":\"u236d23c2e36bd87217655609a1c31cb8\",\"fromChannel\":1241102815,\"id\":\"WB1519-3102846635\",\"to\":[\"u2b6a4ba287028dee7291122094dac827\"],\"toChannel\":1462261375}]} HTTP/1.1" 404 15 "-" "-"
The \"from\":\"ub7dbd4a12c322f6c0117773d739c55a4\" is the pertinent part.
2) If you'd like to get started with receiving messages, you can start like this as your callback script. Simply send your BOT the message 'mid' and it should respond with your mid.
Here is a starting callback script I made with signature verification included for you.
// /callback/index.php
<?php
// Show all errors for testing
error_reporting(E_ALL);
// SDK is installed via composer
require_once __DIR__ . "/includes/vendor/autoload.php";
use LINE\LINEBot;
use LINE\LINEBot\HTTPClient\GuzzleHTTPClient;
// Set these
$config = [
'channelId' => LINE_CHANNEL_ID,
'channelSecret' => LINE_CHANNEL_SECRET,
'channelMid' => LINE_CHANNEL_MID,
];
$sdk = new LINEBot($config, new GuzzleHTTPClient($config));
$postdata = #file_get_contents("php://input");
$messages = $sdk->createReceivesFromJSON($postdata);
// Verify the signature
// REF: http://line.github.io/line-bot-api-doc/en/api/callback/post.html#signature-verification
$sigheader = 'X-LINE-ChannelSignature';
// REF: http://stackoverflow.com/a/541450
$signature = #$_SERVER[ 'HTTP_'.strtoupper(str_replace('-','_',$sigheader)) ];
if($signature && $sdk->validateSignature($postdata, $signature)) {
// Next, extract the messages
if(is_array($messages)) {
foreach ($messages as $message) {
if ($message instanceof LINEBot\Receive\Message\Text) {
$text = $message->getText();
if ($text == "mid") {
$fromMid = $message->getFromMid();
// Send the mid back to the sender and check if the message was delivered
$result = $sdk->sendText([$fromMid], 'mid: ' . $fromMid);
if(!$result instanceof LINE\LINEBot\Response\SucceededResponse) {
error_log('LINE error: ' . json_encode($result));
}
} else {
// Process normally, or do nothing
}
} else {
// Process other types of LINE messages like image, video, sticker, etc.
}
}
} // Else, error
} else {
error_log('LINE signatures didn\'t match');
}

Get delivery reports kannel

I am using kannel sms gateway, to send sms
Sorry, if this question is asked before, but I tried to find solution, but I didn't get any, unfortunately I have to post this question.
I am sending message through php script(smpp client) to smpp server, which connects to bearer box and send message.
There are multiple issues am facing:
1. Am not able to get delivery report
2. Am getting an error in logs of smsbox : ERROR: URL <03b3423a> doesn't start with http://' norhttps://'
I tried different solutions, but none of them are working.
I am in need that if number "A" sends message to number "B", then number "A" should get acknowledgement that message had been delivered to number "B"
Here are my details of configuration files:
kannel.conf
group = core
dlr-storage=internal
admin-port = 13000
smsbox-port = 13001
admin-password = bar
log-file = "/var/log//kannel/kannel.log"
box-deny-ip = "*.*.*.*"
box-allow-ip = "127.0.0.1"
access-log = "/var/log/kannel/access.log"
#---------------------------------------------
# SMSC CONNECTIONS
group = "smsc"
smsc = "http"
smsc-id = "http"
#system-type = "generic"
system-type = "kannel"
port = 13015
log-file = /var/log/kannel/smsc.log
status-success-regex = "success"
status-permfail-regex = "failure"
status-tempfail-regex = "retry later"
generic-status-sent = 200
generic-status-error = 404
#reroute-dlr = true
#transceiver-mode = 0
receive-port=13015
send-url = "http://192.168.1.124:8090"
smsc-username = "cust2"
smsc-password = "cust#123"
connect-allow-ip = "*.*.*.*"
#dlr-url="http://192.168.1.106/dlr.php?type=%d"
#---------------------------------------------
# SMSBOX SETUP
group = smsbox
bearerbox-host = 127.0.0.1
bearerbox-port = 13001
smsbox-id = cust2
#---------------------------------------------
# SEND-SMS USERS
group = sendsms-user
username = cust2
password = cust#123
#user-deny-ip = ""
#user-allow-ip = ""
#---------------------------------------------
# SERVICES
group = sms-service
keyword = default
text = "No service specified"
group = smsbox-route
smsbox-id = cust2
smsc-id = "http"
opensmppbox.conf
group = core
dlr-storage = internal
group = opensmppbox
opensmppbox-id = OPENSMPP
opensmppbox-port = 2775
bearerbox-host = 127.0.0.1
bearerbox-port = 13001
our-system-id = outbind
smpp-logins = /usr/local/kannel/smpplogins.txt
use-systemid-as-smsboxid = true
route-to-smsc = http
log-file = /usr/local/kannel/smppbox.log
transmitter.php
<?php
//print "<pre>";
require_once "smpp.php";
$tx=new SMPP('192.168.1.81',2775);
$tx->debug=true;
$tx->system_type="http";
$tx->addr_npi=1;
$tx->sms_registered_delivery_flag=1;
$tx->sms_sm_default_msg_id=1;
//$tx->dlr_url="http://192.168.1.124/cgi-bim/drl";
//$tx->dlr_url="http://192.168.1.124:8090";
print_r($tx);
//print "open status: ".$tx->state."\n";
$tx->bindTransmitter("cust2","cust#123");
$tx->sms_source_addr_npi=1;
//$tx->sms_source_addr_ton=1;
$tx->sms_dest_addr_ton=1;
$tx->sms_dest_addr_npi=1;
$tx->sendSMS("2121","791400000","Hello world");
//$tx->sendSMS("2121","2121","Hello world!!!");
$tx->close();
unset($tx);
Please let me know, if any further information is needed
Thanks for help in advance
What is the response of the call http://192.168.1.124:8090
send-url = "http://192.168.1.124:8090"
Response must be like success, failure or retry later
status-success-regex = "success"
status-permfail-regex = "failure"
status-tempfail-regex = "retry later"
If the response is correct you will get the correct DLR

ElasticSearch PHP error 503

I'm quite new to ElasticSearch and just figuring some things out for now, but here is a problem. After all the trouble of changing the server we migrated the nodes, but have some missing data in one of them. We have two nodes that have records with the same ID in both of them. In 1'st one everything is ok, but in second some records seems to be missing. For example if I send the request like this:
GET /fnh_detailbeta/main/61UkVww8QGu093RirFG84A
I will get the following error (in Marvel - Sense)
{
"error": "NoShardAvailableActionException[[fnh_detailbeta][0] null]",
"status": 503
}
So, what I'm trying to do now is compare all the records in Node 1 with records in Node 2 via ElasticSearch PHP. Here is the PHP I'm trying to run:
<?php
require '../connector/vendor/autoload.php';
$number = 1;
$params = array();
$params['hosts'] = array (
'146.185.164.121:9200', // IP + Port
);
$client = new Elasticsearch\Client($params);
$getParams = array();
$getParams['index'] = 'fnh_mainbeta';
$getParams['type'] = 'main';
//REQUEST AMOUNT
$json = '{"query": {"match_all": {}},"size": 1,"from":'.$number.'}';
$getParams['body'] = $json;
$retDoc = $client->search($getParams);
$total = $retDoc['hits']['total'];
//END OF REQUEST AMOUNT
//REQUEST ID
for ($i = 1; $i <= $total; $i++) {
$json = '{"query": {"match_all": {}},"size": 1,"from":'.$number.'}';
$getParams = array();
$getParams['index'] = 'fnh_mainbeta';
$getParams['type'] = 'main';
$getParams['body'] = $json;
$getParams['ignore'] = 503;
$getParams['ignore'] = 404;
$retDoc = $client->search($getParams);
$found_id = $retDoc['hits']['hits'][0]['_id'];
echo $found_id;
//REGUEST SECOND DB
$getParams = array();
$getParams['index'] = 'fnh_detailbeta';
$getParams['type'] = 'main';
$getParams['id'] = '61UkVww8QGu093RirFG84A';
$retDoc = $client->get($getParams);
$found_id_two = $retDoc['_id'];
echo $found_id_two;
//END OF REQUEST SECOND DB
$number++;
sleep(1);
};
//END OF REQUEST AMOUNT
It is not finished by now, but I get the fatal error that exits the script:
Fatal error: Uncaught exception 'Guzzle\Http\Exception\ServerErrorResponseException' with message 'Server error response
[status code] 503
[reason phrase] Service Unavailable
This error appears when NoShardAvailableActionException[[fnh_detailbeta][0] null]... So, the question is:
What is the best way to catch this error (something like IF error THEN echo "error") without stop of the PHP execution. In other words - I want to determine this error, delete this record and go further comparing the Nodes.
Any help will be appreciated!

Fatal error with NuSoap 1.94 with PHP 5.2.17 making a soap client call

I'm getting an error message when making a call to an xBase++ based web server that is acting as a web service (not using WSDL) when trying to make a soapclient call to it using NuSoap 1.94 with PHP 5.2.17. This exact same code works with NuSOAP 1.94 on PHP 4. Any ideas or help would be appreciated!
Note (I had to remove the https:// part of the addresses from the error message below - I was getting an error posting saying I needed 10 reputation to post 2 links or more)
Thanks,
Salar
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'xxx.xxx.com:55055' : failed to load external entity "xxx.xxx.com:55055" in /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php:34 Stack trace: #0 /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php(34): SoapClient->SoapClient('https://xxx.xxx...') #1 /hsphere/local/home/xxx/xxx.com/phpinvent/xmsgtest.php(15): XMsg('LOGIN', Array) #2 {main} thrown in /hsphere/local/home/xxx/xxx.com/phpinvent/inc/functions/xmsg.php on line 34
Here's the code of my test page, and the xmsg function:
<?php
ini_set('display_errors', 'On');
ini_set('default_socket_timeout', 300);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// include configuration
require_once('inc/config.php');
require_once('inc/nusoap/nusoap.php'); // include the NuSOAP classes
$xmsg_param[0][0] = "userid";
$xmsg_param[0][1] = "TEST";
$xmsg_param[1][0] = "password";
$xmsg_param[1][1] = "TEST";
$result = XMsg("LOGIN", $xmsg_param);
echo("<br>resulttxt: ".$result['xmsg_resulttxt']);
echo("<br>Sessionid: ".$result['sessionid']);
?>
<?php
// XMsg *************************************************************************
// This function is used to send a message through the robust, connectionless message system
function XMsg($xm_type, $xm_parameters, $xm_target = XMSG_DEFAULT_GATEWAY, $xm_mode = XMSG_DEFAULT_MODE)
{
// Parameters:
// xm_type - C - mandatory – type of message being sent
// xm_parameters - A - optional - 2 dimensional array of name/value pairs that will be sent to the target with the message
// xm_target - C - optional - target - currently supports only URLs of AutoMate agents - defaults to gateway
// xm_mode - C - optional - tokens that allow for modification of the message - currently defaults to #SOAP# to send via SOAP
// Returns:
// xm_result - A - array of name/value pairs returned from the target in same format as xm_target
$xm_SOAPagent = ''; // SOAP Envelope Object - Request
$xm_SOAPresult = ''; // SOAP Envelope Object - Response
$xm_SOAPclass = '';
$xm_retrynum = 0; // Number of retries attempted
$xm_retry = true; // Continue retrying?
$xm_result = Array(); // Array of results returned by XMsg
$xm_numparams = 0; // Number of parameters passed to XMsg
$xm_I = 0; // FOR Loop Counter
// Initialize Parameters
$xm_parameters = (gettype($xm_parameters) == "array" ? $xm_parameters : array());
// check if mandatory parameters are passed
// xm_type must be character and not empty
if (gettype($xm_type)=="string" && !empty($xm_type)) {
switch($xm_mode)
{
case "SOAP":
// open SOAP envelope and initialize
echo("calling xm_target: ".$xm_target."<br>");
$soapclient = new soapclient($xm_target);
$soapparam = array();
// create and pass xmsg structure - NOTE: this section is specialized to PHP
$soapparam['xmsg_id'] = '';
$soapparam['xmsg_source'] = '';
$soapparam['xmsg_target'] = $xm_target;
$soapparam['xmsg_session'] = $_SESSION['SESSIONID'];
$soapparam['xmsg_userid'] = $_SESSION['USERID'];
$soapparam['xmsg_websessid'] = session_id();
$soapparam['xmsg_ip'] = $_SERVER['REMOTE_ADDR'];
$soapparam['xmsg_status'] = 'SENT';
$soapparam['xmsg_type'] = $xm_type;
$soapparam['xmsg_result'] = '';
$soapparam['xmsg_resulttxt'] = '';
$soapparam['xmsg_date'] = date("m/d/y");
$soapparam['xmsg_time'] = date("H:i:s");
$soapparam['xmsg_datereceive'] = '';
$soapparam['xmsg_timereceive'] = '';
$soapparam['xmsg_dateresponse'] = '';
$soapparam['xmsg_timeresponse'] = '';
// count parameters and add to SOAP Envelope
$xm_numparams = count($xm_parameters);
for ($xm_I = 0; $xm_I < $xm_numparams; $xm_I++) {
echo("setting soapparam[".$xm_parameters[$xm_I][0]."] to :".$xm_parameters[$xm_I][1]);
$soapparam[$xm_parameters[$xm_I][0]] = $xm_parameters[$xm_I][1];
}
// SOAP retry loop start - retry until xm_retry is false - set to false when call succeeds or max # retries exceeded
do {
// run remote SOAP call for RemoteCall as specified in
$xm_result = $soapclient->call('XMsg',$soapparam);
// check for fault
echo ("Fault: ".$xm_result['FAULT']."<br>");
echo ("1 Faultcode: ".$xm_result['faultcode']."<br>");
if (empty($xm_result['faultcode'])) {
echo('<hr>'.'<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>');
echo('<hr>'.'<pre>' . htmlspecialchars($soapclient->debug_str, ENT_QUOTES) . '</pre>');
$xm_retry = false;
// update status / response date / time
$xm_result['xmsg_status'] = "RECEIVED";
$xm_result['xmsg_dateresponse'] = date("m/d/y");
$xm_result['xmsg_timeresponse'] = date("H:i:s");
} else {
echo("2 faultcode: ".$xm_result['faultcode']);
}
// SOAP Call retry handling
if ($xm_retry) {
// increase the SOAP comm retry counter to count the number of retries made
$xm_retrynum++;
// check if the maximum number of retries has been reached
if ($xm_retrynum <= XMSG_NUMRETRY) {
sleep(XMSG_RETRYDELAY); // delay for set number of seconds
} else {
$xm_retry = false;
}
}
} while ($xm_retry);
break;
default:
// no other message type handling currently
}
}
}
return $xm_result;
// XMsg *************************************************************************
This is quite simple. Your web server can't see the location the WSDL is hosted at. Can you hit the location if you copy the WSDL url and paste it into your browser? You should check that the URL you are using is correct, and whether your web server can even see that location. If not you will need to remedy that before it will work.

Categories