Xerox network accounting (JBA) C70 sending accounting users - php

I am trying to send a list of users to the Xerox for network accounting purposes.
I successfully do this with 2 Xerox models (XEROX WorkCentre 7556 and XEROX WorkCentre 7830), following sudo code in PHP:
function SendUsersToXerox($ip,$users)
{
$url="{$ip}/acct/set_auth";
$auth='account:jbaserve';
$post="+aaav1.0\n+purge\n";
foreach ($users as $u)
{
$post.="+u\"{$u->login}\"\"{$u->code}\"\n";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'EQ Device Control Engine');
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERPWD, "$auth");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/xrx-acct-data']);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// echo "HTTP CODE: {$httpcode}<br/>";
// echo $data;
}
This code works perfectly on the above named Xerox's but fails on the C70 with a 401 error and the following message:
Invalid accounting authentication version
Network accounting is enabled on the device, and I can collect all jobs from the printer at the URL acct/get_acct
If I pass in bad post data I get a different error message:
HTTP Return 400
The Request had invalid syntax
I can't find any references to JBA or Network Accounting anywhere and am not sure how to find out if the format has changed on set_auth or if it's version difference that needs to be set.
I know there are differences in the get_acct output that does point to a different version of the accounting.

The answer is very simple.
Everything is correct except the following:
$post="+aaav1.0+\n+purge\n";
The plus(+) after the v1.0 allows the users to be uploaded for accounting.

Related

YouTube v3 API call for search.list: proper curl setting

I am sending a call to the YouTube API using search.list (retrieve the first search result for a keyword) but I am getting nothing in return.
Here is my call:
$api_url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&type=video&key=MYKEY&&format=json&q=SEARCHTERMS;
Note: MYKEY is my API key I got from Google (currently active) and SEARCHTERMS is any word to search.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
$value = json_decode(json_encode($data), true);
echo $value;
The URL works correctly (tested on browser) and I'm not getting any kind of error (console), but still this curl request isn't echoing any data from YouTube. Isn't it properly set?
P.s. My quota isn't exceeded.
SOLVED!
Watch out: youtube API doesn't read spaces in url (eg. in search terms), so you gotta streplace all of them with "+"

laravel curl not working on azure

I am connecting my two apps (laravel with python) using curl command. It is working absolutely fine on my local server without changing a single line but when it gives me following error when on azure server
POST https://myweb.com/searchJobs 500 ()
my code is
$ch = curl_init();
//URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'http://python-scrapper-python001.azurewebsites.net/myfunction');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//We are doing a post request
curl_setopt($ch, CURLOPT_POST, 1);
//adding the post data to request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
//Return instead of outputting directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
is there any security protocol that I need to update on azure or what can be possible issue?
Actually these lines were working fine on localhost but not on azure
$arr = "";
$arr['hello'] = '7';
so I changed them as
$arr = [];
$arr['hello'] = '7';
Though i don't no why azure didn't run it. If php convert it to an array on localhost than it must run on azure as well
Since you are using the default domain provided by azure appservice. Instead of just using the HTTP protocol try to use the HTTPS since this is already free on the default domain provided. in this case try this changes.
$ch = curl_init();
//URL to send the request to
curl_setopt($ch, CURLOPT_URL, 'https://python-scrapper-python001.azurewebsites.net/myfunction');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
//We are doing a post request
curl_setopt($ch, CURLOPT_POST, 1);
//adding the post data to request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
//Return instead of outputting directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);

CURL login & submit another post

In order to learn PHP my boss asked me to do some sort of project. I've done so far a To Do List & Reminder (www.frontpagewebdesign.com/newfolder) but what I'm trying to do right now is sending SMS notifications.
Because I cannot afford to buy a SMS gateway for such a small project, I decided to use my account on this website: www.sms-gratuite.ro. My trouble is the automatic Login and SMS sending with CURL.
I followed a tutorial and this is what I've done so far:
<?php
$form_vars = array();
//array for SMS sending form values
$username = '****#****.com';
$password = '********';
$loginUrl = 'http://sms-gratuite.ro/page/autentificare';
$postUrl='http://sms-gratuite.ro/page/acasa';
$form_vars['to'] = "076xxxxxxx";
//my own phone number
$form_vars['mesaj'] = "test";
//SMS text
$encoded_form_vars = http_build_query($form_vars);
$user_agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters (mail and parola are the IDs of the form input fields)
curl_setopt($ch, CURLOPT_POSTFIELDS, 'mail='.$username.'&parola='.$password);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
//execute the request (the login)
$store = curl_exec($ch);
//check if the Login was succcesful by finding a string on the resulting page
if(strpos($store, "Trimite mesaj")===FALSE)
echo "logged in";
else
echo "not logged";
//set the landing url
curl_setopt($ch, CURLOPT_URL, 'http://sms-gratuite.ro/page/autentificare');
$referer='';
curl_setopt($ch, CURLOPT_URL, $postUrl);
//curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'to='.$form_vars['to'].'&mesaj='.$form_vars['mesaj']);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$result = curl_exec($ch);
if(strpos($result, "Mesajul a fost trimis")===FALSE)
echo "<br>sms sent";
else
echo "<br>sms not sent";
curl_close($ch);
?>
I don't have any errors but it surely doesn't work. First of all the login fails. Is this form a particular one and the curl cannot handle it?
You could to put every curl request result into a different file, say page1.html, page2.html, etc. This way you can open then in browser and see what's the exact page you got in return for your request
You need to make exactly same request, as browser would do. There are browser addons like HttpFox (if you are using FireFox) that can show you all fields that were sent, all cookies and everything else related. You can compare that lists to what your curl is forming to find lacking pieces
Try theese steps and comment with further errors that you got, preferably detailed.

