|
|
@@ -2,20 +2,23 @@
|
|
2
|
2
|
|
|
3
|
3
|
namespace App\Http\Controllers;
|
|
4
|
4
|
|
|
|
5
|
+
|
|
|
6
|
+use App\Models\Endpoint;
|
|
|
7
|
+use App\Models\PrintJob;
|
|
|
8
|
+use App\Models\Attivita;
|
|
|
9
|
+use App\Models\Dispositivo;
|
|
5
|
10
|
use Illuminate\Http\Request;
|
|
6
|
11
|
use Illuminate\Support\Facades\Log;
|
|
7
|
12
|
use Illuminate\Support\Facades\Http;
|
|
8
|
|
-use App\Models\Endpoint;
|
|
9
|
|
-use App\Models\Dispositivo;
|
|
10
|
|
-use App\Models\PrintJob;
|
|
11
|
|
-use App\DataTables\EndpointDataTable;
|
|
|
13
|
+use Illuminate\Routing\Controllers\Middleware;
|
|
12
|
14
|
use App\DataTables\EndpointDataTableEditor;
|
|
|
15
|
+use App\DataTables\EndpointDataTable;
|
|
13
|
16
|
use Illuminate\Support\Facades\Validator;
|
|
14
|
|
-use App\Models\Attivita;
|
|
15
|
|
-use Illuminate\Support\Str;
|
|
16
|
17
|
use Illuminate\Support\Facades\Session;
|
|
17
|
|
-use Illuminate\Support\Facades\Auth;
|
|
18
|
18
|
use Illuminate\Support\Facades\Storage;
|
|
|
19
|
+use Illuminate\Support\Facades\Auth;
|
|
|
20
|
+use Illuminate\Support\Str;
|
|
|
21
|
+use App\Services\Attivita\AttivitaService;
|
|
19
|
22
|
|
|
20
|
23
|
class EndpointController extends Controller
|
|
21
|
24
|
{
|
|
|
@@ -31,9 +34,9 @@ class EndpointController extends Controller
|
|
31
|
34
|
public static function middleware(): array
|
|
32
|
35
|
{
|
|
33
|
36
|
return [
|
|
34
|
|
- new Middleware('permission:view-endpoint', only: ['index', 'show', 'istruzioni']),
|
|
|
37
|
+ new Middleware('permission:view-endpoint', only: ['index', 'show', 'istruzioni', 'download_festagent']),
|
|
35
|
38
|
new Middleware('permission:create-endpoint|edit-endpoint|delete-endpoint', only: ['store', 'update', 'destroy']),
|
|
36
|
|
- new Middleware('permission:create-endpoint', only: ['richiedi_nuovo_product_key']),
|
|
|
39
|
+ new Middleware('permission:create-endpoint', only: ['richiedi_nuovo_product_key', 'collega_questo_pc']),
|
|
37
|
40
|
];
|
|
38
|
41
|
}
|
|
39
|
42
|
|
|
|
@@ -52,6 +55,8 @@ class EndpointController extends Controller
|
|
52
|
55
|
abort(404);
|
|
53
|
56
|
}
|
|
54
|
57
|
|
|
|
58
|
+ AttivitaService::garantisciAttivita($endpoint->attivita_id);
|
|
|
59
|
+
|
|
55
|
60
|
return view('endpoint.show', compact('endpoint'));
|
|
56
|
61
|
}
|
|
57
|
62
|
|
|
|
@@ -67,7 +72,10 @@ class EndpointController extends Controller
|
|
67
|
72
|
//deeplink
|
|
68
|
73
|
public function collega_questo_pc(Request $request)
|
|
69
|
74
|
{
|
|
70
|
|
- $endpoint = Endpoint::where('attivita_id', Session::get('attivita_attuale'))
|
|
|
75
|
+ $attivitaId = Session::get('attivita_attuale');
|
|
|
76
|
+ AttivitaService::garantisciAttivita($attivitaId);
|
|
|
77
|
+
|
|
|
78
|
+ $endpoint = Endpoint::where('attivita_id', $attivitaId)
|
|
71
|
79
|
->where('user_id', $request->user()->id)
|
|
72
|
80
|
->where('status', Endpoint::NON_REGISTRATO)
|
|
73
|
81
|
->first();
|
|
|
@@ -78,7 +86,7 @@ class EndpointController extends Controller
|
|
78
|
86
|
}else{
|
|
79
|
87
|
|
|
80
|
88
|
$endpoint = new Endpoint();
|
|
81
|
|
- $endpoint->attivita_id = $request->attivita_id;
|
|
|
89
|
+ $endpoint->attivita_id = $attivitaId;
|
|
82
|
90
|
$endpoint->user_id = $request->user()->id;
|
|
83
|
91
|
$endpoint->deeplink_token = ['token' => Str::random(32) , 'timestamp' => now()->timestamp , 'status' => 'pending'];
|
|
84
|
92
|
$endpoint->product_key = $this->creaProductKey();
|
|
|
@@ -95,7 +103,7 @@ class EndpointController extends Controller
|
|
95
|
103
|
'message' => 'Endpoint collegato con successo',
|
|
96
|
104
|
'status' => 'success',
|
|
97
|
105
|
'success' => true,
|
|
98
|
|
- 'endpoint' => $endpoint,
|
|
|
106
|
+ 'endpoint' => $endpoint->makeHidden(['product_key', 'secret', 'deeplink_token', 'token']),
|
|
99
|
107
|
'url' => url('fest-agent://pair?token=' . $endpoint->deeplink_token['token'] . '&server=' . $server),
|
|
100
|
108
|
]);
|
|
101
|
109
|
}
|
|
|
@@ -132,6 +140,7 @@ class EndpointController extends Controller
|
|
132
|
140
|
}
|
|
133
|
141
|
$endpoint->update([
|
|
134
|
142
|
'status' => Endpoint::DISABILITATO,
|
|
|
143
|
+ 'token' => null,
|
|
135
|
144
|
]);
|
|
136
|
145
|
return response()->json([
|
|
137
|
146
|
'message' => 'Endpoint disattivato con successo',
|
|
|
@@ -145,13 +154,29 @@ class EndpointController extends Controller
|
|
145
|
154
|
'token' => 'required|string|max:255',
|
|
146
|
155
|
]);
|
|
147
|
156
|
$endpoint = Endpoint::where('deeplink_token->token', $request->token)->first();
|
|
|
157
|
+
|
|
|
158
|
+ //Se non c'è return
|
|
148
|
159
|
if(!$endpoint){
|
|
149
|
160
|
return response()->json(['message' => 'Endpoint non trovato', 'status' => 'error', 'success' => false], 404);
|
|
150
|
161
|
}
|
|
|
162
|
+
|
|
|
163
|
+ // Se scaduto dopo 10 minuti return
|
|
|
164
|
+ if($endpoint->deeplink_token['timestamp'] < now()->subMinutes(10)->timestamp){
|
|
|
165
|
+ $endpoint->deeplink_token['status'] = 'expired';
|
|
|
166
|
+ $endpoint->save();
|
|
|
167
|
+ return response()->json(['message' => 'Token scaduto', 'status' => 'error', 'success' => false], 400);
|
|
|
168
|
+ }
|
|
|
169
|
+
|
|
|
170
|
+ //Se già usato return
|
|
|
171
|
+ if($endpoint->deeplink_token['status'] == 'paired'){
|
|
|
172
|
+ return response()->json(['message' => 'Endpoint già registrato', 'status' => 'error', 'success' => false], 400);
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+
|
|
151
|
176
|
$deeplink_token = $endpoint->deeplink_token;
|
|
152
|
177
|
$deeplink_token['status'] = 'paired';
|
|
153
|
178
|
$endpoint->update([
|
|
154
|
|
- 'deeplink_token' => $deeplink_token,
|
|
|
179
|
+ 'deeplink_token' => '',//$deeplink_token,
|
|
155
|
180
|
'status' => Endpoint::REGISTRATO,
|
|
156
|
181
|
'token' => Str::random(32),
|
|
157
|
182
|
]);
|
|
|
@@ -159,7 +184,7 @@ class EndpointController extends Controller
|
|
159
|
184
|
'message' => 'Endpoint registrato con successo',
|
|
160
|
185
|
'status' => 'success',
|
|
161
|
186
|
'success' => true,
|
|
162
|
|
- 'endpoint' => $endpoint,
|
|
|
187
|
+ 'endpoint' => $endpoint->makeHidden(['product_key', 'secret', 'deeplink_token']),
|
|
163
|
188
|
'token' => $endpoint->token,
|
|
164
|
189
|
]);
|
|
165
|
190
|
}
|
|
|
@@ -192,8 +217,8 @@ class EndpointController extends Controller
|
|
192
|
217
|
|
|
193
|
218
|
public function stampanti_register(Request $request)
|
|
194
|
219
|
{
|
|
195
|
|
- Log::info('stampanti_register');
|
|
196
|
|
- Log::info($request->all());
|
|
|
220
|
+ // Log::info('stampanti_register');
|
|
|
221
|
+ // Log::info($request->all());
|
|
197
|
222
|
|
|
198
|
223
|
$stampanti_da_registrare = $request->input('stampanti', []);
|
|
199
|
224
|
$endpoint = $request->endpoint;
|
|
|
@@ -287,12 +312,16 @@ class EndpointController extends Controller
|
|
287
|
312
|
public function esito_stampa(Request $request)
|
|
288
|
313
|
{
|
|
289
|
314
|
$request->validate([
|
|
290
|
|
- 'printJob_id' => 'required|integer|exists:print_job,id',
|
|
|
315
|
+ 'printJob_id' => 'required|integer',
|
|
291
|
316
|
'esito' => 'required|string|in:success,error',
|
|
292
|
317
|
]);
|
|
293
|
318
|
|
|
294
|
319
|
$printJob = PrintJob::query()
|
|
295
|
320
|
->whereKey($request->printJob_id)
|
|
|
321
|
+ ->whereIn(
|
|
|
322
|
+ 'stampante_id',
|
|
|
323
|
+ $request->endpoint->stampanti()->pluck('id')
|
|
|
324
|
+ )
|
|
296
|
325
|
->first();
|
|
297
|
326
|
|
|
298
|
327
|
if (! $printJob) {
|
|
|
@@ -365,11 +394,28 @@ class EndpointController extends Controller
|
|
365
|
394
|
break;
|
|
366
|
395
|
}
|
|
367
|
396
|
}
|
|
|
397
|
+ if (in_array($request->input('action'), ['edit', 'remove'], true)) {
|
|
|
398
|
+ foreach (array_keys($request->input('data', [])) as $id) {
|
|
|
399
|
+ AttivitaService::garantisciAttivita(Endpoint::find($id)?->attivita_id);
|
|
|
400
|
+ }
|
|
|
401
|
+ }
|
|
|
402
|
+
|
|
368
|
403
|
return $editor->process($request);
|
|
369
|
404
|
}
|
|
370
|
405
|
public function index_api(Request $request)
|
|
371
|
406
|
{
|
|
372
|
|
- $endpoints = Endpoint::all();
|
|
|
407
|
+ if($request->attivita_id){
|
|
|
408
|
+ $attivita_id = $request->attivita_id;
|
|
|
409
|
+ }else{
|
|
|
410
|
+ return response()->json([
|
|
|
411
|
+ 'message' => 'Attività non trovata',
|
|
|
412
|
+ 'status' => 'error',
|
|
|
413
|
+ 'success' => false,
|
|
|
414
|
+ ], 404);
|
|
|
415
|
+ }
|
|
|
416
|
+ AttivitaService::api_garantisciAttivita($attivita_id);
|
|
|
417
|
+
|
|
|
418
|
+ $endpoints = Endpoint::where('attivita_id', $attivita_id)->get()->makeHidden(['product_key', 'secret', 'deeplink_token','token']);
|
|
373
|
419
|
return response()->json([
|
|
374
|
420
|
'message' => 'Endpoint trovati con successo',
|
|
375
|
421
|
'count' => $endpoints->count(),
|
|
|
@@ -384,11 +430,11 @@ class EndpointController extends Controller
|
|
384
|
430
|
|
|
385
|
431
|
if($request->has('first_time') && $request->first_time == true){
|
|
386
|
432
|
//la prima registrazione
|
|
387
|
|
- Log::info('api_register_product_key');
|
|
388
|
|
- Log::info('FIRST TIME');
|
|
389
|
|
- Log::info('Request: ' . json_encode($request->all()));
|
|
|
433
|
+ // Log::info('api_register_product_key');
|
|
|
434
|
+ // Log::info('FIRST TIME');
|
|
|
435
|
+ // Log::info('Request: ' . json_encode($request->all()));
|
|
390
|
436
|
$validator = Validator::make($request->all(), [
|
|
391
|
|
- 'product_key' => 'required|string|max:25,exists:endpoint,product_key',
|
|
|
437
|
+ 'product_key' => 'required|string|max:25|exists:endpoint,product_key',
|
|
392
|
438
|
], [
|
|
393
|
439
|
'product_key.required' => 'Il product key è richiesto',
|
|
394
|
440
|
'product_key.string' => 'Il product key deve essere una stringa',
|
|
|
@@ -398,7 +444,7 @@ class EndpointController extends Controller
|
|
398
|
444
|
|
|
399
|
445
|
if($validator->fails()){
|
|
400
|
446
|
Log::error('api_register_product_key');
|
|
401
|
|
- Log::error('Request: ' . $request->all());
|
|
|
447
|
+ // Log::error('Request: ' . $request->all());
|
|
402
|
448
|
Log::error('Validator fails: ' . $validator->messages());
|
|
403
|
449
|
return response()->json([
|
|
404
|
450
|
'message' => $validator->messages(),
|
|
|
@@ -416,10 +462,9 @@ class EndpointController extends Controller
|
|
416
|
462
|
'status' => 'error',
|
|
417
|
463
|
'success' => false,
|
|
418
|
464
|
], 404);
|
|
419
|
|
- }elseif($endpoint->status == Endpoint::REGISTRATO){
|
|
420
|
|
- Log::error('Endpoint già registrato');
|
|
|
465
|
+ }elseif($endpoint->status != Endpoint::NON_REGISTRATO){
|
|
421
|
466
|
return response()->json([
|
|
422
|
|
- 'message' => 'Endpoint già registrato',
|
|
|
467
|
+ 'message' => 'Endpoint non può essere registrato',
|
|
423
|
468
|
'status' => 'error',
|
|
424
|
469
|
'success' => false,
|
|
425
|
470
|
], 400);
|
|
|
@@ -451,7 +496,7 @@ class EndpointController extends Controller
|
|
451
|
496
|
'message' => 'Endpoint trovato con successo',
|
|
452
|
497
|
'status' => 'success',
|
|
453
|
498
|
'success' => true,
|
|
454
|
|
- 'endpoint' => $endpoint,
|
|
|
499
|
+ 'endpoint' => $endpoint->makeHidden(['product_key', 'secret', 'deeplink_token','token']),
|
|
455
|
500
|
'licenza' => $licenza??null,
|
|
456
|
501
|
'attivita' => $attivita??null,
|
|
457
|
502
|
]);
|
|
|
@@ -460,13 +505,14 @@ class EndpointController extends Controller
|
|
460
|
505
|
//se non è la prima registrazione può modificare gli attributi dell'endpoint
|
|
461
|
506
|
Log::info('api_register_product_key');
|
|
462
|
507
|
Log::info('NOT ft');
|
|
463
|
|
- Log::info('Request: ' . json_encode($request->all()));
|
|
|
508
|
+ // Log::info('Request: ' . json_encode($request->all()));
|
|
464
|
509
|
// dd($request->all() , 'NOT ft');
|
|
465
|
510
|
|
|
466
|
511
|
$validator = Validator::make($request->all(), [
|
|
467
|
512
|
'label' => 'required|string|max:255',
|
|
468
|
513
|
'descrizione' => 'nullable|string|max:255',
|
|
469
|
514
|
'ubicazione' => 'nullable|string|max:255',
|
|
|
515
|
+ 'product_key' => 'nullable|string|max:25|exists:endpoint,product_key',
|
|
470
|
516
|
], [
|
|
471
|
517
|
'label.required' => 'Il label è richiesto',
|
|
472
|
518
|
'label.string' => 'Il label deve essere una stringa',
|
|
|
@@ -475,6 +521,9 @@ class EndpointController extends Controller
|
|
475
|
521
|
'descrizione.max' => 'La descrizione deve essere lungo al massimo 255 caratteri',
|
|
476
|
522
|
'ubicazione.string' => 'L\'ubicazione deve essere una stringa',
|
|
477
|
523
|
'ubicazione.max' => 'L\'ubicazione deve essere lungo al massimo 255 caratteri',
|
|
|
524
|
+ 'product_key.string' => 'Il product key deve essere una stringa',
|
|
|
525
|
+ 'product_key.max' => 'Il product key deve essere lungo al massimo 25 caratteri',
|
|
|
526
|
+ 'product_key.exists' => 'Il product key non è valido',
|
|
478
|
527
|
]);
|
|
479
|
528
|
|
|
480
|
529
|
if($validator->fails()){
|
|
|
@@ -490,7 +539,7 @@ class EndpointController extends Controller
|
|
490
|
539
|
$endpoint = Endpoint::where('product_key', $request->product_key)->where('status', Endpoint::REGISTRATO)->first();
|
|
491
|
540
|
if(!$endpoint){
|
|
492
|
541
|
Log::error('Endpoint non trovato');
|
|
493
|
|
- Log::error('Request: ' . json_encode($request->all()));
|
|
|
542
|
+ // Log::error('Request: ' . json_encode($request->all()));
|
|
494
|
543
|
return response()->json([
|
|
495
|
544
|
'message' => 'Endpoint non trovato',
|
|
496
|
545
|
'status' => 'error',
|
|
|
@@ -510,7 +559,7 @@ class EndpointController extends Controller
|
|
510
|
559
|
'message' => 'Endpoint aggiornato con successo',
|
|
511
|
560
|
'status' => 'success',
|
|
512
|
561
|
'success' => true,
|
|
513
|
|
- 'endpoint' => $endpoint,
|
|
|
562
|
+ 'endpoint' => $endpoint->makeHidden(['product_key', 'secret', 'deeplink_token','token']),
|
|
514
|
563
|
'token' => $endpoint->token,
|
|
515
|
564
|
]);
|
|
516
|
565
|
|
|
|
@@ -527,6 +576,7 @@ class EndpointController extends Controller
|
|
527
|
576
|
'attivita_id.exists' => 'L\'attività non è valida',
|
|
528
|
577
|
]);
|
|
529
|
578
|
|
|
|
579
|
+ AttivitaService::garantisciAttivita($request->attivita_id);
|
|
530
|
580
|
|
|
531
|
581
|
$attivita = Attivita::find($request->attivita_id);
|
|
532
|
582
|
|
|
|
@@ -551,6 +601,12 @@ class EndpointController extends Controller
|
|
551
|
601
|
|
|
552
|
602
|
public function download_festagent(Request $request)
|
|
553
|
603
|
{
|
|
|
604
|
+ $filePath = '001_fest.exe';
|
|
|
605
|
+
|
|
|
606
|
+ if (!Storage::disk('festAgent')->exists($filePath)) {
|
|
|
607
|
+ abort(404, 'Il file richiesto non esiste.');
|
|
|
608
|
+ }
|
|
|
609
|
+
|
|
554
|
610
|
return Storage::disk('festAgent')->download('001_fest.exe', '001_fest.exe');
|
|
555
|
611
|
}
|
|
556
|
612
|
}
|