/** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::addAll( Controller::class ); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/tenants", "label" => "Tenants", "icon" => "bi bi-suitcase-lg", "menu" => "administration", ]; $routes[] = [ "path" => "/tenants/{id}", "label" => "Benutzer", ]; return $routes; }); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Systems; use ARUNOX\Plugins\Tenants; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Tenant nicht gefunden", "saved" => "Tenant wurde erfolgreich gespeichert", "deleted" => "Tenant wurde erfolgreich gelöscht", "created" => "Tenant wurde erfolgreich erstellt", "notcreated" => "Tenant konnte nicht erstellt werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll() { $results = Tenants\Model::getAll(); static::restConfigOverview( $results ); return REST\Response::jsonResponse(); } public function get( int $id ) { if( $result = Tenants\Model::get( $id ) ) { static::restConfigDetails( $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function save( int $id, array $data ) { if( $result = Tenants\Model::get( $id ) ) { $result->save( $data ); REST\Response::addNotify( "success", static::getNotify("saved") ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function create( array $data ) { if( $id = Tenants\Model::save( $data ) ) { REST\Response::addNotify( "success", static::$NOTIFY["created"] ); REST\Response::closeModals(); REST\Response::redirect( "/tenants" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notcreated"] ); return REST\Response::jsonResponse(); } public function delete( int $id ) { REST\Response::closeModals(); if( Tenants\Model::delete( $id ) ) { REST\Response::addNotify( "success", static::$NOTIFY["deleted"] ); REST\Response::redirect( "/tenants" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function toggleStatus( int $id ) { if( $result = Tenants\Model::get( $id ) ) { $result->toggleStatus( TRUE ); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ public function validateUUID( int $id, array $data ) { if( isset( $data["value"] ) && $data["value"] ) { if( $result = Tenants\Model::getByUUID( $data["value"] ) ) { if( $result->id != $id ) { return $this->jsonResponse([ "valid" => FALSE ] ); } } } return $this->jsonResponse([ "valid" => TRUE ] ); } /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigOverview( array $data = [] ) { return REST\Response::addWrapper( "overview", "Tenant" ) ->setList( $data ) ->get() ->setAction( "/tenants/{id}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "tenants" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, "tenants" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "tenants" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "label" => "Datenbank", "icon" => "bi-database-gear", "options" => Systems\DBStatus::getAll(), ], "db_status", [], "tenants" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->email", [], "email", TRUE, TRUE, TRUE, "tenants" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "domain", TRUE, TRUE, TRUE, "tenants" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "tenants" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->list", [ "label" => "Systeme", "icon" => "bi-gear-wide-connected", "action" => "/tenants/{id}#systems", ], "tenants" )) ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "tenants" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "tenants" )) ->top(); } public static function restConfigDetails( Tenants\Entity $data ) { return REST\Response::addWrapper( "details", "Tenant bearbeiten" ) ->setData( $data ) ->setBacklink( "/tenants" ) ->get() ->setAction( "/api/v1/tenants/{id}", "PUT" ) ->addTab( "Tenant" )->get() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "tenants" )) // ->addField(...Hooks::filter( "rest.generator::control.type->url", [], "domain", FALSE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->email", [], "email", TRUE, "tenants" )) ->parent() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "address", TRUE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "zipcode", TRUE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "city", TRUE, "tenants" )) ->parent() ->parent() ->addTab( "Systems" )->get() ->addContent( Tenants\Systems\API\v1\Controller::restConfigTable( $data->id ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } public static function restConfigCreate() { return REST\Response::addModal( "details", "Tenant erstellen" ) ->setData([ "id" => 0 ]) ->get() ->setAction( "/api/v1/tenants", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "uuid", TRUE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "hook", TRUE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [], "interval", FALSE, TRUE, "tenants" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "runtime", FALSE, "tenants" )) ->top(); } public static function restConfigDelete( int $id ) { return REST\Response::addModal( "details", "Tenant Löschen" ) ->setData([ "id" => $id ]) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/api/v1/tenants/{id}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$id}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "tenants" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "tenants" )) ->top(); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Systems/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Systems\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::addAll( Controller::class ); // Router::get('/api/v1/tenants/{id}/systems', [ Controller::class, 'getAll' ]); // // Router::get('/api/v1/tenants/{id}/systems/create', [ Controller::class, 'restConfigCreate' ]); // Router::post('/api/v1/tenants/{id}/systems', [ Controller::class, 'create' ]); // // Router::get('/api/v1/tenants/{id}/systems/{id}', [ Controller::class, 'get' ]); // Router::put('/api/v1/tenants/{id}/systems/{id}', [ Controller::class, 'save' ]); // Router::patch('/api/v1/tenants/{id}/systems/{id}/status', [ Controller::class, 'toggleStatus' ]); // Router::patch('/api/v1/tenants/{id}/systems/{id}/db_status', [ Controller::class, 'resolveDBStatus' ]); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Systems/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Systems\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Systems; use ARUNOX\Plugins\Tenants; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "System nicht gefunden", "saved" => "System wurde erfolgreich gespeichert", "added" => "System wurde erfolgreich hinzugefügt", "notadded" => "System konnte nicht hinzugefügt werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll( int $tenant_id ) { $results = Tenants\Systems\Model::getAll([ "tenant_id" => $tenant_id ]); return $this->jsonResponse( $results ); } public function get( int $tenant_id, int $id ) { if( $result = Tenants\Systems\Model::get( $id ) ) { static::restConfigDetails( $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function save( int $tenant_id, int $id, array $data ) { if( $result = Tenants\Systems\Model::get( $id ) ) { $result->save( $data ); REST\Response::addNotify( "success", static::$NOTIFY["saved"] ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", "/api/v1/tenants/{$tenant_id}/systems", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function create( int $tenant_id, array $data ) { if( $id = Tenants\Systems\Model::save( $data ) ) { REST\Response::addNotify( "success", static::$NOTIFY["added"] ); REST\Response::closeModals(); REST\Response::redirect( "/tenants/{$tenant_id}#systems" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notadded"] ); return REST\Response::jsonResponse(); } public function toggleStatus( int $tenant_id, int $id ) { if( $result = Tenants\Systems\Model::get( $id ) ) { $result->toggleStatus( TRUE ); REST\Response::addUpdater( [ "data/table/row", "/api/v1/tenants/{$tenant_id}/systems", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function resolveDBStatus( int $tenant_id, int $id ) { if( $result = Tenants\Systems\Model::get( $id ) ) { $result->resolveDBStatus(); REST\Response::addUpdater( [ "data/table/row", "/api/v1/tenants/{$tenant_id}/systems", $id ], $result ); REST\Response::addNotify( $result->db_status->getColor()->value, $result->db_status->getLabel(), $result->db_status->getIcon() ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigDetails( Tenants\Systems\Entity $data ) { $form = REST\Response::addModal( "details", "System bearbeiten" ) ->setData( $data ) ->get() ->setAction( "/tenants/{tenant_id}/systems/{id}", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Speichern", "tenants/{tenant_id}/systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Systems\Model::getAsOptions(), ], "system_id", TRUE, FALSE, "tenants/{tenant_id}/systems" )); if( $data->type->isTenantIsolated() ) { $form->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => "Datenbankname", "options" => $data->getDatabasesAsOptions() ], "db_name", TRUE, TRUE, "tenants/{tenant_id}/systems" )); } return $form; } public static function restConfigCreate( int $tenant_id ) { return REST\Response::addModal( "details", "System hinzufügen" ) ->setData([ "tenant_id" => $tenant_id ]) ->get() ->setAction( "/tenants/{tenant_id}/systems", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "tenants/{tenant_id}/systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "tenant_id", $tenant_id, "tenants/{tenant_id}/systems" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Systems\Model::getAsOptions(), ], "system_id", TRUE, FALSE, "tenants/{tenant_id}/systems" )); } public static function restConfigTable( int $tenant_id ) { return Systems\API\v1\Controller::restConfigTable("tenants/{$tenant_id}") ->setData([ "tenant_id" => $tenant_id ]) ->setAction( "/tenants/{tenant_id}/systems/{id}" ) ->getColumn("actions") ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "tenants/{tenant_id}/systems" )) ->beforeColumn( ...Hooks::filter( "rest.generator::column.type->text", [], "db_name", TRUE, TRUE, TRUE, "tenants/{tenant_id}" )); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Systems/Plugins/Model.php **/ DBStatus::class, "status" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "type" => "system->type", "name" => "system->name", "domain" => "system->domain", ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } public function connect() { return $this->system->connect( $this->db_name ); } public function getDBConn() { return $this->system->db_conn; } // public function getPlugins() { return $this->system->plugins; } public function checkDBStatus() { return $this->system->checkDBStatus( $this ); } public function resolveDBStatus() { return $this->system->resolveDBStatus( $this ); } public function getSystem() { if( $this->system_id ) { return Systems\Model::get( $this->system_id ); } return NULL; } public function getDatabasesAsOptions() { $system = strtolower( $this->name ); $results = Database::getDatabase(); $options = []; foreach( $results as $item ) { if( preg_match( "/_schema$/", $item ) ) continue; if( !preg_match( "/(^|_){$system}(_|$)/", $item ) ) continue; $options[] = [ "value" => $item, "label" => $item, ]; } return $options; } public function getPlugins() { $plugins = $this->system->plugins; $plugins = array_filter( $plugins, fn( $item ) => $item->status->isActive() ); foreach( $plugins as $plugin ) { $check = Plugins\Model::get([ "tenant_id" => $this->tenant_id, "system_id" => $this->system_id, "plugin" => $plugin->plugin, ]); if( $check ) continue; Plugins\Model::save([ "tenant_id" => $this->tenant_id, "system_id" => $this->system_id, "plugin" => $plugin->plugin, ]); } $plugins = Plugins\Model::getAll([ "tenant_id" => $this->tenant_id, "system_id" => $this->system_id, ]); return $plugins; } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct() { if( !$this->system->type->isTenantIsolated() ) { $this->db_status = $this->system->db_status->getValue(); } parent::__construct(); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Entity.php **/ Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "db_status" => "DBStatus", ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } public function getSystems() { return Systems\Model::getAll([ "tenant_id" => $this->id ]); } public function getDBStatus() { $systems = $this->systems; if( !$systems ) return DBStatus::ByTenant; $status = DBStatus::Ok; foreach( $this->systems as $system ) { if( $system->db_status->getValue() < $status ) { $status = $system->db_status->getValue(); } } return $status; } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Users/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Users\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::addAll( Controller::class ); // Router::get('/api/v1/tenants/{id}/users', [ Controller::class, 'getAll' ]); // Router::get('/api/v1/tenants/create', [ Controller::class, 'restConfigCreate' ]); // Router::post('/api/v1/tenants', [ Controller::class, 'create' ]); // Router::get('/api/v1/tenants/{id}/users/{id}', [ Controller::class, 'get' ]); // Router::put('/api/v1/tenants/{id}', [ Controller::class, 'save' ]); // Router::patch('/api/v1/tenants/{id}/status', [ Controller::class, 'toggleStatus' ]); // Router::get('/api/v1/tenants/{id}/delete', [ Controller::class, 'restConfigDelete' ]); // Router::delete('/api/v1/tenants/{id}', [ Controller::class, 'delete' ]); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/tenants/{id}/users/{id}", "label" => "Benutzer", ]; return $routes; }); } } /** Datei: plugins/tenants/library/ARUNOX/Plugins/Tenants/Users/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Tenants\Users\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; use ARUNOX\Plugins\Tenants; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Benutzer nicht gefunden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll( int $tenant_id ) : HTTP\Response { $results = Users\Model::getAll([ "tenant_id__meta" => $tenant_id ]); return $this->jsonResponse( $results ); } public function get( int $tenant_id, int $user_id ) : HTTP\Response { $result = Users\Model::get([ "id" => $user_id, "tenant_id__meta" => $tenant_id ]); if( $result ) { Users\API\v1\Controller::restConfigDetails( $result ) ->setBacklink( "/tenants/{$tenant_id}#users" ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = Users\API\v1\Controller::restConfigTable() ->setApi( "/tenants/{id}/users" ) ->setAction( "/api/v1/tenants/{tenant_id}/users/{id}" ); foreach( $table->get()->getButtons() as $button ) { $action = $button->getAction(); if( $action["route"] != "/users/{id}" ) continue; $action["route"] = "/tenants/{tenant_id}/users/{id}"; $button->setAction( ...$action ); break; } return $table; } } /** Datei: plugins/tenants/hooks/model/saved_users.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook model::saved->users * @param mixed $result save result * @param string $table Current Database Table Name * @param object $query Database\QueryBuilder Object * * @since 1.0.0 File is created */ use ARUNOX\Core\Auth; use ARUNOX\Plugins\Users; use ARUNOX\Database\QueryBuilder; if( $result === FALSE ) return $result; $user = Users\Model::get( $result ); if( !$user->tenant_id ) return $result; $hash = Auth::createHash( $user->email ); $DBname = "admin"; $table = "tenants_systems_users"; $where = [ "tenant_id" => $user->tenant_id, "system_id" => SYSTEM->id, "user_id" => $user->id, ]; $data = array_merge( $where, [ "hash" => $hash ] ); $exists = QueryBuilder::select( $table ) ->addWhere( $where ) ->using( $DBname ) ->fetch(); // show( $exists, $data, $user ); if( $exists ) $mapping = QueryBuilder::update( $table, $data, $where ); else $mapping = QueryBuilder::insert( $table, $data ); $mapping = $mapping->using( $DBname )->execute(); // show( $result, $mapping, $user ); return $result; /** Datei: plugins/tenants/hooks/model/query.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook model::query * @param object $query Database\QueryBuilder Object * @param string $table Current Database Table Name * * @since 1.0.0 File is created */ use ARUNOX\Database; use ARUNOX\Plugins\Users; use ARUNOX\Plugins\Tenants; if( $table == Tenants\Model::getTable() ) return $query->using("admin"); if( $table == Tenants\Systems\Model::getTable() ) return $query->using("admin"); if( in_array( $query->database->getConfig("name"), [ "default", "admin" ] ) ) { return $query; } // show( $query->database->getConfig("name") ); if( Users\Model::isSuperadmin() || !Users\Model::isLoggedIn() ) return $query; if( !SYSTEM->type->isTenantShared() ) return $query; if( !Database::existsTable( "{$query->table}_meta" ) ) return $query; if( Database::columnExists( $query->table, "origin_id" ) ) { $mainTable = $query->table; $mainTable = explode( "_", $mainTable ); $subTable = array_pop( $mainTable ); $mainTable = implode( "_", $mainTable ); $query->addWhere([ "tenant_id__query" => [ "table" => "{$mainTable}_meta", "on" => "{$mainTable}_meta.origin_id = {$query->table}.origin_id", "CONDITIONS" => [ "meta_key" => "tenant_id", "meta_value" => Users\Model::getTenantId(), ] ] ]); return $query; } $query->addWhere([ "tenant_id__meta" => Users\Model::getTenantId() ] ); return $query; /** Datei: plugins/tenants/hooks/router/dispatch-after_users.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; Hooks::add('router::dispatch->after->patch.users.{id}.status', function( $result, $route, $id ) { if( !REST\Response::hasUpdater() ) return $result; $response = REST\Response::response(); $user = Users\Model::get( $id ); $referer = $route["request"]->getReferer("path"); if( !$user ) return $result; if( !preg_match( "/^tenants/", $referer ) ) return $result; foreach( $response as &$item ) { if( $item->type !== "updater" ) continue; $uuid = base64_decode( $item->updater ); $uuid = explode( ":", $uuid ); if( $uuid[1] != "/api/v1/users" ) continue; $uuid[1] = "/api/v1/tenants/{$user->tenant_id}/users"; $uuid = implode( ":", $uuid ); $uuid = base64_encode( $uuid ); $item->updater = $uuid; break; } return $response; }); Hooks::add('router::dispatch->after->delete.users.{id}', function( $result, $route, $id ) { if( !REST\Response::hasRoute() ) return $result; $response = REST\Response::response(); $user = Users\Model::get( $id ); $referer = $route["request"]->getReferer("path"); if( !$user ) return $result; if( !preg_match( "/^tenants/", $referer ) ) return $result; foreach( $response as &$item ) { if( $item->type !== "route" ) continue; $item->route = "/tenants/{$user->tenant_id}#users"; } return $response; }); /** Datei: plugins/tenants/hooks/router/dispatch-before_login.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook router::dispatch->before->post.login * @param mixed $route current route data * @param object $request current request data * * @since 1.0.0 File is created */ use ARUNOX\Core\Auth; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; use ARUNOX\Database\QueryBuilder; if( !SYSTEM->type->isTenantIsolated() ) return; $post = $request->getBodyParams(); $hash = Auth::createHash( $post["email"] ); $DBname = "admin"; $data = QueryBuilder::select("tenants_systems_users") ->addWhere([ "system_id" => SYSTEM->id, "hash" => $hash, ]) ->using( $DBname ) ->fetch(); // show( $data, "X" ); if( !$data ) { REST\Response::addNotify( "danger", "NO SYSTEM/USER FOUND" ); REST\Response::setTemplate( "login" ); REST\Response::jsonResponse( 401 )->send(); } // show( $post, $hash, $data, "X" ); $data = QueryBuilder::select("tenants_systems") ->addWhere([ "system_id" => SYSTEM->id, "tenant_id" => $data->tenant_id, ]) ->using( $DBname ) ->fetch(); if( !$data ) { REST\Response::addNotify( "danger", "NO SYSTEM/TENANT FOUND" ); REST\Response::setTemplate( "login" ); REST\Response::jsonResponse( 401 )->send(); } if( !$data->db_name ) { REST\Response::addNotify( "danger", "NO DATABASE FOUND" ); REST\Response::setTemplate( "login" ); REST\Response::jsonResponse( 401 )->send(); } SYSTEM->setDBName( $data->db_name ); SYSTEM->connect(); return $route; /** Datei: plugins/tenants/hooks/init.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook config::loaded * @param array $REQUEST Typically contains the data provided by $_REQUEST * * @since 1.0.0 File is created */ use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; use ARUNOX\Plugins\Systems; use ARUNOX\Plugins\Tenants; if( !defined( "SYSTEM" ) ) return; if( !Users\Model::isLoggedIn() || !SYSTEM || SYSTEM->type->isAdmin() ) return; $DBname = "admin"; $DBstatus = SYSTEM->db_status; $data = Tenants\Systems\Model::get([ "system_id" => SYSTEM->id, "tenant_id" => Users\Model::getTenantId(), ]); if( !$data || $data->status->isInactive() ) { Users\Model::removeCurrent(); if( PUBLIC_SCRIPT_NAME == PUBLIC_SCRIPT_NAME_API ) { Users\API\v1\Controller::restConfigLogin(); // show("X"); REST\Response::addNotify( "danger", "NO SYSTEM FOUND" ); REST\Response::jsonResponse( 401 )->send(); } return; } if( SYSTEM->type->isTenantShared() ) return; if( $data->db_status->getValue() < Systems\DBStatus::AdminMissing ) { Users\Model::removeCurrent(); if( PUBLIC_SCRIPT_NAME == PUBLIC_SCRIPT_NAME_API ) { if( $data->db_status->getValue() <= Systems\DBStatus::Failed ) { REST\Response::addNotify( "danger", "FATAL DATABASE ERROR", NULL, 0 ); } if( $data->db_status->getValue() == Systems\DBStatus::Installing ) { REST\Response::addNotify( "warning", "INSTALLING SYSTEM...", NULL, 0 ); } if( $data->db_status->getValue() == Systems\DBStatus::Maintenance ) { REST\Response::addNotify( "warning", "SYSTEM IS UNDER MAINTENANCE...", NULL, 0 ); } Users\API\v1\Controller::restConfigLogin(); REST\Response::jsonResponse( 503 )->send(); } return; } if( !$data->db_name ) { Users\Model::removeCurrent(); return; } SYSTEM->connect( $data->db_name ); /** Datei: plugins/tenants/config.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @preload TRUE * @system-need admin * @system-only admin * * @since 1.0.0 File is created */ /** Datei: plugins/tenants/config/schema/v1.0.0.php **/ array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'status' => 'TINYINT(1) DEFAULT \'0\'', 'name' => 'VARCHAR(255)', 'domain' => 'VARCHAR(255)', 'email' => 'VARCHAR(255)', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), 'tenants_meta' => array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'origin_id' => 'INT NOT NULL', 'meta_key' => 'VARCHAR(255) NOT NULL', 'meta_value' => 'TEXT', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( 'origin_id' => array ( 0 => 'origin_id', 1 => 'meta_key', ), ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), 'tenants_systems' => array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'status' => 'TINYINT(1) DEFAULT \'0\'', 'tenant_id' => 'INT', 'system_id' => 'INT', 'db_name' => 'VARCHAR(20)', 'db_status' => 'TINYINT(1) DEFAULT \'0\'', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( 'tenants_systems_tenant_id_system_id_uindex' => array ( 0 => 'tenant_id', 1 => 'system_id', ), ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), 'tenants_systems_users' => array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'tenant_id' => 'INT', 'system_id' => 'INT', 'user_id' => 'INT', 'hash' => 'VARCHAR(255)', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( 'tenants_systems_users_system_id_tenant_id_hash_uindex' => array ( 0 => 'system_id', 1 => 'tenant_id', 2 => 'hash', ), 'tenants_systems_users_tenants_id_fk' => array ( 0 => 'tenant_id', ), ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), );