diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php
new file mode 100644
index 0000000..43fe035
--- /dev/null
+++ b/app/Http/Controllers/ApiController.php
@@ -0,0 +1,61 @@
+validate([
+ "token" => "required",
+ ]);
+
+ $caller_by = new Caller_DB();
+ $caller_by = $caller_by->where('token', $data['token'])->first();
+
+ if (!$caller_by) {
+ $this->logRequest($request, null, 'failed', '401 Unauthorized', null);
+ return response()->json(['error' => 'Unauthorized'], 401);
+ }
+
+ $this->logRequest($request, $caller_by, 'success', 'accepted command');
+ return response()->json(['success' => true], 200);
+
+ } catch (\Illuminate\Validation\ValidationException $exception) {
+ $this->logRequest($request, null, 'failed', '401 Unauthorized');
+ return response()->json(['error' => 'Unauthorized'], 401);
+
+ } catch (\Exception $exception) {
+ $this->logRequest($request, null, 'failed', $exception->getMessage());
+ return response()->json(['error' => 'An unexpected error occurred.' . $exception->getMessage()], 500);
+ }
+ }
+
+ private function logRequest($request, $caller_by = null, $status, $error = null)
+ {
+ $logger = new CallerLog_DB();
+ if ($caller_by) {
+ $logger->caller_id = $caller_by->id;
+ $logger->caller_name = $caller_by->node_name;
+ $logger->token_by = $caller_by->token;
+ $manager = $caller_by->manager;
+ } else {
+ $logger->caller_id = "not responsible";
+ $logger->caller_name = "not responsible";
+ $logger->token_by = "not responsible";
+ }
+
+ $logger->req_ip = $request->ip();
+ $logger->req_command = $request->path();
+ $logger->status = $status;
+ $logger->error_exception = $error;
+ $logger->save();
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/SmartController.php b/app/Http/Controllers/SmartController.php
index f33b45b..ed2ae86 100644
--- a/app/Http/Controllers/SmartController.php
+++ b/app/Http/Controllers/SmartController.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Caller_DB;
+use App\Models\CallerLog_DB;
class SmartController extends Controller
{
@@ -21,8 +22,19 @@ class SmartController extends Controller
{
$callers = Caller_DB::all();
- $callers_count = [$callers->count()];
- return view('smart.caller', compact('callers', 'callers_count'));
+ return view('smart.caller', compact('callers'));
+ }
+
+ public function caller_log()
+ {
+ $caller_logs = CallerLog_DB::paginate(15);
+ $caller_logs->getCollection()->transform(function ($log) {
+ $caller = Caller_DB::where('created_by', $log->created_by)->first();
+ $log->token_by = $caller ? $caller->created_by : null;
+ return $log;
+ });
+
+ return view('smart.caller_log', compact('caller_logs'));
}
}
diff --git a/app/Models/CallerLog_DB.php b/app/Models/CallerLog_DB.php
new file mode 100644
index 0000000..a488692
--- /dev/null
+++ b/app/Models/CallerLog_DB.php
@@ -0,0 +1,12 @@
+id()->autoIncrement();
+ $table->string('caller_id');
+ $table->string('caller_name');
+ $table->string('req_ip');
+ $table->string('req_command');
+ $table->string('token_by');
+ $table->enum('status', ['success', 'failed']);
+ $table->longtext('error_exception')->nullable();
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ //
+ }
+};
diff --git a/resources/views/smart/caller.blade.php b/resources/views/smart/caller.blade.php
index a705495..76dca10 100644
--- a/resources/views/smart/caller.blade.php
+++ b/resources/views/smart/caller.blade.php
@@ -160,7 +160,7 @@
-
+
Logs
@@ -270,33 +270,33 @@
-
- @php
- $counter = 1;
- foreach($callers_count as $caller_id) {
- echo $counter++;
- }
- @endphp
- |
- @foreach($callers as $caller)
-
-
-
- {{ $caller->node_name }}
-
+
+ @php
+ $counter = 1;
+ foreach($callers as $caller_id) {
+ echo $counter++;
+ }
+ @endphp
+ |
+ @foreach($callers as $caller)
+
+
+
+ {{ $caller->node_name }}
- |
-
-
- {{ $caller->status }}
-
- |
- @endforeach
-
-
- |
- |
-
+
+
+
+
+ {{ $caller->status }}
+
+ |
+
+
+ |
+ @endforeach
+
+
diff --git a/resources/views/smart/caller_log.blade.php b/resources/views/smart/caller_log.blade.php
new file mode 100644
index 0000000..82424d6
--- /dev/null
+++ b/resources/views/smart/caller_log.blade.php
@@ -0,0 +1,327 @@
+
+
+
+ @vite(['resources/css/app.css','resources/js/app.js'])
+
+ NCORE - Smart Caller Logging Request
+
+
+
+
+
+
+
+
+
+
+
+
Smart Call API Logs
+
+
+
+
+
+
+ ID |
+ Node |
+ Status |
+ Requested IPv4 |
+ Requested Url |
+ Token Managed By |
+ Exception |
+ Date |
+
+
+
+ @php
+ $counter = 1;
+ @endphp
+ @foreach($caller_logs as $caller)
+
+ {{ $counter++ }} |
+ {{ $caller->caller_name }} |
+
+ @if ( $caller->status === "success" )
+
+ {{ $caller->status }}
+
+ @else
+
+ {{ $caller->status }}
+
+ @endif
+ |
+
+ {{ $caller->req_ip }}
+ |
+
+
+ {{ $caller->req_command }}
+ |
+
+
+ {{ $caller->token_by }}
+ |
+
+
+ {{ $caller->error_exception }}
+ |
+
+
+ {{ $caller->created_at }}
+ |
+
+
+ @endforeach
+
+
+
+
+
+
+
+
+
+
+
+
+
+