Skip to content

Commit

Permalink
fix: disable ssl verification on www.stcp.pt (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisDuarte1 authored Oct 2, 2023
2 parents 15ad001 + 1047345 commit 60bc6ae
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions uni/lib/controller/fetchers/departures_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart' as http;
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/bus.dart';
import 'package:uni/model/entities/bus_stop.dart';
Expand All @@ -13,12 +14,17 @@ class DeparturesFetcher {

final String _stopCode;
final BusStopData _stopData;
static final _client = http.IOClient(
HttpClient(context: SecurityContext())
..badCertificateCallback =
(cert, host, port) => host == 'www.stcp.pt' && port == 443,
);

Future<String> _getCSRFToken() async {
final url =
'https://www.stcp.pt/en/travel/timetables/?paragem=$_stopCode&t=smsbus';

final response = await http.get(url.toUri());
final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);

final scriptText = htmlResponse
Expand Down Expand Up @@ -50,7 +56,7 @@ class DeparturesFetcher {
final url =
'https://www.stcp.pt/pt/itinerarium/soapclient.php?codigo=$_stopCode&hash123=$csrfToken';

final response = await http.get(url.toUri());
final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);

final tableEntries =
Expand Down Expand Up @@ -111,7 +117,8 @@ class DeparturesFetcher {
// Search by approximate name
final url =
'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopname=$stopCode';
final response = await http.post(url.toUri());

final response = await _client.post(url.toUri());
final json = jsonDecode(response.body) as List<dynamic>;
for (final busKey in json) {
final bus = busKey as Map<String, dynamic>;
Expand All @@ -134,7 +141,8 @@ class DeparturesFetcher {
static Future<List<Bus>> getBusesStoppingAt(String stop) async {
final url =
'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopcode=$stop';
final response = await http.post(url.toUri());

final response = await _client.post(url.toUri());

final json = jsonDecode(response.body) as List<dynamic>;

Expand Down

0 comments on commit 60bc6ae

Please sign in to comment.