|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Pterodactyl - Panel |
|
4
|
|
|
* Copyright (c) 2015 - 2016 Dane Everitt <[email protected]> |
|
5
|
|
|
* Some Modifications (c) 2015 Dylan Seidt <[email protected]>. |
|
6
|
|
|
* |
|
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
* in the Software without restriction, including without limitation the rights |
|
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
* furnished to do so, subject to the following conditions: |
|
13
|
|
|
* |
|
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
15
|
|
|
* copies or substantial portions of the Software. |
|
16
|
|
|
* |
|
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
23
|
|
|
* SOFTWARE. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace Pterodactyl\Http\Controllers\Admin; |
|
27
|
|
|
|
|
28
|
|
|
use Log; |
|
29
|
|
|
use Alert; |
|
30
|
|
|
use Illuminate\Http\Request; |
|
31
|
|
|
use Pterodactyl\Models\User; |
|
32
|
|
|
use Pterodactyl\Models\Server; |
|
33
|
|
|
use Pterodactyl\Exceptions\DisplayException; |
|
34
|
|
|
use Pterodactyl\Http\Controllers\Controller; |
|
35
|
|
|
use Pterodactyl\Repositories\UserRepository; |
|
36
|
|
|
use Pterodactyl\Exceptions\DisplayValidationException; |
|
37
|
|
|
|
|
38
|
|
|
class UserController extends Controller |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* Controller Constructor. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
|
|
// |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getIndex(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
$query = User::select('users.*'); |
|
51
|
|
|
if ($request->input('filter') && ! is_null($request->input('filter'))) { |
|
52
|
|
|
preg_match_all('/[^\s"\']+|"([^"]*)"|\'([^\']*)\'/', urldecode($request->input('filter')), $matches); |
|
53
|
|
|
foreach ($matches[0] as $match) { |
|
54
|
|
|
$match = str_replace('"', '', $match); |
|
55
|
|
|
if (strpos($match, ':')) { |
|
56
|
|
|
list($field, $term) = explode(':', $match); |
|
57
|
|
|
$query->orWhere($field, 'LIKE', '%' . $term . '%'); |
|
58
|
|
|
} else { |
|
59
|
|
|
$query->where('email', 'LIKE', '%' . $match . '%'); |
|
60
|
|
|
$query->orWhere([ |
|
61
|
|
|
['uuid', 'LIKE', '%' . $match . '%'], |
|
62
|
|
|
['root_admin', 'LIKE', '%' . $match . '%'], |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
try { |
|
69
|
|
|
$users = $query->paginate(20); |
|
70
|
|
|
} catch (\Exception $ex) { |
|
71
|
|
|
Alert::warning('There was an error with the search parameters provided.'); |
|
72
|
|
|
$users = User::all()->paginate(20); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return view('admin.users.index', [ |
|
76
|
|
|
'users' => $users, |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getNew(Request $request) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
return view('admin.users.new'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function getView(Request $request, $id) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return view('admin.users.view', [ |
|
88
|
|
|
'user' => User::findOrFail($id), |
|
89
|
|
|
'servers' => Server::select('servers.*', 'nodes.name as nodeName', 'locations.long as location') |
|
90
|
|
|
->join('nodes', 'servers.node', '=', 'nodes.id') |
|
91
|
|
|
->join('locations', 'nodes.location', '=', 'locations.id') |
|
92
|
|
|
->where('owner', $id) |
|
93
|
|
|
->get(), |
|
94
|
|
|
]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
View Code Duplication |
public function deleteUser(Request $request, $id) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
try { |
|
100
|
|
|
$repo = new UserRepository; |
|
101
|
|
|
$repo->delete($id); |
|
102
|
|
|
Alert::success('Successfully deleted user from system.')->flash(); |
|
103
|
|
|
|
|
104
|
|
|
return redirect()->route('admin.users'); |
|
105
|
|
|
} catch (DisplayException $ex) { |
|
106
|
|
|
Alert::danger($ex->getMessage())->flash(); |
|
107
|
|
|
} catch (\Exception $ex) { |
|
108
|
|
|
Log::error($ex); |
|
109
|
|
|
Alert::danger('An exception was encountered while attempting to delete this user.')->flash(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return redirect()->route('admin.users.view', $id); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function postNew(Request $request) |
|
116
|
|
|
{ |
|
117
|
|
|
try { |
|
118
|
|
|
$user = new UserRepository; |
|
119
|
|
|
$userid = $user->create($request->only([ |
|
120
|
|
|
'email', |
|
121
|
|
|
'password', |
|
122
|
|
|
'name_first', |
|
123
|
|
|
'name_last', |
|
124
|
|
|
'username' |
|
125
|
|
|
])); |
|
126
|
|
|
Alert::success('Account has been successfully created.')->flash(); |
|
127
|
|
|
|
|
128
|
|
|
return redirect()->route('admin.users.view', $userid); |
|
|
|
|
|
|
129
|
|
|
} catch (DisplayValidationException $ex) { |
|
130
|
|
|
return redirect()->route('admin.users.new')->withErrors(json_decode($ex->getMessage()))->withInput(); |
|
131
|
|
|
} catch (\Exception $ex) { |
|
132
|
|
|
Log::error($ex); |
|
133
|
|
|
Alert::danger('An error occured while attempting to add a new user.')->flash(); |
|
134
|
|
|
|
|
135
|
|
|
return redirect()->route('admin.users.new'); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function updateUser(Request $request, $user) |
|
140
|
|
|
{ |
|
141
|
|
|
try { |
|
142
|
|
|
$repo = new UserRepository; |
|
143
|
|
|
$repo->update($user, $request->only([ |
|
144
|
|
|
'email', |
|
145
|
|
|
'password', |
|
146
|
|
|
'name_first', |
|
147
|
|
|
'name_last', |
|
148
|
|
|
'username', |
|
149
|
|
|
'root_admin', |
|
150
|
|
|
])); |
|
151
|
|
|
Alert::success('User account was successfully updated.')->flash(); |
|
152
|
|
|
} catch (DisplayValidationException $ex) { |
|
153
|
|
|
return redirect()->route('admin.users.view', $user)->withErrors(json_decode($ex->getMessage())); |
|
154
|
|
|
} catch (\Exception $e) { |
|
155
|
|
|
Log::error($e); |
|
156
|
|
|
Alert::danger('An error occured while attempting to update this user.')->flash(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return redirect()->route('admin.users.view', $user); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function getJson(Request $request) |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
|
|
foreach (User::select('email')->get() as $user) { |
|
165
|
|
|
$resp[] = $user->email; |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
return $resp; |
|
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.