diff --git a/extras/android-event-viewer/.gitignore b/extras/android-event-viewer/.gitignore new file mode 100644 index 0000000000..28a312e757 --- /dev/null +++ b/extras/android-event-viewer/.gitignore @@ -0,0 +1,56 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/dictionaries +.idea/libraries + +# Keystore files +*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + diff --git a/extras/android-event-viewer/.idea/compiler.xml b/extras/android-event-viewer/.idea/compiler.xml new file mode 100644 index 0000000000..96cc43efa6 --- /dev/null +++ b/extras/android-event-viewer/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/extras/android-event-viewer/.idea/copyright/profiles_settings.xml b/extras/android-event-viewer/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000000..e7bedf3377 --- /dev/null +++ b/extras/android-event-viewer/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/extras/android-event-viewer/.idea/misc.xml b/extras/android-event-viewer/.idea/misc.xml new file mode 100644 index 0000000000..38041c7cc6 --- /dev/null +++ b/extras/android-event-viewer/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/extras/android-event-viewer/.idea/modules.xml b/extras/android-event-viewer/.idea/modules.xml new file mode 100644 index 0000000000..135b400226 --- /dev/null +++ b/extras/android-event-viewer/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/extras/android-event-viewer/.idea/runConfigurations.xml b/extras/android-event-viewer/.idea/runConfigurations.xml new file mode 100644 index 0000000000..7f68460d8b --- /dev/null +++ b/extras/android-event-viewer/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/extras/android-event-viewer/app/build.gradle b/extras/android-event-viewer/app/build.gradle new file mode 100644 index 0000000000..92924f93b3 --- /dev/null +++ b/extras/android-event-viewer/app/build.gradle @@ -0,0 +1,19 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 8 + buildToolsVersion "25.0.2" + + defaultConfig { + applicationId "pandroid_event_viewer.pandorafms" + minSdkVersion 8 + targetSdkVersion 8 + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } +} diff --git a/extras/pandroid_event_viewer/lint.xml b/extras/android-event-viewer/app/lint.xml similarity index 61% rename from extras/pandroid_event_viewer/lint.xml rename to extras/android-event-viewer/app/lint.xml index f4be1f0ca4..b148b1a931 100644 --- a/extras/pandroid_event_viewer/lint.xml +++ b/extras/android-event-viewer/app/lint.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/extras/pandroid_event_viewer/AndroidManifest.xml b/extras/android-event-viewer/app/src/main/AndroidManifest.xml similarity index 98% rename from extras/pandroid_event_viewer/AndroidManifest.xml rename to extras/android-event-viewer/app/src/main/AndroidManifest.xml index 443f3c8bd0..bdd70a163e 100644 --- a/extras/pandroid_event_viewer/AndroidManifest.xml +++ b/extras/android-event-viewer/app/src/main/AndroidManifest.xml @@ -16,8 +16,8 @@ --> + android:versionCode="6" + android:versionName="1.5" > parameters = new ArrayList(); 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("return_type", returnType)); parameters.add(new BasicNameValuePair("other", serializeEventsParamsToAPI(filterAgentName, idGroup, filterSeverity, filterStatus, filterEventSearch, @@ -159,6 +162,88 @@ public class API { more_criticity))); return Core.httpGet(context, parameters); } + + /** + * Performs a get_events API call. + * + * @param context + * Application context. + * @param filterAgentName + * Agent name. + * @param idGroup + * Group id. + * @param filterSeverity + * Severity. + * @param filterStatus + * Status. + * @param filterEventSearch + * Text in event title. + * @param filterTag + * Tag. + * @param filterTimestamp + * Events after this time. + * @param itemsPerPage + * Number of items retrieved per list in each call. + * @param offset + * List offset. + * @param total + * Retrieve number of events instead of events info. + * @param more_criticity + * Retrieve maximum criticity instead of events info. + * + * @return API call result. + * @throws IOException + * if there was any problem. + */ + public static String getEvents (Context context, String filterAgentName, + int idGroup, int filterSeverity, int filterStatus, + String filterEventSearch, String filterTag, + long filterTimestamp, long itemsPerPage, long offset, + boolean total, boolean more_criticity) throws IOException { + return API.getEvents(context, + filterAgentName, idGroup, filterSeverity, filterStatus, filterEventSearch, + filterTag, filterTimestamp, itemsPerPage, offset, total, more_criticity, "csv"); + } + + /** + * Performs a get_events API call. + * + * @param context + * Application context. + * @param filterAgentName + * Agent name. + * @param idGroup + * Group id. + * @param filterSeverity + * Severity. + * @param filterStatus + * Status. + * @param filterEventSearch + * Text in event title. + * @param filterTag + * Tag. + * @param filterTimestamp + * Events after this time. + * @param itemsPerPage + * Number of items retrieved per list in each call. + * @param offset + * List offset. + * @param returnType + * To chose the type of the returned data (csv, json...). + * + * @return API call result. + * @throws IOException + * if there was any problem. + */ + public static String getEvents (Context context, String filterAgentName, + int idGroup, int filterSeverity, int filterStatus, + String filterEventSearch, String filterTag, + long filterTimestamp, long itemsPerPage, long offset, + String returnType) throws IOException { + return API.getEvents(context, + filterAgentName, idGroup, filterSeverity, filterStatus, filterEventSearch, + filterTag, filterTimestamp, itemsPerPage, offset, false, false, returnType); + } /** * Get tags through an api call. diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/About.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/About.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/About.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/About.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Core.java similarity index 95% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Core.java index 462a0af2d5..4363e7d57a 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Core.java +++ b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Core.java @@ -34,6 +34,8 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; @@ -755,4 +757,32 @@ public class Core { return null; } } + + /** + * Returns the major version by extracting it from the api_version token from the preferences. + * + * @param context Application context. + * @return int Major API version + * + * @throws Exception If the major version cannot be extracted. + * @throws NumberFormatException If the major version cannot be casted to integer. + */ + public static int getMajorVersion (Context context) throws Exception { + SharedPreferences preferences = context.getSharedPreferences( + context.getString(R.string.const_string_preferences), + Activity.MODE_PRIVATE); + // It is something like v5.0SP1 + String api_version = preferences.getString("api_version", ""); + + // Try to get the version number + Matcher apiVerMatcher = Pattern.compile("^v(\\d)+\\.\\d+.*$").matcher(api_version); + + if (apiVerMatcher.find()) { + String apiVerString = apiVerMatcher.group(1); + int apiVerNumber = Integer.parseInt(apiVerString); + + return apiVerNumber; + } + throw new Exception("The version number cannot be extracted from the version string"); + } } diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/EventList.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventList.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/EventList.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventListItem.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/EventListItem.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/EventListItem.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/EventListItem.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Info.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Info.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Info.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Info.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Main.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Main.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Main.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/NaiveTrustManager.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/NaiveTrustManager.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/NaiveTrustManager.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/NaiveTrustManager.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/OnBootLoader.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/OnBootLoader.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/OnBootLoader.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/OnBootLoader.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Options.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/Options.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/Options.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java similarity index 60% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java index 510fe0303c..df270c8fc7 100644 --- a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java +++ b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PandroidEventviewerActivity.java @@ -22,6 +22,8 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import android.app.Activity; import android.app.Notification; @@ -39,9 +41,12 @@ import android.widget.BaseAdapter; import android.widget.TabHost; import android.widget.Toast; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; -public class PandroidEventviewerActivity extends TabActivity implements - Serializable { + +public class PandroidEventviewerActivity extends TabActivity implements Serializable { private static String TAG = "PandroidEventviewerActivity"; private static final int PROBLEM_NOTIFICATION_ID = 1; private static final long serialVersionUID = 1L; @@ -259,250 +264,220 @@ public class PandroidEventviewerActivity extends TabActivity implements "Configuration changes commited (timestamp)"); } } - + /** - * Get events from pandora console. For only Pandora 5.0 version - * - * @throws IOException - * If there is any connection problem. - * + * Parses a JSON object and returns a valid event list item. + * For >= v7. + * + * @param item Object with the event columns. + * + * @return EventListItem + * @throws JSONException, NumberFormatException */ - private void getEvents_v50(String[] lines) { - for (int i = 0; i < lines.length; i++) { - String[] items = lines[i].split(";"); + private EventListItem parseEvent (JSONObject item) throws JSONException, NumberFormatException { + EventListItem event = new EventListItem(); - EventListItem event = new EventListItem(); - boolean extract = true; + // Event id + event.id_event = item.optInt("id_evento"); + // Agent id + event.id_agent = item.optInt("id_agente"); + // User id + event.id_user = item.getString("id_usuario"); + // Group id + event.id_group = item.optInt("id_grupo"); + // Status + event.status = item.optInt("estado"); + // Timestamp (Y-M-d H:m:s) + event.timestamp = item.getString("timestamp"); + // Event text + event.event = item.getString("evento"); + // Unix timestamp + event.utimestamp = item.optInt("utimestamp"); + // Event type + event.event_type = item.getString("event_type"); + // Module id + event.id_agentmodule = item.optInt("id_agentmodule"); + // Alert id + event.id_alert_am = item.optInt("id_alert_am"); + // Event priority + event.criticity = item.optInt("criticity"); + // User comments + event.user_comment = item.getString("user_comment"); + // Tags + event.tags = item.getString("tags"); + // Agent name (try to use the alias) + event.agent_name = item.optString("agent_alias", item.optString("agent_name")); + // Group name + event.group_name = item.optString("group_name"); + // Group icon + event.group_icon = item.optString("group_icon"); + // Event description + event.description_event = item.optString("description_event"); + // Event description image + event.description_image = item.optString("img_description"); + // Event priority name + event.criticity_name = item.optString("criticity_name"); + // Event priority image + event.criticity_image = item.optString("img_criticy"); + + event.opened = false; + + return event; + } + + /** + * Parses a string array and returns a valid event list item. + * + * THIS IS AN HORRIBLE WAY TO DO THIS. + * Any change on the columns order on the tevento's table from the database + * or any change to the public API can break this in multiple ways. + * CSV is bad for a maintainable and scalable APIs, but someone could almost map the + * head (nonexistent) with the line columns indexes... /rage + * + * For <= v6. + * + * @param columns String array with the event columns. + * @param old Whether to use the csv parsing for the <=v4 or the >=v5 && <= v6. + * + * @return EventListItem + * @throws NumberFormatException + */ + private EventListItem parseEvent (String[] columns, boolean old) throws NumberFormatException { + EventListItem event = new EventListItem(); + + // Event id + event.id_event = (columns[0].length() > 0) ? Integer.parseInt(columns[0]) : 0; + // Agent id + event.id_agent = (columns[1].length() > 0) ? Integer.parseInt(columns[1]) : 0; + // User id + event.id_user = columns[2]; + //Get id group + event.id_group = (columns[3].length() > 0) ? Integer.parseInt(columns[3]) : 0; + // Status + event.status = (columns[4].length() > 0) ? Integer.parseInt(columns[4]) : 0; + // Timestamp (format Y-M-d H:m:s) + event.timestamp = columns[5]; + //Get event as text + event.event = columns[6]; + // Unix timestamp + event.utimestamp = (columns[7].length() > 0) ? Integer.parseInt(columns[7]) : 0; + // Event type + event.event_type = columns[8]; + // Module id + event.id_agentmodule = (columns[9].length() > 0) ? Integer.parseInt(columns[9]) : 0; + // Alert id + event.id_alert_am = (columns[10].length() > 0) ? Integer.parseInt(columns[10]) : 0; + // Priority + event.criticity = (columns[11].length() > 0) ? Integer.parseInt(columns[11]) : 0; + // User comment + event.user_comment = columns[12]; + // Tags + event.tags = columns[13]; + + // For <= v4 + if (old) { + // Agent name + event.agent_name = (columns.length >= 15) ? columns[14] : ""; + // Group name + event.group_name = (columns.length >= 16) ? columns[15] : ""; + // Group icon + event.group_icon = (columns.length >= 17) ? columns[16] : ""; + // Event description + event.description_event = (columns.length >= 18) ? columns[17] : ""; + // Event description image + event.description_image = (columns.length >= 19) ? columns[18] : ""; + // Priority image + event.criticity_image = (columns.length >= 20) ? columns[19] : ""; + // Priority name + event.criticity_name = (columns.length >= 21) ? columns[20] : ""; + } + // For v5 and v6 + else { + // Agent name + event.agent_name = (columns.length >= 23) ? columns[22] : ""; + // Group name + event.group_name = (columns.length >= 24) ? columns[23] : ""; + // Group icon + event.group_icon = (columns.length >= 25) ? columns[24] : ""; + // Event description + event.description_event = (columns.length >= 26) ? columns[25] : ""; + // Event description image + event.description_image = (columns.length >= 27) ? columns[26] : ""; + // Priority image + event.criticity_image = (columns.length >= 28) ? columns[27] : ""; + // Priority name + event.criticity_name = (columns.length >= 29) ? columns[28] : ""; + } + + event.opened = false; + + return event; + } + + /** + * Process a JSON response from the api and save the new events. + * For >= v7. + * + * @param items JSONObject array with the event rows. + */ + private void saveEvents (JSONArray items) { + if (items.length() == 0) { + Log.d("WORKS?", "NEWEVENTS = FALSE"); + this.newEvents = false; + return; + } + this.newEvents = true; + + // Iterate the JSON Objects + for (int i = 0; i < items.length(); i++) { try { - if (items.length < 14) { - extract = false; - continue; - } - //Get id event - if (items[0].length() == 0) { - event.id_event = 0; - } - else { - event.id_event = Integer.parseInt(items[0]); - } - - //Get id agent - if (items[1].length() == 0) { - event.id_agent = 0; - } - else { - event.id_agent = Integer.parseInt(items[1]); - } - - //Get id user - event.id_user = items[2]; - - //Get id group - if (items[3].length() == 0) { - event.id_group = 0; - } - else { - event.id_group = Integer.parseInt(items[3]); - } - - //Get status - if (items[4].length() == 0) { - event.status = 0; - } - else { - event.status = Integer.parseInt(items[4]); - } - - //Get timestamp (format Y-M-d H:m:s) - event.timestamp = items[5]; - - //Get event as text - event.event = items[6]; - - //Get unix timestamp - if (items[7].length() == 0) { - event.utimestamp = 0; - } - else { - event.utimestamp = Integer.parseInt(items[7]); - } - - //Get event type - event.event_type = items[8]; - - //Get id module - if (items[9].length() == 0) { - event.id_agentmodule = 0; - } - else { - event.id_agentmodule = Integer.parseInt(items[9]); - } - - //Get id alert - if (items[10].length() == 0) { - event.id_alert_am = 0; - } - else { - event.id_alert_am = Integer.parseInt(items[10]); - } - - //Get criticity - if (items[11].length() == 0) { - event.criticity = 0; - } - else { - event.criticity = Integer.parseInt(items[11]); - } - - //Get user comment - event.user_comment = items[12]; - - //Get tags - event.tags = items[13]; - - /* This fields are not used in the Pandroid event - - event.source = item[14]; - event.id_extra = item[15]; - event.critical_instructions = item[16]; - event.warning_instructions = item[17]; - event.unknown_instructions = item[18]; - event.owner_user = item[19]; - event.ack_utimestamp = item[20]; - event.custom_data = item[21] - - */ - - event.agent_name = ""; - event.group_name = ""; - event.group_icon = ""; - event.description_event = ""; - event.description_image = ""; - event.criticity_name = ""; - event.criticity_image = ""; - - if (items.length >= 23) - event.agent_name = items[22]; - if (items.length >= 24) - event.group_name = items[23]; - if (items.length >= 25) - event.group_icon = items[24]; - if (items.length >= 26) - event.description_event = items[25]; - if (items.length >= 27) - event.description_image = items[26]; - if (items.length >= 28) - event.criticity_name = items[28]; - if (items.length >= 27) - event.criticity_image = items[27]; - - event.opened = false; - } - catch (NumberFormatException nfe) { - event.event = getApplication().getString( - R.string.unknown_event_str); - launchProblemParsingNotification(); - } - if (extract) + JSONObject item = items.getJSONObject(i); + EventListItem event = this.parseEvent(item); this.eventList.add(event); - } - } - - /** - * Get events from pandora console. For old versions of Pandora (v4 <) - * - * @throws IOException - * If there is any connection problem. - * - */ - private void getEvents_old(String[] lines) { - for (int i = 0; i < lines.length; i++) { - String[] items = lines[i].split(";"); - - EventListItem event = new EventListItem(); - try { - - 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[14]; - event.group_name = items[15]; - event.group_icon = items[16]; - event.description_event = items[17]; - event.description_image = items[18]; - event.criticity_name = items[19]; - event.criticity_image = items[20]; - - event.opened = false; } catch (NumberFormatException nfe) { - event.event = getApplication().getString( - R.string.unknown_event_str); launchProblemParsingNotification(); } - this.eventList.add(event); + catch (JSONException e) { + launchProblemParsingNotification(); + } } } - + + /** + * Process a CSV response from the api and save the new events. + * For <= v6. + * + * @param lines String array with the event lines in CSV format. + * @param old Whether to use the csv parsing for the <=v4 or the >=v5 && <= v6. + */ + private void saveEvents (String[] lines, boolean old) { + if (lines.length == 0) { + Log.d("WORKS?", "NEWEVENTS = FALSE"); + this.newEvents = false; + return; + } + this.newEvents = true; + + // Iterate the CSV lines + for (int i = 0; i < lines.length; i++) { + try { + String[] columns = lines[i].split(";"); + EventListItem event = this.parseEvent(columns, old); + this.eventList.add(event); + } + catch (NumberFormatException nfe) { + launchProblemParsingNotification(); + } + } + } + /** * Get events from pandora console. * - * @throws IOException - * If there is any connection problem. - * + * @throws IOException If there is any connection problem. */ - private void getEvents() throws IOException { + private void getEvents () throws IOException { // Get total count. String return_api = API.getEvents(getApplicationContext(), agentNameStr, id_group, severity, status, eventSearch, @@ -521,35 +496,42 @@ public class PandroidEventviewerActivity extends TabActivity implements return; } + // Try to get the API version number + int apiVerNumber = 0; + try { + apiVerNumber = Core.getMajorVersion(getApplicationContext()); + } + catch (Exception e) {} + // Get the list of events. - return_api = API.getEvents(getApplicationContext(), agentNameStr, - id_group, severity, status, eventSearch, eventTag, timestamp, - pagination, offset, false, false); + String returnType = (apiVerNumber < 7) ? "csv" : "json"; + return_api = API.getEvents(getApplicationContext(), + agentNameStr, id_group, severity, status, eventSearch, + eventTag, timestamp, pagination, offset, returnType); + Log.d(TAG, "List of events: " + return_api); - Log.i(TAG + " getEvents - return_api", return_api); - String[] lines = return_api.split("\n"); - newEvents = true; - if (return_api.length() == 0) { - Log.d("WORKS?", "NEWEVENTS = FALSE"); - newEvents = false; - return; + try { + if (apiVerNumber >= 7) { + JSONObject response = new JSONObject(return_api); + if (!response.optString("type").equals("array")) { + throw new Exception("Invalid API return type"); + } + + JSONArray rows = response.getJSONArray("data"); + this.saveEvents(rows); + } + else { + String[] lines = return_api.split("\n"); + + // The Console API changed in the v5 + boolean old = apiVerNumber < 5; + this.saveEvents(lines, old); + } } - - SharedPreferences preferences = getSharedPreferences( - getString(R.string.const_string_preferences), - Activity.MODE_PRIVATE); - String api_version = preferences.getString("api_version", ""); - - // Get the short form of the version. I.E. "v5" for "v5.0SP1" - String[] api_version_short = api_version.split("\\."); - - if (api_version_short[0].equals("v5")) { - this.getEvents_v50(lines); - } - else { - this.getEvents_old(lines); + catch (Exception e) { + this.newEvents = false; } } diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PandroidEventviewerService.java diff --git a/extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java b/extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PopupValidationEvent.java similarity index 100% rename from extras/pandroid_event_viewer/src/pandroid_event_viewer/pandorafms/PopupValidationEvent.java rename to extras/android-event-viewer/app/src/main/java/pandroid_event_viewer/pandorafms/PopupValidationEvent.java diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/about.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/about.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/about.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/about.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/b_green.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_green.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/b_green.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_green.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/b_red.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_red.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/b_red.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_red.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/b_yellow.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_yellow.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/b_yellow.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/b_yellow.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/bell.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/bell.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/bell.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/bell.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/cog.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/cog.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/cog.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/cog.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/config.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/config.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/config.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/config.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_0.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_0.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_0.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_0.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_1.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_1.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_1.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_1.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_2.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_2.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_2.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_2.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_3.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_3.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_3.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_3.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_4.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_4.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_4.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_4.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/criticity_default.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_default.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/criticity_default.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/criticity_default.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/cross.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/cross.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/cross.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/cross.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/delete.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/delete.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/delete.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/delete.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/delete_pressed.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/delete_pressed.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/delete_pressed.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/delete_pressed.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/err.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/err.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/err.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/err.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/error.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/error.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/error.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/error.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/eye.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/eye.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/eye.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/eye.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/help.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/help.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/help.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/help.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/icon_filter.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_filter.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/icon_filter.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_filter.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/icon_filter_pressed.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_filter_pressed.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/icon_filter_pressed.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_filter_pressed.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/icon_refresh.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_refresh.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/icon_refresh.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_refresh.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/icon_refresh_pressed.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_refresh_pressed.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/icon_refresh_pressed.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/icon_refresh_pressed.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/network.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/network.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/network.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/network.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/ok.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/ok.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/ok.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/ok.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/pandorafms_logo.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/pandorafms_logo.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/pandorafms_logo.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/pandorafms_logo.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/refresh.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/refresh.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/refresh.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/refresh.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/save.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/save.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/save.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/save.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/save_pressed.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/save_pressed.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/save_pressed.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/save_pressed.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/severity_critical.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_critical.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/severity_critical.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_critical.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/severity_informational.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_informational.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/severity_informational.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_informational.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/severity_maintenance.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_maintenance.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/severity_maintenance.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_maintenance.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/severity_normal.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_normal.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/severity_normal.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_normal.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/severity_warning.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_warning.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/severity_warning.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/severity_warning.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/tick.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/tick.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/tick.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/tick.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/tick_off.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/tick_off.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/tick_off.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/tick_off.png diff --git a/extras/pandroid_event_viewer/res/drawable-ldpi/wand.png b/extras/android-event-viewer/app/src/main/res/drawable-ldpi/wand.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable-ldpi/wand.png rename to extras/android-event-viewer/app/src/main/res/drawable-ldpi/wand.png diff --git a/extras/pandroid_event_viewer/res/drawable/btn_dropdown.xml b/extras/android-event-viewer/app/src/main/res/drawable/btn_dropdown.xml similarity index 93% rename from extras/pandroid_event_viewer/res/drawable/btn_dropdown.xml rename to extras/android-event-viewer/app/src/main/res/drawable/btn_dropdown.xml index 6632f1172e..d02baf24eb 100644 --- a/extras/pandroid_event_viewer/res/drawable/btn_dropdown.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/btn_dropdown.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/button_normal.9.png b/extras/android-event-viewer/app/src/main/res/drawable/button_normal.9.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable/button_normal.9.png rename to extras/android-event-viewer/app/src/main/res/drawable/button_normal.9.png diff --git a/extras/pandroid_event_viewer/res/drawable/button_pressed.9.png b/extras/android-event-viewer/app/src/main/res/drawable/button_pressed.9.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable/button_pressed.9.png rename to extras/android-event-viewer/app/src/main/res/drawable/button_pressed.9.png diff --git a/extras/pandroid_event_viewer/res/drawable/combobox_normal.9.png b/extras/android-event-viewer/app/src/main/res/drawable/combobox_normal.9.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable/combobox_normal.9.png rename to extras/android-event-viewer/app/src/main/res/drawable/combobox_normal.9.png diff --git a/extras/pandroid_event_viewer/res/drawable/combobox_pressed.9.png b/extras/android-event-viewer/app/src/main/res/drawable/combobox_pressed.9.png similarity index 100% rename from extras/pandroid_event_viewer/res/drawable/combobox_pressed.9.png rename to extras/android-event-viewer/app/src/main/res/drawable/combobox_pressed.9.png diff --git a/extras/pandroid_event_viewer/res/drawable/delete_icon_button.xml b/extras/android-event-viewer/app/src/main/res/drawable/delete_icon_button.xml similarity index 92% rename from extras/pandroid_event_viewer/res/drawable/delete_icon_button.xml rename to extras/android-event-viewer/app/src/main/res/drawable/delete_icon_button.xml index 12fb68eebd..e84bc69184 100644 --- a/extras/pandroid_event_viewer/res/drawable/delete_icon_button.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/delete_icon_button.xml @@ -1,4 +1,4 @@ - + + + + + diff --git a/extras/pandroid_event_viewer/res/drawable/round_event_item_blue.xml b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_blue.xml similarity index 84% rename from extras/pandroid_event_viewer/res/drawable/round_event_item_blue.xml rename to extras/android-event-viewer/app/src/main/res/drawable/round_event_item_blue.xml index c92f785f94..80eda4b5a7 100644 --- a/extras/pandroid_event_viewer/res/drawable/round_event_item_blue.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_blue.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/round_event_item_green.xml b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_green.xml similarity index 84% rename from extras/pandroid_event_viewer/res/drawable/round_event_item_green.xml rename to extras/android-event-viewer/app/src/main/res/drawable/round_event_item_green.xml index 34214ad096..bca8d276f9 100644 --- a/extras/pandroid_event_viewer/res/drawable/round_event_item_green.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_green.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/round_event_item_grey.xml b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_grey.xml similarity index 84% rename from extras/pandroid_event_viewer/res/drawable/round_event_item_grey.xml rename to extras/android-event-viewer/app/src/main/res/drawable/round_event_item_grey.xml index 184aa46014..fb034f0191 100644 --- a/extras/pandroid_event_viewer/res/drawable/round_event_item_grey.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_grey.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/round_event_item_red.xml b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_red.xml similarity index 84% rename from extras/pandroid_event_viewer/res/drawable/round_event_item_red.xml rename to extras/android-event-viewer/app/src/main/res/drawable/round_event_item_red.xml index 15c4cc96e9..2102af9a64 100644 --- a/extras/pandroid_event_viewer/res/drawable/round_event_item_red.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_red.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/round_event_item_yellow.xml b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_yellow.xml similarity index 84% rename from extras/pandroid_event_viewer/res/drawable/round_event_item_yellow.xml rename to extras/android-event-viewer/app/src/main/res/drawable/round_event_item_yellow.xml index 07e2edaf5e..0b2f00baf3 100644 --- a/extras/pandroid_event_viewer/res/drawable/round_event_item_yellow.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/round_event_item_yellow.xml @@ -1,4 +1,4 @@ - + diff --git a/extras/pandroid_event_viewer/res/drawable/save_icon_button.xml b/extras/android-event-viewer/app/src/main/res/drawable/save_icon_button.xml similarity index 92% rename from extras/pandroid_event_viewer/res/drawable/save_icon_button.xml rename to extras/android-event-viewer/app/src/main/res/drawable/save_icon_button.xml index 4412e49258..8f4f24ecc1 100644 --- a/extras/pandroid_event_viewer/res/drawable/save_icon_button.xml +++ b/extras/android-event-viewer/app/src/main/res/drawable/save_icon_button.xml @@ -1,4 +1,4 @@ - + + - 'forced_title_layer', 'class' => 'forced_title_layer', 'hidden' => true)); -html_print_div(array('id' => 'modal_alert', 'hidden' => true)); +//html_print_div(array('id' => 'modal_alert', 'hidden' => true)); ?> - - There is a new version: " . $result[0]['version'] . "

