73 lines
No EOL
1.4 KiB
PHP
73 lines
No EOL
1.4 KiB
PHP
<?php
|
|
namespace Includes;
|
|
|
|
use Classes\Xmpp;
|
|
use Classes\Webhook;
|
|
use Config\Config;
|
|
|
|
/**
|
|
* Main Application Class
|
|
* @package Includes
|
|
*/
|
|
class App
|
|
{
|
|
protected $config;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->config = new Config();
|
|
}
|
|
|
|
/**
|
|
* Main application loop
|
|
*/
|
|
public function start(){
|
|
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization()) {
|
|
$this->handleIncomingData();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if client is authorized to post via this gate
|
|
* @return bool
|
|
*/
|
|
private function checkAuthorization()
|
|
{
|
|
if(isset($_GET['apikey']) && $_GET['apikey'] === $this->config->api_key)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
die("ERROR: Client not authenticated to use this application");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Check if request method is post
|
|
* @return bool
|
|
*/
|
|
private function checkIfRequestMethodIsPost()
|
|
{
|
|
if($_SERVER["REQUEST_METHOD"])
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
private function handleIncomingData()
|
|
{
|
|
$post = file_get_contents("php://input");
|
|
$wh = new Webhook($post);
|
|
$xmpp = new Xmpp();
|
|
|
|
$xmpp->start();
|
|
$xmpp->connect();
|
|
$xmpp->sendMessage($wh->getMessage());
|
|
$xmpp->disconnect();
|
|
}
|
|
} |