Commit f4351c9f authored by jonasled's avatar jonasled

Merge branch 'develop'

parents 6d6d5074 d63e3b7d
......@@ -166,7 +166,8 @@ public class HelperFunctions {
connection.connect();
Certificate[] certificates = connection.getServerCertificates();
for (int i = certificates.length - 1; i <= 0; i--) { //for every certificate in chain ask if we should trust it.
for (int i = 0; i < certificates.length; i++) { //for every certificate in chain ask if we should trust it.
final boolean[] returnBool = new boolean[1];
Certificate certificate;
certificate = certificates[i];
......@@ -178,6 +179,7 @@ public class HelperFunctions {
result[2] = c.getNotAfter().toString();
result[3] = c.getSerialNumber().toString();
int finalI = i;
((Activity) context).runOnUiThread(() -> { //We have to run the alert on the main thread
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context);
......@@ -193,7 +195,9 @@ public class HelperFunctions {
dlgAlert2.setMessage(R.string.errRunAgain);
dlgAlert2.setTitle(R.string.errRunAgainTitle);
dlgAlert2.setPositiveButton(R.string.ok, (DialogInterface dialog2, int which2) -> {});
dlgAlert2.show();
if(finalI == certificates.length - 1) { //only show the dialog on last certificate
dlgAlert2.show();
}
});
dlgAlert.setNegativeButton(R.string.deny, (DialogInterface dialog, int which) -> {//close the activity if user denies the cert
((Activity) context).finish();
......
......@@ -127,7 +127,13 @@ public class NewServer extends AppCompatActivity {
}
inputURL.setOnFocusChangeListener((View v, boolean hasFocus) ->{//on leave focus of the url input, replace https with HTTPS and add / at the end if missing (to fix some problems with android URL handling)
inputURL.setText(inputURL.getText().toString().replace("https", "HTTPS"));
try {
if (!inputURL.getText().toString().substring(0, 4).toLowerCase().equals("http")) {
inputURL.setText("HTTP://" + inputURL.getText().toString());
}
} catch (IndexOutOfBoundsException e) {}
inputURL.setText(inputURL.getText().toString().replace("https:", "HTTPS:"));
inputURL.setText(inputURL.getText().toString().replace("http:", "HTTP:"));
try {
if (inputURL.getText().toString().charAt(inputURL.getText().toString().length() - 1) != '/') {
inputURL.setText(inputURL.getText().toString() + "/");
......@@ -138,7 +144,13 @@ public class NewServer extends AppCompatActivity {
checkBoxRequiresTOTP.setOnCheckedChangeListener((CompoundButton compoundButton, boolean checked) -> inputTOTP.setEnabled(checked));//if the user enables 2FA, enable the 2FA token input
fab.setOnClickListener((View v) -> {//save button
inputURL.setText(inputURL.getText().toString().replace("https", "HTTPS"));
try {
if (!inputURL.getText().toString().substring(0, 4).toLowerCase().equals("http")) {
inputURL.setText("HTTP://" + inputURL.getText().toString());
}
} catch (IndexOutOfBoundsException e) {}
inputURL.setText(inputURL.getText().toString().replace("https:", "HTTPS:"));
inputURL.setText(inputURL.getText().toString().replace("http:", "HTTP:"));
try {
if (inputURL.getText().toString().charAt(inputURL.getText().toString().length() - 1) != '/') {
inputURL.setText(inputURL.getText().toString() + "/");
......
......@@ -133,7 +133,7 @@ public class ProxmoxConnected extends AppCompatActivity {
String sStackTrace = sw.toString(); // stack trace as a string
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(ProxmoxConnected.this);
dlgAlert.setMessage(sStackTrace);
dlgAlert.setTitle("error1");
dlgAlert.setTitle(R.string.errUnknown);
dlgAlert.setCancelable(false);
dlgAlert.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> {});
dlgAlert.create().show();
......@@ -194,6 +194,8 @@ public class ProxmoxConnected extends AppCompatActivity {
sb.append(line + "\n");
}
System.out.println("output: " + sb.toString());
login = (JSONObject) (new JSONObject(sb.toString())).get("data");//parse the JSON
ticket = login.getString("ticket");//get the ticket
CSRFPreventionToken = login.getString("CSRFPreventionToken");//get the CSRFPreventionToken
......@@ -327,18 +329,35 @@ public class ProxmoxConnected extends AppCompatActivity {
return "";
} catch (SSLHandshakeException e){//handle some exceptions
e.printStackTrace();
HelperFunctions.trustCert(ProxmoxConnected.this, strings[0] + "/");
return "";
} catch (IOException e){
e.printStackTrace();
return "failedIO";
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString(); // stack trace as a string
return "failedIO|" + sStackTrace;
} catch (JSONException e){
e.printStackTrace();
return "failedJSON";
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString(); // stack trace as a string
return "failedJSON|" + sStackTrace;
} catch (IllegalArgumentException e){
e.printStackTrace();
return "failedJSON";
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString(); // stack trace as a string
return "failedJSON|" + sStackTrace;
} catch (Exception e){
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
......@@ -353,7 +372,15 @@ public class ProxmoxConnected extends AppCompatActivity {
@Override
protected void onPostExecute(String result) {
pd.dismiss();//close the loading dialog
if (result == "failedIO") {//handle the exceptions from above
AlertDialog.Builder dlgAlert2 = new AlertDialog.Builder(ProxmoxConnected.this);
if(result != ""){//if a error occurred, build the dialog for the detailed info
dlgAlert2.setMessage(result.substring(result.indexOf("|") + 1));
dlgAlert2.setTitle(R.string.detailedError);
dlgAlert2.setCancelable(false);
dlgAlert2.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> finish());
}
if (result.startsWith("failedIO")) {//handle the exceptions from above
SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(ProxmoxConnected.this);
if(mPreferences.getBoolean("callIntent", false) && !HelperFunctions.lastConnectName.equals(urlString)) {
PackageManager pm = getApplicationContext().getPackageManager();
......@@ -379,21 +406,25 @@ public class ProxmoxConnected extends AppCompatActivity {
dlgAlert.setMessage(R.string.errNotReachable);
dlgAlert.setTitle(R.string.errNotReachableTitle);
dlgAlert.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> finish());
dlgAlert.setNegativeButton(R.string.moreDetails, (DialogInterface dialog, int which) -> dlgAlert2.show());
dlgAlert.setNegativeButton(R.string.moreDetails, (DialogInterface dialog, int which) -> dlgAlert2.show());
dlgAlert.create().show();
}
} else if (result == "failedJSON") {
} else if (result.startsWith("failedJSON")) {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(ProxmoxConnected.this);
dlgAlert.setMessage(R.string.errInvalidJson);
dlgAlert.setTitle(R.string.errInvalidJsonTitle);
dlgAlert.setCancelable(false);
dlgAlert.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> finish());
dlgAlert.setNegativeButton(R.string.moreDetails, (DialogInterface dialog, int which) -> dlgAlert2.show());
dlgAlert.create().show();
} else if(result != "") {
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(ProxmoxConnected.this);
dlgAlert.setMessage(result);
dlgAlert.setTitle("error2");
dlgAlert.setTitle(R.string.errUnknown);
dlgAlert.setCancelable(false);
dlgAlert.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> {});
dlgAlert.setPositiveButton(R.string.ok, (DialogInterface dialog, int which) -> finish());
dlgAlert.setNegativeButton(R.string.moreDetails, (DialogInterface dialog, int which) -> dlgAlert2.show());
dlgAlert.create().show();
return;
}
......
......@@ -130,4 +130,6 @@
<string name="black">Schwarz</string>
<string name="dark">Dunkel</string>
<string name="automatic">Automatisch</string>
<string name="detailedError">Detaillierter Fehler</string>
<string name="moreDetails">Mehr Details</string>
</resources>
\ No newline at end of file
......@@ -149,4 +149,6 @@
<string name="testIntent">Test Intent</string>
<string name="feedbackMail" translatable="false">proxdroid_feedback_gSt44pHrBC@jonasled.de</string>
<string name="translatorsDescription" translatable="false">German: jonasled\nSwedish: McTwist</string>
<string name="moreDetails">More details</string>
<string name="detailedError">Detailed error</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment