private void AcceptClient(IAsyncResult ar) { Socket client = null; try { client = server.EndAccept(ar); } catch (Exception) { return; } IPEndPoint client_ep = (IPEndPoint)client.RemoteEndPoint; string remoteAddress = client_ep.Address.ToString(); string remotePort = client_ep.Port.ToString(); //TODO: Implement block command -> keep the server and existing connections alive, but drop new connections bool allow; if (!autoAllow) { allow = console.ChoicePrompt("\n[IN] Connection " + remoteAddress + ":" + remotePort + "\nDo you want to allow connection"); } else { allow = true; } if (allow) { clientList.Add(client); ReadObj obj = new ReadObj { buffer = new byte[1024], s = client }; client.BeginReceive(obj.buffer, 0, obj.buffer.Length, SocketFlags.None, new AsyncCallback(ReadPackets), obj); } else { KillSocket(client, !stopping); ctx.LogMod.Log("[REJECT] " + remoteAddress + ":" + remotePort, VLogger.LogLevel.information); } if (!stopping) { server.BeginAccept(new AsyncCallback(AcceptClient), null); } }
public void AddFile(string fileName, string friendlyName = null, bool useQuestion = true) { if (Dir != "") { fileName = Dir + "\\" + fileName; } if (!File.Exists(fileName)) { File.Create(fileName).Close(); dumpFiles.Add(fileName); if (fName != null) { int lstIndex = dumpFiles.Count - 1; string entry = friendlyName + ":" + lstIndex; fName.Add(entry); } } else { bool overwrite = false; if (useQuestion) { string p = console.GetPrompt(); console.SetPrompt("[Y/N]"); overwrite = console.ChoicePrompt("File already exists.\r\nDo you want to override it? [Y/N]"); console.SetPrompt(p); } if (overwrite) { File.Delete(fileName); AddFile(fileName, friendlyName, useQuestion); } else { dumpFiles.Add(fileName); if (fName != null) { int lstIndex = dumpFiles.Count - 1; string entry = friendlyName + ":" + lstIndex; fName.Add(entry); } } } }
public void Save(string filename) { if (File.Exists(defaultDir + "\\" + filename + ".xml")) { bool result = console.ChoicePrompt("The file name you specified already exists.\r\nDo you want to overwrite it?"); if (result) { File.Delete(defaultDir + "\\" + filename + ".xml"); } else { return; } } using (System.Xml.XmlWriter xml = System.Xml.XmlWriter.Create(defaultDir + "\\" + filename + ".xml")) { xml.WriteStartDocument(); xml.WriteStartElement("proxyServer"); foreach (object obj in objlist) { ISettings iso = (ISettings)obj; iso.WriteSettings(xml); } /*//Write Main Options (Form1) * ctx.WriteSettings(xml); * //Write Console Options (VConsole) * console.WriteSettings(xml); * //Write Pin Options (VPin) * pinManager.WriteSettings(xml); * if (ctx.server != null) ctx.server.WriteSettings(xml); * //Write Filters (VFilter) * ctx.vf.WriteSettings(xml); * //Write Logger Options (VLogger) * logger.WriteSettings(xml); * //Write SSL Certificate Options (VSslCertificate) * ctx.CertMod.WriteSettings(xml); * //Write ending tags*/ xml.WriteEndElement(); xml.WriteEndDocument(); } ctx.LogMod.Log("Settings Saved to: " + defaultDir + "\\" + filename + ".xml", VLogger.LogLevel.information); }