TTY and/or ARF Response from Experian's API

I'm trying to use the PHP Curl library to connect to Experian's API.
When I post a HTTPS request to Experian, I get an HTTP 200 OK response, but nothing more. I am expecting a TTY or ARF response. Do anyone have insight in what I'm doing wrong?
Here's a snippet of my code below for reference
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://stg1.experian.com/lookupServlet1?lookupServiceName=AccessPoint&lookupServiceVersion=1.0&serviceName=NetConnectDemo&serviceVersion=2.0&responseType=text/plain'); //not the actual site
//For Debugging
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,1);
//#2-Net Connect client receives ECALS response. This is the Net Connect URL.
$ecals_url = curl_exec($ch);
//#3-Net Connect client validates that the URL ends with “.experian.com”. If the URL is valid, the processing continues; otherwise, processing ends.
$host_name = parse_url( $ecals_url );
$host_name = explode(".", $host_name['host'] );
$host_name = $host_name[1].'.'.$host_name[2];
if( $host_name == "experian.com" )
{
//#4-Net Connect client connects to Experian using URL returned from ECALS.
echo "step 4 - connect to secure connection<br>";
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch,CURLOPT_URL,$ecals_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_CERTINFO,1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //times out after 10s
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec ($ch);
print_r ($result);
It has been a while since I messed with our Experian Net Connect service but I believe you have to base64 encode the username:password value for their system to take it.

Using SMS Gateway API in PHP

i couldnt send sms using the following code, but i can sent sms using the same url, while i paste the url($murl) it into browser address bar
connection timed out, takes too much time to execute, but no result
what is the problem?
$amount="500";
$d="23-03-09";
$mNumber="98689988898";
$mName="TEST";
$mMessage ="\"We have debited Rs.$amount. Your account on $d. Thank you for your valuable support.";
$u1 = 'http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?';
$u2= 'username='.urlencode('some').'&password='. urlencode('some').'&sendername='.urlencode('some') .'&mobileno='
. urlencode($mNumber).'&message='.urlencode($mMessage).'&submit=Submit';
$murl=$u1.$u2;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $murl);
//curl_setopt($ch, CURLOPT_HEADER, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
/*curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $u2);
*/$response = curl_exec($ch);
print "Respons : $response";
curl_close($ch);
mysmsmantra is now available as a drupal module you can use the same with triggers and actions the module can be found at http://drupal.org/project/sms_mysmsmantra
Change your code to this. Should work:
FROM
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $murl);
TO
$ch = curl_init($murl);
You can set the URL in the curl_init function as well.
You can also omit curl with $response = file_get_contents($murl) if you don't need server side header answers. Check also http_build_query().
Perhaps you need to set a user agent. The service you're using could be blocking the default user agent:
curl_setopt($ch, CURLOPT_USERAGENT, 'SMS Gateway Agent/1.0'); // Pick something creative, or use a browser UA
Hope this helps!
Looking at the symptoms, I think this is an issue with firewall/access. Have you tried a script that just gets a page from the same site just to see that there is no firewall/proxy setting blocking the access. You could just use a command line web browser such as lynx to access the site from the server you are running the script to check whether the server is allowing the request to go out.
If you are game enough, run some packet sniffers to see whether any request packets are going out from the server.
<?php
if(isset($_POST['submit'])){
$message= rawurlencode($_POST['message']);
$phone=$_POST['phone'];
$url='http://sms.yourdomain.com/httpapi/smsapi?uname=xxxx&password=******&sender=XXXXX&receiver='.$phone.'&route=TA&msgtype=1&sms='.$message;
$ch = curl_init();
$header = array("Content-Type:application/json", "Accept:application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_POST, 1);
// response of the POST request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$responseBody = json_decode($response);
curl_close($ch);
}
?>
<form action="sms.php" method="post">
Phone: <input type="text" name="phone"><br>
Message: <input type="text" name="message"><br>
<input type="submit" name="submit" value="sent">
</form>

Categories