コード例 #1
0
ファイル: Tools.php プロジェクト: robindv/WebDB
 function linux_users()
 {
     /* For all groups.. */
     foreach (Group::all() as $group) {
         if (!$group->server->created) {
             continue;
         }
         /* Find the user of the assistant */
         if ($group->assistant_id != null) {
             $su = ServerUser::where('user_id', $group->assistant_id)->where('server_id', $group->server->id)->first();
             /* Not created, create! */
             if (!$su && $group->assistant_id) {
                 $su = new ServerUser();
                 $su->user_id = $group->assistant_id;
                 $su->server_id = $group->server->id;
                 $su->created = 0;
                 $su->save();
             }
         }
         /* All students */
         foreach ($group->students as $student) {
             /* Check if not already created */
             $su = ServerUser::where('user_id', $student->user_id)->where('server_id', $group->server->id)->first();
             /* Not created, create! */
             if (!$su) {
                 $su = new ServerUser();
                 $su->user_id = $student->user_id;
                 $su->server_id = $group->server->id;
                 $su->created = 0;
                 $su->save();
             }
         }
     }
 }
コード例 #2
0
ファイル: HomeController.php プロジェクト: robindv/WebDB
 public function getProfile()
 {
     $user_id = Auth::user()->id;
     $data['user'] = Auth::user();
     $data['passwords'] = ServerUser::with('server')->whereHas('server', function ($q) {
         $q->where('configured', 1);
     })->orderBy('server_id')->where('created', 1)->where('user_id', $user_id)->get();
     return view('layout')->nest('page', 'pages.profile', $data);
 }
コード例 #3
0
ファイル: ServerUsers.php プロジェクト: robindv/WebDB
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Creating users..');
     $tasks = \App\Models\ServerUser::with('server', 'user')->where('created', '=', '0')->get();
     if (!count($tasks)) {
         echo $this->info('All users are created.');
         return;
     }
     $i = 0;
     foreach ($tasks as $task) {
         if ($task->server->state != 'Running') {
             $this->error($task->server->name . ' not running.');
             continue;
         }
         if ($task->server->configured != '1') {
             $this->error($task->server->name . ' not configured.');
             continue;
         }
         $i++;
         /* Generate a password */
         $task->password = $this->rand_string(8);
         $task->username = $task->user->linux_name;
         /* Connect to the server */
         $commands = [];
         $commands[] = "unset HISTFILE";
         $commands[] = "useradd -g users -G sudo -s /bin/bash -m -p`mkpasswd " . $task->password . "` " . $task->username;
         $commands[] = "mysql -u debian-sys-maint -p" . $task->server->mysql_debian_pass . " mysql -e \"CREATE USER '" . $task->username . "'@'localhost' IDENTIFIED BY '" . $task->password . "'; GRANT ALL PRIVILEGES ON *.* TO '" . $task->username . "'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES\"";
         $commands[] = "htpasswd -b /etc/apache2/.mailcatcher-htpasswd " . $task->username . " " . $task->password;
         $commands[] = "mkdir /home/" . $task->username . "/public_html";
         $commands[] = "chmod +x /home/" . $task->username . "/public_html";
         $commands[] = "echo 'Dit bestand staat in je <u>public_html</u> directory!' > /home/" . $task->username . "/public_html/test.html";
         $commands[] = "chown -R " . $task->username . ":users /home/" . $task->username . "/public_html";
         $commands[] = "chmod g-w /home/" . $task->username;
         SSH::into($task->server->name)->run($commands);
         /* Done, set completed to 1 */
         $task->created = 1;
         $task->save();
     }
 }
コード例 #4
0
ファイル: server.php プロジェクト: robindv/WebDB
 echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">Extern IP-adres</span>';
 echo '<span class="col-sm-4">' . env('WEBDB_IP') . '</span></div>';
 echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">Intern IP-adres</span>';
 echo '<span class="col-sm-4">' . $server->ip_address . '</span></div>';
 echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">SSH poort</span>';
 echo '<span class="col-sm-4">' . $server->ssh_port . '</span></div>';
 echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">State</span>';
 echo '<span class="col-sm-4">' . $server->state;
 if ($server->state == 'Off') {
     echo '&nbsp;(' . link_to('staff/server-on/' . $server->id, 'Aanzetten') . ')';
 }
 echo '</span></div>';
 echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">Up Time</span>';
 echo '<span class="col-sm-4">' . $server->uptime . '</span></div>';
 echo '</div>';
 $su = \App\Models\ServerUser::where('server_id', $server->id)->where('created', 1)->where('user_id', Auth::id())->first();
 if ($su) {
     echo '<h2>Inloggegevens</h2>';
     echo '<p>Met onderstaande gegevens kun je inloggen op SSH, MySQL en MailCatcher.</p>';
     echo '<div class="container">';
     echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">Gebruikersnaam</span>';
     echo '<span class="col-sm-4">' . $su->username . '</span></div>';
     echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">Wachtwoord</span>';
     echo '<span class="col-sm-4">' . $su->password . '</span></div>';
     echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">SSH-commando</span>';
     echo '<span class="col-sm-4">ssh -p ' . $server->ssh_port . ' ' . $su->username . '@' . $server->hostname . '.' . env('WEBDB_URL') . '</span></div>';
     echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">phpMyAdmin</span>';
     echo '<span class="col-sm-4">' . link_to('https://' . $server->hostname . '.' . env('WEBDB_URL') . '/phpmyadmin') . '</span></div>';
     echo '<div class="row"><span class="col-sm-2" style="text-align:left;font-weight: bold;">MailCatcher</span>';
     echo '<span class="col-sm-4">' . link_to('https://' . $server->hostname . '-mail.' . env('WEBDB_URL')) . '</span></div>';
     echo '</div>';