Skip to content

Commit b1ee76f

Browse files
committed
[CORE] Add network settings
1 parent c47bd7c commit b1ee76f

File tree

12 files changed

+78
-22
lines changed

12 files changed

+78
-22
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<application
3030
android:name="io.flutter.app.FlutterApplication"
3131
android:icon="@mipmap/ic_launcher"
32+
android:usesCleartextTraffic="true"
3233
android:label="Receipt Manager">
3334
<activity
3435
android:name=".MainActivity"

ios/Runner/Info.plist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040
<string>UIInterfaceOrientationLandscapeRight</string>
4141
</array>
4242
<key>UIViewControllerBasedStatusBarAppearance</key>
43+
<key>NSAppTransportSecurity</key>
44+
<dict>
45+
<key>NSAllowsArbitraryLoads</key>
46+
<false/>
47+
<key>NSExceptionDomains</key>
48+
<dict>
49+
<key>example.com</key> <!--Include your domain at this line -->
50+
<dict>
51+
<key>NSIncludesSubdomains</key>
52+
<true/>
53+
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
54+
<true/>
55+
<key>NSTemporaryExceptionMinimumTLSVersion</key>
56+
<string>TLSv1.1</string>
57+
</dict>
58+
</dict>
59+
</dict>
4360
<false/>
4461
</dict>
4562
</plist>

lib/generated/intl/messages_de_DE.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class MessageLookup extends MessageLookupByLibrary {
5858
"handshakeException" : MessageLookupByLibrary.simpleMessage("Zertifikat ungültig"),
5959
"healthCategory" : MessageLookupByLibrary.simpleMessage("Gesundheit"),
6060
"highContrast" : MessageLookupByLibrary.simpleMessage("Hoher Kontrast"),
61+
"https" : MessageLookupByLibrary.simpleMessage("Aktiviere HTTPS"),
6162
"income" : MessageLookupByLibrary.simpleMessage("Einnahme"),
6263
"insertServerApiToken" : MessageLookupByLibrary.simpleMessage("Insert server api token"),
6364
"insertYourApiToken" : MessageLookupByLibrary.simpleMessage("Insert your api token"),

lib/generated/intl/messages_en_US.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class MessageLookup extends MessageLookupByLibrary {
5858
"handshakeException" : MessageLookupByLibrary.simpleMessage("Bad certificate. Please regenerate the certificate"),
5959
"healthCategory" : MessageLookupByLibrary.simpleMessage("Health"),
6060
"highContrast" : MessageLookupByLibrary.simpleMessage("High contrast"),
61+
"https" : MessageLookupByLibrary.simpleMessage("Aktiviere HTTPS"),
6162
"income" : MessageLookupByLibrary.simpleMessage("Income"),
6263
"insertServerApiToken" : MessageLookupByLibrary.simpleMessage("Insert server API token"),
6364
"insertYourApiToken" : MessageLookupByLibrary.simpleMessage("Insert your api token"),

lib/generated/l10n.dart

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/l10n/intl_de_DE.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,6 @@
123123
"detectReceiptServer": "Erkenne Receipt Server",
124124
"noReceiptServer": "Kein Receipt Server wurde gefunden",
125125
"noServicesFound": "No services found",
126-
"type" : "Typ"
126+
"type" : "Typ",
127+
"https" : "Aktiviere HTTPS"
127128
}

lib/l10n/intl_en_GB.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@
115115
"detectReceiptServer": "Detect Receipt Server",
116116
"noReceiptServer": "No receipt server found.",
117117
"noServicesFound": "No services found",
118-
"type" : "Type"
118+
"type" : "Type",
119+
"https" : "Enable HTTPS"
119120
}

lib/l10n/intl_en_US.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@
122122
"detectReceiptServer": "Detect Receipt Server",
123123
"noReceiptServer": "No receipt server found.",
124124
"noServicesFound": "No services found",
125-
"type" : "Type"
125+
"type" : "Type",
126+
"https" : "Aktiviere HTTPS"
126127
}

lib/network/network_client.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import '../main.dart';
4343
/// After, a new receipt object is crafted and send to the [ReceiptForm].
4444
/// The receipt form uses this object to fill the corresponding text fields.
4545
class NetworkClient {
46-
final _protocol = "https://";
46+
final _https = "https://";
47+
final _http = "http://";
4748
final _uploadPath = "/api/upload";
4849
final _trainingPath = "/api/training";
4950
final _token = "?access_token=";
@@ -59,19 +60,20 @@ class NetworkClient {
5960

6061
NetworkClient._internal();
6162

62-
init() {
63-
/// override the agent to provide support for self signed
64-
/// certificates.
65-
///
66-
/// Since the server runs local and the certificate is protected
67-
/// with a password, the security risk is small.
68-
HttpOverrides.global = new SelfSignedHttpAgent();
69-
}
70-
7163
String getAPIUrl(final ip, final token, final legacyParser, final gaussian,
72-
final grayscale, final rotate) {
73-
if (token == null || token == "")
74-
return _protocol +
64+
final grayscale, final rotate, final https) {
65+
66+
if (https)
67+
/// override the agent to provide support for self signed
68+
/// certificates.
69+
///
70+
/// Since the server runs local and the certificate is protected
71+
/// with a password, the security risk is small.
72+
HttpOverrides.global = new SelfSignedHttpAgent();
73+
74+
String protocol = https ? _https : _http;
75+
if (token == null || token == "") {
76+
return protocol +
7577
ip +
7678
":" +
7779
_port +
@@ -84,7 +86,9 @@ class NetworkClient {
8486
getValue(gaussian) +
8587
"&rotate=" +
8688
getValue(rotate);
87-
return _protocol +
89+
}
90+
91+
return protocol +
8892
ip +
8993
":" +
9094
_port +
@@ -119,7 +123,6 @@ class NetworkClient {
119123

120124
sendTrainingData(String ip, String token, String company, String date,
121125
String total, BuildContext context) async {
122-
init();
123126

124127
log("Submit training data.");
125128
Map<String, String> headers = {"Content-type": "application/json"};
@@ -142,7 +145,6 @@ class NetworkClient {
142145
/// Send image via post request to the server and capture the response.
143146
sendImage(File imageFile, NetworkClientHolder holder, BuildContext context,
144147
[GlobalKey<ScaffoldState> key]) async {
145-
init();
146148

147149
log("Try to upload new image.");
148150
if (holder.ip == null || holder.ip.isEmpty) {
@@ -163,7 +165,7 @@ class NetworkClient {
163165

164166
var length = await imageFile.length();
165167
var uri = Uri.parse(getAPIUrl(holder.ip, holder.token, holder.legacyParser,
166-
holder.gaussian, holder.grayscale, holder.rotate));
168+
holder.gaussian, holder.grayscale, holder.rotate, holder.https));
167169

168170
log(uri.toString());
169171

@@ -325,7 +327,7 @@ class NetworkClient {
325327
}
326328

327329
getTrainingUrl(String ip, String token) {
328-
return _protocol + ip + ":" + _port + _trainingPath + _token + token;
330+
return _https + ip + ":" + _port + _trainingPath + _token + token;
329331
}
330332
}
331333

lib/network/network_client_holder.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ class NetworkClientHolder {
5252
/// Show receipt article list
5353
bool showItemList;
5454

55+
/// send via https
56+
bool https;
57+
5558
static final NetworkClientHolder _networkClientHolder =
5659
NetworkClientHolder._internal();
5760

5861
NetworkClientHolder._internal();
5962
factory NetworkClientHolder() {
6063
return _networkClientHolder;
6164
}
65+
6266
void readOptions(SharedPreferences sharedPrefs) {
6367
ip = sharedPrefs.get("ipv4");
6468
token = sharedPrefs.get("api_token");
@@ -68,5 +72,6 @@ class NetworkClientHolder {
6872
legacyParser = sharedPrefs.get("legacyParser");
6973
rotate = sharedPrefs.get("rotate");
7074
showItemList = sharedPrefs.get("showItemList");
75+
https = sharedPrefs.get("https");
7176
}
7277
}

0 commit comments

Comments
 (0)