diff --git a/app/Http/Controllers/PostHandler.php b/app/Http/Controllers/PostHandler.php new file mode 100644 index 0000000..1084782 --- /dev/null +++ b/app/Http/Controllers/PostHandler.php @@ -0,0 +1,55 @@ +validate([ + "node_name" => "required|string", + "whitelist_ip" => "nullable|string", + "token" => "required|string", + ]); + + $data["status"] = "active"; + $user = Auth::user(); + + $caller = new Caller_DB(); + $caller->node_name = $data["node_name"]; + $caller->whitelist_ip = $data["whitelist_ip"]; + if ($data["whitelist_ip"]) { + $ips = explode(',', $data["whitelist_ip"]); + foreach ($ips as $ip) { + $ip = trim($ip); + if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + throw new \Exception('Invalid IPv4 format.'); + } + } + $caller->whitelist_ip = implode(',', $ips); + } else { + $caller->whitelist_ip = null; + } + $caller->token = $data["token"]; + $caller->status = $data["status"]; + $caller->created_by = $user->name; + $caller->updated_by = $user->name; + $caller->save(); + + return response()->json([ + "message" => "Caller added successfully.", + "redirect" => "3000", + ], 200); + + } catch (\Illuminate\Validation\ValidationException $exception) { + return response()->json(['error' => $exception->errors()], 422); + } catch (\Exception $exception) { + return response()->json(['error' => 'An unexpected error occurred.' . $exception->getMessage()], 500); + } + } +} diff --git a/app/Http/Controllers/SmartController.php b/app/Http/Controllers/SmartController.php index ee23a7a..f33b45b 100644 --- a/app/Http/Controllers/SmartController.php +++ b/app/Http/Controllers/SmartController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Models\Caller_DB; class SmartController extends Controller { @@ -15,4 +16,13 @@ class SmartController extends Controller { return view('smart.dashboard'); } + + public function caller() + { + + $callers = Caller_DB::all(); + $callers_count = [$callers->count()]; + + return view('smart.caller', compact('callers', 'callers_count')); + } } diff --git a/app/Models/Caller_DB.php b/app/Models/Caller_DB.php new file mode 100644 index 0000000..834fdeb --- /dev/null +++ b/app/Models/Caller_DB.php @@ -0,0 +1,12 @@ +id()->autoIncrement(); + $table->string('node_name'); + $table->string('whitelist_ip')->nullable(); + $table->string('token'); + $table->string('status'); + $table->string('created_by'); + $table->string('updated_by'); + $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 new file mode 100644 index 0000000..a705495 --- /dev/null +++ b/resources/views/smart/caller.blade.php @@ -0,0 +1,371 @@ + + + + @vite(['resources/css/app.css','resources/js/app.js']) + + NCORE - Smart Caller + + + + + + + +
+
+
+
+
Smart Call API
+
+
+
+ + + + + + + + + + +
+ +
+ + + + + + + + + @foreach($callers as $caller) + + + @endforeach + + + +
IDNodeStatusAction
+ @php + $counter = 1; + foreach($callers_count as $caller_id) { + echo $counter++; + } + @endphp + +
+
+ {{ $caller->node_name }} +
+
+
+ + {{ $caller->status }} + + + +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/resources/views/smart/dashboard.blade.php b/resources/views/smart/dashboard.blade.php index 00069b7..d6d04ea 100644 --- a/resources/views/smart/dashboard.blade.php +++ b/resources/views/smart/dashboard.blade.php @@ -154,7 +154,7 @@