Skip to content

Commit

Permalink
feat: Log rotation page fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Aug 12, 2024
1 parent 5d5db99 commit aeb0bb6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app/Http/Controllers/API/Settings/LogRotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,45 @@
use App\Http\Controllers\Controller;
use App\System\Command;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class LogRotationController extends Controller
{
/**
* Get log rotation configuration
*
* @return JsonResponse
*/
public function getConfiguration()
{
try {
$config = Command::runSystem('cat /etc/rsyslog.d/liman.conf');

$config = explode("\n", $config);

$type = explode('protocol="', $config[2]);
$type = explode('"', $type[1])[0];

$ip = explode('target="', $config[2]);
$ip = explode('"', $ip[1])[0];

$port = explode('port="', $config[2]);
$port = explode('"', $port[1])[0];

return response()->json([
'type' => $type,
'ip_address' => $ip,
'port' => $port,
]);
} catch (\Throwable $e) {
return response()->json([
'type' => 'tcp',
'ip_address' => '',
'port' => '',
]);
}
}

/**
* Set log rotation configuration
*
Expand All @@ -23,6 +59,26 @@ public function saveConfiguration(Request $request)
'port' => 'required|numeric|between:1,65535'
]);

// Check if the port is open
// Disable fsockopen error reporting
error_reporting(0);
try {
$connection = @fsockopen($request->ip_address, $request->port, $errno, $errstr, 0.1);
if (! $connection) {
return response()->json([
'ip_address' => ['Sunucuya erişim sağlanamadı.'],
], Response::HTTP_UNPROCESSABLE_ENTITY);
} else {
fclose($connection);
}
} catch (\Throwable $e) {
return response()->json([
'ip_address' => ['Sunucuya erişim sağlanamadı.'],
], Response::HTTP_UNPROCESSABLE_ENTITY);
}
// Restore error reporting
error_reporting(E_ALL);

$template = 'module(load="imfile")
input(type="imfile" File="/liman/logs/liman_new.log" Tag="engine" ruleset="remote")
ruleset(name="remote"){action(type="omfwd" target="<TARGET>" port="<PORT>" protocol="<PROTOCOL>")}
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@

// Log Rotation
Route::group(['prefix' => 'log_rotation'], function () {
Route::get('/', [Settings\LogRotationController::class, 'getConfiguration']);
Route::post('/', [Settings\LogRotationController::class, 'saveConfiguration']);
});
});
Expand Down

0 comments on commit aeb0bb6

Please sign in to comment.