mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-25 14:54:52 +02:00
2012-06-21 Santiago Munin <burning1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Added a new method which checks if a website is online. * src/pandroid_event_viewer/pandorafms/Options.java: Fixed a bug. The app didn't check if the url were online before checking the certificate. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6673 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
42d58d76bf
commit
c9c1fff106
@ -1,3 +1,7 @@
|
|||||||
|
2012-06-21 Santiago Munín <burning1@gmail.com>
|
||||||
|
* src/pandroid_event_viewer/pandorafms/Core.java: Added a new method which checks if a website is online.
|
||||||
|
* src/pandroid_event_viewer/pandorafms/Options.java: Fixed a bug. The app didn't check if the url were online before checking the certificate.
|
||||||
|
|
||||||
2012-06-21 Santiago Munín <burning1@gmail.com>
|
2012-06-21 Santiago Munín <burning1@gmail.com>
|
||||||
* src/pandroid_event_viewer/pandorafms/EventList.java: Restored to the previous version.
|
* src/pandroid_event_viewer/pandorafms/EventList.java: Restored to the previous version.
|
||||||
* src/pandroid_event_viewer/pandorafms/Core.java: Added a line which checks if the connection is secure.
|
* src/pandroid_event_viewer/pandorafms/Core.java: Added a line which checks if the connection is secure.
|
||||||
|
@ -386,7 +386,7 @@ public class Core {
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Downloading image "+fileUrl+": error");
|
Log.e(TAG, "Downloading image " + fileUrl + ": error");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -437,13 +437,15 @@ public class Core {
|
|||||||
* Finds out if the given url has a CA signed certificate.
|
* Finds out if the given url has a CA signed certificate.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param url
|
||||||
* @return
|
* @return boolean
|
||||||
|
* @throws IOException
|
||||||
|
* If the given url is not accessible.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidCertificate(URL url) {
|
public static boolean isValidCertificate(URL url) {
|
||||||
|
|
||||||
HttpsURLConnection con;
|
HttpsURLConnection con;
|
||||||
try {
|
try {
|
||||||
con = (HttpsURLConnection) url.openConnection();
|
con = (HttpsURLConnection) url.openConnection();
|
||||||
|
con.getResponseCode();
|
||||||
con.connect();
|
con.connect();
|
||||||
con.disconnect();
|
con.disconnect();
|
||||||
return true;
|
return true;
|
||||||
@ -452,6 +454,24 @@ public class Core {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isOnline(URL url) {
|
||||||
|
HttpsURLConnection con;
|
||||||
|
try {
|
||||||
|
con = (HttpsURLConnection) url.openConnection();
|
||||||
|
con.setHostnameVerifier(new HostnameVerifier() {
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
con.setSSLSocketFactory(getSocketFactory());
|
||||||
|
if (con.getResponseCode()!=400) {
|
||||||
|
return false;
|
||||||
|
} else return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String httpsGet(String url,
|
public static String httpsGet(String url,
|
||||||
List<NameValuePair> additionalParameters) {
|
List<NameValuePair> additionalParameters) {
|
||||||
String result = "";
|
String result = "";
|
||||||
@ -487,7 +507,7 @@ public class Core {
|
|||||||
String temp;
|
String temp;
|
||||||
while ((temp = bufferedReader.readLine()) != null) {
|
while ((temp = bufferedReader.readLine()) != null) {
|
||||||
Log.d("CONTENT", temp);
|
Log.d("CONTENT", temp);
|
||||||
result += temp+"\n";
|
result += temp + "\n";
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -315,41 +315,48 @@ public class Options extends Activity {
|
|||||||
|
|
||||||
private class CheckCertificateAsyncTask extends
|
private class CheckCertificateAsyncTask extends
|
||||||
AsyncTask<URL, Void, Boolean> {
|
AsyncTask<URL, Void, Boolean> {
|
||||||
|
private URL url;
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(URL... arg0) {
|
protected Boolean doInBackground(URL... arg0) {
|
||||||
|
url = arg0[0];
|
||||||
return Core.isValidCertificate(arg0[0]);
|
return Core.isValidCertificate(arg0[0]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
retrievingCertificate.dismiss();
|
retrievingCertificate.dismiss();
|
||||||
if (!result) {
|
if (!Core.isOnline(url)) {
|
||||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
switch (which) {
|
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
R.string.options_not_saved,
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
|
||||||
writeChanges();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
||||||
context);
|
|
||||||
builder.setMessage(getString(R.string.certificate_not_valid))
|
|
||||||
.setPositiveButton(getString(android.R.string.yes),
|
|
||||||
dialogClickListener)
|
|
||||||
.setNegativeButton(getString(android.R.string.no),
|
|
||||||
dialogClickListener).show();
|
|
||||||
} else {
|
|
||||||
writeChanges();
|
writeChanges();
|
||||||
|
} else {
|
||||||
|
if (!result) {
|
||||||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
switch (which) {
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
R.string.options_not_saved,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
writeChanges();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
|
context);
|
||||||
|
builder.setMessage(
|
||||||
|
getString(R.string.certificate_not_valid))
|
||||||
|
.setPositiveButton(getString(android.R.string.yes),
|
||||||
|
dialogClickListener)
|
||||||
|
.setNegativeButton(getString(android.R.string.no),
|
||||||
|
dialogClickListener).show();
|
||||||
|
} else {
|
||||||
|
writeChanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user