"; echo "" . + "\", \"" . $result[0]['version'] ."\", \"" . $baseurl ."\");'>" . __("Update to the last version") . ""; } else { @@ -604,17 +604,11 @@ function update_manager_remote_read_messages ($id_message) { return $result['success']; } -/** - * The update copy entirire the tgz or fail (leave some parts copies and some part not). - * This does make any thing with the BD. - */ -function update_manager_starting_update() { +function update_manager_extract_package() { global $config; $path_package = $config['attachment_store'] . "/downloads/last_package.tgz"; - - $full_path = $config['attachment_store'] . "/downloads/unix"; ob_start(); @@ -624,6 +618,7 @@ function update_manager_starting_update() { } $extracted = false; + // Phar and exception working fine in 5.5.0 or higher if (PHP_VERSION_ID >= 50505) { $phar = new PharData($path_package); @@ -636,13 +631,17 @@ function update_manager_starting_update() { $extracted = false; } } + $return = true; if($extracted === false) { + $return = false; + if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { // unsupported OS echo "This OS [" . PHP_OS . "] does not support direct extraction of tgz files. Upgrade PHP version to be > 5.5.0"; } else { + $return = true; system('tar xzf "' . $path_package . '" -C ' . $config['attachment_store'] . "/downloads/"); } } @@ -668,17 +667,27 @@ function update_manager_starting_update() { db_process_sql_update('tconfig', array('value' => 50), array('token' => 'progress_update')); + + return $return; +} + +/** + * The update copy entirire the tgz or fail (leave some parts copies and some part not). + * This does make any thing with the BD. + */ +function update_manager_starting_update() { + global $config; - + $full_path = $config['attachment_store'] . "/downloads"; $homedir = $config['homedir']; - + $result = update_manager_recurse_copy( $full_path, $homedir, array('install.php')); - rrmdir($full_path); + rrmdir($full_path . "/pandora_console"); if (!$result) { db_process_sql_update('tconfig', @@ -711,13 +720,11 @@ function update_manager_starting_update() { } } - function update_manager_recurse_copy($src, $dst, $black_list) { $dir = opendir($src); @mkdir($dst); @trigger_error("NONE"); - //debugPrint("mkdir(" . $dst . ")", true); while (false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' ) && (!in_array($file, $black_list))) { if ( is_dir($src . '/' . $file) ) { diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index ad38e4a4e9..6941e435ba 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -2434,12 +2434,9 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $proportion_height = 0; $proportion_width = 0; - - if (!is_null($height) && !is_null($width)) { $resizedMap = true; - if ($keep_aspect_ratio) { $ratio = min($width / $layout['width'], $height / $layout['height']); $mapWidth = $ratio * $layout['width']; @@ -2453,49 +2450,48 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $dif_height = $layout["height"] - $mapHeight; $dif_width = $layout["width"] - $mapWidth; - $proportion_height = $mapHeight / $layout["height"]; $proportion_width = $mapWidth / $layout["width"]; - - if (is_metaconsole()) { - $backgroundImage = - '/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' . - $config['homeurl'] . 'images/console/background/' . - $layout["background"]; - } - else { - $backgroundImage = - '/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' . - $config['homedir'] . '/images/console/background/' . - ($layout["background"]); + if ($layout["background"] != 'None.png' ) { + if (is_metaconsole()) { + $backgroundImage = + '/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' . + $config['homeurl'] . 'images/console/background/' . + $layout["background"]; + } + else { + $backgroundImage = + '/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' . + $config['homedir'] . '/images/console/background/' . + ($layout["background"]); + } } } else { $mapWidth = $layout["width"]; $mapHeight = $layout["height"]; - $backgroundImage = $metaconsole_hack . 'images/console/background/' . - $layout["background"]; + $backgroundImage = ''; + if ($layout["background"] != 'None.png' ) + $backgroundImage = $metaconsole_hack . 'images/console/background/' . + $layout["background"]; } if (defined('METACONSOLE')) { echo "
"; } - echo '
'; - echo ""; + height:' . $mapHeight . 'px; + background-color:'.$layout["background_color"].';">'; + + if ($layout["background"] != 'None.png' ) + echo ""; $layout_datas = db_get_all_rows_field_filter('tlayout_data', diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index 8fa3306927..83f7c99a81 100755 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -446,7 +446,10 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) { html_print_input_text('width_module_graph', 300, '', 3, 5, true) . ' X ' . html_print_input_text('height_module_graph', 180, '', 3, 5, true) . - ''; + ' X ' . + '1 '. + ' item/s + '; //Insert and modify before the buttons to create or update. @@ -587,6 +590,49 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) { $(".border_color").attachColorPicker(); $(".fill_color").attachColorPicker(); $(".line_color").attachColorPicker(); + + $("input[name=radio_choice]").change(function(){ + $('#count_items').html(1); + }); + + $("#custom_graph").click(function(){ + $('#count_items').html(1); + jQuery.get ("ajax.php", + {"page": "general/cg_items","data": $(this).val()}, + function (data, status) { + if(data.split(",")[0] == 8){ + size = 400+(data.split(",")[1] * 50); + if(data.split(",")[1]>3){ + size = 400+(3 * 50); + } + $('#text-width_module_graph').val(size); + $('#text-height_module_graph').val(140); + + } + else if (data.split(",")[0] == 4) { + size = data.split(",")[1]; + if(data.split(",")[1] > 1){ + $('#count_items').html(data.split(",")[1]); + $('#dir_items').html('vertical'); + } + $('#text-width_module_graph').val(300); + $('#text-height_module_graph').val(50); + } + else if (data.split(",")[0] == 5) { + size = data.split(",")[1]; + if(data.split(",")[1] > 1){ + $('#count_items').html(data.split(",")[1]); + $('#dir_items').html('horizontal'); + } + $('#text-width_module_graph').val(100); + $('#text-height_module_graph').val(100); + } + + }); + + }); + + }); "; + if (is_metaconsole()) { + return ""; + } + else { + return ""; + } } diff --git a/pandora_console/include/graphs/flot/jquery.flot.pie.js b/pandora_console/include/graphs/flot/jquery.flot.pie.js index dfd5c72702..ef36e97246 100644 --- a/pandora_console/include/graphs/flot/jquery.flot.pie.js +++ b/pandora_console/include/graphs/flot/jquery.flot.pie.js @@ -195,9 +195,9 @@ More detail and specific examples can be found in the included HTML file. if (options.series.pie.offset.left=='auto') if (options.legend.position.match('w')) - centerLeft += legendWidth/2; + centerLeft += legendWidth; else - centerLeft -= legendWidth/2; + centerLeft -= legendWidth; else centerLeft += options.series.pie.offset.left; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 00f2e44467..d21e6ceada 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -142,23 +142,31 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, } var label_conf; - - label_conf = { - show: true, - radius: 0.75, - formatter: function(label, series) { - return '
' + - series.percent.toFixed(2) + '%
'; - }, - background: { - opacity: 0.5, - color: '' - } - }; - var show_legend = true; + if((width <= 450)) { + show_legend = false; + label_conf = { + show: false + }; + } + else { + label_conf = { + show: true, + radius: 0.75, + formatter: function(label, series) { + return '
' + + series.percent.toFixed(2) + '%
'; + }, + background: { + opacity: 0.5, + color: '' + } + }; + + } + var conf_pie = { series: { pie: { @@ -176,6 +184,9 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, clickable: true } }; + if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { + conf_pie.series.pie.label = {show: false}; + } var plot = $.plot($('#'+graph_id), data, conf_pie); if (no_data == data.length) { @@ -205,17 +216,17 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, var pielegends = $('#'+graph_id+' .pieLabelBackground'); pielegends.each(function () { - $(this).css('transform', "rotate(-35deg)"); + $(this).css('transform', "rotate(-35deg)").css('color', 'black'); }); var labelpielegends = $('#'+graph_id+' .pieLabel'); labelpielegends.each(function () { - $(this).css('transform', "rotate(-35deg)"); + $(this).css('transform', "rotate(-35deg)").css('color', 'black'); }); // Events $('#' + graph_id).bind('plothover', pieHover); $('#' + graph_id).bind('plotclick', Clickpie); - $('#' + graph_id).bind('mouseout',resetInteractivity); + $('#' + graph_id).bind('mouseout', resetInteractivity); $('#' + graph_id).css('margin-left', 'auto'); $('#' + graph_id).css('margin-right', 'auto'); @@ -309,15 +320,19 @@ function pandoraFlotHBars(graph_id, values, labels, water_mark, borderWidth: 1, backgroundColor: { colors: ["#FFF", "#FFF"] } }, + xaxis: { + axisLabelUseCanvas: true, + axisLabelFontSizePixels: font_size, + axisLabelFontFamily: font+'Font', + tickFormatter: xFormatter, + }, yaxis: { - axisLabelUseCanvas: true, - axisLabelFontSizePixels: 12, - axisLabelFontFamily: font+'Font', - axisLabelPadding: 3, - ticks: yFormatter, - tickSize: 1, - color: '', - }, + axisLabelUseCanvas: true, + axisLabelFontSizePixels: font_size, + axisLabelFontFamily: font+'Font', + ticks: yFormatter, + color: '', + }, legend: { show: false } @@ -339,141 +354,38 @@ function pandoraFlotHBars(graph_id, values, labels, water_mark, $('#' + graph_id).HUseTooltip(); $('#' + graph_id).css("margin-left","auto"); $('#' + graph_id).css("margin-right","auto"); - $('#' + graph_id).find('div.legend-tooltip').tooltip({ track: true }); - // Adjust the top of yaxis tick to set it in the middle of the bars - //yAxisHeight = $('#' + graph_id + ' .yAxis .tickLabel') - //.css('height').split('px')[0]; + //~ $('#' + graph_id).find('div.legend-tooltip').tooltip({ track: true }); - //~ i = 0; - //~ $('#' + graph_id + ' .yAxis .tickLabel').each(function() { - //~ $(this).css('display','none'); - //~ $(this).addClass("legend_"+i); - //~ i++; - //~ }); - - $('#' + graph_id + ' .xAxis .tickLabel').each(function() { - /* - tickTop = $(this).css('top').split('px')[0]; - tickNewTop = parseInt(parseInt(tickTop) - (yAxisHeight / 2) - 3); - $(this).css('top', tickNewTop + 'px'); - - valuesNewTop = parseInt(parseInt(tickTop) - (yAxisHeight)); - - $('#value_' + i + '_' + graph_id) - .css('top',parseInt(plot.offset().top) + parseInt(valuesNewTop)); - - pixelPerValue = parseInt(plot.width()) / maxvalue; - - inCanvasValuePos = parseInt(pixelPerValue * - ($('#value_' + i + '_' + graph_id).html())); - label_width = ($('#value_' + i + '_' + graph_id) - .css('width').split('px')[0] - 3); - - label_left_offset = plot.offset().left + inCanvasValuePos + 5; //Label located on right side of bar + 5 pixels - - //If label fit into the bar just recalculate left position to fit on right side of bar - if (inCanvasValuePos > label_width) { - label_left_offset = plot.offset().left + inCanvasValuePos - - $('#value_' + i + '_' + graph_id).css('width').split('px')[0] - 3; - } - - $('#value_' + i + '_' + graph_id) - .css('left', label_left_offset); - i++; - */ - label = parseFloat($(this).text()); - text = label.toLocaleString(); - if ( label >= 1000000) - text = text.substring(0,4) + "M"; - else if (label >= 100000) - text = text.substring(0,3) + "K"; - else if (label >= 1000) - text = text.substring(0,2) + "K"; - - $(this).text(text); - - }); - /* - // When resize the window, adjust the values - $('#' + graph_id).parent().resize(function () { - i = 0; - pixelPerValue = parseInt(plot.width()) / maxvalue; - - $('#' + graph_id + ' .yAxis .tickLabel').each(function() { - inCanvasValuePos = parseInt(pixelPerValue * - ($('#value_' + i + '_' + graph_id).html())); - label_width = ($('#value_' + i + '_' + graph_id) - .css('width').split('px')[0] - 3); - - label_left_offset = plot.offset().left + inCanvasValuePos + 5; //Label located on right side of bar + 5 pixels - - //If label fit into the bar just recalculate left position to fit on right side of bar - if (inCanvasValuePos > label_width) { - label_left_offset = plot.offset().left + inCanvasValuePos - - $('#value_' + i + '_' + graph_id) - .css('width').split('px')[0] - 3; - } - - $('#value_' + i + '_' + graph_id) - .css('left', label_left_offset); - i++; - }); - }); - - // Format functions - function xFormatter(v, axis) { - if (labels[v] != undefined) { - return labels[v]; - } - else { - return ''; - } - } - - function yFormatter(v, axis) { - return v; - } - - // Events - $('#' + graph_id).bind('plothover', function (event, pos, item) { - $('.values_' + graph_id).css('font-weight', ''); - if (item != null) { - index = item.dataIndex; - $('#value_' + index + '_' + graph_id) - .css('font-weight', 'bold'); - } - }); - - if (water_mark) { - set_watermark(graph_id, plot, - $('#watermark_image_' + graph_id).attr('src')); - } - - if (maxvalue == 0) { - - // Fixed the position for the graphs with all values in - // bars is 0. - - $(".values_" + graph_id).css("left", (plot.offset().left + 5) + "px"); - } - * */ function yFormatter(v, axis) { format = new Array(); for (i = 0; i < labels_total.length; i++) { var label = labels_total[i][1]; - var shortLabel = reduceText(label, 30); + var shortLabel = reduceText(label, 25); var title = ''; if (label !== shortLabel) { title = label; label = shortLabel; } - format.push([i,'
' + format.push([i,'
' + label + '
']); } return format; } + function xFormatter(v, axis) { + label = parseFloat(v); + text = label.toLocaleString(); + if ( label >= 1000000) + text = text.substring(0,4) + "M"; + else if (label >= 100000) + text = text.substring(0,3) + "K"; + else if (label >= 1000) + text = text.substring(0,2) + "K"; + + return '
'+text+'
'; + } + if (water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } @@ -600,20 +512,30 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, }, xaxis: { axisLabelUseCanvas: true, - axisLabelFontSizePixels: 7, + axisLabelFontSizePixels: font_size, axisLabelFontFamily: font+'Font', axisLabelPadding: 0, ticks: xFormatter, labelWidth: 130, + labelHeight: 50, }, yaxis: { axisLabelUseCanvas: true, - axisLabelFontSizePixels: 7, + axisLabelFontSizePixels: font_size, axisLabelFontFamily: font+'Font', axisLabelPadding: 100, autoscaleMargin: 0.02, tickFormatter: function (v, axis) { - return v ; + label = parseFloat(v); + text = label.toLocaleString(); + if ( label >= 1000000) + text = text.substring(0,4) + "M"; + else if (label >= 100000) + text = text.substring(0,3) + "K"; + else if (label >= 1000) + text = text.substring(0,2) + "K"; + + return '
'+text+'
'; } }, legend: { @@ -630,82 +552,43 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, } }; + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) + options.xaxis.labelWidth = 100; + var plot = $.plot($('#'+graph_id),datas, options ); $('#' + graph_id).VUseTooltip(); $('#' + graph_id).css("margin-left","auto"); $('#' + graph_id).css("margin-right","auto"); - $('#' + graph_id).find('div.legend-tooltip').tooltip({ track: true }); - // Adjust the top of yaxis tick to set it in the middle of the bars - //yAxisHeight = $('#'+graph_id+' .yAxis .tickLabel').css('height').split('px')[0]; - - //plot.getPlaceholder().onload = function(){pruebas}; - //~ i = 0; - //~ $('#'+graph_id+' .xAxis .tickLabel').each(function() { - //~ $(this).css('display','none'); - //~ $(this).addClass("legend_"+i); - //~ i++; - //~ tickNewTop = parseInt(parseInt(tickTop) - (yAxisHeight/2)-3); - //~ $(this).css('top', tickNewTop+'px'); - //~ - //~ valuesNewTop = parseInt(parseInt(tickTop) - (yAxisHeight)); - //~ - //~ $('#value_'+i+'_'+graph_id).css('top',parseInt(plot.offset().top) + parseInt(valuesNewTop)); -//~ - //~ pixelPerValue = parseInt(plot.width()) / maxvalue; - //~ - //~ inCanvasValuePos = parseInt(pixelPerValue * ($('#value_'+i+'_'+graph_id).html())); - //~ - //~ $('#value_'+i+'_'+graph_id).css('left',plot.offset().left + inCanvasValuePos - $('#value_'+i+'_'+graph_id).css('width').split('px')[0] - 3); - //~ }); - - // When resize the window, adjust the values - //~ $('#'+graph_id).parent().resize(function () { - //~ i = 0; - //~ pixelPerValue = parseInt(plot.width()) / maxvalue; - //~ - //~ $('#'+graph_id+' .yAxis .tickLabel').each(function() { - //~ inCanvasValuePos = parseInt(pixelPerValue * ($('#value_'+i+'_'+graph_id).html())); - //~ - //~ $('#value_'+i+'_'+graph_id).css('left',plot.offset().left + inCanvasValuePos - $('#value_'+i+'_'+graph_id).css('width').split('px')[0] - 3); - //~ i++; - //~ }); - //~ }); - - - - $('#'+graph_id+' .yAxis .tickLabel').each(function() { - label = parseFloat($(this).text()); - text = label.toLocaleString(); - if ( label >= 1000000) - text = text.substring(0,4) + "M"; - else if (label >= 100000) - text = text.substring(0,3) + "K"; - else if (label >= 1000) - text = text.substring(0,2) + "K"; - - $(this).text(text); - }); + //~ $('#' + graph_id).find('div.legend-tooltip').tooltip({ track: true }); $('#'+graph_id+' .xAxis .tickLabel') .css('transform', 'rotate(-45deg)') + .css('max-width','100px') .find('div') .css('position', 'relative') .css('top', '+10px') - .css('left', '-20px'); - + .css('left', '-30px'); + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) + $('#'+graph_id+' .xAxis .tickLabel') + .find('div') + .css('top', '+0px') + .css('left', '-20px'); // Format functions function xFormatter(v, axis) { var format = new Array(); for (i = 0; i < labels_total.length; i++) { var label = labels_total[i][1]; - var shortLabel = reduceText(label, 35); + var shortLabel = reduceText(label, 28); + if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) + shortLabel = reduceText(label, 18); var title = ''; if (label !== shortLabel) { title = label; label = shortLabel; } + format.push([i, - '
' + '
' + label + '
']); } @@ -713,22 +596,13 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, } function yFormatter(v, axis) { - return v; + return '
'+v+'
'; } function lFormatter(v, axis) { - return '
'+v+'
'; + return '
'+v+'
'; } - - // Events - //~ $('#'+graph_id).bind('plothover', function (event, pos, item) { - //~ $('.values_'+graph_id).css('font-weight', ''); - //~ if(item != null) { - //~ index = item.dataIndex; - //~ $('#value_'+index+'_'+graph_id).css('font-weight', 'bold'); - //~ } - //~ }); - + if (water_mark) { set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src')); } @@ -857,7 +731,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, force_integer, separator, separator2, yellow_up, red_up, yellow_inverse, red_inverse, series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color) { - + var threshold = true; var thresholded = false; font = font.split("/").pop().split(".").shift(); @@ -1577,7 +1451,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, // Re-calculate the graph height with the legend height if (dashboard || vconsole) { var hDiff = $('#'+graph_id).height() - $('#legend_'+graph_id).height(); - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){ + if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){ } else { $('#'+graph_id).css('height', hDiff); @@ -1645,8 +1519,21 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, if (thresholded) { var zoom_data_threshold = new Array (); + var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, + red_threshold, extremes, red_up); + plot = $.plot($('#' + graph_id), data_base, + $.extend(true, {}, options, { + yaxis: { + max: y_recal.max, + min: y_recal.min + }, + xaxis: { + min: plot.getAxes().xaxis.min, + max: plot.getAxes().xaxis.max + } + })); zoom_data_threshold = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, - yellow_threshold, red_threshold, extremes, red_up); + red_threshold, extremes, red_up); plot.setData(zoom_data_threshold); plot.draw(); } @@ -1870,7 +1757,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, if (labels[v] == undefined) { return ''; } - extra_css = ''; return '
'+labels[v]+'
'; } @@ -1929,28 +1815,32 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, plot = $.plot($('#' + graph_id), data_base, $.extend(true, {}, options, { yaxis: {max: max_draw}, + xaxis: { + min: plot.getAxes().xaxis.min, + max: plot.getAxes().xaxis.max + } })); thresholded = false; } else { var max_draw = plot.getAxes().yaxis.datamax; - if (max_draw < red_threshold || max_draw < yellow_threshold) { - - var maxim_data = (red_threshold < yellow_threshold) ? yellow_threshold : red_threshold - - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - yaxis: {max: maxim_data + (maxim_data*0.5)}, - })); - } else { - plot = $.plot($('#' + graph_id), data_base, - $.extend(true, {}, options, { - yaxis: {max: plot.getAxes().yaxis.max}, - })); - } + // Recalculate the y axis + var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, + red_threshold, extremes, red_up); + plot = $.plot($('#' + graph_id), data_base, + $.extend(true, {}, options, { + yaxis: { + max: y_recal.max, + min: y_recal.min + }, + xaxis: { + min: plot.getAxes().xaxis.min, + max: plot.getAxes().xaxis.max + } + })); datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, - yellow_threshold, red_threshold, extremes, red_up); + red_threshold, extremes, red_up); thresholded = true; } @@ -2050,6 +1940,7 @@ function set_watermark(graph_id, plot, watermark_src) { if ($('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height') != undefined) { down_ticks_height = $('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height').split('px')[0]; } + var left_pos = parseInt(context.canvas.width - 3) - $('#watermark_image_'+graph_id)[0].width; var top_pos = 6; //var top_pos = parseInt(context.canvas.height - down_ticks_height - 10) - $('#watermark_image_'+graph_id)[0].height; @@ -2139,7 +2030,65 @@ function number_format(number, force_integer, unit) { return number + ' ' + shorts[pos] + unit; } -function add_threshold (data_base, threshold_data, y_min, y_max, yellow_threshold, +// Recalculate the threshold data depends on warning and critical +function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes, red_up) { + + var y = { + min: 0, + max: 0 + }; + + // Default values + var yaxis_resize = { + up: null, + normal_up: 0, + normal_down: 0, + down: null + }; + // Resize the y axis to display all intervals + $.each(threshold_data, function() { + if (/_up/.test(this.id)){ + yaxis_resize['up'] = this.data[0][1]; + } + if (/_down/.test(this.id)){ + if (/critical/.test(this.id)) { + yaxis_resize['down'] = red_threshold; + } else { + yaxis_resize['down'] = extremes[this.id]; + } + } + if (/_normal/.test(this.id)){ + var end; + if (/critical/.test(this.id)) { + end = red_up; + } else { + end = extremes[this.id + '_2']; + } + if (yaxis_resize['normal_up'] < end) yaxis_resize['normal_up'] = end; + if (yaxis_resize['normal_down'] > this.data[0][1]) yaxis_resize['normal_down'] = this.data[0][1]; + } + }); + + // If you need to display a up or a down bar, display 10% of data height + var margin_up_or_down = (y_max - y_min)*0.10; + + // Calculate the new axis + y['max'] = yaxis_resize['normal_up'] > y_max ? yaxis_resize['normal_up'] : y_max; + y['min'] = yaxis_resize['normal_down'] > y_min ? yaxis_resize['normal_down'] : y_min; + if (yaxis_resize['up'] !== null) { + y['max'] = (yaxis_resize['up'] + margin_up_or_down) < y_max + ? y_max + : yaxis_resize['up'] + margin_up_or_down; + } + if (yaxis_resize['down'] !== null) { + y['min'] = (yaxis_resize['down'] - margin_up_or_down) < y_min + ? yaxis_resize['up'] + margin_up_or_down + : y_min; + } + + return y; +} +function add_threshold (data_base, threshold_data, y_min, y_max, red_threshold, extremes, red_up) { var datas = new Array (); @@ -2191,5 +2140,6 @@ function add_threshold (data_base, threshold_data, y_min, y_max, yellow_threshol function reduceText (text, maxLength) { if (text.length <= maxLength) return text var firstSlideEnd = parseInt((maxLength - 3) / 2); - return text.substr(0, firstSlideEnd) + '...' + text.substr(-firstSlideEnd - 3); + var str_cut = text.substr(0, firstSlideEnd); + return str_cut + '...' + text.substr(-firstSlideEnd - 3); } diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index ea7a3a122a..a8b7f250ab 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -205,7 +205,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, // Parent layer $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. - $return .= "

"; + $return .= "

"; if (!empty($threshold_data)) { $yellow_up = $threshold_data['yellow_up']; @@ -272,7 +272,9 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, } $return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); $return .= ""; - $return .= "
"; + $return .= "
"; if ($menu) { $height = 100; } @@ -605,7 +607,7 @@ function flot_custom_pie_chart ($flash_charts, $graph_values, $graph_id = uniqid('graph_'); - $return = "
"; + $return = "
"; if ($water_mark != '') { $return .= ""; diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 14dc2e96eb..68c1958c45 100644 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -749,6 +749,7 @@ function pch_bar_graph ($graph_type, $index, $data, $width, $height, $font, "GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "LabelRotation" => 60); $margin_left = 40; + $margin_right = 0; $margin_top = 10; $margin_bottom = 3 * $max_chars; break; @@ -757,24 +758,14 @@ function pch_bar_graph ($graph_type, $index, $data, $width, $height, $font, "CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "Pos"=>SCALE_POS_TOPBOTTOM, "LabelValuesRotation" => 30); $margin_left = $font_size * $max_chars; + $margin_right = 15; $margin_top = 40; $margin_bottom = 10; break; } - $water_mark_height = 0; - $water_mark_width = 0; - if (!empty($water_mark)) { - $size_water_mark = getimagesize($water_mark); - $water_mark_height = $size_water_mark[1]; - $water_mark_width = $size_water_mark[0]; - - $myPicture->drawFromPNG(($width - $water_mark_width), - ($height - $water_mark_height) - $margin_bottom, $water_mark); - } - /* Define the chart area */ - $myPicture->setGraphArea($margin_left,$margin_top,$width - $water_mark_width,$height-$margin_bottom); + $myPicture->setGraphArea($margin_left, $margin_top, $width - $margin_right, $height - $margin_bottom); $myPicture->drawScale($scaleSettings); /* @@ -792,6 +783,15 @@ function pch_bar_graph ($graph_type, $index, $data, $width, $height, $font, $myPicture->drawBarChart($settings); + // Paint the water mark at the last moment to show it in front + if (!empty($water_mark)) { + $size_water_mark = getimagesize($water_mark); + $water_mark_width = $size_water_mark[0]; + + $myPicture->drawFromPNG(($width - $water_mark_width - $margin_right), + $margin_top, $water_mark); + } + /* Render the picture */ $myPicture->stroke(); } @@ -907,7 +907,7 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, } /* Create the pChart object */ - $myPicture = new pImage($width, $height, $MyData, $transparent, + $myPicture = new pImage($width, $height + $font_size, $MyData, $transparent, $backgroundColor, $fontColor); /* Turn of Antialiasing */ @@ -920,6 +920,8 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $myPicture->setFontProperties( array("FontName" =>$font, "FontSize" => $font_size)); + // By default, set a top margin of 5 px + $top_margin = 5; if (isset($legend)) { /* Set horizontal legend if is posible */ $legend_mode = LEGEND_HORIZONTAL; @@ -930,6 +932,9 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $size = $myPicture->getLegendSize(array("Style"=>LEGEND_NOBORDER,"Mode"=>$legend_mode)); } + // Update the top margin to add the legend Height + $top_margin = $size['Height']; + /* Write the chart legend */ $myPicture->drawLegend($width - $size['Width'], 8, array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode)); @@ -948,7 +953,7 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $myPicture->drawFromPNG( ($width - $water_mark_width), - ($height - $water_mark_height) - $margin_bottom, + $top_margin, $water_mark); } @@ -999,20 +1004,9 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $chart_size = $default_chart_size; } - if (isset($size['Height'])) { - /* Define the chart area */ - //if ($yaxisname != '') { - //} - $myPicture->setGraphArea($chart_size, $size['Height'], - ($width - $water_mark_width), - ($height - $margin_bottom)); - } - else { - /* Define the chart area */ - $myPicture->setGraphArea($chart_size, 5, - ($width - $water_mark_width), - ($height - $margin_bottom)); - } + $myPicture->setGraphArea($chart_size, $top_margin, + $width, + ($height - $margin_bottom)); /*Get minimun value to draw axis properly*/ $min_data = min(min($data)); diff --git a/pandora_console/include/help/en/help_alert_config.php b/pandora_console/include/help/en/help_alert_config.php index 1ce11e5ce3..05e93abac0 100644 --- a/pandora_console/include/help/en/help_alert_config.php +++ b/pandora_console/include/help/en/help_alert_config.php @@ -31,6 +31,7 @@ Apart from the defined module macros, the following macros are also available:
  • _agentdescription_ : Description of the agent who fired alert.
  • _agentgroup_ : Agent group name.
  • _agentstatus_ : Current status of the agent.
  • +
  • _agentos_: Agent's operative system.
  • _address_ : Address of the agent that fired the alert.
  • _timestamp_ : Time when the alert was fired (yy-mm-dd hh:mm:ss).
  • _timezone_ : Timezone name that _timestamp_ represents in.
  • diff --git a/pandora_console/include/help/en/help_alert_macros.php b/pandora_console/include/help/en/help_alert_macros.php index 6753e2c59a..544fd5ec36 100644 --- a/pandora_console/include/help/en/help_alert_macros.php +++ b/pandora_console/include/help/en/help_alert_macros.php @@ -25,6 +25,7 @@ Besides the defined module macros, the following macros are available:
  • _agentdescription_: Description of the agent that triggered the alert.
  • _agentgroup_: Agent’s group name.
  • _agentstatus_: Current agent status.
  • +
  • _agentos_: Agent's operative system.
  • _address_: Address of the agent that triggered the alert.
  • _timestamp_: Time and date on which the alert was triggered (yy-mm-dd hh:mm:ss).
  • _timezone_: Timezone that is represented on _timestamp_.
  • diff --git a/pandora_console/include/help/es/help_alert_config.php b/pandora_console/include/help/es/help_alert_config.php index 483e494332..4791dc716e 100644 --- a/pandora_console/include/help/es/help_alert_config.php +++ b/pandora_console/include/help/es/help_alert_config.php @@ -34,6 +34,7 @@ Además de las macros de módulo definidas, las siguientes macros están disponi
  • _agentgroup_ : Nombre del grupo del agente.
  • _agentstatus_ : Estado actual del agente.
  • _address_: Dirección del agente que disparó la alerta.
  • +
  • _agentos_: Sistema operativo del agente.
  • _timestamp_: Hora y fecha en que se disparó la alerta.
  • _timezone_: Area Nombre _timestamp_ que representa en.
  • _data_: Dato que hizo que la alerta se disparase.
  • diff --git a/pandora_console/include/help/es/help_alert_macros.php b/pandora_console/include/help/es/help_alert_macros.php index f4c8f476d9..335d583d5a 100644 --- a/pandora_console/include/help/es/help_alert_macros.php +++ b/pandora_console/include/help/es/help_alert_macros.php @@ -25,6 +25,7 @@ Además de las macros de módulo definidas, las siguientes macros están disponi
  • _agentdescription_: Descripción del agente que disparó la alerta.
  • _agentgroup_: Nombre del grupo del agente.
  • _agentstatus_: Estado actual del agente.
  • +
  • _agentos_: Sistema operativo del agente.
  • _address_: Dirección del agente que disparó la alerta.
  • _timestamp_: Hora y fecha en que se disparó la alerta.
  • _timezone_: Area Nombre _timestamp_ que representa en.
  • diff --git a/pandora_console/include/help/ja/help_alert_config.php b/pandora_console/include/help/ja/help_alert_config.php index ae4fcd469f..fa50e43aa9 100644 --- a/pandora_console/include/help/ja/help_alert_config.php +++ b/pandora_console/include/help/ja/help_alert_config.php @@ -31,6 +31,7 @@ email アクションを設定するには、_field1_ (送信先アドレス)、
  • _agentdescription_ : 発生したアラートの説明
  • _agentgroup_ : エージェントグループ名
  • _agentstatus : エージェントの現在の状態
  • +
  • _agentos_: Agent's operative system
  • _address_ : アラートが発生したエージェントのアドレス
  • _timestamp_ : アラートが発生した日時 (yy-mm-dd hh:mm:ss).
  • _timezone_: _timestamp_ で使用されるタイムゾーン名.
  • diff --git a/pandora_console/include/help/ja/help_alert_macros.php b/pandora_console/include/help/ja/help_alert_macros.php index 15b892651c..cd1e2534cf 100644 --- a/pandora_console/include/help/ja/help_alert_macros.php +++ b/pandora_console/include/help/ja/help_alert_macros.php @@ -25,6 +25,7 @@
  • _agentdescription_ : 発生したアラートの説明
  • _agentgroup_ : エージェントグループ名
  • _agentstatus_ : エージェントの現在の状態
  • +
  • _agentos_: Agent's operative system
  • _address_ : アラートが発生したエージェントのアドレス
  • _timestamp_ : アラートが発生した日時 (yy-mm-dd hh:mm:ss).
  • _timezone_: _timestamp_ で使用されるタイムゾーン名.
  • diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index c0742e65d4..86ab6bd914 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -172,7 +172,6 @@ function delete_link(source_id, source_module_id, target_id, target_module_id, i init_drag_and_drop(); set_positions_graph(); } - $("#dialog_node_edit").dialog("close"); } }); @@ -219,6 +218,43 @@ function update_fictional_node(id_db_node) { } } +function update_node_name (id_db_node) { + if (enterprise_installed) { + var name = $("input[name='edit_name_node']").val(); + + var params = []; + params.push("update_node_name=1"); + params.push("networkmap_id=" + networkmap_id); + params.push("node_id=" + id_db_node); + params.push("name=" + name); + params.push("page=enterprise/operation/agentes/pandora_networkmap.view"); + + jQuery.ajax ({ + data: params.join ("&"), + dataType: 'json', + type: 'POST', + url: action="ajax.php", + success: function (data) { + if (data['correct']) { + $("#dialog_node_edit").dialog("close"); + + jQuery.each(graph.nodes, function(i, element) { + if (element.id_db == id_db_node) { + graph.nodes[i].text = name; + + $("#id_node_" + i + networkmap_id + " title").html(name); + $("#id_node_" + i + networkmap_id + " tspan").html(name); + } + }); + + draw_elements_graph(); + set_positions_graph(); + } + } + }); + } +} + function change_shape(id_db_node) { if (enterprise_installed) { var shape = $("select[name='shape']").val(); @@ -532,6 +568,9 @@ function update_link(row_index, id_link) { temp_link["status_start"] = "0"; temp_link["status_end"] = "0"; + temp_link["text_start"] = data["text_start"]; + temp_link["text_end"] = data["text_end"]; + $.each(graph.nodes, function(k, node) { if (node['id_agent'] == data['id_db_target']) { temp_link["target"] = graph.nodes[k]; @@ -579,7 +618,7 @@ function add_new_link (new_link) { graph.links.push(new_link); } -function edit_node(data, dblClick) { +function edit_node(data_node, dblClick) { if (enterprise_installed) { var flag_edit_node = true; var edit_node = null @@ -594,7 +633,7 @@ function edit_node(data, dblClick) { edit_node = selection[0].pop(); } else if (dblClick){ - edit_node = d3.select("#id_node_" + data['id'] + networkmap_id); + edit_node = d3.select("#id_node_" + data_node['id'] + networkmap_id); edit_node = edit_node[0][0]; } else { @@ -615,18 +654,22 @@ function edit_node(data, dblClick) { selected_links = get_relations(node_selected); - $("select[name='shape'] option[value='" + data.shape + "']") + $("select[name='shape'] option[value='" + node_selected.shape + "']") .prop("selected", true); $("select[name='shape']").attr("onchange", - "javascript: change_shape(" + data.id_db + ");"); + "javascript: change_shape(" + node_selected.id_db + ");"); $("#node_options-fictional_node_update_button-1 input") - .attr("onclick", "update_fictional_node(" + data.id_db + ");"); + .attr("onclick", "update_fictional_node(" + node_selected.id_db + ");"); + + $("#node_options-node_name-2 input") + .attr("onclick", "update_node_name(" + node_selected.id_db + ");"); - $("#node_details-0-1").html('' + data["text"] + ''); + $("#node_details-0-1").html('' + node_selected["text"] + ''); var params = []; params.push("get_agent_info=1"); - params.push("id_agent=" + data["id_agent"]); + params.push("id_agent=" + node_selected["id_agent"]); params.push("page=enterprise/operation/agentes/pandora_networkmap.view"); + jQuery.ajax ({ data: params.join ("&"), dataType: 'json', @@ -640,75 +683,47 @@ function edit_node(data, dblClick) { $("#node_details-1-1").html(adressess); $("#node_details-2-1").html(data["os"]); $("#node_details-3-1").html(data["group"]); - } - }); - - $("#interface_information").find("tr:gt(0)").remove(); - - var params = []; - params.push("get_interface_info=1"); - params.push("id_agent=" + data["id_agent"]); - params.push("page=enterprise/operation/agentes/pandora_networkmap.view"); - jQuery.ajax ({ - data: params.join ("&"), - dataType: 'json', - type: 'POST', - url: action="ajax.php", - success: function (data) { - if (data.length == 0) { - $("#interface_information").find('tbody') - .append($('').html("

    It has no interface to display

    ")); - } - else { - jQuery.each(data, function(j, interface) { - $("#interface_information").find('tbody') - .append($('') - .append($('') - .html(interface['name']) - ) - .append($('') - .html(interface['status']) - ) - .append($('') - .html(interface['graph']) - ) - .append($('') - .html(interface['ip']) - ) - .append($('') - .html(interface['mac']) - ) - ); - }); - } + + $('[aria-describedby=dialog_node_edit]').css({'top':'200px'}); + $('#foot').css({'top':parseInt($("[aria-describedby=dialog_node_edit]").css('height')+$("[aria-describedby=dialog_node_edit]").css('top')),'position':'relative'}); + + get_interface_data_to_table(node_selected, selected_links); } }); $("#dialog_node_edit" ) .dialog( "option", "title", - dialog_node_edit_title.replace("%s", data.text)); + dialog_node_edit_title.replace("%s", node_selected.text)); $("#dialog_node_edit").dialog("open"); - if (data.id_agent == -2) { + if (node_selected.id_agent == undefined || node_selected.id_agent == -2) { //Fictional node $("#node_options-fictional_node_name") .css("display", ""); $("input[name='edit_name_fictional_node']") - .val(data.text); + .val(node_selected.text); $("#node_options-fictional_node_networkmap_link") .css("display", ""); $("#edit_networkmap_to_link") - .val(data.networkmap_id); + .val(node_selected.networkmap_id); $("#node_options-fictional_node_update_button") .css("display", ""); + $("#node_options-node_name") + .css("display", "none"); + $("#node_options-node_update_button") + .css("display", "none"); } else { + $("input[name='edit_name_node']") + .val(node_selected.text); $("#node_options-fictional_node_name") .css("display", "none"); $("#node_options-fictional_node_networkmap_link") .css("display", "none"); $("#node_options-fictional_node_update_button") .css("display", "none"); + $("#node_options-node_name") + .css("display", ""); } //Clean @@ -716,124 +731,160 @@ function edit_node(data, dblClick) { //Show the no relations $("#relations_table-loading").css('display', 'none'); $("#relations_table-no_relations").css('display', ''); - - - jQuery.each(selected_links, function(i, link_each) { - - $("#relations_table-no_relations").css('display', 'none'); - $("#relations_table-loading").css('display', ''); - - var template_relation_row = $("#relations_table-template_row") - .clone(); - - $(template_relation_row).css('display', ''); - $(template_relation_row).attr('class', 'relation_link_row'); - - $("select[name='interface_source']", template_relation_row) - .attr('name', "interface_source_" + i) - .attr('id', "interface_source_" + i + networkmap_id); - $("select[name='interface_target']", template_relation_row) - .attr('name', "interface_target_" + i) - .attr('id', "interface_target_" + i + networkmap_id); - $(".edit_icon_progress", template_relation_row) - .attr('class', "edit_icon_progress_" + i); - $(".edit_icon", template_relation_row) - .attr('class', "edit_icon_" + i); - $(".edit_icon_correct", template_relation_row) - .attr('class', "edit_icon_correct_" + i); - $(".edit_icon_fail", template_relation_row) - .attr('class', "edit_icon_fail_" + i); - $(".edit_icon_link", template_relation_row) - .attr('class', "edit_icon_link_" + i) - .click(function() { - update_link(i, link_each.id_db); - } - ); - - var params = []; - params.push("get_intefaces=1"); - params.push("id_agent=" + link_each.source.id_agent); - params.push("page=enterprise/operation/agentes/pandora_networkmap.view"); - - jQuery.ajax ({ - data: params.join ("&"), - dataType: 'json', - type: 'POST', - url: action="ajax.php", - success: function (data) { - if (data['correct']) { - $("select[name='interface_source_" + i + "']", template_relation_row).empty(); - $("select[name='interface_source_" + i + "']", template_relation_row).append(''); - jQuery.each(data['interfaces'], function(j, interface) { - - $("select[name='interface_source_" + i + "']", template_relation_row) - .append($("'); - jQuery.each(data['interfaces'], function(j, interface) { - $("select[name='interface_target_" + i + "']", template_relation_row) - .append($("'); + + $("select[name='interface_source_" + i + "']", template_relation_row).empty(); + $("select[name='interface_source_" + i + "']", template_relation_row).append(''); + jQuery.each(data['target_interfaces'], function(j, interface) { + $("select[name='interface_target_" + i + "']", template_relation_row) + .append($("