osticket, create ticket through REST API - php

I'm trying to create a ticket in osticket through its REST API (https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md)
The problem is /api/tickets.json returns 404. I have it installed in a server on osticket folder (something like http://my.net.work.ip/osticket/api/tickets.json - 404)
Also, I've tried to CURL the server (logged in through ssh), created an APIKey for the server's IP address and had the same response.
What am I missing here?
Thank you

So, I had to add http.php after api/ (/api/http.php/tickets.json) and now I can create tickets.
Check http://tmib.net/using-osticket-1812-api. The sample used has this info in the comments.
The two really important parts are on lines 18 and 19.
'url'=>'http://your.domain.tld/api/http.php/tickets.json', // URL to site.tld/api/tickets.json
'key'=>'PUTyourAPIkeyHERE' // API Key goes here
//Edit line 18 to have your URL.
//Edit line 19 by changing "PUTyourAPIkeyHERE" to your API key (aka the "THISISAFAKEAPIKEYHERE!" from earlier).

The piece that seems to be missing from the docs is how to pass the API key. Through a bit of testing and the script mentioned above, I found the X-API-Key header. That means you can create tickets without using a script, you can use curl as easily as:
curl -X POST -H "X-API-Key: 1234567890ABCDEF" -v -d'{"autorespond":false, "source": "API", "name": "Doctor Who", "email":"who#tardis.com", "subject":"Have you seen my Tardis key?", "message":"I have managed to lock myself out of the Tardis, can you send me a spare key?"}' http://support.gallifrey.org/api/tickets.json
This will only work if it is run from the IP address you specified when you created the API key.

Besides changing lines 18 and 19 you need to make sure that you have the correct IP address. You can check that by going to your site here: http://your.domain.tld/support/scp/logs.php
Then look to see if you get the error API Error (401). If you do then look at the IP address and create a new API key for that IP address.
The problem I was facing was I typed in my IPv4 address, but the server was getting my IPv6 address.

Related

Amazon SES not working with eu_west_1 but ok using us_east_1 PHP

Im rewriting a few scripts to make use of the new v4 signature for Amazon AWS.
I am trying to send an email using the code on this page:
https://github.com/okamos/php-ses
When I use his code exactly as it is just adding secret keys etc I get an error saying my email address isnt verified on us_east_1. This makes sense as all my things are on EU_WEST_1.
So Ive tried adding the EU endpoint as a third parameter but get this error:
'Warning: SimpleEmailService::sendEmail(): 6 Could not resolve host: EU_WEST_1'
This is the line of code which seems to work but connecting to the wrong endpoint
$ses = new SimpleEmailService('apikey', 'secretkey');
print_r($ses->sendEmail($m));
I have tried adding the new endpoint as the third parameter like this
$ses = new SimpleEmailService('apikey', 'secret','eu-west-1');
But that just generates the error.
Can anyone tell me the correct code to use to set the eu-west-1 endpoint to send emails through?
Thanks
I had faced the same problem with AWS PHP library for uploading files to S3. Even though I was setting up the region from us-east-1 to eu-west-1 it was still taking us-east-1 as by default. I would suggest you to look for region configurations in library and how it is overriding.
SES Email Host for us-east-1 and eu-west-1 are different. So even though if you are passing correct API and Secret, it might not work because of default region.
If this debug process doesn't work can share the screenshot of what you region you are getting before email dispatch. I would love to explore further.
I found the problem.
Looks like there was a typo within the code on github, it had these 3 lines in the file 'SimpleEmailServices.php:
const AWS_US_EAST_1 = 'email.us-east-1.amazonaws.com';
const AWS_US_WEST_2 = 'email.us-west-2.amazonaws.com';
const AWS_EU_WEST1 = 'email.eu-west-1.amazonaws.com';
He'd missed the underscore in the AWS_EU_WEST1.

simpleSAMLphp and Azure gives me "AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application"

I am a novice for Azure SSO so I might have missed some obvious things here - please have that in mind ;-)
I need to integrate my application to Azure Active Directory. There is not much help to get in our organisation for that so I am left for myself to find the problem here :-/ My exact problem is that when I login then I get this error from Azure:
AADSTS50011: The reply URL specified in the request does not match the
reply URLs configured for the application: 'https://192.168.0.1/secure/'.
I have of course searched for how to solve this myself but I didn't find anything that could get me any closer.
I have this setup:
IIS
PHP
simpleSAMLphp
Azure AD
I have not setup nor access to the Azure part as this is setup by our IT guys but they have setup this:
Basic SAML Configuration
Identifier (Entity ID) : https://192.168.0.1/secure/
Reply URL (Assertion Consumer Service URL) : https://192.168.0.1/secure/
Sign on URL : Optional
Relay State : Optional
Logout URL : Optional
I have recived a federation XML file from Azure and have converted/populated that in to the simpleSAMLphp file \metadata\saml20-idp-remote.php
I have setup the \config\authsources.php file:
'entityID' => "https://192.168.0.1/secure/",
'idp' => "https://sts.windows.net/06dg12k9-1wl2-4mue-79gh-40ff1a8dnd4a/",
'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
'simplesaml.nameidattribute' => 'eduPersonTargetedID',
Everything has been configured with this guide in mind, https://www.lewisroberts.com/2015/09/05/single-sign-on-to-azure-ad-using-simplesamlphp/
When I launch https://192.168.0.1/simpleSAMLphp/www/ and go to Authentication and Test configured authentication sources and I test with default-sp then I do get an Azure login screen. If I view the URL for that then it looks like this:
https://login.microsoftonline.com/0ad94219-6af5-474e-99d0-60f9188f3fce/saml2
?SAMLRequest=f[CUT]2Fy%2Fi%2Bjc%3D
&RelayState=https%3A%2F%2F192.168.0.1%2FsimpleSAMLphp%2Fwww%2Fmodule.php%2Fcore%2Fauthenticate.php%3Fas%3Ddefault-sp
I assume the RelayState is where the request comes from on my server. I have tried to setup the Entity ID and Reply URL in Azure to be https://192.168.0.1/simpleSAMLphp/www/module.php/core/authenticate.php?as=default-sp but with the same result.
So I have provided everything I know here but I am really blank on how to fix this problem? Do I need to configure a Reply URL in simpleSAMLphp so it is passed as an URL parameter?
Any help would really be appreciated.
### UPDATE 1 - another problem ###
After revising the logfile from simpleSAMLphp then it showed what was sent to Azure:
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_25e3fb2" Version="2.0" Destination="https://login.microsoftonline.com/088f3fce/saml2" AssertionConsumerServiceURL="https://192.168.0.1/simpleSAMLphp/www/module.php/saml/sp/saml2-acs.php/default-sp" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST">
<saml:Issuer>https://192.168.0.1/simpleSAMLphp/www/module.php/saml/sp/metadata.php/default-sp</saml:Issuer>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" AllowCreate="true"/>
</samlp:AuthnRequest>
I then took the AssertionConsumerServiceURL from there and used that as Reply URL in Azure. Also I took the Entity ID from the simpleSAMLphp Federation page and now the simpleSAMLphp demo page works :-)
So my Azure setup now looks like this:
Basic SAML Configuration
Identifier (Entity ID) : https://192.168.0.1/simpleSAMLphp/www/module.php/saml/sp/metadata.php/default-sp
Reply URL (Assertion Consumer Service URL) : https://192.168.0.1/simpleSAMLphp/www/module.php/saml/sp/saml2-acs.php/default-sp
Sign on URL : Optional
Relay State : Optional
Logout URL : Optional
(note the difference in the URL)
However I sadly still have problems. When I have a PHP file in my web scope with this content:
<?PHP
require_once ("../../simpleSAMLphp/lib/_autoload.php");
$as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth();
$attributes = $as->getAttributes();
echo '<pre>';
print_r($attributes);
echo '</pre>';
// Get a logout URL
$url = $as->getLogoutURL();
echo 'Logout';
?>
Then it ends up in an infinite loop redirecting between my server and Azure!? Viewing the log provide no major insight for me. It seems that I do receive data from Azure and that I am authenticated as I can see the user attributes in the debug log but ... if I am authenticated then why am I redirected back to Azure!?
### UPDATE 2 - solution ###
After a few more hours of looking in the simpleSAMLphp logfile and cleaning out the WARNINGS (they are actually important) then I found out that my infinite redirection was caused by a mismatch between the PHP sessions and simpleSAMLphp sessions.
My solution was to align the two and have the exact same settings all places. Make sure to check the php.ini session settings and the \config\config.php session settings and make them identical.
Also I found out that the PHP source code I have used is for an older version of simpleSAMLphp though I don't think it was a problem.
Instead of this old method:
$as = new SimpleSAML_Auth_Simple('default-sp');
Then it should be this new method:
$as = new \SimpleSAML\Auth\Simple('default-sp');
RelayState is just a parameter that is echoed back to your SP as-is. It can be used to store the page url the user tried to access before authentication, for example.
If you're using SAML2, the replyURL should be your AssertionConsumerService url in your SP metadata. Azure will send the SAML Response there. If that url differs from https://192.168.0.1/secure/ you will get that error. Even a missing trailing / will cause the error.

Why do I receive an error 500 when trying to access Paysafe Api server?

The Paysafe API was working perfectly fine in localhost, I was able to complete payment to Netbanx. I started to integrate the system on the website. I have a page for billing information, then a page for card payment where I use paysafe.js to create a token.
Then, I use PHP to get response from the server. This works in local. But online, this last part where I try to settle a payment, I get an error 500. I think it could be because the server is not using HTTPS. I want to know if it's possible that the error 500 is coming from the fact we don't have HTTPS or if it's something else?
P.S: It's complicated to access to the server because of bureaucracy, I don't want to make all the process if it's sure it's not that!
Thank you!
P.S.: I also tried using curl instead, and the response was bool(false).
require_once("config.php");
use Paysafe\Environment;
use Paysafe\PaysafeApiClient;
use Paysafe\CardPaymentService;
use Paysafe\CardPayments\Authorization;
$client = new PaysafeApiClient($paysafeApiKeyId, $paysafeApiKeySecret, Environment::TEST, $paysafeAccountNumber);
$info = new Authorization(array(
//PAYMENT ARRAY (Getting POST variable from previous page)
));
$response = $client->cardPaymentService()->authorize($info);
$statut = $response->status;
That Environment::TEST obviously does not match the production environment (or host-name).
Just enable PHP error reporting for your IP only, in order not to possibly leak any details.
Also check the console there (if any), if that host if even authorized to access the API.
I mean, HTTP500 is an error description just alike "it does not work".

