|
@@ -1,9 +1,15 @@
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
|
|
|
|
|
|
+import android.content.SharedPreferences;
|
|
|
|
+import android.preference.PreferenceManager;
|
|
|
|
+
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import de.tudarmstadt.informatik.hostage.Hostage;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.Listener;
|
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
|
import org.alfresco.jlan.server.auth.spnego.OID;
|
|
import org.alfresco.jlan.server.auth.spnego.OID;
|
|
@@ -62,13 +68,19 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String toString(){
|
|
|
|
|
|
+ public String toString() {
|
|
return "SNMP";
|
|
return "SNMP";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
private String address;
|
|
private String address;
|
|
|
|
|
|
|
|
+ private String externalIP;
|
|
|
|
+
|
|
|
|
+ SharedPreferences pref1;
|
|
|
|
+
|
|
|
|
+ private Listener sListener;
|
|
|
|
+
|
|
public SNMP(String address) throws IOException {
|
|
public SNMP(String address) throws IOException {
|
|
|
|
|
|
super(new File("conf.agent"), new File("bootCounter.agent"),
|
|
super(new File("conf.agent"), new File("bootCounter.agent"),
|
|
@@ -104,18 +116,18 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString("cpublic"), new OctetString("v1v2group"), StorageType.nonVolatile);
|
|
vacmMIB.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString("cpublic"), new OctetString("v1v2group"), StorageType.nonVolatile);
|
|
|
|
|
|
vacmMIB.addAccess(new OctetString("v1v2group"), new OctetString("public"),
|
|
vacmMIB.addAccess(new OctetString("v1v2group"), new OctetString("public"),
|
|
- SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV,
|
|
|
|
- MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"),
|
|
|
|
- new OctetString("fullWriteView"), new OctetString("fullNotifyView"), StorageType.nonVolatile);
|
|
|
|
|
|
+ SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.NOAUTH_NOPRIV,
|
|
|
|
+ MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadView"),
|
|
|
|
+ new OctetString("fullWriteView"), new OctetString("fullNotifyView"), StorageType.nonVolatile);
|
|
|
|
|
|
vacmMIB.addViewTreeFamily(new OctetString("fullReadView"), new org.snmp4j.smi.OID("1.3"),
|
|
vacmMIB.addViewTreeFamily(new OctetString("fullReadView"), new org.snmp4j.smi.OID("1.3"),
|
|
- new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
|
|
|
|
|
|
+ new OctetString(), VacmMIB.vacmViewIncluded, StorageType.nonVolatile);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
|
|
protected void addCommunities(SnmpCommunityMIB snmpCommunityMIB) {
|
|
|
|
|
|
- Variable[] com2sec = new Variable[] { new OctetString("public"),
|
|
|
|
|
|
+ Variable[] com2sec = new Variable[]{new OctetString("public"),
|
|
|
|
|
|
new OctetString("cpublic"), // security name
|
|
new OctetString("cpublic"), // security name
|
|
|
|
|
|
@@ -133,31 +145,37 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
|
|
|
|
MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
|
|
MOTableRow row = snmpCommunityMIB.getSnmpCommunityEntry().createRow(
|
|
|
|
|
|
- new OctetString("public2public").toSubIndex(true), com2sec);
|
|
|
|
|
|
+ new OctetString("public2public").toSubIndex(true), com2sec);
|
|
|
|
|
|
snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
|
|
snmpCommunityMIB.getSnmpCommunityEntry().addRow((SnmpCommunityMIB.SnmpCommunityEntryRow) row);
|
|
}
|
|
}
|
|
|
|
|
|
- public void start() throws IOException {
|
|
|
|
|
|
+ public void start() {
|
|
|
|
|
|
- init();
|
|
|
|
|
|
+ try {
|
|
|
|
+ init();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
// This method reads some old config from a file and causes
|
|
// This method reads some old config from a file and causes
|
|
// unexpected behavior.
|
|
// unexpected behavior.
|
|
// loadConfig(ImportModes.REPLACE_CREATE);
|
|
// loadConfig(ImportModes.REPLACE_CREATE);
|
|
addShutdownHook();
|
|
addShutdownHook();
|
|
getServer().addContext(new OctetString("public"));
|
|
getServer().addContext(new OctetString("public"));
|
|
|
|
+
|
|
|
|
+
|
|
finishInit();
|
|
finishInit();
|
|
run();
|
|
run();
|
|
sendColdStartNotification();
|
|
sendColdStartNotification();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- protected void initTransportMappings() throws IOException {
|
|
|
|
|
|
+ protected void initTransportMappings() {
|
|
transportMappings = new TransportMapping[1];
|
|
transportMappings = new TransportMapping[1];
|
|
Address addr = GenericAddress.parse(address);
|
|
Address addr = GenericAddress.parse(address);
|
|
|
|
|
|
TransportMapping tm = TransportMappings.getInstance()
|
|
TransportMapping tm = TransportMappings.getInstance()
|
|
- .createTransportMapping(addr);
|
|
|
|
|
|
+ .createTransportMapping(addr);
|
|
transportMappings[0] = tm;
|
|
transportMappings[0] = tm;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -165,19 +183,36 @@ public class SNMP extends BaseAgent implements Protocol {
|
|
public void registerManagedObject(ManagedObject mo) {
|
|
public void registerManagedObject(ManagedObject mo) {
|
|
try {
|
|
try {
|
|
server.register(mo, null);
|
|
server.register(mo, null);
|
|
- } catch (DuplicateRegistrationException ex) {
|
|
|
|
|
|
+ } catch (DuplicateRegistrationException ex) {
|
|
|
|
|
|
throw new RuntimeException(ex);
|
|
throw new RuntimeException(ex);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void unregisterManagedObject(MOGroup moGroup){
|
|
|
|
- moGroup.unregisterMOs(server,getContext(moGroup));
|
|
|
|
|
|
+ public void unregisterManagedObject(MOGroup moGroup) {
|
|
|
|
+ moGroup.unregisterMOs(server, getContext(moGroup));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ //Listner for SNMP
|
|
|
|
+ public Listener getListener() {
|
|
|
|
+ return sListener;
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ public void initialize(Listener sListener) {
|
|
|
|
+
|
|
|
|
+ this.sListener = sListener;
|
|
|
|
+
|
|
|
|
+ // Hostage service = sListener.getService();
|
|
|
|
+ // pref1 = PreferenceManager.getDefaultSharedPreferences(service);
|
|
|
|
+ // agent = new SNMP();
|
|
|
|
+ // externalIP = connInfo.getString(service.getString(R.string.connection_info_external_ip), null);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|