2012-05-31 Santiago Munín <burnin1@gmail.com>
* src/pandroid_event_viewer/pandorafms/Core.java: Added a method which performs http petitions. * src/pandroid_event_viewer/pandorafms/EventList.java: Added javadoc comments. * src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java, src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java, src/pandroid_event_viewer/pandorafms/Main.java, src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Changed api request (now they use Core's new method). git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6394 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
abe4634acf
commit
4ebdcee15d
|
@ -1,3 +1,12 @@
|
|||
2012-05-31 Santiago Munín <burnin1@gmail.com>
|
||||
* src/pandroid_event_viewer/pandorafms/Core.java: Added a method which performs http petitions.
|
||||
* src/pandroid_event_viewer/pandorafms/EventList.java: Added javadoc comments.
|
||||
* src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java,
|
||||
src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java,
|
||||
src/pandroid_event_viewer/pandorafms/Main.java,
|
||||
src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java: Changed api request (now they use Core's new method).
|
||||
|
||||
|
||||
2012-05-31 Santiago Munín <burnin1@gmail.com>
|
||||
* src/pandroid_event_viewer/pandorafms/Main.java: Now, on MainActivity's restart, fetches groups and tags if url was changed.
|
||||
* src/pandroid_event_viewer/pandorafms/Options.java: Puts a boolean in SharedPreferences if url was changed.
|
||||
|
|
|
@ -20,7 +20,17 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
|
@ -168,7 +178,8 @@ public class Core {
|
|||
}
|
||||
|
||||
/**
|
||||
* Converts max event age chosen from spinner to seconds (either are seconds or not)
|
||||
* Converts max event age chosen from spinner to seconds (either are seconds
|
||||
* or not)
|
||||
*
|
||||
* @return Time in milliseconds.
|
||||
*/
|
||||
|
@ -243,19 +254,63 @@ public class Core {
|
|||
|
||||
return returnvar * 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public static String serializeParams2Api(String[] params) {
|
||||
String return_var = params[0];
|
||||
String return_var = params[0];
|
||||
|
||||
for (int i = 1; i < params.length; i++) {
|
||||
return_var+= "|" + params[i];
|
||||
}
|
||||
|
||||
Log.i(TAG + " serializeParams2Api", return_var);
|
||||
return return_var;
|
||||
for (int i = 1; i < params.length; i++) {
|
||||
return_var += "|" + params[i];
|
||||
}
|
||||
|
||||
Log.i(TAG + " serializeParams2Api", return_var);
|
||||
return return_var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an http get petition.
|
||||
* @param context Application context.
|
||||
* @param additionalParameters Petition additional parameters
|
||||
* @return Petition result.
|
||||
*/
|
||||
public static String httpGet(Context context,
|
||||
List<NameValuePair> additionalParameters) {
|
||||
SharedPreferences preferences = context.getSharedPreferences(
|
||||
context.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
|
||||
String url = preferences.getString("url", "") + "/include/api.php";
|
||||
String user = preferences.getString("user", "");
|
||||
String password = preferences.getString("password", "");
|
||||
if (url.length() == 0 || user.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", user));
|
||||
parameters.add(new BasicNameValuePair("pass", password));
|
||||
parameters.addAll(additionalParameters);
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
UrlEncodedFormEntity entity;
|
||||
HttpPost httpPost;
|
||||
HttpResponse response;
|
||||
HttpEntity entityResponse;
|
||||
String return_api;
|
||||
httpPost = new HttpPost(url);
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
return_api = Core
|
||||
.convertStreamToString(entityResponse.getContent());
|
||||
return return_api;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG+" http petition", e.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,7 +302,12 @@ public class EventList extends ListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO comment
|
||||
/**
|
||||
* Sets an image to the left of a TextView.
|
||||
* @param view Parent view.
|
||||
* @param url Image uri.
|
||||
* @param id TextView's id;
|
||||
*/
|
||||
private void setTextViewImage(View view, String url, int id) {
|
||||
TextView tview = (TextView) view.findViewById(id);
|
||||
Bitmap img = null;
|
||||
|
@ -324,7 +329,12 @@ public class EventList extends ListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO comment
|
||||
/**
|
||||
* Sets an image to the left of group's TextView.
|
||||
* @param view Parent view.
|
||||
* @param group_icon Icon name.
|
||||
* @param id Group's TextView id;
|
||||
*/
|
||||
private void setTextViewGroupImage(View view, String group_icon, int id) {
|
||||
TextView tview = (TextView) view.findViewById(id);
|
||||
Bitmap img = null;
|
||||
|
|
|
@ -201,22 +201,8 @@ public class Main extends Activity {
|
|||
private List<String> getGroups() {
|
||||
ArrayList<String> array = new ArrayList<String>();
|
||||
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
this.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
|
||||
String url = preferences.getString("url", "");
|
||||
String user = preferences.getString("user", "");
|
||||
String password = preferences.getString("password", "");
|
||||
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
|
||||
HttpPost httpPost = new HttpPost(url + "/include/api.php");
|
||||
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", user));
|
||||
parameters.add(new BasicNameValuePair("pass", password));
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "groups"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
|
@ -224,16 +210,7 @@ public class Main extends Activity {
|
|||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", ";"));
|
||||
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(parameters);
|
||||
|
||||
httpPost.setEntity(entity);
|
||||
|
||||
HttpResponse response = httpClient.execute(httpPost);
|
||||
HttpEntity entityResponse = response.getEntity();
|
||||
|
||||
String return_api = Core.convertStreamToString(entityResponse
|
||||
.getContent());
|
||||
|
||||
String return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
|
@ -352,7 +329,6 @@ public class Main extends Activity {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
// TODO here
|
||||
list = getTags();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -20,16 +20,10 @@ package pandroid_event_viewer.pandorafms;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -73,7 +67,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
public String eventTag;
|
||||
public String eventSearch;
|
||||
public int filterLastTime;
|
||||
|
||||
|
||||
public boolean showOptionsFirstTime;
|
||||
public boolean showTabListFirstTime;
|
||||
|
||||
|
@ -162,8 +156,8 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
this.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
boolean changes = false;
|
||||
|
||||
//Checks if there are filter changes
|
||||
|
||||
// Checks if there are filter changes
|
||||
if (!preferences.getBoolean("filterChanges", false)) {
|
||||
SharedPreferences.Editor editorPreferences = preferences.edit();
|
||||
editorPreferences.putBoolean("filterChanges", false);
|
||||
|
@ -173,11 +167,11 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
if (count_events > 0) {
|
||||
process_notification(i);
|
||||
}
|
||||
if (changes || this.showTabListFirstTime ) {
|
||||
if (changes || this.showTabListFirstTime) {
|
||||
executeBackgroundGetEvents();
|
||||
this.showTabListFirstTime = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
|
@ -283,8 +277,7 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
String.valueOf(this.offset), // Event list offset
|
||||
totalStr, // Count or show
|
||||
String.valueOf(this.id_group), // Group id
|
||||
this.eventTag
|
||||
});
|
||||
this.eventTag });
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,174 +286,138 @@ public class PandroidEventviewerActivity extends TabActivity implements
|
|||
* @param newEvents
|
||||
*/
|
||||
private void getEvents(boolean newEvents) {
|
||||
SharedPreferences preferences = getSharedPreferences(
|
||||
this.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
|
||||
String url = preferences.getString("url", "");
|
||||
String user = preferences.getString("user", "");
|
||||
String password = preferences.getString("password", "");
|
||||
|
||||
// Get total count.
|
||||
ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(true)));
|
||||
String return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
Log.i(TAG + " getEvents", return_api);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
UrlEncodedFormEntity entity;
|
||||
HttpPost httpPost;
|
||||
List<NameValuePair> parameters;
|
||||
HttpResponse response;
|
||||
HttpEntity entityResponse;
|
||||
String return_api;
|
||||
|
||||
httpPost = new HttpPost(url + "/include/api.php");
|
||||
|
||||
// Get total count.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", user));
|
||||
parameters.add(new BasicNameValuePair("pass", password));
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(true)));
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
return_api = Core
|
||||
.convertStreamToString(entityResponse.getContent());
|
||||
return_api = return_api.replace("\n", "");
|
||||
Log.i(TAG + " getEvents", return_api);
|
||||
this.count_events = new Long(return_api).longValue();
|
||||
|
||||
if (this.count_events == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of events.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", user));
|
||||
parameters.add(new BasicNameValuePair("pass", password));
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(false)));
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
|
||||
return_api = Core
|
||||
.convertStreamToString(entityResponse.getContent());
|
||||
return_api = return_api.replaceAll("\\<.*?\\>", ""); // Clean html
|
||||
// tags.
|
||||
|
||||
Pattern pattern = Pattern
|
||||
.compile("Unable to process XML data file '(.*)'");
|
||||
Matcher matcher;
|
||||
String filename;
|
||||
|
||||
boolean endReplace = false;
|
||||
int i22 = 0;
|
||||
while (!endReplace) {
|
||||
Log.i(TAG + " getEvents - loop", i22 + "");
|
||||
i22++;
|
||||
matcher = pattern.matcher(return_api);
|
||||
|
||||
if (matcher.find()) {
|
||||
filename = matcher.group(1);
|
||||
return_api = return_api
|
||||
.replaceFirst(
|
||||
"Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
|
||||
"Bad XML: " + filename);
|
||||
} else {
|
||||
endReplace = true;
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG + " getEvents - return_api", return_api);
|
||||
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
if (return_api.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] items = lines[i].split(";",23);
|
||||
|
||||
EventListItem event = new EventListItem();
|
||||
|
||||
if (items.length != 23) {
|
||||
event.event = getApplication().getString(
|
||||
R.string.unknown_event_str);
|
||||
} else {
|
||||
if (items[0].length() == 0) {
|
||||
event.id_event = 0;
|
||||
} else {
|
||||
event.id_event = Integer.parseInt(items[0]);
|
||||
}
|
||||
if (items[1].length() == 0) {
|
||||
event.id_agent = 0;
|
||||
} else {
|
||||
event.id_agent = Integer.parseInt(items[1]);
|
||||
}
|
||||
event.id_user = items[2];
|
||||
if (items[3].length() == 0) {
|
||||
event.id_group = 0;
|
||||
} else {
|
||||
event.id_group = Integer.parseInt(items[3]);
|
||||
}
|
||||
if (items[4].length() == 0) {
|
||||
event.status = 0;
|
||||
} else {
|
||||
event.status = Integer.parseInt(items[4]);
|
||||
}
|
||||
event.timestamp = items[5];
|
||||
event.event = items[6];
|
||||
if (items[7].length() == 0) {
|
||||
event.utimestamp = 0;
|
||||
} else {
|
||||
event.utimestamp = Integer.parseInt(items[7]);
|
||||
}
|
||||
event.event_type = items[8];
|
||||
if (items[9].length() == 0) {
|
||||
event.id_agentmodule = 0;
|
||||
} else {
|
||||
event.id_agentmodule = Integer.parseInt(items[9]);
|
||||
}
|
||||
if (items[10].length() == 0) {
|
||||
event.id_alert_am = 0;
|
||||
} else {
|
||||
event.id_alert_am = Integer.parseInt(items[10]);
|
||||
}
|
||||
if (items[11].length() == 0) {
|
||||
event.criticity = 0;
|
||||
} else {
|
||||
event.criticity = Integer.parseInt(items[11]);
|
||||
}
|
||||
event.user_comment = items[12];
|
||||
event.tags = items[13];
|
||||
event.agent_name = items[16];
|
||||
event.group_name = items[17];
|
||||
event.group_icon = items[18];
|
||||
event.description_event = items[19];
|
||||
event.description_image = items[20];
|
||||
event.criticity_name = items[21];
|
||||
event.criticity_image = items[22];
|
||||
|
||||
event.opened = false;
|
||||
}
|
||||
this.eventList.add(event);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + " getEvents", e.getMessage());
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.count_events == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list of events.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(false)));
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
|
||||
Pattern pattern = Pattern
|
||||
.compile("Unable to process XML data file '(.*)'");
|
||||
Matcher matcher;
|
||||
String filename;
|
||||
|
||||
boolean endReplace = false;
|
||||
int i22 = 0;
|
||||
while (!endReplace) {
|
||||
Log.i(TAG + " getEvents - loop", i22 + "");
|
||||
i22++;
|
||||
matcher = pattern.matcher(return_api);
|
||||
|
||||
if (matcher.find()) {
|
||||
filename = matcher.group(1);
|
||||
return_api = return_api
|
||||
.replaceFirst(
|
||||
"Unable to process XML data file[^\n]*\n[^\n]*line 187 thread .*\n",
|
||||
"Bad XML: " + filename);
|
||||
} else {
|
||||
endReplace = true;
|
||||
}
|
||||
}
|
||||
|
||||
Log.i(TAG + " getEvents - return_api", return_api);
|
||||
|
||||
String[] lines = return_api.split("\n");
|
||||
|
||||
if (return_api.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String[] items = lines[i].split(";", 23);
|
||||
|
||||
EventListItem event = new EventListItem();
|
||||
|
||||
if (items.length != 23) {
|
||||
event.event = getApplication().getString(
|
||||
R.string.unknown_event_str);
|
||||
} else {
|
||||
if (items[0].length() == 0) {
|
||||
event.id_event = 0;
|
||||
} else {
|
||||
event.id_event = Integer.parseInt(items[0]);
|
||||
}
|
||||
if (items[1].length() == 0) {
|
||||
event.id_agent = 0;
|
||||
} else {
|
||||
event.id_agent = Integer.parseInt(items[1]);
|
||||
}
|
||||
event.id_user = items[2];
|
||||
if (items[3].length() == 0) {
|
||||
event.id_group = 0;
|
||||
} else {
|
||||
event.id_group = Integer.parseInt(items[3]);
|
||||
}
|
||||
if (items[4].length() == 0) {
|
||||
event.status = 0;
|
||||
} else {
|
||||
event.status = Integer.parseInt(items[4]);
|
||||
}
|
||||
event.timestamp = items[5];
|
||||
event.event = items[6];
|
||||
if (items[7].length() == 0) {
|
||||
event.utimestamp = 0;
|
||||
} else {
|
||||
event.utimestamp = Integer.parseInt(items[7]);
|
||||
}
|
||||
event.event_type = items[8];
|
||||
if (items[9].length() == 0) {
|
||||
event.id_agentmodule = 0;
|
||||
} else {
|
||||
event.id_agentmodule = Integer.parseInt(items[9]);
|
||||
}
|
||||
if (items[10].length() == 0) {
|
||||
event.id_alert_am = 0;
|
||||
} else {
|
||||
event.id_alert_am = Integer.parseInt(items[10]);
|
||||
}
|
||||
if (items[11].length() == 0) {
|
||||
event.criticity = 0;
|
||||
} else {
|
||||
event.criticity = Integer.parseInt(items[11]);
|
||||
}
|
||||
event.user_comment = items[12];
|
||||
event.tags = items[13];
|
||||
event.agent_name = items[16];
|
||||
event.group_name = items[17];
|
||||
event.group_icon = items[18];
|
||||
event.description_event = items[19];
|
||||
event.description_image = items[20];
|
||||
event.criticity_name = items[21];
|
||||
event.criticity_image = items[22];
|
||||
|
||||
event.opened = false;
|
||||
}
|
||||
this.eventList.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,12 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -85,94 +80,57 @@ public class PandroidEventviewerService extends IntentService {
|
|||
SharedPreferences preferences = context.getSharedPreferences(
|
||||
context.getString(R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
|
||||
this.url = preferences.getString("url", "");
|
||||
this.user = preferences.getString("user", "");
|
||||
this.password = preferences.getString("password", "");
|
||||
Calendar c = Calendar.getInstance();
|
||||
long now = (c.getTimeInMillis() / 1000);
|
||||
long old_previous_filterTimestamp = preferences.getLong(
|
||||
"previous_filterTimestamp", now);
|
||||
|
||||
if ((user.length() == 0) && (password.length() == 0)
|
||||
&& (url.length() == 0)) {
|
||||
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
|
||||
String parametersAPI = serializeParams2Api(context, true, false,
|
||||
false);
|
||||
|
||||
// Get total count.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", parametersAPI));
|
||||
String return_api = Core.httpGet(getApplicationContext(),
|
||||
parameters);
|
||||
Log.i(TAG + " checkNewEvents", return_api);
|
||||
return_api = return_api.replace("\n", "");
|
||||
try {
|
||||
this.count_events = new Long(return_api).longValue();
|
||||
} catch (NumberFormatException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
UrlEncodedFormEntity entity;
|
||||
HttpPost httpPost;
|
||||
List<NameValuePair> parameters;
|
||||
HttpResponse response;
|
||||
HttpEntity entityResponse;
|
||||
String return_api;
|
||||
|
||||
httpPost = new HttpPost(this.url + "/include/api.php");
|
||||
|
||||
String parametersAPI = serializeParams2Api(context, true,
|
||||
false, false);
|
||||
Log.d(TAG, "Parameters checking new events: " + parametersAPI);
|
||||
|
||||
// Get total count.
|
||||
// Check the event more critical
|
||||
if (this.count_events != 0) {
|
||||
Log.i(TAG, "There are new events");
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", this.user));
|
||||
parameters.add(new BasicNameValuePair("pass", this.password));
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other", parametersAPI));
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
return_api = Core.convertStreamToString(entityResponse
|
||||
.getContent());
|
||||
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(context, false, true, true)));
|
||||
return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
return_api = return_api.replace("\n", "");
|
||||
Log.i(TAG + " checkNewEvents", return_api);
|
||||
this.count_events = new Long(return_api).longValue();
|
||||
this.more_criticity = new Integer(return_api).intValue();
|
||||
notificationEvent(context);
|
||||
} else {
|
||||
this.more_criticity = -1;
|
||||
|
||||
// Check the event more critical
|
||||
if (this.count_events != 0) {
|
||||
Log.i(TAG, "There are new events");
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", this.user));
|
||||
parameters
|
||||
.add(new BasicNameValuePair("pass", this.password));
|
||||
parameters.add(new BasicNameValuePair("op", "get"));
|
||||
parameters.add(new BasicNameValuePair("op2", "events"));
|
||||
parameters.add(new BasicNameValuePair("other_mode",
|
||||
"url_encode_separator_|"));
|
||||
parameters
|
||||
.add(new BasicNameValuePair("return_type", "csv"));
|
||||
parameters.add(new BasicNameValuePair("other",
|
||||
serializeParams2Api(context, false, true, true)));
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
return_api = Core.convertStreamToString(entityResponse
|
||||
.getContent());
|
||||
return_api = return_api.replace("\n", "");
|
||||
this.more_criticity = new Integer(return_api).intValue();
|
||||
notificationEvent(context);
|
||||
} else {
|
||||
this.more_criticity = -1;
|
||||
|
||||
// Restore timestamp
|
||||
SharedPreferences.Editor editorPreferences = preferences
|
||||
.edit();
|
||||
editorPreferences.putLong("previous_filterTimestamp",
|
||||
old_previous_filterTimestamp);
|
||||
editorPreferences.commit();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG + " EXCEPTION checkNewEvents", e.getMessage());
|
||||
return;
|
||||
// Restore timestamp
|
||||
SharedPreferences.Editor editorPreferences = preferences.edit();
|
||||
editorPreferences.putLong("previous_filterTimestamp",
|
||||
old_previous_filterTimestamp);
|
||||
editorPreferences.commit();
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Check finished at "
|
||||
|
@ -199,7 +157,6 @@ public class PandroidEventviewerService extends IntentService {
|
|||
String filterAgentName = preferences.getString("filterAgentName", "");
|
||||
|
||||
int idGroup = preferences.getInt("filterIDGroup", 0);
|
||||
Log.d(TAG, "idGroup: " + idGroup);
|
||||
int filterSeverity = preferences.getInt("filterSeverity", -1);
|
||||
int filterStatus = preferences.getInt("filterStatus", 3);
|
||||
String filterEventSearch = preferences.getString("filterEventSearch",
|
||||
|
@ -244,7 +201,7 @@ public class PandroidEventviewerService extends IntentService {
|
|||
Long.toString(0), // The offset of list events
|
||||
totalStr, // Count or show
|
||||
Integer.toString(idGroup), // Group ID
|
||||
filterTag });
|
||||
filterTag }); // Tag
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,5 +308,4 @@ public class PandroidEventviewerService extends IntentService {
|
|||
mNotificationManager.notify(NOTIFICATION_PANDROID_EVENT_VIEWER,
|
||||
notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,20 +19,13 @@ package pandroid_event_viewer.pandorafms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
@ -48,9 +41,6 @@ import android.widget.Toast;
|
|||
public class PopupValidationEvent extends Activity {
|
||||
private int id_event;
|
||||
private String comment;
|
||||
private String url;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -102,52 +92,19 @@ public class PopupValidationEvent extends Activity {
|
|||
private boolean sendValidation() {
|
||||
boolean return_var = false;
|
||||
|
||||
if (this.url == null) {
|
||||
SharedPreferences preferences = getApplicationContext()
|
||||
.getSharedPreferences(
|
||||
getApplicationContext().getString(
|
||||
R.string.const_string_preferences),
|
||||
Activity.MODE_PRIVATE);
|
||||
List<NameValuePair> parameters;
|
||||
// Set event validation.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("op", "set"));
|
||||
parameters.add(new BasicNameValuePair("op2", "validate_events"));
|
||||
parameters.add(new BasicNameValuePair("id", new Integer(this.id_event)
|
||||
.toString()));
|
||||
parameters.add(new BasicNameValuePair("other", this.comment));
|
||||
String return_api = Core.httpGet(getApplicationContext(), parameters);
|
||||
|
||||
this.url = preferences.getString("url", "");
|
||||
this.user = preferences.getString("user", "");
|
||||
this.password = preferences.getString("password", "");
|
||||
if (return_api.startsWith("Correct validation")) {
|
||||
return_var = true;
|
||||
}
|
||||
try {
|
||||
DefaultHttpClient httpClient = new DefaultHttpClient();
|
||||
UrlEncodedFormEntity entity;
|
||||
HttpPost httpPost;
|
||||
List<NameValuePair> parameters;
|
||||
HttpResponse response;
|
||||
HttpEntity entityResponse;
|
||||
String return_api;
|
||||
|
||||
httpPost = new HttpPost(this.url + "/include/api.php");
|
||||
|
||||
// Set event validation.
|
||||
parameters = new ArrayList<NameValuePair>();
|
||||
parameters.add(new BasicNameValuePair("user", this.user));
|
||||
parameters.add(new BasicNameValuePair("pass", this.password));
|
||||
parameters.add(new BasicNameValuePair("op", "set"));
|
||||
parameters.add(new BasicNameValuePair("op2", "validate_events"));
|
||||
parameters.add(new BasicNameValuePair("id", new Integer(
|
||||
this.id_event).toString()));
|
||||
parameters.add(new BasicNameValuePair("other", this.comment));
|
||||
entity = new UrlEncodedFormEntity(parameters);
|
||||
httpPost.setEntity(entity);
|
||||
response = httpClient.execute(httpPost);
|
||||
entityResponse = response.getEntity();
|
||||
return_api = Core
|
||||
.convertStreamToString(entityResponse.getContent());
|
||||
return_api = return_api.replace("\n", "");
|
||||
|
||||
if (return_api.startsWith("Correct validation")) {
|
||||
return_var = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("EXCEPTION sendValidation", e.getMessage());
|
||||
}
|
||||
|
||||
return return_var;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue