116 lines
No EOL
3.7 KiB
PHP
Executable file
116 lines
No EOL
3.7 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Session;
|
|
use \SoapClient;
|
|
|
|
class KasController extends Controller
|
|
{
|
|
|
|
|
|
// Logindaten
|
|
private $kas_user = 'w017f6e4'; // KAS-Logon
|
|
private $kas_pass = '7mMJUF4YSVWNpp39'; // KAS-Passwort
|
|
private $session_lifetime = 600; // Gültigkeit des Tokens in Sek. bis zur neuen Authentifizierung
|
|
private $session_update_lifetime = 'Y'; // bei N läuft die Session nach <$session_lifetime> Sekunden ab, bei Y verlängert sich die Session mit jeder Benutzung
|
|
private $CredentialToken = false;
|
|
private $kas_flood_delay = 2;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->login();
|
|
}
|
|
|
|
|
|
public function action($func, $para = array()){
|
|
|
|
$this->checkSession($func);
|
|
try
|
|
{
|
|
$Params = array(); // Parameter für die API-Funktion
|
|
$SoapRequest = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl', [
|
|
'cache_wsdl' => WSDL_CACHE_NONE,
|
|
'exceptions' => false
|
|
]);
|
|
$req = $SoapRequest->KasApi(json_encode(array(
|
|
'KasUser' => $this->kas_user, // KAS-User
|
|
'KasAuthType' => 'session', // Auth per Sessiontoken
|
|
'KasAuthData' => $this->CredentialToken, // Auth-Token
|
|
'KasRequestType' => $func, // API-Funktion
|
|
'KasRequestParams' => $para // Parameter an die API-Funktion
|
|
)));
|
|
Session::put('flood_protection.'.$func, time() + $this->kas_flood_delay + 0.2);
|
|
|
|
if(is_array($req) && isset($req['Response']['ReturnString']) && $req['Response']['ReturnString'] == "TRUE"){
|
|
return $req['Response']['ReturnInfo'];
|
|
}
|
|
return $req;
|
|
}
|
|
|
|
// Fehler abfangen und ausgeben
|
|
catch (SoapFault $fault)
|
|
{
|
|
trigger_error(" Fehlernummer: {$fault->faultcode},
|
|
Fehlermeldung: {$fault->faultstring},
|
|
Verursacher: {$fault->faultactor},
|
|
Details: {$fault->detail}", E_USER_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
private function login(){
|
|
|
|
$this->checkSession('auth');
|
|
try
|
|
{
|
|
|
|
$SoapLogon = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl', [
|
|
'cache_wsdl' => WSDL_CACHE_NONE,
|
|
'exceptions' => false
|
|
]);
|
|
$this->CredentialToken = $SoapLogon->KasAuth(json_encode(array(
|
|
'KasUser' => $this->kas_user,
|
|
'KasAuthType' => 'plain',
|
|
'KasPassword' => $this->kas_pass,
|
|
'SessionLifeTime' => $this->session_lifetime,
|
|
'SessionUpdateLifeTime' => $this->session_update_lifetime
|
|
)));
|
|
Session::put('flood_protection.auth', time() + $this->kas_flood_delay + 0.2);
|
|
|
|
}
|
|
|
|
// Fehler abfangen und ausgeben
|
|
catch (SoapFault $fault)
|
|
{
|
|
trigger_error("Fehlernummer: {$fault->faultcode},
|
|
Fehlermeldung: {$fault->faultstring},
|
|
Verursacher: {$fault->faultactor},
|
|
Details: {$fault->detail}", E_USER_ERROR);
|
|
}
|
|
|
|
}
|
|
|
|
private function checkSession($func)
|
|
{
|
|
$name = 'flood_protection.'.$func;
|
|
|
|
if(Session::exists($name)){
|
|
$time_to_wait = (float)Session::get($name) - time();
|
|
Session::forget($name);
|
|
}else {
|
|
$time_to_wait = 0;
|
|
}
|
|
if ( $time_to_wait >= 0 ) {
|
|
usleep( intval( $time_to_wait*1000000 ) );
|
|
}
|
|
|
|
}
|
|
} |