web.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <?php
  2. use App\Http\Livewire\Report;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Log;
  8. /*
  9. |--------------------------------------------------------------------------
  10. | Web Routes
  11. |--------------------------------------------------------------------------
  12. |
  13. | Here is where you can register web routes for your application. These
  14. | routes are loaded by the RouteServiceProvider and all of them will
  15. | be assigned to the "web" middleware group. Make something great!
  16. |
  17. */
  18. Route::get('/', function () {
  19. return view('login');
  20. })->name('login');
  21. Route::post('/logout', function (Request $request) {
  22. Auth::logout();
  23. $request->session()->invalidate();
  24. $request->session()->regenerateToken();
  25. return redirect('/');
  26. });
  27. Route::post('/login', function (Request $request) {
  28. $credentials = $request->validate([
  29. 'email' => 'required|email',
  30. 'password' => 'required|string|min:6',
  31. ]);
  32. if (Auth::attempt($credentials)) {
  33. $request->session()->regenerate();
  34. $user = Auth::user();
  35. $isAdmin = false; // Default value
  36. // Clear previous session values to avoid stale data
  37. session()->forget(['user_group_id', 'user_group_name', 'is_admin']);
  38. $userGroup = \App\Models\UserUserGroup::where('user_id', $user->id)->first();
  39. if ($userGroup) {
  40. $group = \App\Models\UserGroup::find($userGroup->group_id);
  41. if ($group) {
  42. session(['user_group_id' => $group->id]);
  43. session(['user_group_name' => $group->name]);
  44. $isAdmin = ($group->name === 'Amministrazione');
  45. session(['is_admin' => $isAdmin]);
  46. Log::info('User logged in with group', [
  47. 'user_id' => $user->id,
  48. 'group_id' => $group->id,
  49. 'group_name' => $group->name,
  50. 'isAdmin' => $isAdmin
  51. ]);
  52. } else {
  53. Log::warning('User group_id references non-existent group', [
  54. 'user_id' => $user->id,
  55. 'group_id' => $userGroup->group_id
  56. ]);
  57. }
  58. } else {
  59. Log::warning('User has no group assigned', ['user_id' => $user->id]);
  60. session(['is_admin' => false]);
  61. }
  62. return redirect()->intended('/reports');
  63. }
  64. Log::info('Failed login attempt', ['email' => $request->email]);
  65. return back()->withErrors([
  66. 'message' => 'Dati di accesso errati',
  67. ]);
  68. });
  69. Route::group(['middleware' => 'auth'],function(){
  70. Route::get('/dashboard', \App\Http\Livewire\Dashboard::class);
  71. Route::get('/accertatore-grado', \App\Http\Livewire\AccertatoreGrado::class);
  72. Route::get('/ausilio-altri-enti', \App\Http\Livewire\AusilioAltriEnti::class);
  73. Route::get('/assicurazioni', \App\Http\Livewire\Compagnia::class);
  74. Route::get('/condizioni-strada', \App\Http\Livewire\CondizioneStrada::class);
  75. Route::get('/condizioni-atmosferiche', \App\Http\Livewire\CondizioniAtmosferiche::class);
  76. Route::get('/condizioni-luce', \App\Http\Livewire\CondizioniLuce::class);
  77. Route::get('/fondo-stradale', \App\Http\Livewire\FondoStradale::class);
  78. Route::get('/marche', \App\Http\Livewire\MarcaVeicolo::class);
  79. Route::get('/modelli', \App\Http\Livewire\ModelloVeicolo::class);
  80. Route::get('/materiale-recuperato', \App\Http\Livewire\MaterialeRecuperato::class);
  81. Route::get('/nomenclatura-strada', \App\Http\Livewire\NomenclaturaStrada::class);
  82. Route::get('/particolarita-strada', \App\Http\Livewire\ParticolaritaStrada::class);
  83. Route::get('/pavimentazione-strada', \App\Http\Livewire\PavimentazioneStrada::class);
  84. Route::get('/rilievi', \App\Http\Livewire\Rilievi::class);
  85. Route::get('/segnalazione-pervenuta-da', \App\Http\Livewire\SegnalazionePervenutaDa::class);
  86. Route::get('/segnalazione-verticale', \App\Http\Livewire\SegnalazioneVerticale::class);
  87. Route::get('/segnalazione-orizzontale', \App\Http\Livewire\SegnalazioneOrizzontale::class);
  88. Route::get('/stradario', \App\Http\Livewire\Stradario::class);
  89. Route::get('/tipo-segnalazione', \App\Http\Livewire\TipoSegnalazione::class);
  90. Route::get('/tipo-strada', \App\Http\Livewire\TipoStrada::class);
  91. Route::get('/entita-danno', \App\Http\Livewire\EntitaDanno::class);
  92. Route::get('/effetto-danno', \App\Http\Livewire\EffettoDanno::class);
  93. Route::get('/tipo-danno', \App\Http\Livewire\TipoDanno::class);
  94. Route::get('/tipo-urto', \App\Http\Livewire\TipoUrto::class);
  95. Route::get('/parte-macchina', \App\Http\Livewire\ParteMacchina::class);
  96. Route::get('/tipo-veicolo', \App\Http\Livewire\TipoVeicolo::class);
  97. Route::get('/users', \App\Http\Livewire\User::class);
  98. Route::get('/vpn', \App\Http\Livewire\VpnManagement::class);
  99. Route::get('/vpn/status', [\App\Http\Controllers\VpnController::class, 'getStatus'])->name('vpn.status');
  100. Route::get('/reports', \App\Http\Livewire\Report::class);
  101. Route::get('/istat', \App\Http\Livewire\Istat::class);
  102. Route::get('/print', Report::class);
  103. Route::get('/stradario_api', function(){
  104. if (isset($_GET["q"]))
  105. $stradario = \App\Models\Stradario::where('descrizione', 'like', '%' . $_GET["q"] . '%')->orderBy('descrizione')->get();
  106. else
  107. $stradario = \App\Models\Stradario::orderBy('descrizione')->get();
  108. $data = array();
  109. foreach($stradario as $s)
  110. {
  111. $data[] = array("id" => $s->id, "text" => $s->TOPONIMO . " " . $s->DESCRIZIONE);
  112. }
  113. return array("results" => $data);
  114. });
  115. Route::get('/anagrafica', function() {
  116. if (isset($_GET["q"])) {
  117. $anagrafica = \App\Models\Anagrafica::where('lastname', 'like', '%' . $_GET["q"] . '%')
  118. ->orWhere('firstname', 'like', '%' . $_GET["q"] . '%')
  119. ->orWhere('rag_soc', 'like', '%' . $_GET["q"] . '%')
  120. ->orderBy('lastname')
  121. ->orderBy('firstname')
  122. ->get();
  123. } else {
  124. $anagrafica = \App\Models\Anagrafica::orderBy('lastname')
  125. ->orderBy('firstname')
  126. ->get();
  127. }
  128. $data = [];
  129. foreach ($anagrafica as $a) {
  130. $text = (empty($a->lastname) && empty($a->firstname))
  131. ? $a->rag_soc // Use company name if names are empty
  132. : trim($a->lastname . ' ' . $a->firstname);
  133. $data[] = ["id" => $a->id, "text" => $text];
  134. }
  135. return ["results" => $data];
  136. });
  137. Route::get('/localita', function(){
  138. if (isset($_GET["q"]))
  139. $localita = \App\Models\LocationTown::where('title', 'like', '%' . $_GET["q"] . '%')->orderBy('title')->get();
  140. else
  141. $localita = \App\Models\LocationTown::orderBy('title')->get();
  142. $data = array();
  143. foreach($localita as $l)
  144. {
  145. if (strtoupper(trim($l->title)) == 'ROMA')
  146. array_unshift($data, array("id" => $l->id, "text" => $l->title));
  147. else
  148. $data[] = array("id" => $l->id, "text" => $l->title);
  149. }
  150. return array("results" => $data);
  151. });
  152. Route::get('/veicoli', function(){
  153. if (isset($_GET["q"]))
  154. {
  155. $value = $_GET["q"];
  156. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->whereHas('marca', function ($q) use ($value) {
  157. $q->where('name', "LIKE", '%' . $value . '%');
  158. })->orWhereHas('modello', function ($q) use ($value) {
  159. $q->where('name', "LIKE", '%' . $value . '%');
  160. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  161. }
  162. else
  163. $veicoli = \App\Models\Vehicle::with('marca')->with('modello')->get()->sortBy('marca.name',SORT_REGULAR,false);
  164. $data = array();
  165. foreach($veicoli as $v)
  166. {
  167. $data[] = array("id" => $v->id, "text" => ($v->marca ? $v->marca->name : '') . " " . ($v->modello ? $v->modello->name : '') . " " . $v->targa);
  168. }
  169. return array("results" => $data);
  170. });
  171. Route::get('/accertatori', function(){
  172. if (isset($_GET["q"]))
  173. {
  174. $value = $_GET["q"];
  175. $accertatori = DB::table('fcf_users')
  176. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  177. ->selectRaw('fcf_users.*')
  178. ->where('fcf_user_user_groups.group_id', 2)
  179. ->where(function ($query) {
  180. $query->where('fcf_users.lastname', 'like', '%' . $_GET["q"] . '%')
  181. ->orWhere('fcf_users.firstname', 'like', '%' . $_GET["q"] . '%');
  182. })
  183. ->orderBy('fcf_users.lastname')
  184. ->get();
  185. }
  186. else
  187. $accertatori = DB::table('fcf_users')
  188. ->leftjoin('fcf_user_user_groups','fcf_user_user_groups.user_id','=','fcf_users.id')
  189. ->selectRaw('fcf_users.*')
  190. ->where('fcf_user_user_groups.group_id', 2)
  191. ->orderBy('fcf_users.lastname')
  192. ->get();
  193. $data = array();
  194. foreach($accertatori as $a)
  195. {
  196. $data[] = array("id" => $a->id, "text" => $a->lastname . " " . $a->firstname);
  197. }
  198. return array("results" => $data);
  199. });
  200. Route::get('/polizze', function(){
  201. if (isset($_GET["q"]))
  202. {
  203. $value = $_GET["q"];
  204. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->where('agenzia', 'LIKE', '%' . $_GET["q"] . '%')
  205. ->orWhereHas('compagnia', function ($q) use ($value) {
  206. $q->where('name', "LIKE", '%' . $value . '%');
  207. })->orWhereHas('anagrafica', function ($q) use ($value) {
  208. $q->where('lastname', "LIKE", '%' . $value . '%')->orWhere('firstname', "LIKE", '%' . $value . '%');
  209. })->get()->sortBy('marca.name',SORT_REGULAR,false);
  210. }
  211. else
  212. $polizze = \App\Models\Polizza::with('compagnia')->with('anagrafica')->get()->sortBy('agenzia',SORT_REGULAR,false);
  213. $data = array();
  214. foreach($polizze as $p)
  215. {
  216. $data[] = array("id" => $p->id, "text" => $p->agenzia . " " . ($p->compagnia ? $p->compagnia->name : '') . " " . ($p->anagrafica ? ($p->anagrafica->lastname . " " . $p->anagrafica->firstname) : ''));
  217. }
  218. return array("results" => $data);
  219. });
  220. });
  221. Route::get('/test_targa/{targa}', function ($targa) {
  222. try
  223. {
  224. $wd = "dettaglioAutoveicoloBase";
  225. $wd = "datiCartaCircolazioneAutoveicoloProprietario";
  226. $url = 'https://www.ilportaledellautomobilista.it/Info-ws/services';
  227. $client = new \SoapClient($url . '/' . $wd . '/' . $wd . '.wsdl', array(
  228. 'stream_context' => stream_context_create(array(
  229. 'ssl' => array(
  230. 'verify_peer' => false,
  231. 'verify_peer_name' => false,
  232. 'allow_self_signed' => true
  233. )
  234. )),
  235. 'trace'=>1
  236. ));
  237. $utente = 'CMRM001301';
  238. $password = '2PMPM*86';
  239. $xml = '<wsse:Security
  240. xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
  241. SOAP-ENV:mustUnderstand="1">
  242. <wsse:UsernameToken
  243. xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
  244. wsu:Id="XWSSGID-1253605895203984534550">
  245. <wsse:Username>' . $utente . '</wsse:Username>
  246. <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $password . '</wsse:Password>
  247. </wsse:UsernameToken>
  248. </wsse:Security>';
  249. $header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd',
  250. 'Security',
  251. new \SoapVar($xml, XSD_ANYXML),
  252. true
  253. );
  254. $client->__setSoapHeaders($header);
  255. $classe = "dettaglioAutoveicoloBase";
  256. $classe = "dettaglioCartaCircolazioneProprietarioAutoveicolo";
  257. try
  258. {
  259. // Run the function
  260. $obj = $client->__soapCall($classe, array(
  261. $classe . "Request" => array(
  262. "login" => array(
  263. ),
  264. //"dettaglioAutoveicoloBaseInput" => array(
  265. "targa" => array("numeroTarga" => $targa),
  266. //),
  267. "pdf" => false
  268. )
  269. ));
  270. print "<pre>";
  271. print_r($obj);
  272. print "</pre>";
  273. }
  274. catch(\SoapFault $fault)
  275. {
  276. print $fault;
  277. // <xmp> tag displays xml output in html
  278. //echo 'Request : <br/><xmp>',
  279. //$client->__getLastRequest(),
  280. //'</xmp><br/><br/> Error Message : <br/>',
  281. //$fault->getMessage();
  282. }
  283. }
  284. catch(Exception $ex)
  285. {
  286. print "QUA5";
  287. print $ex;
  288. }
  289. });
  290. Route::get('/print-pdf/{id}/{type?}', [Report::class, 'print'])->name('print.pdf');
  291. Route::get('/countries', function() {
  292. $search = request()->get('search');
  293. $query = \App\Models\LocationCountry::query();
  294. if($search) {
  295. $query->where('name', 'like', "%{$search}%");
  296. }
  297. $countries = $query->get()->map(function($country) {
  298. return [
  299. 'id' => $country->id,
  300. 'text' => $country->name
  301. ];
  302. });
  303. return response()->json([
  304. 'results' => $countries
  305. ]);
  306. });
  307. Route::get('/compagnie', function(){
  308. if (isset($_GET["q"]))
  309. $compagnie = \App\Models\Compagnia::where('name', 'like', '%' . $_GET["q"] . '%')->orderBy('name')->get();
  310. else
  311. $compagnie = \App\Models\Compagnia::orderBy('name')->get();
  312. $data = array();
  313. foreach($compagnie as $c)
  314. {
  315. $data[] = array("id" => $c->id, "text" => $c->name);
  316. }
  317. return array("results" => $data);
  318. });
  319. Route::get('/polizze/agenzie', function(Request $request) {
  320. $query = \App\Models\Polizza::query();
  321. if ($request->has('q')) {
  322. $query->where('agenzia', 'like', '%' . $request->q . '%');
  323. }
  324. // Get unique agenzie
  325. $agenzie = $query->distinct()
  326. ->whereNotNull('agenzia')
  327. ->where('agenzia', '!=', '')
  328. ->pluck('agenzia');
  329. return [
  330. 'results' => $agenzie->map(function($agenzia) {
  331. return [
  332. 'id' => $agenzia,
  333. 'text' => $agenzia
  334. ];
  335. })
  336. ];
  337. });