|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Installer; |
|
4
|
|
|
|
|
5
|
|
|
use Zip; |
|
6
|
|
|
use App\Files; |
|
7
|
|
|
use Module; |
|
|
|
|
|
|
8
|
|
|
use App\Http\Controllers\Controller; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use Illuminate\Support\Facades\Artisan; |
|
11
|
|
|
use Pion\Laravel\ChunkUpload\Receiver\FileReceiver; |
|
12
|
|
|
use Pion\Laravel\ChunkUpload\Handler\HandlerFactory; |
|
13
|
|
|
use Pion\Laravel\ChunkUpload\Exceptions\UploadMissingFileException; |
|
14
|
|
|
use Illuminate\Http\UploadedFile; |
|
15
|
|
|
use Illuminate\Support\Facades\Log; |
|
16
|
|
|
use Illuminate\Support\Facades\Route; |
|
17
|
|
|
use Illuminate\Support\Facades\Auth; |
|
18
|
|
|
use Illuminate\Support\Facades\File; |
|
19
|
|
|
use Illuminate\Support\Facades\Storage; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
class ModuleController extends Controller |
|
23
|
|
|
{ |
|
24
|
|
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->middleware(['auth', 'can:is_installer']); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function index() |
|
30
|
|
|
{ |
|
31
|
|
|
return view('installer.moduleIndex'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getEnabled() |
|
35
|
|
|
{ |
|
36
|
|
|
$moduleList = []; |
|
37
|
|
|
$mods = Module::allEnabled(); |
|
38
|
|
|
foreach($mods as $name => $mod) |
|
39
|
|
|
{ |
|
40
|
|
|
$moduleList[] = [ |
|
41
|
|
|
'name' => $name, |
|
42
|
|
|
'status' => 'Enabled', |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
$mods = Module::allDisabled(); |
|
46
|
|
|
foreach ($mods as $name => $mod) { |
|
47
|
|
|
$moduleList[] = [ |
|
48
|
|
|
'name' => $name, |
|
49
|
|
|
'status' => 'Disabled', |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $moduleList; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getStaged() |
|
57
|
|
|
{ |
|
58
|
|
|
$moduleList = []; |
|
59
|
|
|
$mods = Storage::disk('staging')->files('modules'); |
|
60
|
|
|
foreach($mods as $mod) |
|
61
|
|
|
{ |
|
62
|
|
|
$baseName = explode('/', $mod); |
|
63
|
|
|
if($baseName[1] !== '.gitignore') |
|
64
|
|
|
{ |
|
65
|
|
|
$moduleList[] = [ |
|
66
|
|
|
'name' => $baseName[1], |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $moduleList; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function upload(Request $request) |
|
75
|
|
|
{ |
|
76
|
|
|
$request->validate([ |
|
77
|
|
|
'file' => 'required', |
|
78
|
|
|
]); |
|
79
|
|
|
|
|
80
|
|
|
$receiver = new FileReceiver('file', $request, HandlerFactory::classFromRequest($request)); |
|
81
|
|
|
|
|
82
|
|
|
// Verify that the upload is valid and being processed |
|
83
|
|
|
if ($receiver->isUploaded() === false) { |
|
84
|
|
|
Log::error('Upload File Missing - ' . |
|
85
|
|
|
/** @scrutinizer ignore-type */ |
|
86
|
|
|
$request->toArray()); |
|
87
|
|
|
throw new UploadMissingFileException(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Recieve and process the file |
|
91
|
|
|
$save = $receiver->receive(); |
|
92
|
|
|
|
|
93
|
|
|
// See if the uploade has finished |
|
94
|
|
|
if ($save->isFinished()) { |
|
95
|
|
|
$this->saveFile($save->getFile()); |
|
96
|
|
|
|
|
97
|
|
|
return 'uploaded successfully'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
// Get the current progress |
|
101
|
|
|
$handler = $save->handler(); |
|
102
|
|
|
|
|
103
|
|
|
Log::debug('Route ' . Route::currentRouteName() . ' visited by User ID-' . Auth::user()->user_id); |
|
104
|
|
|
Log::debug('File being uploaded. Percentage done - ' . $handler->getPercentageDone()); |
|
105
|
|
|
return response()->json([ |
|
106
|
|
|
'done' => $handler->getPercentageDone(), |
|
107
|
|
|
'status' => true |
|
108
|
|
|
]); |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// Save a file attached to the link |
|
113
|
|
|
private function saveFile(UploadedFile $file) |
|
114
|
|
|
{ |
|
115
|
|
|
$filePath = config('filesystems.disks.staging.root') . DIRECTORY_SEPARATOR . 'modules'.DIRECTORY_SEPARATOR; |
|
116
|
|
|
|
|
117
|
|
|
// Clean the file and store it |
|
118
|
|
|
$fileName = Files::cleanFilename($filePath, $file->getClientOriginalName()); |
|
119
|
|
|
Storage::disk('staging')->putFileAs('modules', $file, $fileName); |
|
120
|
|
|
|
|
121
|
|
|
return true; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function activate($name) |
|
125
|
|
|
{ |
|
126
|
|
|
// |
|
127
|
|
|
if(Storage::disk('staging')->missing('modules'.DIRECTORY_SEPARATOR.$name)) |
|
128
|
|
|
{ |
|
129
|
|
|
return response()->json(['success' => false]); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$modName = str_replace('.zip', '', $name); |
|
133
|
|
|
$module = Zip::open(config('filesystems.disks.staging.root').DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR.$name); |
|
134
|
|
|
|
|
135
|
|
|
$module->extract(config('modules.paths.modules').DIRECTORY_SEPARATOR.$modName); |
|
136
|
|
|
$module->close(); |
|
137
|
|
|
|
|
138
|
|
|
Artisan::call('module:enable', ['module' => $modName]); |
|
139
|
|
|
Artisan::call('module:migrate', ['module' => $modName]); |
|
140
|
|
|
$this->delStaged($name); |
|
141
|
|
|
|
|
142
|
|
|
return response()->json(['success' => true]); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function enable($name) |
|
146
|
|
|
{ |
|
147
|
|
|
Artisan::call('module:enable', ['module' => $name]); |
|
148
|
|
|
|
|
149
|
|
|
return response()->json(['success' => true]); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function disable($name) |
|
153
|
|
|
{ |
|
154
|
|
|
Artisan::call('module:disable', ['module' => $name]); |
|
155
|
|
|
|
|
156
|
|
|
return response()->json(['success' => true]); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function delStaged($name) |
|
160
|
|
|
{ |
|
161
|
|
|
Storage::disk('staging')->delete('modules'.DIRECTORY_SEPARATOR.$name); |
|
162
|
|
|
|
|
163
|
|
|
return response()->json(['success' => true]); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths