|
@@ -8,8 +8,11 @@ import de.tudarmstadt.informatik.hostage.persistence.HostageDBOpenHelper;
|
|
|
public class Logger extends IntentService {
|
|
|
|
|
|
private static final String ACTION_LOG = "de.tudarmstadt.informatik.hostage.action.LOG";
|
|
|
+ private static final String ACTION_LOG_PORTSCAN = "de.tudarmstadt.informatik.hostage.action.LOG_PORTSCAN";
|
|
|
|
|
|
private static final String EXTRA_RECORD = "de.tudarmstadt.informatik.hostage.extra.RECORD";
|
|
|
+ private static final String EXTRA_TIMESTAMP = "de.tudarmstadt.informatik.hostage.extra.TIMESTAMP";
|
|
|
+ private static final String EXTRA_IP = "de.tudarmstadt.informatik.hostage.extra.IP";
|
|
|
|
|
|
public static void log(Context context, Record record) {
|
|
|
Intent intent = new Intent(context, Logger.class);
|
|
@@ -18,6 +21,14 @@ public class Logger extends IntentService {
|
|
|
context.startService(intent);
|
|
|
}
|
|
|
|
|
|
+ public static void logPortscan(Context context, long timestamp, String ip) {
|
|
|
+ Intent intent = new Intent(context, Logger.class);
|
|
|
+ intent.setAction(ACTION_LOG);
|
|
|
+ intent.putExtra(EXTRA_TIMESTAMP, timestamp);
|
|
|
+ intent.putExtra(EXTRA_IP, ip);
|
|
|
+ context.startService(intent);
|
|
|
+ }
|
|
|
+
|
|
|
private HostageDBOpenHelper mDbHelper;
|
|
|
|
|
|
public Logger() {
|
|
@@ -34,6 +45,10 @@ public class Logger extends IntentService {
|
|
|
mDbHelper.addRecord(record);
|
|
|
}
|
|
|
|
|
|
+ private void handleActionLogPortscan(long timestamp, String ip) {
|
|
|
+ mDbHelper.insertPortscan(timestamp, ip);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onHandleIntent(Intent intent) {
|
|
|
if (intent != null) {
|
|
@@ -41,6 +56,10 @@ public class Logger extends IntentService {
|
|
|
if (ACTION_LOG.equals(action)) {
|
|
|
final Record record = intent.getParcelableExtra(EXTRA_RECORD);
|
|
|
handleActionLog(record);
|
|
|
+ } else if (ACTION_LOG_PORTSCAN.equals(action)) {
|
|
|
+ final long timestamp = intent.getParcelableExtra(EXTRA_TIMESTAMP);
|
|
|
+ final String ip = intent.getParcelableExtra(EXTRA_IP);
|
|
|
+ handleActionLogPortscan(timestamp, ip);
|
|
|
}
|
|
|
}
|
|
|
}
|