Skip to content

Commit

Permalink
Merge pull request #34 from gotify/cleartext-traffic
Browse files Browse the repository at this point in the history
Allow cleartext traffic
  • Loading branch information
jmattheis authored Dec 22, 2018
2 parents 95aa9b3 + 7626046 commit 51f49dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity
android:name=".init.InitializationActivity"
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/com/github/gotify/login/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ private void invalidateUrl() {
@OnClick(R.id.checkurl)
public void doCheckUrl() {
String url = urlField.getText().toString();
if (HttpUrl.parse(url) == null) {
HttpUrl parsedUrl = HttpUrl.parse(url);
if (parsedUrl == null) {
Utils.showSnackBar(LoginActivity.this, "Invalid URL (include http:// or https://)");
return;
}

if ("http".equals(parsedUrl.scheme())) {
showHttpWarning();
}

checkUrlProgress.setVisibility(View.VISIBLE);
checkUrlButton.setVisibility(View.GONE);

Expand All @@ -117,6 +122,15 @@ public void doCheckUrl() {
.enqueue(callInUI(this, onValidUrl(fixedUrl), onInvalidUrl(fixedUrl)));
}

public void showHttpWarning() {
new AlertDialog.Builder(this)
.setTitle(R.string.warning)
.setCancelable(true)
.setMessage(R.string.http_warning)
.setPositiveButton(R.string.i_understand, (a, b) -> {})
.show();
}

@OnClick(R.id.open_logs)
public void openLogs() {
startActivity(new Intent(this, LogsActivity.class));
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@
<string name="done">Done</string>
<string name="no_certificate_selected">No certificate selected</string>
<string name="remove_ca_certificate">Remove CA Certificate</string>
<string name="warning">Warning</string>
<string name="http_warning">Using http is insecure and it\'s recommend to use https instead. Use your favorite search engine to get more information about this topic.</string>
<string name="i_understand">I Understand</string>
</resources>

0 comments on commit 51f49dd

Please sign in to comment.