Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: cliffparnitzky
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ public function __construct()
/**
* Get the data from the client.
*/
public function scanClient($clientUrl, $token)
public function scanClient($clientUrl, $endpoint, $token)
{
if (!function_exists('curl_exec'))
{
return $GLOBALS['TL_LANG']['ERR']['monitoringScanClient']['CURL_NOT_INSTALLED'];
}
$url = $clientUrl . "?token=" . $token;

$url = $clientUrl . "/contao-manager.phar.php" . $endpoint;

$agent = \Config::get('MONITORING_AGENT_NAME');
$headers = array(
'Content-Type: application/json',
'Connection: Close'
'Connection: Close',
'Authorization: Bearer ' . $token,
);
$curl = curl_init($url);

Expand All @@ -79,9 +80,32 @@ public function scanClient($clientUrl, $token)
$response = curl_exec ($curl);
curl_close($curl);
}

$arrData = json_decode($response, true);

if($arrData['status'] == 401) {
$url = $clientUrl . "/system/modules/MonitoringClient/api/api.php?token=" . $token;

$agent = \Config::get('MONITORING_AGENT_NAME');
$headers = array(
'Content-Type: application/json',
'Connection: Close',
);
$curl = curl_init($url);

if ($curl)
{
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

$response = curl_exec ($curl);
curl_close($curl);
}

$arrData = json_decode($response, true);
}

if($response === FALSE || empty($arrData))
{
return sprintf($GLOBALS['TL_LANG']['ERR']['monitoringScanClient']['FAILED'], $url, $url);
Expand All @@ -95,4 +119,4 @@ public function scanClient($clientUrl, $token)
}
}

?>
?>
118 changes: 103 additions & 15 deletions system/modules/MonitoringScanClient/dca/tl_monitoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@
'eval' => array('tl_class'=>'clr', 'submitOnChange' => true, 'doNotCopy'=>true),
'sql' => "char(1) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_monitoring']['fields']['client_url'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring']['client_url'],
'exclude' => true,
'inputType' => 'text',
'save_callback' => array(array('tl_monitoring', 'prepareUrl')),
'eval' => array('tl_class'=>'clr long', 'mandatory'=>true, 'rgxp'=>'url', 'doNotCopy'=>true, 'maxlength'=>512, 'decodeEntities'=>true),
'sql' => "varchar(512) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_monitoring']['fields']['client_token'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_monitoring']['client_token'],
Expand Down Expand Up @@ -103,13 +94,112 @@ public function __construct()
*/
public function getClientData($varValue, DataContainer $dc)
{
if (!$dc->activeRecord || empty($dc->activeRecord->client_url) || empty($dc->activeRecord->client_token))
if (!$dc->activeRecord || empty($dc->activeRecord->website) || empty($dc->activeRecord->client_token))
{
return "";
}
$monitoringScanClient = new \MonitoringScanClient();
$response = $monitoringScanClient->scanClient($dc->activeRecord->client_url, $dc->activeRecord->client_token);
if (is_array($response))
$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/server/contao', $dc->activeRecord->client_token);

if( is_array($response) && !array_key_exists('monitoring.server.agent', $response) ) {

foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'contao.' . $responseKey . ": " . $responseValue . "\n";
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/server/self-update' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'contao_manager.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/config/manager' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'contao_manager.config.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/server/config' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'server.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/server/php-web' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'php.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/server/composer' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'composer.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/config/composer' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'composer.config.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}

$response = $monitoringScanClient->scanClient($dc->activeRecord->website, '/api/users' , $dc->activeRecord->client_token);
if (is_array($response))
{
foreach($response as $responseKey=>$responseValue)
{
$varValue .= 'users.' . $responseKey . ": " . $responseValue . "\n";
}
}
else
{
\Message::addError($response);
}
}
elseif (is_array($response) && array_key_exists('monitoring.server.agent', $response))
{
foreach($response as $responseKey=>$responseValue)
{
Expand All @@ -120,9 +210,7 @@ public function getClientData($varValue, DataContainer $dc)
{
\Message::addError($response);
}

return $varValue;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_monitoring']['client_scan_active'] = array('MonitoringClient Daten auslesen', 'Legen Sie fest, ob die internen Daten des überwachten Systems aus dem installierten MonitoringClient ausgelesen werden sollen.');
$GLOBALS['TL_LANG']['tl_monitoring']['client_url'] = array('MonitoringClient API URL', 'Die Adresse zur API des MonitoringClient auf dem überwachten System. Eingabe <u>mit</u> Protokoll (z.B. http:// oder https://)!');
$GLOBALS['TL_LANG']['tl_monitoring']['client_token'] = array('MonitoringClient Token', 'Das Token des MonitoringClient zur Authentifizierung der Datenabfrage.');
$GLOBALS['TL_LANG']['tl_monitoring']['client_data'] = array('MonitoringClient Daten', 'Zeigt die internen Daten des überwachten Systems aus dem installierten MonitoringClient an.');

Expand All @@ -40,4 +39,4 @@
*/
$GLOBALS['TL_LANG']['tl_monitoring']['client_legend'] = 'MonitoringClient Daten';

?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_monitoring']['client_scan_active'] = array('Read MonitoringClient data', 'Define whether the internal data of the monitored system should be read from the installed MonitoringClient.');
$GLOBALS['TL_LANG']['tl_monitoring']['client_url'] = array('MonitoringClient API URL', 'The address to the API of the MonitoringClient on the monitored system. Enter <u>with</u> protocol (for example http:// or https://)!');
$GLOBALS['TL_LANG']['tl_monitoring']['client_token'] = array('MonitoringClient token', 'The token of the MonitoringClient for authentication of the data query.');
$GLOBALS['TL_LANG']['tl_monitoring']['client_data'] = array('MonitoringClient data', 'Displays the internal data of the monitored system from the installed MonitoringClient.');

Expand All @@ -40,4 +39,4 @@
*/
$GLOBALS['TL_LANG']['tl_monitoring']['client_legend'] = 'MonitoringClient data';

?>
?>