|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Support\Facades\Hash; |
|
7
|
|
|
use Illuminate\Auth\Events\Registered; |
|
8
|
|
|
use Illuminate\Support\Facades\Schema; |
|
9
|
|
|
use Illuminate\Support\Facades\File; |
|
10
|
|
|
use Illuminate\Support\Facades\DB; |
|
11
|
|
|
|
|
12
|
|
|
use GeoSot\EnvEditor\Controllers\EnvController; |
|
13
|
|
|
use GeoSot\EnvEditor\Exceptions\EnvException; |
|
14
|
|
|
use GeoSot\EnvEditor\Helpers\EnvFileContentManager; |
|
15
|
|
|
use GeoSot\EnvEditor\Helpers\EnvFilesManager; |
|
16
|
|
|
use GeoSot\EnvEditor\Helpers\EnvKeysManager; |
|
17
|
|
|
use GeoSot\EnvEditor\Facades\EnvEditor; |
|
18
|
|
|
use GeoSot\EnvEditor\ServiceProvider; |
|
19
|
|
|
|
|
20
|
|
|
use Auth; |
|
21
|
|
|
use Exception; |
|
22
|
|
|
use ZipArchive; |
|
23
|
|
|
use Artisan; |
|
24
|
|
|
|
|
25
|
|
|
use App\Models\User; |
|
26
|
|
|
use App\Models\Admin; |
|
27
|
|
|
use App\Models\Button; |
|
28
|
|
|
use App\Models\Link; |
|
29
|
|
|
use App\Models\Page; |
|
30
|
|
|
|
|
31
|
|
|
class InstallerController extends Controller |
|
32
|
|
|
{ |
|
33
|
|
|
|
|
34
|
|
|
public function showInstaller() |
|
35
|
|
|
{ |
|
36
|
|
|
return view('installer/installer'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function db(request $request) |
|
40
|
|
|
{ |
|
41
|
|
|
if($request->database == 'MySQL'){ |
|
42
|
|
|
return redirect(url('?mysql')); |
|
43
|
|
|
}else{ |
|
44
|
|
|
return redirect(url('?4')); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function createAdmin(request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
|
|
51
|
|
|
$email = $request->email; |
|
52
|
|
|
$password = $request->password; |
|
53
|
|
|
$handle = $request->handle; |
|
54
|
|
|
$name = $request->name; |
|
55
|
|
|
|
|
56
|
|
|
$file = base_path('INSTALLERLOCK'); |
|
57
|
|
|
if (!file_exists($file)) { |
|
58
|
|
|
$handleFile = fopen($file, 'w') or die('Cannot create file: '.$file); |
|
|
|
|
|
|
59
|
|
|
fclose($handleFile); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
try{EnvEditor::addKey('ADMIN_EMAIL', $email);}catch(Exception $e){} |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
if(DB::table('users')->count() == '0'){ |
|
65
|
|
|
Schema::disableForeignKeyConstraints(); |
|
66
|
|
|
DB::table('users')->delete(); |
|
67
|
|
|
DB::table('users')->truncate(); |
|
68
|
|
|
Schema::enableForeignKeyConstraints(); |
|
69
|
|
|
|
|
70
|
|
|
$user = User::create([ |
|
|
|
|
|
|
71
|
|
|
'name' => $name, |
|
72
|
|
|
'email' => $email, |
|
73
|
|
|
'email_verified_at' => '0001-01-01 00:00:00', |
|
74
|
|
|
'password' => Hash::make($password), |
|
75
|
|
|
'littlelink_name' => $handle, |
|
76
|
|
|
'littlelink_description' => 'admin page', |
|
77
|
|
|
'block' => 'no', |
|
78
|
|
|
]); |
|
79
|
|
|
|
|
80
|
|
|
User::where('id', '1')->update(['role' => 'admin']); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return redirect(url('?5')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function mysql(request $request) |
|
87
|
|
|
{ |
|
88
|
|
|
$DB_CONNECTION = 'mysql'; |
|
89
|
|
|
$DB_HOST = $request->host; |
|
90
|
|
|
$DB_PORT = $request->port; |
|
91
|
|
|
$DB_DATABASE = $request->name; |
|
92
|
|
|
$DB_USERNAME = $request->username; |
|
93
|
|
|
$DB_PASSWORD = $request->password; |
|
94
|
|
|
|
|
95
|
|
|
if(EnvEditor::keyExists('DB_CONNECTION')){EnvEditor::editKey('DB_CONNECTION', $DB_CONNECTION);}else{EnvEditor::addKey('DB_CONNECTION', $DB_CONNECTION);} |
|
96
|
|
|
if(EnvEditor::keyExists('DB_HOST')){EnvEditor::editKey('DB_HOST', $DB_HOST);}else{EnvEditor::addKey('DB_HOST', $DB_HOST);} |
|
97
|
|
|
if(EnvEditor::keyExists('DB_PORT')){EnvEditor::editKey('DB_PORT', $DB_PORT);}else{EnvEditor::addKey('DB_PORT', $DB_PORT);} |
|
98
|
|
|
if(EnvEditor::keyExists('DB_DATABASE')){EnvEditor::editKey('DB_DATABASE', $DB_DATABASE);}else{EnvEditor::addKey('DB_DATABASE', $DB_DATABASE);} |
|
99
|
|
|
if(EnvEditor::keyExists('DB_USERNAME')){EnvEditor::editKey('DB_USERNAME', $DB_USERNAME);}else{EnvEditor::addKey('DB_USERNAME', $DB_USERNAME);} |
|
100
|
|
|
if(EnvEditor::keyExists('DB_PASSWORD')){EnvEditor::editKey('DB_PASSWORD', $DB_PASSWORD);}else{EnvEditor::addKey('DB_PASSWORD', $DB_PASSWORD);} |
|
101
|
|
|
|
|
102
|
|
|
return redirect(url('mysql-test')); |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function mysqlTest(request $request) |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
try {Artisan::call('migrate');} catch (exception $e) {$failed = "true";} |
|
109
|
|
|
try {Artisan::call('db:seed --force');} catch (exception $e) {$failed = "true";} |
|
110
|
|
|
try {Artisan::call('db:seed --class="PageSeeder" --force');} catch (exception $e) {$failed = "true";} |
|
111
|
|
|
try {Artisan::call('db:seed --class="ButtonSeeder" --force');} catch (exception $e) {$failed = "true";} |
|
112
|
|
|
|
|
113
|
|
|
try {$users = DB::table('buttons')->count(); $failed = false;} catch (exception $e) {$failed = true;} |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
if($failed == true){ |
|
|
|
|
|
|
116
|
|
|
if(EnvEditor::keyExists('DB_CONNECTION')){EnvEditor::editKey('DB_CONNECTION', 'sqlite');}else{EnvEditor::addKey('DB_CONNECTION', 'sqlite');} |
|
117
|
|
|
if(EnvEditor::keyExists('DB_HOST')){EnvEditor::deleteKey('DB_HOST');} |
|
118
|
|
|
if(EnvEditor::keyExists('DB_PORT')){EnvEditor::deleteKey('DB_PORT');} |
|
119
|
|
|
if(EnvEditor::keyExists('DB_DATABASE')){EnvEditor::deleteKey('DB_DATABASE');} |
|
120
|
|
|
if(EnvEditor::keyExists('DB_USERNAME')){EnvEditor::deleteKey('DB_USERNAME');} |
|
121
|
|
|
if(EnvEditor::keyExists('DB_PASSWORD')){EnvEditor::deleteKey('DB_PASSWORD');} |
|
122
|
|
|
return redirect(url('?error')); |
|
123
|
|
|
}else{ |
|
124
|
|
|
return redirect(url('?4')); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function options(request $request) |
|
129
|
|
|
{ |
|
130
|
|
|
|
|
131
|
|
|
$user = User::find(1); |
|
132
|
|
|
$llName = $user->littlelink_name; |
|
133
|
|
|
|
|
134
|
|
|
if($request->register == 'Yes'){ |
|
135
|
|
|
if(EnvEditor::keyExists('ALLOW_REGISTRATION')){EnvEditor::editKey('ALLOW_REGISTRATION', 'true');}else{EnvEditor::addKey('ALLOW_REGISTRATION', 'true');} |
|
136
|
|
|
} else { |
|
137
|
|
|
if(EnvEditor::keyExists('ALLOW_REGISTRATION')){EnvEditor::editKey('ALLOW_REGISTRATION', 'false');}else{EnvEditor::addKey('ALLOW_REGISTRATION', 'false');} |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
if($request->verify == 'Yes'){$value = "verified";}else{$value = "auth";} |
|
141
|
|
|
if(EnvEditor::keyExists('REGISTER_AUTH')){EnvEditor::editKey('REGISTER_AUTH', $value);} |
|
142
|
|
|
|
|
143
|
|
|
if($request->page == 'No'){$value = "";}else{$value = '"' . $llName . '"';} |
|
144
|
|
|
if(EnvEditor::keyExists('HOME_URL')){EnvEditor::editKey('HOME_URL', $value);} |
|
145
|
|
|
|
|
146
|
|
|
if(EnvEditor::keyExists('APP_NAME')){EnvEditor::editKey('APP_NAME', '"' . $request->app . '"');} |
|
147
|
|
|
|
|
148
|
|
|
if(file_exists(base_path("INSTALLING"))){unlink(base_path("INSTALLING"));} |
|
149
|
|
|
|
|
150
|
|
|
$file = base_path('INSTALLERLOCK'); |
|
151
|
|
|
if (file_exists($file)) { |
|
152
|
|
|
unlink($file) or die('Cannot delete file: '.$file); |
|
|
|
|
|
|
153
|
|
|
sleep(1); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return redirect(url('dashboard')); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function editConfigInstaller(request $request) |
|
160
|
|
|
{ |
|
161
|
|
|
|
|
162
|
|
|
$type = $request->type; |
|
|
|
|
|
|
163
|
|
|
$entry = $request->entry; |
|
164
|
|
|
$value = $request->value; |
|
|
|
|
|
|
165
|
|
|
$value = '"' . $request->value . '"'; |
|
166
|
|
|
|
|
167
|
|
|
if(EnvEditor::keyExists($entry)){EnvEditor::editKey($entry, $value);} |
|
168
|
|
|
|
|
169
|
|
|
return Redirect(url('dashboard')); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.