I'm trying to pipe support emails from my production mail server (Plesk 12 and Postfix) to send them to another VPS hosting my helpdesk installation, I have chosen ostickets helpdesk for many reasons (Open source,PHP/MySQL...)
So, the idea is to trigger email reception on some adresses such as contact#company.com, support#company.com... then resend them to ostickets via its API in order to create a new ticket there.
I tried this way
http://blog.absolutedisaster.co.uk/osticket-plesk-9-postfix-pipe-mail-to-a-progr/
It explains how to create a pipe to trigger email, lunch php script ...etc
Because of some permission issues, I kept all this configuration and change just the last thing : php script
So I've replaced this php script by a simple bash script doing the same thing : send a request to API to create a new ticket via CURL.
Now In my production mail server the pipe is recognized and the email is trigged successfully :
The same in the other side, osticket API is receiving the request:
The problem is that the http response is 400 as you can see, which means ans error code #66 in ostickets (malformed email).
So, I think the problem is in my bash script :
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data - 'http://support.company.com/api/tickets.email'
the original PHP script I have replaced by this is :
#!/usr/bin/php -q
<?php
# Configuration: Enter the url and key. That is it.
# url => URL to api/tickets.email e.g http://yourdomain.com/support/api/tickets.email
# key => API's Key (see admin panel on how to generate a key)
#
$config = array(
'url'=>'http://support.company.com/api/tickets.email',
'key'=>'API_KEY_HERE'
);
#pre-checks
function_exists('file_get_contents') or die('upgrade php >=4.3');
function_exists('curl_version') or die('CURL support required');
#read stdin (piped email)
$data=file_get_contents('php://stdin') or die('Error reading stdin. No message');
#set timeout
set_time_limit(10);
#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
curl_close($ch);
//Use postfix exit codes...expected by MTA.
$code = 75;
if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status)) {
switch($status[1]) {
case 201: //Success
$code = 0;
break;
case 400:
$code = 66;
break;
case 401: /* permission denied */
case 403:
$code = 77;
break;
case 415:
case 416:
case 417:
case 501:
$code = 65;
break;
case 503:
$code = 69;
break;
case 500: //Server error.
default: //Temp (unknown) failure - retry
$code = 75;
}
}
exit($code);
?>
What is missing in my bash script ? (especially the stdin input)
thank you so much,
UPDATE
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'
The problem was indeed in the bash script, here is the solution I came up with:
#!/bin/bash
data=`cat -`
exec curl --header 'X-API-Key: API_KEY_HERE' --user-agent 'osTicket API Client v1.7' --data "$data" 'http://support.company.com/api/tickets.email'
Related
I have a simple Intranet set up with 1 router, 1 computer, and 10 ESP8266.
I have a Laravel app served on that computer that sends Get Request to an ESP8266 module locally.
After a successful request, ESP8266 needs to activate some hardware and the Laravel app needs to update the database that the request was actually sent.
I have a simple cURL like below:
$url = "$machine->ip_address/activate";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
$curl_error = curl_error($curl);
curl_close($curl);
if($curl_error) {
// rollback the database
} else {
// update the database that the request was actually sent/received
}
In my ESP8266, I have this code snippet
void handleRequest() {
// some logic to activate the hardware
server.send(200, "text/html", "1");
}
The snippet above and the cURL work just fine. But there are times that the cURL failed to receive the response from ESP8266 but the hardware was activated. That means that the request was sent, but the response wasn't received. In that instance, the device will be activated but the database will not be updated. Because the Laravel app would believe that the request was not sent/received.
TLDR: How can I make sure that the request actually failed/succeeded?
Do I need some configuration for the router to make it more stable?
I am trying to upload a file to OneDrive using the following code:
$graph_url = 'https://graph.microsoft.com/v1.0/me/drive/root:/filename:/createUploadSession';
$file = file_get_contents('logo.jpeg');
$headers = [
'Content-Type: json',
"Cache-Control: no-cache",
"Pragma: no-cache",
"Authorization: bearer EwAQA61DBAAUcSSzoTJJsy+XrnQXgAKO5cj4yc8AAewWnvfTuLAC2gDmYesGiVawqeIpfS8lJjyCyeXQMrKOu92FA0SK12N/87GBTs4ba2LJ5buqmm9gX18by0jPWzZ5qvpc+BdfMC2wUyiMYxh8QH8BJFBctAVgSaKM1KmhA8mAwb2czyw4OeWdupKH7qSPvjRtwBTTxxX8iIO3IeNbpXDghri9MWRGyVIffGf2Oi+RzQm5jbGuDtXrQa4K80m1o8PHcEkdIEXbaAgIE8oBYCVBQ7fyYxA84b0NjghSRbCZDj5rVbo1MDeBv0J4inmPthEbAMcS3fRSBdFs3+SSz+jZwb3SgSp5Q+VXiRs+keDQHspaoSNt4Ho0+pX94WQDZgAACAk/KNYU0yEY4AHihrs84QKvmWWfIOTYCBudQZD7tKp2ZeOpXEI7q3tOTuwHTv7uUmYxkpGswiNSeW2r9DEBdQ5gBtZ/YCXMPhlBLSxxahrl816zsj/UDi2c6dmB+6J1wk60/hm1Ll6vqn8YbtlyQh9hFLpWejo8+Vofh5/kRUfUSl1v7FIP7YIJLvTyNn1gGy9IMnxYdvba9ACGotVpFTAMNdjz6aQwUk4MJjD7csqYVpyMBh8O7bS40dRMjiUkdhXYvA03L/JV818qgo0W0uwJmoqzPJfe7VB+VekqxPCyVT6A86y/OaD1EsTaLwBILG8eS48Odr/qg7azjUsrdryS+rg7wfQEBEL+kIkS5Ne8eTg1/t2aAXFsUukiIBkTYp+Sold4yhqJU2w/cRDZiz9m3GBltjTS+JiIX2Ll0ABbOwmY9pkc6O8/3T0ZhgVuIigfIILTdMGMu9sNvJtVxYL4gbRlNX+gyMBHZHDo2zktdD5l4vDa+TTgn2Fc3CDUli/qLU1UX2SfJ6+B+epmX/wA32cXVtfDPcm605c18LipDoOVGxzf9RVyNe9e3VCFvR9UBmkobodVfE1VhUfzw/s5CHrjzCZ7ZZDt84Hm6VoWIVZLtYueHCuAaEhLa0gWZTKUSwvu3hCDwZUaAg==",
"Content-Length: ".filesize('logo.jpeg'),
];
$ch = curl_init($graph_url);
curl_setopt($ch, CURLOPT_URL, $graph_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{}');
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
The result, however, is the always the following error:
"error": {
"code": "InvalidAuthenticationToken",
"message": "CompactToken parsing failed with error code: 8004920A",
"innerError": {
"request-id": "bab6035c-17c5-45ea-99ac-7c809e446ca2",
"date": "2018-12-22T09:42:03"
}
}
First of all, it seems like your token is incorrect. So step 1 is verify the token is correct. You can do that by copying your token and pasting it on the website Microsoft created specifically for this job. https://jwt.ms
Secondly as the microsoft documentation describes you have 2 ways of uploading a file to onedrive.
Direct upload (only for small files) docs
Through a upload session, docs
You're trying to do a direct upload to the CreateUploadSession endpoint.
The first way works (for small files) by uploading the file to the /content endpoint, but that is just a file only upload. So no content headers with json in them.
The second way works by creating an upload sessions (that responds with some json) and then do a second request for uploading the file to the endpoint you got from the url.
The documentation on these things are quite clear, and I think you're using PHP, so it should be easy to mimic the provided curl requests with php.
I'm working on a project where i need to fetch contacts from yahoo mail. and I'm using Oauth2.0. I'm getting access_token and all things from here https:// api.login.yahoo.com/oauth2/get_token via curl with passing grant_type and all required parameters which is fine. but the problem is refresh_token and xoauth_yahoo_guid from yahoo I'm redirecting to this url https://social.yahooapis.com/v1/user/{xoauth_yahoo_guid}/contacts?format=json. I'm getting this output:-
{"error":{"#lang":"en-US","#uri":"http://yahoo.com","description":"Not Authorized - Either YT cookies or a valid OAuth token must be passed for authorization","detail":"Not Authorized - Either YT cookies or a valid OAuth token must be passed for authorization"}}
However I'm working in codeigniter and i need this task to be done in ajax or javascript But I've tried a lot but unfortunately nothing worked out for me. Please help me to get rid out of this problem.
Thanks.
Finally I got the answer. I just have to send the header
$headers= array(
'Authorization: Bearer '.< access_token >,
'Accept: application/json',
'Content-Type: application/json'
);
with following Code:-
$ch = curl_init();
$url = "https://social.yahooapis.com/v1/user/me/contacts?format=json";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$output3 = curl_exec ($ch);
curl_close ($ch); // close curl handle
$finalresult = json_decode($output3);
echo'<pre>';print_r($finalresult);
Is it possible to send custom XML messages from oracle service cloud while maintaining HTTP session?
So far I've managed to send a single message using cURL:
<?php
use \Rightnow\Connect\v1_2 as RNCPHP;
use \Rightnow\CPM\v1 as RNCPM;
$url1 = "";
$startInterviewHeaders = array("SOAPAction: http://oracle");
$startInterview;
// session
//$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
if(!function_exists("\curl_init")){
\load_curl();
echo "curl loaded";
} else {
echo "curl already exists ";
}
$ch = curl_init();
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POSTFIELDS, $startInterview);
curl_setopt($ch, CURLOPT_HTTPHEADER, $startInterviewHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$startInterviewresponse = curl_exec($ch);
//echo $response;
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errno= curl_errno($ch);
echo "</br> HTTP status: " . $http_status . "</br> cURL error: " .$curl_errno . "</br>";
curl_close($ch); // close cURL
echo $startInterviewresponse;
?>
EDIT: Code above sends a single message and gets a response, but when I try to maintain HTTP session with CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE, second cURL message response complains that there is no active session.
sessions.com.oracle.determinations.server.exceptions.NoActiveInterviewExceptionaction "Investigate" can not be performed without an active interview
Code I used to maintain session (worked when testing outside Rightnow environment)
curl_setopt($ch,CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name'); //could be empty, but cause problems on some hosts
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/ip4.x/file/tmp'); //could be empty, but cause problems
Thanks!
Your code sample is a Custom Process Model. CPMs do not allow persistence and will be closed once the CPM completes. You can run multiple curl calls from one CPM, but that is not recommended; you should use an integration middleware if you need multiple calls per CPM.
As long as you're running this code from an asynchronous CPM (synchronous CPMs don't expose curl, so that should be the case here), then an error on the OSvC side is likely an issue connecting to your "local test server", which is almost always not exposed to the public internet in an enterprise environment. Therefore, your "crash" is likely a connection error.
Per #drew010, you need to include your error in the context of this question as well.
I'm working on a script that send a POST request to an URL, actually I'm sending the cookies manually in the header.. but how to take it from the current browser session?
I used tcpdump and grep but it's really the wrong choice :,D
Some suggestions?
I wont take them from a file but from the browser session and without enter in the cookie path of the browser
Curl can handle that for you; there is an option to store the cookies in a cookiejar and use those in subsequent requests.
Here is an example from the main curl site, which uses cookies from a file cookies.txt to set some and at the same time stores new cookies in newcookies.txt.
http://curl.haxx.se/docs/httpscripting.html#Cookie_Basics
curl --cookie cookies.txt --cookie-jar newcookies.txt http://www.example.com
When going through a login process, for example, one would reuse the cookies from cookie jar.
I had found a link now broken with an example from snipplr.com. I'll post it here for future references (credits to the owner):
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (isset($_COOKIE[session_name()])) {
curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.$_COOKIE[session_name()].'; path=/');
}
session_write_close();
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'curl error: '.curl_error($ch);
}
curl_close($ch);
session_start();