PP_E_RPS_CERT_NOT_FOUND error when querying Outlook API

I am trying to retrieve the contents of my calendar using the Outlook REST API, but I am getting weird error responses.
The code is based on the example code supplied by Microsoft in https://github.com/microsoftgraph/php-connect-rest-sample
I have created an application and specified it want access to calendar.read and changed the scope in the testcode, Constants::SCOPE, to include this scope.
After succesfully retrieving a token I can verify that the application requests and sets the correct privileges. After that I try to retrieve the events in my calendar as described at the documentation: https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#get-series-master-and-single-events-rest
I use the Advanced REST client add-on for Chrome to create a GET request with the following specs:
Url: https://outlook.office.com/api/v2.0/me/events
Headers:
Authorization: Bearer [token]
Prefer: outlook.timezone=Europe/Berlin
The response I get is a 401 status code with the following content for the X-Ms-Diagnostics header:
2000010;reason="ErrorCode: 'PP_E_RPS_CERT_NOT_FOUND'. Message: 'Certificate cannot be found. Certificate required for the operation cannot be found.%0d%0a Internal error: spRPSTicket->ProcessToken failed. Failed to call CRPSDataCryptImpl::UnpackData:Certificate cannot be found. Certificate required for the operation cannot be found.%0d%0a Internal error: Failed to decrypt data. :Failed to get session key. RecipientId=293577. spCache->GetCacheItem returns error.:Cert Name: (null). SKI: d6c3dacffd2b3fba2fb3d6c2b0fcd78680a3acd1...'";error_category="invalid_msa_ticket"
The Www-Authenticate header specifies 'error="invalid_token"' while the token was just received.
Any idea what I am doing wrong?
I think another thing you might be able to check out is the scope when you request the v2 endpoint. for V2 endpoint, the scope is different between Graph API and outlook api. you need to specify scope as "https://outlook.office.com/calendars.read" instead of Graph scope.
I hope it will help.
Basically, the message means that the token you're trying to use is not valid for the operation.
I went through this. This is how I've solved:
I use the suggested scopes here (I was creating an event): https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations#create-events
To get the authorization code I used this URL schema:
https://login.live.com/oauth20_authorize.srf?client_id=[YourClientID]&scope=[ScopeYouNeed]&response_type=code&redirect_uri=[YourRedirectURI]
Then I get the refresh & the access token. And now it's working!
You need to just change the URL from https://outlook.office.com/api/v2.0/me/events to https://graph.microsoft.com/v1.0/me/events

Can't get "Live Delegated Authentication" to work

I try to get the Live Delegated Authentication to work for the purpose of reading the email addresses.
I am doing this in PHP with the help of the windowslivelogin library. The problem is that I get an error.
I'm not sure what I'm doing wrong, i registered my application on the Azure webpage and got the appid and the secret into the code. This is what i use to initialize the Live Library :
$o = new WindowsLiveLogin();
$o->setAppId('000000004801B670');
$o->setSecret('secret');
$o->setSecurityAlgorithm('wsignin1.0');
$o->setDebug(true);
$o->setPolicyUrl('http://www.google.com/aides.html');
$o->setReturnUrl("http://michaelp.dev.gamepoint.net/framework/mainsite/contactimporter/?service=live");
return $o;
Then I call
$this->LiveLibrary->getLoginUrl()
And after I Login in to Live, it posts 2 things back, $_POST['stoken'] and $_POST['action'].
As soon as I call
$this->LiveLibrary->processLogin($_REQUEST);
It fails and gives back an error that the token is invalid.
I tried getting Consent straight away by making redirecting to
$this->LiveLibrary->getConsentUrl("Contacts.View");
But that gives an 3007 error and says that it cant share the information
According to MS this means the following :
3007
Consent Service API failed in the <method name> method. The application verifier is invalid.
The offer security level requires that a valid application verifier be passed with the request.
I am using the following URL, generated by the library
https://consent.live.com/Delegation.aspx?ps=Contacts.Invite&ru=http%3A%2F%2Fmichaelp.dev.gamepoint.net%2Fframework%2Fmainsite%2Fcontactimporter%2F%3Fservice%3Dlive&pl=http%3A%2F%2Fwww.google.com%2Faides.html&app=appid%3D000000004801B670%26ts%3D1251722931%26sig%3DD2gkM%252F%252FwlRXXfS64NMrV%252Bkt50v6dAOcESblfRk7j%252FUE%253D
I don't understand most of the documentation Microsoft has on this thing, I think its really unclear and chaotic. Also the Sample I tried doesn't work. I get an error message, it can't validate/decode the token. Same I get when I try the processLogin().
Thanks in Advance,
Michael

Categories