$customer]); } public function liste() { $clients = Customer::orderBy("created_at", 'desc')->paginate(10); return view('customer.customerslist', ['clients' => $clients]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $customer = new Customer; $customer->nom = $request->input('nom'); $customer->email = $request->input('email'); $customer->telephone = $request->input('telephone'); $customer->sous_domaine = $request->input('sousdomaine'); $customer->db_name = $request->input('database'); $customer->date_debut = $request->input('date_debut'); $customer->date_fin = $request->input('date_fin'); if ($customer->save()) { Session::flash('message', 'le nouveau Client a été ajouté'); return redirect()->route("customerlist"); } } public function delete($id) { $customer = Customer::find($id); if ($customer->delete()) { Session::flash('message', 'le Client a été supprimé'); return redirect()->route("customerlist"); } $customer->delete(); } public function creedb($dbname, $client_id) { if (DB::statement('CREATE DATABASE IF NOT EXISTS ' . $dbname . '')) { $customer = Customer::find($client_id); $customer->database_created = true; $customer->save(); Session::flash('dbmessage', 'la base de donnée ' . $dbname . ' est créé'); return redirect()->back(); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $customer = Customer::find($id); if (!$customer) { throw new HttpException(400, "invalid data"); } $customer->nom = $request->input('nom'); $customer->prenom = $request->input('prenom'); // $customer->sous_domaine = $request->input('domaine'); $customer->email = $request->input('email'); $customer->host = $request->input('lien'); $customer->telephone = $request->input('telephone'); $customer->db_name = $request->input('database'); $customer->user_name = $request->input('username'); $customer->password = $request->input('password'); if ($customer->save()) { return redirect()->route("customerlist"); } } public function cloner($nom, $dbname, $client_id) { $process = new Process('sudo rm -rf cloudmattineapp'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $customer = Customer::find($client_id); $sousdomaine = $customer->sous_domaine; ComposerInstall::dispatch($nom, $dbname, $sousdomaine); $process = new Process('php /var/www/clients/$nom artisan queue:listen'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); //exec('php artisan queue:work'); $customer->project_created = true; $customer->save(); Session::flash('message', 'le projet est clonné'); return redirect()->back(); } public function clonerAPI($nom, $dbname, $client_id) { $process = new Process('sudo rm -rf mattine-api'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $customer = Customer::find($client_id); $customer->api_created = true; $customer->save(); $process = new Process('./cloningapi.sh ' . $nom . '-api ' . $dbname . ''); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $process = new Process('./hostconfig.sh ' . $nom . '-api ' . $nom . '-api'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); Session::flash('message', 'le projet est clonné'); return redirect()->back(); } public function shearch(Request $request) { //$customer = DB::table('customers')->where('nom', $request->input('nom'))->paginate(10); $customer = DB::table('customers') ->where('nom', 'like', '%' . $request->input('nom') . '%')->orderBy("created_at", 'desc') ->paginate(10); if (!$customer->isEmpty()) { return view('customer.customerslist', ['clients' => $customer]); } else { $clients = Customer::orderBy("created_at", 'desc')->paginate(10); return view('customer.customerslist', ['clients' => $clients]); } } public function lister() { $files = shell_exec('cd /var/www/clients/&&ls -1'); $files = explode("\n", $files); array_pop($files); return view('files', ['files' => $files]); } public function abonnement() { return view("customer.abonnement"); } public function vider($dbname){ $process = new Process('mysql -u sagatec -pSagaTeC@2016 -h 62.171.189.81 ' . $dbname . ' < /var/www/clients/vider.sql'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $process = new Process('sudo systemctl reload httpd.service'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); Session::flash('message', 'Sortie stock est vide'); return redirect()->back(); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { } public function nvpass($id) { $customer = Customer::find($id); return view('customer.nvpass', ['client' => $customer]); } public function ajouteruser(Request $request, $client) { $customer = Customer::find($client); $faker = Faker::create(); $client = new Client(); $client->request('POST', 'http://' . $customer->sous_domaine . '.mcsystem.net/api/management/user', [ 'form_params' => [ 'email' => $request->input('email'), 'password' => $request->input('password'), 'name' => $customer->nom, 'cin' => strtoupper($faker->randomLetter) . random_int(10000, 99999) ] ]); Session::flash('message', 'le nouveau utilisateur est créé'); return redirect()->route("customerlist"); } public function deleteprojet($id) { $customer = Customer::find($id); $process = new Process('rm -rf /var/www/clients/' . $customer->nom . '/'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $process = new Process('rm -rf /var/www/clients/' . $customer->nom . '-api/'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $process = new Process('rm -rf /etc/httpd/conf.d/' . $customer->nom . '-api.conf'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $customer->project_created = false; $customer->api_created = false; $customer->save(); Session::flash('deletemessage', ' le projet au serveur est supprimer'); return redirect()->back(); } public function deletedatabase($id) { $customer = Customer::find($id); if (DB::statement('DROP DATABASE IF EXISTS ' . $customer->db_name . '')) { $customer->database_created = false; $customer->save(); Session::flash('deletemessage', 'la base de donnée ' . $customer->db_name . ' est supprimer'); return redirect()->back(); } return redirect()->back(); } public function reload() { $process = new Process('sudo systemctl reload httpd.service'); Session::flash('message', 'server reloaded '); return redirect()->back(); } public function searchclient(Request $request) { //return 'ok'; $customer = DB::table('customers') ->where('nom', 'like', '%' . $request->nom . '%')->orderBy("created_at", 'desc') ->paginate(10); if (!$customer->isEmpty()) { return view('customershearch.customerslist2', ['clients' => $customer]); } else { $clients = Customer::orderBy("created_at", 'desc')->paginate(10); return view('customershearch.customerslist2', ['clients' => $clients]); } } public function searchclientbyemail(Request $request) { $customer = DB::table('customers') ->where('email', 'like', '%' . $request->email . '%')->orderBy("created_at", 'desc') ->paginate(10); if (!$customer->isEmpty()) { return view('customershearch.customerslist2', ['clients' => $customer]); } else { $clients = Customer::orderBy("created_at", 'desc')->paginate(10); return view('customershearch.customerslist2', ['clients' => $clients]); } } public function updatecloud($nom, $dbname, $client_id) { $process = new Process('cd /var/www/clients/' . $nom . '&&/usr/bin/git pull'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); $process = new Process('cd /var/www/clients/' . $nom . '-api&&/usr/bin/git pull'); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $process->getOutput(); Session::flash('message', 'le Cloud et API est updated'); return redirect()->back(); } }