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); }
/** * 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(); } }