diff --git a/app/Server/Connections/ControlConnection.php b/app/Server/Connections/ControlConnection.php index c11db09..e748372 100644 --- a/app/Server/Connections/ControlConnection.php +++ b/app/Server/Connections/ControlConnection.php @@ -51,4 +51,9 @@ class ControlConnection ], ])); } + + public function close() + { + $this->socket->close(); + } } diff --git a/app/Server/Factory.php b/app/Server/Factory.php index ddd3209..e94f7d5 100644 --- a/app/Server/Factory.php +++ b/app/Server/Factory.php @@ -8,6 +8,7 @@ use App\Contracts\UserRepository; use App\Http\Server as HttpServer; use App\Server\Connections\ConnectionManager; use App\Server\Http\Controllers\Admin\DeleteUsersController; +use App\Server\Http\Controllers\Admin\DisconnectSiteController; use App\Server\Http\Controllers\Admin\ListSitesController; use App\Server\Http\Controllers\Admin\ListUsersController; use App\Server\Http\Controllers\Admin\RedirectToUsersController; @@ -120,6 +121,7 @@ class Factory $this->router->post('/users', StoreUsersController::class, $adminCondition); $this->router->delete('/users/{id}', DeleteUsersController::class, $adminCondition); $this->router->get('/sites', ListSitesController::class, $adminCondition); + $this->router->delete('/sites/{id}', DisconnectSiteController::class, $adminCondition); } protected function bindConfiguration() diff --git a/app/Server/Http/Controllers/Admin/DisconnectSiteController.php b/app/Server/Http/Controllers/Admin/DisconnectSiteController.php new file mode 100644 index 0000000..2ad7fb2 --- /dev/null +++ b/app/Server/Http/Controllers/Admin/DisconnectSiteController.php @@ -0,0 +1,43 @@ +connectionManager = $connectionManager; + } + + public function handle(Request $request, ConnectionInterface $httpConnection) + { + $connection = $this->connectionManager->findControlConnectionForClientId($request->get('id')); + + if (! is_null($connection)) { + $connection->close(); + + $this->connectionManager->removeControlConnection($connection); + } + + $httpConnection->send(respond_json([ + 'sites' => $this->connectionManager->getConnections() + ])); + } +} diff --git a/app/Server/Http/Controllers/Admin/ListSitesController.php b/app/Server/Http/Controllers/Admin/ListSitesController.php index a093d54..dd97095 100644 --- a/app/Server/Http/Controllers/Admin/ListSitesController.php +++ b/app/Server/Http/Controllers/Admin/ListSitesController.php @@ -27,15 +27,11 @@ class ListSitesController extends AdminController public function handle(Request $request, ConnectionInterface $httpConnection) { - try { - $sites = $this->getView($httpConnection, 'server.sites.index', [ - 'scheme' => $this->configuration->port() === 443 ? 'https' : 'http', - 'configuration' => $this->configuration, - 'sites' => $this->connectionManager->getConnections() - ]); - } catch (\Exception $e) { - dump($e->getMessage()); - } + $sites = $this->getView($httpConnection, 'server.sites.index', [ + 'scheme' => $this->configuration->port() === 443 ? 'https' : 'http', + 'configuration' => $this->configuration, + 'sites' => $this->connectionManager->getConnections() + ]); $httpConnection->send( respond_html($sites) diff --git a/resources/views/server/sites/index.twig b/resources/views/server/sites/index.twig index 6870823..1747e77 100644 --- a/resources/views/server/sites/index.twig +++ b/resources/views/server/sites/index.twig @@ -21,23 +21,24 @@ - {% for site in sites %} - + - {{ site.host }} + @{ site.host } - {{ site.subdomain }}.{{ configuration.hostname()}}:{{ configuration.port() }} + @{ site.subdomain }.{{ configuration.hostname()}}:{{ configuration.port() }} - {{ site.shared_at }} + @{ site.shared_at } - Visit + Disconnect - {% endfor %} @@ -52,40 +53,17 @@ delimiters: ['@{', '}'], data: { - userForm: { - name: '', - errors: {}, - }, - users: {{ users|json_encode|raw }} + sites: {{ sites|json_encode|raw }} }, methods: { - deleteUser(user) { - fetch('/expose/users/' + user.id, { + disconnectSite(id) { + fetch('/sites/' + id, { method: 'DELETE', }).then((response) => { return response.json(); }).then((data) => { - this.users = this.users.filter(u => u.id !== user.id); - }); - }, - saveUser() { - fetch('/expose/users', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(this.userForm) - }).then((response) => { - return response.json(); - }).then((data) => { - if (data.user) { - this.userForm.errors = {}; - this.users.unshift(data.user); - } - if (data.errors) { - this.userForm.errors = data.errors; - } + this.sites = data.sites; }); } } diff --git a/resources/views/server/users/index.twig b/resources/views/server/users/index.twig index 7691fd3..6dea0ff 100644 --- a/resources/views/server/users/index.twig +++ b/resources/views/server/users/index.twig @@ -60,7 +60,7 @@ methods: { deleteUser(user) { - fetch('/expose/users/delete/'+user.id, { + fetch('/users/delete/'+user.id, { method: 'DELETE', }).then((response) => { return response.json(); @@ -69,7 +69,7 @@ }); }, saveUser() { - fetch('/expose/users', { + fetch('/users', { method: 'POST', headers: { 'Content-Type': 'application/json'