827 lines
37 KiB
PHP
Executable File
827 lines
37 KiB
PHP
Executable File
<?php declare(strict_types=1); namespace IR\App\Controllers; if (!defined('IR_START')) exit('<pre>No direct script access allowed</pre>');
|
|
/**
|
|
* @framework iResponse Framework
|
|
* @version 1.0
|
|
* @author Amine Idrissi <contact@iresponse.tech>
|
|
* @date 2019
|
|
* @name Tools.php
|
|
*/
|
|
|
|
# defaults
|
|
use \DOMDocument;
|
|
|
|
# core
|
|
use IR\Core\Application as Application;
|
|
|
|
# mvc
|
|
use IR\Mvc\Controller as Controller;
|
|
|
|
# models
|
|
use IR\App\Models\Admin\ServerVmta as ServerVmta;
|
|
|
|
# http
|
|
use IR\Http\Request as Request;
|
|
|
|
# helpers
|
|
use IR\App\Helpers\Authentication as Authentication;
|
|
use IR\App\Helpers\Page as Page;
|
|
use IR\App\Helpers\Permissions as Permissions;
|
|
|
|
# exceptions
|
|
use IR\Exceptions\Types\PageException as PageException;
|
|
|
|
/**
|
|
* @name Tools
|
|
* @description Tools Controller
|
|
*/
|
|
class Tools extends Controller
|
|
{
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $app;
|
|
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $authenticatedUser;
|
|
|
|
/**
|
|
* @name init
|
|
* @description initializing process before the action method executed
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function init()
|
|
{
|
|
# set the current application to a local variable
|
|
$this->app = Application::getCurrent();
|
|
|
|
# connect to the database
|
|
$this->app->database('system')->connect();
|
|
|
|
# check for authentication
|
|
if(!Authentication::isUserAuthenticated())
|
|
{
|
|
Page::redirect($this->app->http->request->getBaseURL() . RDS . 'auth' . RDS . 'login.' . DEFAULT_EXTENSION);
|
|
}
|
|
|
|
# check users roles
|
|
Authentication::checkUserRoles();
|
|
|
|
# get the authenticated user
|
|
$this->authenticatedUser = Authentication::getAuthenticatedUser();
|
|
}
|
|
|
|
/**
|
|
* @name mailboxExtractor
|
|
* @description the mailboxExtractor action
|
|
* @before init
|
|
* @after closeConnections
|
|
*/
|
|
public function mailboxExtractor()
|
|
{
|
|
# check for permissions
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
|
|
|
|
if($access == false)
|
|
{
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
|
|
# set menu status
|
|
$this->masterView->set([
|
|
'tools' => 'true',
|
|
'mailboxtractor' => 'true'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @name spfLookup
|
|
* @description the spf lookup action
|
|
* @before init
|
|
* @after closeConnections,checkForMessage
|
|
*/
|
|
public function spfLookup()
|
|
{
|
|
# check for permissions
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
|
|
|
|
if($access == false)
|
|
{
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
|
|
# get post data
|
|
$data = $this->app->http->request->retrieve(Request::ALL,Request::POST);
|
|
$results = '';
|
|
|
|
if(count($data))
|
|
{
|
|
$flag = 'error';
|
|
$message = 'Could not check spfs !';
|
|
|
|
$values = [];
|
|
$domains = explode(PHP_EOL,strval($this->app->utils->arrays->get($data,'domains')));
|
|
|
|
if(count($domains))
|
|
{
|
|
foreach ($domains as $line)
|
|
{
|
|
if($this->app->utils->domains->isValidDomain(trim($line)))
|
|
{
|
|
$values[] = trim($line);
|
|
}
|
|
}
|
|
}
|
|
|
|
$resultGrabbed = false;
|
|
|
|
# check values
|
|
if(count($values))
|
|
{
|
|
$rgbArray = [];
|
|
|
|
foreach ($values as $value)
|
|
{
|
|
|
|
$rgbArray[$value]['domain'] = $value;
|
|
$rgbArray[$value]['dmarc'] = 'No DMARC';
|
|
$rgbArray[$value]['spf'] = 'No spf records found ! ';
|
|
|
|
$spf = dns_get_record($value,DNS_TXT);
|
|
$dmarc = dns_get_record("_dmarc.".$value,DNS_TXT);
|
|
|
|
if(count($dmarc))
|
|
{
|
|
foreach($dmarc as $row)
|
|
{
|
|
$dtxt = $this->app->utils->arrays->get($row,'txt');
|
|
|
|
if($dtxt != null && $this->app->utils->strings->indexOf(strval($dtxt),'v=DMARC1') > -1)
|
|
{
|
|
$rgbArray[$value]['dmarc'] = $dtxt;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(count($spf))
|
|
{
|
|
|
|
foreach ($spf as $row)
|
|
{
|
|
$txt = $this->app->utils->arrays->get($row,'txt');
|
|
|
|
if($txt != null && $this->app->utils->strings->indexOf(strval($txt),'v=spf1') > -1)
|
|
{
|
|
$rgbArray[$value]['spf'] = $txt;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>DMARC</th><th>SPF</th></tr></thead><tbody>';
|
|
|
|
foreach ($rgbArray as $key)
|
|
{
|
|
$results .= "<tr><td>{$key['domain']}</td><td>{$key['dmarc']}</td><td>{$key['spf']}</td></tr>";
|
|
}
|
|
|
|
$results .= '</tbody></table>';
|
|
$resultGrabbed = true;
|
|
}
|
|
|
|
if($resultGrabbed == true)
|
|
{
|
|
$flag = 'success';
|
|
$message = 'spf check completed !';
|
|
}
|
|
|
|
# stores the message in the session
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
|
|
# set menu status
|
|
$this->masterView->set([
|
|
'tools' => 'true',
|
|
'spfLookup' => 'true'
|
|
]);
|
|
|
|
# set data to the page view
|
|
$this->pageView->set([
|
|
'results' => $results
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @name blacklist
|
|
* @description the blacklist action
|
|
* @before init
|
|
* @after closeConnections,checkForMessage
|
|
*/
|
|
public function blacklist()
|
|
{
|
|
# check for permissions
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
|
|
|
|
if($access == false)
|
|
{
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
|
|
# get post data
|
|
$data = $this->app->http->request->retrieve(Request::ALL,Request::POST);
|
|
$results = '';
|
|
|
|
if(count($data))
|
|
{
|
|
$flag = 'error';
|
|
$message = 'Could not check reputations !';
|
|
|
|
$values = [];
|
|
|
|
$type = strval($this->app->utils->arrays->get($data,'type'));
|
|
$lines = explode(PHP_EOL,strval($this->app->utils->arrays->get($data,'text')));
|
|
|
|
if(count($lines))
|
|
{
|
|
foreach ($lines as $line)
|
|
{
|
|
if($type == 'ips')
|
|
{
|
|
if(filter_var(trim($line),FILTER_VALIDATE_IP))
|
|
{
|
|
$values[] = trim($line);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if($this->app->utils->domains->isValidDomain(trim($line)))
|
|
{
|
|
$values[] = trim($line);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$resultGrabbed = false;
|
|
|
|
# check values
|
|
if(count($values))
|
|
{
|
|
$res = $this->app->http->request->curl("https://www.bulkblacklist.com/",[$type => implode(PHP_EOL,$values)],Request::POST,false,true);
|
|
|
|
if($res != '')
|
|
{
|
|
// create new DOMDocument
|
|
$html = new DOMDocument('1.0', 'UTF-8');
|
|
$internalErrors = libxml_use_internal_errors(true);
|
|
$html->loadHTML($res);
|
|
libxml_use_internal_errors($internalErrors);
|
|
|
|
$rows = [];
|
|
|
|
foreach($html->getElementsByTagName('tr') as $element)
|
|
{
|
|
$td = [];
|
|
|
|
foreach($element->getElementsByTagName('td') as $row)
|
|
{
|
|
$td [] = $row->ownerDocument->saveHTML($row->childNodes[0]);
|
|
}
|
|
|
|
$rows[] = $td;
|
|
}
|
|
|
|
if(count($rows) > 1)
|
|
{
|
|
$results .= '<table class="console-table"><thead><tr>';
|
|
|
|
for ($i = 1; $i < count($rows[0]); $i++)
|
|
{
|
|
$results .= '<th>' . ucwords(strtolower(str_replace('SURBL - ','',$rows[0][$i]))) . '</th>';
|
|
}
|
|
|
|
$results .= '</tr></thead><tbody>';
|
|
|
|
for ($i = 1; $i < count($rows); $i++)
|
|
{
|
|
$results .= '<tr>';
|
|
$row = $rows[$i];
|
|
|
|
if(count($row))
|
|
{
|
|
for ($j = 1; $j < count($row); $j++)
|
|
{
|
|
$results .= '<td>';
|
|
|
|
if($this->app->utils->strings->indexOf($row[$j],'images/g.png') > -1)
|
|
{
|
|
$results .= str_replace('<img src="images/g.png">','<i class="fa fa-check green"></i>',$row[$j]);
|
|
}
|
|
else if($this->app->utils->strings->indexOf($row[$j],'images/r.png') > -1)
|
|
{
|
|
$results .= str_replace('<img src="images/r.png">','<i class="fa fa-close red"></i>',$row[$j]);
|
|
}
|
|
else
|
|
{
|
|
$results .= $row[$j];
|
|
}
|
|
|
|
$results .= '</td>';
|
|
}
|
|
}
|
|
|
|
$results .= '</tr>';
|
|
}
|
|
|
|
$results .= '</tbody></table>';
|
|
}
|
|
}
|
|
|
|
$resultGrabbed = true;
|
|
}
|
|
|
|
if($resultGrabbed == true)
|
|
{
|
|
$flag = 'success';
|
|
$message = 'Blacklist check completed !';
|
|
}
|
|
|
|
# stores the message in the session
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
|
|
# set menu status
|
|
$this->masterView->set([
|
|
'tools' => 'true',
|
|
'blacklist' => 'true'
|
|
]);
|
|
|
|
# set data to the page view
|
|
$this->pageView->set([
|
|
'results' => $results
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @name extractor
|
|
* @description the extractor action
|
|
* @before init
|
|
* @after closeConnections,checkForMessage
|
|
*/
|
|
public function extractor()
|
|
{
|
|
# check for permissions
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser,__CLASS__,__FUNCTION__);
|
|
|
|
if($access == false)
|
|
{
|
|
throw new PageException('Access Denied !',403);
|
|
}
|
|
|
|
# get post data
|
|
$data = $this->app->http->request->retrieve(Request::ALL,Request::POST);
|
|
$result = '';
|
|
|
|
if(count($data))
|
|
{
|
|
$flag = 'error';
|
|
$message = 'Could not extract sub domains names !';
|
|
|
|
$text = $this->app->utils->arrays->get($data,'text');
|
|
$type = $this->app->utils->arrays->get($data,'type');
|
|
$unique = $this->app->utils->arrays->get($data,'unique','enabled');
|
|
$ips = [];
|
|
|
|
if(strlen($text) > 0)
|
|
{
|
|
if(in_array($type,['all-our-ips','all-our-ips-v4','all-our-ips-v6']))
|
|
{
|
|
$res = ServerVmta::all(ServerVmta::FETCH_ARRAY,['status = ?','Activated']);
|
|
|
|
foreach ($res as $row)
|
|
{
|
|
$ips[] = trim($row['ip']);
|
|
}
|
|
|
|
$ips = array_unique($ips);
|
|
}
|
|
|
|
switch ($type)
|
|
{
|
|
case 'all-ips':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
$matches = [];
|
|
preg_match_all("/((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
break;
|
|
}
|
|
case 'all-ips-v4':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
break;
|
|
}
|
|
case 'all-ips-v6':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
break;
|
|
}
|
|
case 'all-our-ips':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
$matches = [];
|
|
preg_match_all("/((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
if(count($matches[0]))
|
|
{
|
|
foreach ($matches[0] as $ip)
|
|
{
|
|
if(in_array(trim($ip),$ips))
|
|
{
|
|
$result .= trim($ip) . PHP_EOL;
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 'all-our-ips-v4':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
if(count($matches[0]))
|
|
{
|
|
foreach ($matches[0] as $ip)
|
|
{
|
|
if(in_array(trim($ip),$ips))
|
|
{
|
|
$result .= trim($ip) . PHP_EOL;
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 'all-our-ips-v6':
|
|
{
|
|
$matches = [];
|
|
preg_match_all("/((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?/",$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
if(count($matches[0]))
|
|
{
|
|
foreach ($matches[0] as $ip)
|
|
{
|
|
if(in_array(trim($ip),$ips))
|
|
{
|
|
$result .= trim($ip) . PHP_EOL;
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 'all-emails':
|
|
{
|
|
$matches = [];
|
|
preg_match_all('/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i',$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
$result .= implode(PHP_EOL,$matches[0]);
|
|
|
|
break;
|
|
}
|
|
case 'all-senders':
|
|
{
|
|
$matches = [];
|
|
preg_match_all('/[a-z0-9_\-\+\.]+@[a-z0-9\-]+\.([a-z]{2,4})(?:\.[a-z]{2})?/i',$text, $matches);
|
|
|
|
if($unique == 'enabled')
|
|
{
|
|
$matches[0] = array_unique($matches[0]);
|
|
}
|
|
|
|
foreach ($matches[0] as $match)
|
|
{
|
|
$result .= $this->app->utils->arrays->first(explode('@',$match)) . PHP_EOL;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
$flag = 'success';
|
|
$message = 'Values extracted successfully !';
|
|
}
|
|
|
|
# stores the message in the session
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
|
|
# set menu status
|
|
$this->masterView->set([
|
|
'tools' => 'true',
|
|
'extractor' => 'true'
|
|
]);
|
|
|
|
# set data to the page view
|
|
$this->pageView->set([
|
|
'result' => $result
|
|
]);
|
|
}
|
|
|
|
|
|
/** @name proxyChecker @description proxy checker @before init @after closeConnections,checkForMessage */
|
|
public function proxyChecker()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check proxies!';
|
|
$proxyInput = strval($this->app->utils->arrays->get($data, 'proxies'));
|
|
$lines = explode(PHP_EOL, $proxyInput); $valid = [];
|
|
foreach ($lines as $l) { $t = trim($l); if (!empty($t)) $valid[] = $t; }
|
|
if(count($valid)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Proxy</th><th>Status</th><th>Time</th></tr></thead><tbody>';
|
|
foreach ($valid as $p) {
|
|
$parts = explode(',', $p); $ip = $parts[0]; $port = isset($parts[1]) ? $parts[1] : '80';
|
|
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
|
|
curl_setopt($ch, CURLOPT_PROXY, $ip.':'.$port); curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_NOBODY, true);
|
|
$s = microtime(true); curl_exec($ch); $e = curl_errno($ch); curl_close($ch);
|
|
$t = round((microtime(true)-$s)*1000); $st = ($e===0)?'Working':'Not Working'; $cl = ($e===0)?'success':'danger';
|
|
$results .= "<tr class='{$cl}'><td>{$ip}:{$port}</td><td>{$st}</td><td>{$t}ms</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'Proxy check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'proxyChecker' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name extraspfLookup @description extra spf lookup @before init @after closeConnections,checkForMessage */
|
|
public function extraspfLookup()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check SPF!';
|
|
$values = []; $domains = explode(PHP_EOL, strval($this->app->utils->arrays->get($data, 'domains')));
|
|
foreach ($domains as $l) { if($this->app->utils->domains->isValidDomain(trim($l))) $values[] = trim($l); }
|
|
if(count($values)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>SPF</th><th>Includes</th></tr></thead><tbody>';
|
|
foreach ($values as $v) {
|
|
$spf = 'No SPF'; $inc = [];
|
|
$recs = @dns_get_record($v, DNS_TXT);
|
|
if($recs) { foreach ($recs as $r) { $t = $r['txt'] ?? ''; if(strpos($t,'v=spf1')!==false) { $spf=$t; preg_match_all('/include:([^\s]+)/',$t,$mm); $inc=$mm[1]??[]; } } }
|
|
$is = count($inc) ? implode('<br>', $inc) : 'None';
|
|
$results .= "<tr><td>{$v}</td><td>{$spf}</td><td>{$is}</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'SPF check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'extraspfLookup' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name dmarcLookup @description dmarc lookup @before init @after closeConnections,checkForMessage */
|
|
public function dmarcLookup()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check DMARC!';
|
|
$values = []; $domains = explode(PHP_EOL, strval($this->app->utils->arrays->get($data, 'domains')));
|
|
foreach ($domains as $l) { if($this->app->utils->domains->isValidDomain(trim($l))) $values[] = trim($l); }
|
|
if(count($values)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>DMARC</th><th>Policy</th></tr></thead><tbody>';
|
|
foreach ($values as $v) {
|
|
$dm = 'No DMARC'; $pol = 'N/A';
|
|
$recs = @dns_get_record("_dmarc.".$v, DNS_TXT);
|
|
if($recs) { foreach($recs as $r) { $t=$r['txt']??''; if(strpos($t,'v=DMARC1')!==false){$dm=$t; if(preg_match('/p=([^;]+)/',$t,$mm))$pol=$mm[1];} } }
|
|
$results .= "<tr><td>{$v}</td><td>{$dm}</td><td>{$pol}</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'DMARC check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'dmarcLookup' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name checkDomainAge @description check domain age @before init @after closeConnections,checkForMessage */
|
|
public function checkDomainAge()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check domain age!';
|
|
$values = []; $domains = explode(PHP_EOL, strval($this->app->utils->arrays->get($data, 'domains')));
|
|
foreach ($domains as $l) { if($this->app->utils->domains->isValidDomain(trim($l))) $values[] = trim($l); }
|
|
if(count($values)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>Created</th><th>Age</th></tr></thead><tbody>';
|
|
foreach ($values as $v) {
|
|
$cd='Unknown'; $age='N/A';
|
|
$w = @shell_exec("whois ".escapeshellarg($v)." 2>/dev/null");
|
|
if($w && preg_match('/Creat.*?Date:\s*(.+)/i',$w,$mm)){$cd=trim($mm[1]);$ts=@strtotime($cd);if($ts)$age=intval((time()-$ts)/86400).' days';}
|
|
$results .= "<tr><td>{$v}</td><td>{$cd}</td><td>{$age}</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'Domain age check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'checkDomainAge' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name checkDomainAuthority @description check domain authority @before init @after closeConnections,checkForMessage */
|
|
public function checkDomainAuthority()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check!';
|
|
$values = []; $domains = explode(PHP_EOL, strval($this->app->utils->arrays->get($data, 'domains')));
|
|
foreach ($domains as $l) { if($this->app->utils->domains->isValidDomain(trim($l))) $values[] = trim($l); }
|
|
if(count($values)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>NS</th><th>MX</th><th>A</th></tr></thead><tbody>';
|
|
foreach ($values as $v) {
|
|
$ns = @dns_get_record($v, DNS_NS); $nsS = $ns ? implode(', ', array_column($ns,'target')) : 'None';
|
|
$mx = @dns_get_record($v, DNS_MX); $mxS = $mx ? implode(', ', array_column($mx,'target')) : 'None';
|
|
$a = @dns_get_record($v, DNS_A); $aS = $a ? implode(', ', array_column($a,'ip')) : 'None';
|
|
$results .= "<tr><td>{$v}</td><td>{$nsS}</td><td>{$mxS}</td><td>{$aS}</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'Check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'checkDomainAuthority' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name checkDomainIndex @description check domain index @before init @after closeConnections,checkForMessage */
|
|
public function checkDomainIndex()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not check!';
|
|
$values = []; $domains = explode(PHP_EOL, strval($this->app->utils->arrays->get($data, 'domains')));
|
|
foreach ($domains as $l) { if($this->app->utils->domains->isValidDomain(trim($l))) $values[] = trim($l); }
|
|
if(count($values)) {
|
|
$results .= '<table class="console-table"><thead><tr><th>Domain</th><th>A</th><th>TXT</th><th>MX</th></tr></thead><tbody>';
|
|
foreach ($values as $v) {
|
|
$a = @dns_get_record($v, DNS_A); $aS = $a ? implode(', ', array_column($a,'ip')) : 'None';
|
|
$txt = @dns_get_record($v, DNS_TXT); $tA=[];
|
|
foreach($txt as $t){if(isset($t['txt']))$tA[]=htmlspecialchars(substr($t['txt'],0,60));} $tS=count($tA)?implode('<br>',$tA):'None';
|
|
$mx = @dns_get_record($v, DNS_MX); $mxS = $mx ? implode(', ', array_column($mx,'target')) : 'None';
|
|
$results .= "<tr><td>{$v}</td><td>{$aS}</td><td>{$tS}</td><td>{$mxS}</td></tr>";
|
|
}
|
|
$results .= '</tbody></table>'; $flag = 'success'; $message = 'Check completed!';
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'checkDomainIndex' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name serversTools @description servers tools @before init @after closeConnections,checkForMessage */
|
|
public function serversTools()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$data = $this->app->http->request->retrieve(Request::ALL, Request::POST);
|
|
$results = '';
|
|
if(count($data)) {
|
|
$flag = 'error'; $message = 'Could not execute!';
|
|
$ip = strval($this->app->utils->arrays->get($data, 'server-ip'));
|
|
$tool = strval($this->app->utils->arrays->get($data, 'tool-type'));
|
|
if(!empty($ip)) {
|
|
switch($tool) { case 'ping': $o=@shell_exec("ping -c 4 ".escapeshellarg($ip)." 2>&1"); break; case 'traceroute': $o=@shell_exec("traceroute -m 15 ".escapeshellarg($ip)." 2>&1"); break; default: $o=@shell_exec("ping -c 4 ".escapeshellarg($ip)." 2>&1"); }
|
|
if(!empty($o)) { $results = '<pre class="console-output">'.htmlspecialchars($o).'</pre>'; $flag='success'; $message=ucfirst($tool).' completed!'; }
|
|
}
|
|
Page::registerMessage($flag, $message);
|
|
}
|
|
$this->masterView->set(['tools' => 'true', 'serversTools' => 'true']);
|
|
$this->pageView->set(['results' => $results]);
|
|
}
|
|
|
|
/** @name jobsManagement @description jobs management @before init @after closeConnections,checkForMessage */
|
|
public function jobsManagement()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$this->masterView->set(['tools' => 'true', 'jobsManagement' => 'true']);
|
|
$this->pageView->set(['jobs' => []]);
|
|
}
|
|
|
|
|
|
/**
|
|
* @name closeConnections
|
|
* @description close all connections
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function closeConnections()
|
|
{
|
|
# connect to the database
|
|
$this->app->database('system')->disconnect();
|
|
$this->app->database('clients')->disconnect();
|
|
}
|
|
|
|
/**
|
|
* @name checkForMessage
|
|
* @description checks for session messages
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function checkForMessage()
|
|
{
|
|
# check for message
|
|
Page::checkForMessage($this);
|
|
}
|
|
}
|
|
|
|
|