|
@@ -1,89 +1,53 @@
|
|
|
package de.tudarmstadt.informatik.hostage.protocol;
|
|
|
|
|
|
|
|
|
-import org.alfresco.config.ConfigElement;
|
|
|
-import org.alfresco.jlan.debug.ConsoleDebug;
|
|
|
-import org.alfresco.jlan.debug.DebugConfigSection;
|
|
|
+import android.content.Context;
|
|
|
+import android.net.DhcpInfo;
|
|
|
+import android.net.wifi.WifiManager;
|
|
|
+
|
|
|
+import org.alfresco.jlan.app.CifsOnlyXMLServerConfiguration;
|
|
|
import org.alfresco.jlan.server.SessionListener;
|
|
|
import org.alfresco.jlan.server.SrvSession;
|
|
|
-import org.alfresco.jlan.server.auth.CifsAuthenticator;
|
|
|
-import org.alfresco.jlan.server.auth.DefaultAuthenticator;
|
|
|
-import org.alfresco.jlan.server.config.CoreServerConfigSection;
|
|
|
-import org.alfresco.jlan.server.config.GlobalConfigSection;
|
|
|
import org.alfresco.jlan.server.config.InvalidConfigurationException;
|
|
|
-import org.alfresco.jlan.server.config.SecurityConfigSection;
|
|
|
-import org.alfresco.jlan.server.config.ServerConfiguration;
|
|
|
-import org.alfresco.jlan.server.core.DeviceContextException;
|
|
|
-import org.alfresco.jlan.server.filesys.DiskDeviceContext;
|
|
|
-import org.alfresco.jlan.server.filesys.DiskInterface;
|
|
|
-import org.alfresco.jlan.server.filesys.DiskSharedDevice;
|
|
|
import org.alfresco.jlan.server.filesys.FileListener;
|
|
|
-import org.alfresco.jlan.server.filesys.FilesystemsConfigSection;
|
|
|
import org.alfresco.jlan.server.filesys.NetworkFile;
|
|
|
import org.alfresco.jlan.smb.server.CIFSConfigSection;
|
|
|
import org.alfresco.jlan.smb.server.SMBServer;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.net.InetAddress;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import de.tudarmstadt.informatik.hostage.Handler;
|
|
|
-import de.tudarmstadt.informatik.hostage.protocol.cifs.PseudoCIFSDiskDriver;
|
|
|
+import de.tudarmstadt.informatik.hostage.Listener;
|
|
|
+import de.tudarmstadt.informatik.hostage.R;
|
|
|
+import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
|
|
|
import de.tudarmstadt.informatik.hostage.wrapper.Packet;
|
|
|
|
|
|
public class CIFS implements Protocol, SessionListener, FileListener {
|
|
|
- private Handler mHandler;
|
|
|
+ private Listener mHandler;
|
|
|
private SMBServer mSmbServer;
|
|
|
|
|
|
- public void initialize(Handler mHandler) {
|
|
|
+ public void initialize(Listener mHandler) {
|
|
|
this.mHandler = mHandler;
|
|
|
|
|
|
- DiskInterface disk = new PseudoCIFSDiskDriver(mHandler);
|
|
|
- DiskDeviceContext context = null;
|
|
|
- try {
|
|
|
- context = (DiskDeviceContext) disk.createContext("theContext", new ConfigElement("",""));
|
|
|
- } catch (DeviceContextException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ CifsOnlyXMLServerConfiguration smbConfig = new CifsOnlyXMLServerConfiguration();
|
|
|
|
|
|
- ServerConfiguration config = new ServerConfiguration("HostageConfig");
|
|
|
- CIFSConfigSection cifsConfig = new CIFSConfigSection(config);
|
|
|
try {
|
|
|
- cifsConfig.setHostAnnouncer(false);
|
|
|
- cifsConfig.setNetBIOSSMB(true);
|
|
|
- cifsConfig.setWin32NetBIOS(false);
|
|
|
- cifsConfig.setAuthenticator(DefaultAuthenticator.class.getCanonicalName(), new ConfigElement("", ""), 0x10000000, true);
|
|
|
- cifsConfig.setTcpipSMB(true);
|
|
|
- cifsConfig.setNetBIOSDebug(true);
|
|
|
- cifsConfig.setTcpipSMBPort(28582);
|
|
|
- cifsConfig.setNameServerPort(28274);
|
|
|
- cifsConfig.setDatagramPort(28275);
|
|
|
- cifsConfig.setSessionPort(28276);
|
|
|
- cifsConfig.setServerName("HAHAHA");
|
|
|
- cifsConfig.setDomainName("Workgroup");
|
|
|
-
|
|
|
- FilesystemsConfigSection filesystems = new FilesystemsConfigSection(config);
|
|
|
- DiskSharedDevice dev = new DiskSharedDevice("VirtualDisk", disk, context);
|
|
|
- filesystems.addShare(dev);
|
|
|
-
|
|
|
- GlobalConfigSection global = new GlobalConfigSection(config);
|
|
|
-
|
|
|
- CoreServerConfigSection core = new CoreServerConfigSection(config);
|
|
|
- core.setThreadPool(2, 8);
|
|
|
-
|
|
|
- DebugConfigSection debugConfigSection = new DebugConfigSection(config);
|
|
|
- debugConfigSection.setDebug(ConsoleDebug.class.getCanonicalName(), new ConfigElement("append", ""));
|
|
|
-
|
|
|
- this.mSmbServer = new SMBServer(config);
|
|
|
+ smbConfig.loadConfiguration(new InputStreamReader(MainActivity.context.getResources().openRawResource(R.raw.jlan_config)));
|
|
|
+ CIFSConfigSection cifsConfig = (CIFSConfigSection) smbConfig.getConfigSection(CIFSConfigSection.SectionName);
|
|
|
+ cifsConfig.setBroadcastMask(getBroadcastAddress());
|
|
|
+
|
|
|
+ this.mSmbServer = new SMBServer(smbConfig);
|
|
|
this.mSmbServer.addSessionListener(this);
|
|
|
this.mSmbServer.addFileListener(this);
|
|
|
- this.mSmbServer.startServer();
|
|
|
|
|
|
- } catch (InvalidConfigurationException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ this.mSmbServer.startServer();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } catch (InvalidConfigurationException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -139,4 +103,16 @@ public class CIFS implements Protocol, SessionListener, FileListener {
|
|
|
public void fileOpened(SrvSession srvSession, NetworkFile networkFile) {
|
|
|
System.out.println("---------------------- [CIFS] File closed!");
|
|
|
}
|
|
|
+
|
|
|
+ private String getBroadcastAddress() throws IOException {
|
|
|
+ WifiManager wifi = (WifiManager) MainActivity.context.getSystemService(Context.WIFI_SERVICE);
|
|
|
+ DhcpInfo dhcp = wifi.getDhcpInfo();
|
|
|
+
|
|
|
+
|
|
|
+ int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
|
|
|
+ byte[] quads = new byte[4];
|
|
|
+ for (int k = 0; k < 4; k++)
|
|
|
+ quads[k] = (byte) (broadcast >> (k * 8));
|
|
|
+ return InetAddress.getByAddress(quads).toString().substring(1);
|
|
|
+ }
|
|
|
}
|