Add connection module
This commit is contained in:
59
core/admin/connection/index.php
Normal file
59
core/admin/connection/index.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
use Classes\StatsHelper;
|
||||||
|
use Connection\Common\ConnectionService;
|
||||||
|
|
||||||
|
$moduleName = 'connection';
|
||||||
|
$moduleGroup = 'admin';
|
||||||
|
define('MODULE_PATH',dirname(__FILE__));
|
||||||
|
include APP_BASE_PATH.'header.php';
|
||||||
|
include APP_BASE_PATH.'modulejslibs.inc.php';
|
||||||
|
|
||||||
|
$isIceHrmPro = false;
|
||||||
|
if (class_exists('\\Classes\\ProVersion')) {
|
||||||
|
$data = \Classes\ProVersion::$data;
|
||||||
|
$isIceHrmPro = true;
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$employeeCount = StatsHelper::getEmployeeCount();
|
||||||
|
$userCount = StatsHelper::getUserCount();
|
||||||
|
$connectionService = new ConnectionService();
|
||||||
|
?><div class="span9">
|
||||||
|
|
||||||
|
<ul class="nav nav-tabs" id="modTab" style="margin-bottom:0px;margin-left:5px;border-bottom: none;">
|
||||||
|
<li class="active"><a id="tabConnection" href="#tabConnection"><?=t('Connection')?></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="tab-content">
|
||||||
|
<div class="tab-pane active" id="tabConnection">
|
||||||
|
<div class="reviewBlock" data-content="List">
|
||||||
|
<div id="connectionData"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="dataGroup"></div>
|
||||||
|
<?php
|
||||||
|
$moduleData = [
|
||||||
|
'user_level' => $user->user_level,
|
||||||
|
'components' => [
|
||||||
|
'employeeCount' => [
|
||||||
|
'isIceHrmPro' => $isIceHrmPro,
|
||||||
|
'count' => $employeeCount,
|
||||||
|
'allowed' => $isIceHrmPro ? intval($data['employees']) : 'N/A',
|
||||||
|
'validUntil' => $data['licenseActivated'],
|
||||||
|
'licenseId' => $data['key'],
|
||||||
|
],
|
||||||
|
'systemData' => [
|
||||||
|
'data' => $connectionService->getSystemReport(),
|
||||||
|
'issues' => $connectionService->getSystemErrors(),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
initAdminConnection(<?=json_encode($moduleData)?>);
|
||||||
|
</script>
|
||||||
|
<?php include APP_BASE_PATH.'footer.php';?>
|
||||||
|
|
||||||
12
core/admin/connection/meta.json
Normal file
12
core/admin/connection/meta.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"label": "Ice Connect",
|
||||||
|
"menu": "System",
|
||||||
|
"order": "9",
|
||||||
|
"icon": "fa-wifi",
|
||||||
|
"user_levels": [
|
||||||
|
"Admin"
|
||||||
|
],
|
||||||
|
"permissions": [],
|
||||||
|
"model_namespace": "\\Connection\\Common\\Model",
|
||||||
|
"manager": "\\Connection\\Admin\\Api\\ConnectionAdminManager"
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
namespace Connection\Admin\Api;
|
||||||
|
|
||||||
|
use Classes\SubActionManager;
|
||||||
|
|
||||||
|
class ConnectionActionManager extends SubActionManager
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
38
core/src/Connection/Admin/Api/ConnectionAdminManager.php
Normal file
38
core/src/Connection/Admin/Api/ConnectionAdminManager.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Connection\Admin\Api;
|
||||||
|
|
||||||
|
use Classes\AbstractModuleManager;
|
||||||
|
use Connection\Common\ConnectionService;
|
||||||
|
|
||||||
|
class ConnectionAdminManager extends AbstractModuleManager
|
||||||
|
{
|
||||||
|
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
$iceConnect = new ConnectionService();
|
||||||
|
if ($iceConnect->dispatchInstallationRequest()) {
|
||||||
|
$iceConnect->reportInstallationData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initializeUserClasses()
|
||||||
|
{
|
||||||
|
// TODO: Implement initializeUserClasses() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initializeFieldMappings()
|
||||||
|
{
|
||||||
|
// TODO: Implement initializeFieldMappings() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initializeDatabaseErrorMappings()
|
||||||
|
{
|
||||||
|
// TODO: Implement initializeDatabaseErrorMappings() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setupModuleClassDefinitions()
|
||||||
|
{
|
||||||
|
// TODO: Implement setupModuleClassDefinitions() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
135
core/src/Connection/Common/ConnectionService.php
Normal file
135
core/src/Connection/Common/ConnectionService.php
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
namespace Connection\Common;
|
||||||
|
|
||||||
|
use Classes\BaseService;
|
||||||
|
use Classes\SettingsManager;
|
||||||
|
use Classes\StatsHelper;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use Users\Common\Model\User;
|
||||||
|
|
||||||
|
class ConnectionService
|
||||||
|
{
|
||||||
|
public function getInstallationData()
|
||||||
|
{
|
||||||
|
$proKey = '';
|
||||||
|
if (class_exists('\\Classes\\ProVersion')) {
|
||||||
|
$data = \Classes\ProVersion::$data;
|
||||||
|
$data = json_decode($data, true);
|
||||||
|
$proKey = $data['key'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => BaseService::getInstance()->getInstanceId(),
|
||||||
|
'secret' => md5(BaseService::getInstance()->getInstanceKey()),
|
||||||
|
'external_ip' => $this->getExternalIP(),
|
||||||
|
'internal_ip' => $_SERVER['SERVER_ADDR'],
|
||||||
|
'employees' => StatsHelper::getEmployeeCount(),
|
||||||
|
'users' => StatsHelper::getUserCount(),
|
||||||
|
'version' => VERSION,
|
||||||
|
'company' => SettingsManager::getInstance()->getSetting('Company: Name'),
|
||||||
|
'pro_key' => $proKey,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSystemReport()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'name' => 'Installation ID',
|
||||||
|
'value' => BaseService::getInstance()->getInstanceId(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'PHP Version',
|
||||||
|
'value' => phpversion(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'PHP Extensions',
|
||||||
|
'value' => join(', ', get_loaded_extensions()),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Web Server',
|
||||||
|
'value' => $_SERVER['SERVER_SOFTWARE'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'MySQL Server',
|
||||||
|
'value' => mysqli_get_server_info((new User())->DB()->_connectionID),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Modules Loaded',
|
||||||
|
'value' => join(', ', array_keys(BaseService::getInstance()->getModuleManagerNames())),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSystemErrors()
|
||||||
|
{
|
||||||
|
$errors = [];
|
||||||
|
$res = fopen(CLIENT_BASE_PATH.'data/connection_test.txt', "w");
|
||||||
|
|
||||||
|
if (false === $res) {
|
||||||
|
$errors[] = [
|
||||||
|
'type' => 'error',
|
||||||
|
'message' =>
|
||||||
|
'Data directory is not writable. Please make sure php can has write access to <icehrm>/app/data',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
fwrite($res, date('Y-m-d'));
|
||||||
|
$file = CLIENT_BASE_URL.'data/connection_test.txt';
|
||||||
|
$file_headers = @get_headers($file);
|
||||||
|
if ($file_headers && $file_headers[0] !== 'HTTP/1.1 404 Not Found') {
|
||||||
|
$errors[] = [
|
||||||
|
'type' => 'error',
|
||||||
|
'link' => 'https://icehrm.gitbook.io/icehrm/getting-started/securing-icehrm-installation',
|
||||||
|
'linkText' => 'Learn how to fix',
|
||||||
|
'message' => 'Data directory is accessible from outside.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dispatchInstallationRequest()
|
||||||
|
{
|
||||||
|
$timeNow = time();
|
||||||
|
$time = BaseService::getInstance()->getSystemData('sysDataTime');
|
||||||
|
if (null === $time) {
|
||||||
|
BaseService::getInstance()->setSystemData('sysDataTime', $timeNow);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$time = intval($time);
|
||||||
|
if ($timeNow > $time + 3600) {
|
||||||
|
BaseService::getInstance()->setSystemData('sysDataTime', $timeNow);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExternalIP()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$externalContent = file_get_contents('http://checkip.dyndns.com/');
|
||||||
|
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
|
||||||
|
return $m[1];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function reportInstallationData()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$client = new Client();
|
||||||
|
$response = $client->request('POST', APP_WEB_URL . '/sapi/installtion-data', [
|
||||||
|
'json' => $this->getInstallationData(),
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user