Fix
This commit is contained in:
parent
3f7f9ce7e6
commit
73f3eb8178
4 changed files with 30 additions and 34 deletions
|
@ -11,10 +11,10 @@
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Classes;
|
namespace classes;
|
||||||
|
|
||||||
|
|
||||||
use Config\Config;
|
use config\config;
|
||||||
|
|
||||||
class core
|
class core
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Classes;
|
namespace classes;
|
||||||
|
|
||||||
class Webhook extends Core
|
class webhook extends core
|
||||||
{
|
{
|
||||||
private $json;
|
private $json;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Classes;
|
namespace classes;
|
||||||
|
|
||||||
use Norgul\Xmpp\Options;
|
use Norgul\Xmpp\Options;
|
||||||
use Norgul\Xmpp\XmppClient;
|
use Norgul\Xmpp\XmppClient;
|
||||||
|
|
||||||
class Xmpp extends Core{
|
class xmpp extends core{
|
||||||
private $xmpp_options;
|
private $xmpp_options;
|
||||||
private $xmpp_client;
|
private $xmpp_client;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class Xmpp extends Core{
|
||||||
$this->xmpp_options = new Options();
|
$this->xmpp_options = new Options();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start()
|
public function start(): void
|
||||||
{
|
{
|
||||||
$this->xmpp_options->setHost($this->config->xmpp_server);
|
$this->xmpp_options->setHost($this->config->xmpp_server);
|
||||||
$this->xmpp_options->setUseTls($this->config->xmpp_tls);
|
$this->xmpp_options->setUseTls($this->config->xmpp_tls);
|
||||||
|
@ -23,12 +23,12 @@ class Xmpp extends Core{
|
||||||
$this->xmpp_client = new XmppClient($this->xmpp_options);
|
$this->xmpp_client = new XmppClient($this->xmpp_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect()
|
public function connect(): void
|
||||||
{
|
{
|
||||||
$this->xmpp_client->connect();
|
$this->xmpp_client->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendMessage(string $text)
|
public function sendMessage(string $text): void
|
||||||
{
|
{
|
||||||
foreach($this->config->xmpp_recipients as $receipient)
|
foreach($this->config->xmpp_recipients as $receipient)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ class Xmpp extends Core{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getChatType(int $type)
|
private function getChatType(int $type): string
|
||||||
{
|
{
|
||||||
if($type === 1)
|
if($type === 1)
|
||||||
{
|
{
|
||||||
|
@ -60,7 +60,7 @@ class Xmpp extends Core{
|
||||||
return $return_type;
|
return $return_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function disconnect()
|
public function disconnect(): void
|
||||||
{
|
{
|
||||||
$this->xmpp_client->disconnect();
|
$this->xmpp_client->disconnect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Includes;
|
namespace includes;
|
||||||
|
|
||||||
use Classes\Xmpp;
|
use classes\xmpp;
|
||||||
use Classes\Webhook;
|
use classes\webhook;
|
||||||
use Config\Config;
|
use config\config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Application Class
|
* Main Application Class
|
||||||
* @package Includes
|
* @package Includes
|
||||||
*/
|
*/
|
||||||
class App
|
class app
|
||||||
{
|
{
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->config = new Config();
|
$this->config = new config();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main application loop
|
* Main application loop
|
||||||
*/
|
*/
|
||||||
public function start(){
|
public function start(): void
|
||||||
|
{
|
||||||
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization() && $this->checkIfIpOnWhitelistAndWhitelistEnabled()) {
|
if($this->checkIfRequestMethodIsPost() && $this->checkAuthorization() && $this->checkIfIpOnWhitelistAndWhitelistEnabled()) {
|
||||||
$this->handleIncomingData();
|
$this->handleIncomingData();
|
||||||
}
|
}
|
||||||
|
@ -31,43 +32,38 @@ class App
|
||||||
* Check if client is authorized to post via this gate
|
* Check if client is authorized to post via this gate
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function checkAuthorization()
|
private function checkAuthorization(): ?bool
|
||||||
{
|
{
|
||||||
if(isset($_GET['apikey']) && $_GET['apikey'] === $this->config->api_key)
|
if(isset($_GET['apikey']) && $_GET['apikey'] === $this->config->api_key)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
die("ERROR: Client not authenticated to use this application");
|
die("ERROR: Client not authenticated to use this application");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if whitelist and ip address is in whitelist
|
* Check if whitelist and ip address is in whitelist
|
||||||
*/
|
*/
|
||||||
private function checkIfIpOnWhitelistAndWhitelistEnabled(){
|
private function checkIfIpOnWhitelistAndWhitelistEnabled(): bool
|
||||||
|
{
|
||||||
if($this->config->ip_whitelist)
|
if($this->config->ip_whitelist)
|
||||||
{
|
{
|
||||||
if(in_array($this->getRealIPAddr(),$this->config->ips_whitelist_list))
|
if(in_array($this->getRealIPAddr(),$this->config->ips_whitelist_list))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}else
|
}
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Check if request method is post
|
* Check if request method is post
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function checkIfRequestMethodIsPost()
|
private function checkIfRequestMethodIsPost(): bool
|
||||||
{
|
{
|
||||||
if($_SERVER["REQUEST_METHOD"])
|
if($_SERVER["REQUEST_METHOD"])
|
||||||
{
|
{
|
||||||
|
@ -78,7 +74,7 @@ class App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function handleIncomingData()
|
private function handleIncomingData(): void
|
||||||
{
|
{
|
||||||
$post = file_get_contents("php://input");
|
$post = file_get_contents("php://input");
|
||||||
$wh = new Webhook($post);
|
$wh = new Webhook($post);
|
||||||
|
|
Loading…
Add table
Reference in a new issue