Skip to content

Commit

Permalink
bugfix - can't use Schema with other db, so changed to plain sql
Browse files Browse the repository at this point in the history
  • Loading branch information
wi-wissen committed Oct 12, 2018
1 parent 4e5765f commit ebd620f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/Http/Controllers/HubController.php
Expand Up @@ -350,18 +350,19 @@ public function readonly($id)

\DB::statement("REVOKE ALL ON ". env('DB_DATABASE') ."_" . $hub->id . ".* FROM '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");
\DB::statement("GRANT SELECT ON ". env('DB_DATABASE') ."_" . $hub->id . ".* TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");
if (Schema::hasTable('analytics')) {
\DB::statement("GRANT INSERT ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");
}
//a bit hacky to prevent failing if table does not exist you have to grant 'CREATE', but you may remove it later
\DB::statement("GRANT CREATE, INSERT ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");
\DB::statement("REVOKE CREATE ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics FROM '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");

//otherwise logout will fail
\DB::statement("GRANT UPDATE (remember_token, updated_at) ON ". env('DB_DATABASE') ."_" . $hub->id . ".users TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'localhost';");

if(env('ALLOW_PUBLIC_DB_ACCESS')) { //second user needed because % means all except localhost
\DB::statement("REVOKE ALL ON ". env('DB_DATABASE') ."_" . $hub->id . ".* FROM '". env('DB_DATABASE') ."_" . $hub->id . "'@'%'");
\DB::statement("GRANT SELECT ON ". env('DB_DATABASE') ."_" . $hub->id . ".* TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'%';");
if (Schema::hasTable('analytics')) {
\DB::statement("GRANT INSERT ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'%';");
}
//a bit hacky to prevent failing if table does not exist you have to grant 'CREATE', but you may remove it later
\DB::statement("GRANT CREATE, INSERT ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics TO '". env('DB_DATABASE') ."_" . $hub->id . "'@'%';");
\DB::statement("REVOKE CREATE ON ". env('DB_DATABASE') ."_" . $hub->id . ".analytics FROM '". env('DB_DATABASE') ."_" . $hub->id . "'@'%';");
}

flash('Hub may now only log user activity')->success();
Expand Down

0 comments on commit ebd620f

Please sign in to comment.