Added support for HTTPS. Removed PHP version.

main
Yasen Pramatarov 2024-10-02 18:54:52 +03:00
parent d030f58776
commit 5d346bd01e
11 changed files with 29 additions and 117 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
go/jilo-agent jilo-agent

View File

@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
--- ---
## Unreleased
#### Links
- upstream: https://code.lindeas.com/lindeas/jilo-agent/compare/v0.1...HEAD
- codeberg: https://codeberg.org/lindeas/jilo-agent/compare/v0.1...HEAD
- github: https://github.com/lindeas/jilo-agent/compare/v0.1...HEAD
- gitlab: https://gitlab.com/lindeas/jilo-agent/-/compare/v0.1...HEAD
### Added
- Removed PHP version
- Added support for HTTPS
---
## 0.1 - 2024-10-02 ## 0.1 - 2024-10-02
#### Links #### Links

View File

@ -2,11 +2,7 @@
## overview ## overview
Jilo Agent - a remote agent for Jilo Web Jilo Agent - a remote agent for Jilo Web written in Go.
Initial version is in PHP.
The current version is in "go" folder and is in Go.
## license ## license
@ -32,6 +28,8 @@ go build -o jilo-agent main.go
The config file is "jilo-agent.json", in the same folder as the "jilo-agent" binary. The config file is "jilo-agent.json", in the same folder as the "jilo-agent" binary.
If you add the SSL config options, HTTPS will be used.
You can run the agent without a config file - then default vales are used. You can run the agent without a config file - then default vales are used.
## usage ## usage

View File

@ -1,7 +0,0 @@
<?php
$jicofoStatsURL = 'http://localhost:8888/stats';
$jvbStatsURL = 'http://localhost:8080/colibri/stats';
$nginxPort = '80';
?>

View File

@ -15,6 +15,6 @@
# - upx # - upx
### ###
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent main.go CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o jilo-agent ../main.go
upx --best --lzma -o jilo-agent-upx jilo-agent upx --best --lzma -o jilo-agent-upx jilo-agent
mv jilo-agent-upx jilo-agent mv jilo-agent-upx jilo-agent

View File

@ -8,6 +8,12 @@ agent_port: 8081
# secret for checking JWT (same as in Jilo Web agent config) # secret for checking JWT (same as in Jilo Web agent config)
secret_key: "mysecretkey" secret_key: "mysecretkey"
# SSL certificate file (relative or full path)
ssl_cert: "jilo-agent.crt"
# SSL key file (relative or full path)
ssl_key: "jilo-agent.key"
# the port we check for nginx # the port we check for nginx
nginx_port: 80 nginx_port: 80

View File

@ -1,50 +0,0 @@
<?php
// get nginx data
function getNginxStatus() {
$status = trim(shell_exec('systemctl is-active nginx'));
return ($status === 'active') ? 'running' : 'not running';
}
function getNginxConnections() {
$connections = shell_exec("netstat -an | grep ':$nginxPort' | wc -l");
return intval(trim($connections));
}
// get prosody data
function getProsodyStatus() {
$status = trim(shell_exec('systemctl is-active prosody'));
return ($status === 'active') ? 'running' : 'not running';
}
// get jicofo data
function getJicofoStatus() {
$status = trim(shell_exec('systemctl is-active jicofo'));
return ($status === 'active') ? 'running' : 'not running';
}
function getJicofoStats($command) {
$data = shell_exec($command);
$decodedData = json_decode($data, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return ['error' => 'Failed to decode the JSON reply from the service.'];
}
return $decodedData;
}
// get JVB data
function getJVBStatus() {
$status = trim(shell_exec('systemctl is-active jitsi-videobridge2'));
return ($status === 'active') ? 'running' : 'not running';
}
function getJVBStats($command) {
$data = shell_exec($command);
$decodedData = json_decode($data, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return ['error' => 'Failed to decode the JSON reply from the service.'];
}
return $decodedData;
}
?>

View File

View File

View File

@ -1,52 +0,0 @@
<?php
require 'config.php';
include 'functions.php';
$scriptname = basename($_SERVER['SCRIPT_NAME']);
$request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// the response is in JSON
header('Content-Type: application/json');
// nginx status
if ($request === '/nginx' || $request === "/$scriptname/nginx") {
$data = [
'nginx_status' => getNginxStatus(),
'nginx_connections' => getNginxConnections(),
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// prosody status
} elseif ($request === '/prosody' || $request === "/$scriptname/prosody") {
$data = [
'prosody_status' => getProsodyStatus(),
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// jicofo status
} elseif ($request === '/jicofo' || $request === "/$scriptname/jicofo") {
$jicofoStatsCommand = "curl -s $jicofoStatsURL";
$jicofoStatsData = getJicofoStats($jicofoStatsCommand);
$data = [
'jicofo_status' => getJicofoStatus(),
'jicofo_API_stats' => $jicofoStatsData,
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// jvb status
} elseif ($request === '/jvb' || $request === "/$scriptname/jvb") {
$jvbStatsCommand = "curl -s $jvbStatsURL";
$jvbStatsData = getJVBStats($jvbStatsCommand);
$data = [
'jvb_status' => getJVBStatus(),
'jvb_API_stats' => $jvbStatsData,
];
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
// default response - error
} else {
echo json_encode(['error' => 'Endpoint not found']) . "\n";
}
?>

View File

@ -28,6 +28,8 @@ import (
// Config holds the structure of the configuration file // Config holds the structure of the configuration file
type Config struct { type Config struct {
AgentPort int `yaml:"agent_port"` AgentPort int `yaml:"agent_port"`
SSLcert string `yaml:"ssl_cert"`
SSLkey string `yaml:"ssl_key"`
SecretKey string `yaml:"secret_key"` SecretKey string `yaml:"secret_key"`
NginxPort int `yaml:"nginx_port"` NginxPort int `yaml:"nginx_port"`
ProsodyPort int `yaml:"prosody_port"` ProsodyPort int `yaml:"prosody_port"`
@ -317,7 +319,8 @@ func main() {
// start the http server // start the http server
agentPortStr := fmt.Sprintf(":%d", config.AgentPort) agentPortStr := fmt.Sprintf(":%d", config.AgentPort)
fmt.Printf("Starting Jilo agent on port %d.\n", config.AgentPort) fmt.Printf("Starting Jilo agent on port %d.\n", config.AgentPort)
if err := http.ListenAndServe(agentPortStr, corsHandler); err != nil { // if err := http.ListenAndServe(agentPortStr, corsHandler); err != nil {
if err := http.ListenAndServeTLS(agentPortStr, config.SSLcert, config.SSLkey, corsHandler); err != nil {
log.Fatalf("Could not start the agent: %v\n", err) log.Fatalf("Could not start the agent: %v\n", err)
} }
} }