public Json SendCommand(Json request, UiClient sender) { Command c = new Command(); c.Request = request; c.Sender = sender; lock (m_commands) m_commands.Add(c); c.Complete.WaitOne(); return(c.Response); }
public void Start2(UiClient client) { Json jReport = new Json(); jReport["command"].Value = "system.report.progress"; jReport["step"].Value = LanguageManager.GetText("ReportStepCollectEnvironmentInfo"); jReport["body"].Value = LanguageManager.GetText("PleaseWait"); jReport["perc"].Value = 0; client.OnReceive(jReport); Environment(); jReport["step"].Value = LanguageManager.GetText("ReportStepTests"); jReport["body"].Value = ToString(); jReport["perc"].Value = 10; client.OnReceive(jReport); Tests(); jReport["step"].Value = LanguageManager.GetText("ReportStepLogs"); jReport["body"].Value = ToString(); jReport["perc"].Value = 50; client.OnReceive(jReport); Add(LanguageManager.GetText("ReportOptions"), Engine.Instance.Storage.GetReportForSupport()); Add(LanguageManager.GetText("ReportLogs"), Engine.Instance.Logs.ToString()); jReport["step"].Value = LanguageManager.GetText("ReportStepLogs"); jReport["body"].Value = ToString(); jReport["perc"].Value = 60; client.OnReceive(jReport); jReport["step"].Value = LanguageManager.GetText("ReportStepPlatform"); jReport["body"].Value = ToString(); jReport["perc"].Value = 70; client.OnReceive(jReport); NetworkInfo(); Platform.Instance.OnReport(this); jReport["step"].Value = LanguageManager.GetText("ReportStepDone"); jReport["body"].Value = ToString(); jReport["perc"].Value = 100; client.OnReceive(jReport); }
public void Start(UiClient client) { Json jReport = new Json(); jReport["command"].Value = "system.report.progress"; jReport["step"].Value = Messages.ReportStepCollectEnvironmentInfo; jReport["body"].Value = Messages.PleaseWait; jReport["perc"].Value = 0; client.OnReceive(jReport); Environment(); jReport["step"].Value = Messages.ReportStepTests; jReport["body"].Value = ToString(); jReport["perc"].Value = 10; client.OnReceive(jReport); Tests(); jReport["step"].Value = Messages.ReportStepLogs; jReport["body"].Value = ToString(); jReport["perc"].Value = 50; client.OnReceive(jReport); Add(Messages.ReportOptions, Engine.Instance.Storage.GetReportForSupport()); Add(Messages.ReportLogs, Engine.Instance.Logs.ToString()); jReport["step"].Value = Messages.ReportStepLogs; jReport["body"].Value = ToString(); jReport["perc"].Value = 60; client.OnReceive(jReport); jReport["step"].Value = Messages.ReportStepPlatform; jReport["body"].Value = ToString(); jReport["perc"].Value = 70; client.OnReceive(jReport); NetworkInfo(); Platform.Instance.OnReport(this); jReport["step"].Value = Messages.ReportStepDone; jReport["body"].Value = ToString(); jReport["perc"].Value = 100; client.OnReceive(jReport); }
public void Start(UiClient client) { System.Threading.ThreadPool.QueueUserWorkItem(s => Start2(client)); }
public Json OnCommand(Json data, UiClient sender) { string cmd = data["command"].Value as string; if (cmd == "test-json") { Json j = new Json(); j["result"].Value = "works"; return(j); } else if (cmd == "exit") { Engine.Instance.OnExit(); } else if (cmd == "system.report.start") { Report report = new Report(); report.Start(sender); } else if (cmd == "openvpn_management") { if (Engine.Instance.SendManagementCommand(data["management_command"].Value as string) == false) { Engine.Instance.Logs.Log(LogType.Warning, Messages.OpenVpnManagementCommandFail); } } else if (cmd == "tor_control") { string resultC = TorControl.SendCommand(data["control_command"].Value as string); foreach (string line in resultC.Split('\n')) { string l = line.Trim(); if (l != "") { Engine.Instance.Logs.Log(LogType.Verbose, l); } } } else if (cmd == "set_option") { string name = data["name"].Value as string; string value = data["value"].Value as string; if (Engine.Instance.Storage.Set(name, data["value"].Value)) { if (name == "tools.openvpn.path") { Software.Checking(); } } } else if (cmd == "ui.stats.pathprofile") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathProfile").Value); } else if (cmd == "ui.stats.pathdata") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathData").Value); } else if (cmd == "ui.stats.pathapp") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathApp").Value); } else if (cmd == "man") { string format = "text"; if (data.HasKey("format")) { format = data["format"].Value as string; } string body = Engine.Instance.Storage.GetMan(format); Engine.Instance.OnShowText("man", body); } else if (cmd == "ui.show.os.info") { Engine.Instance.OnShowText("ui.show.os.info", Engine.Instance.GenerateOsInfo().ToJsonPretty()); } else if (cmd == "tor.guard") { Engine.Instance.Logs.LogVerbose("Tor Guard IPs:" + TorControl.GetGuardIps(true).ToString()); } else if (cmd == "tor.NEWNYM") { TorControl.SendNEWNYM(); } else if (cmd == "ip.exit") { Engine.Instance.Logs.LogVerbose(Engine.Instance.DiscoverExit().ToString()); } else if (cmd == "test.log.info") { Engine.Instance.Logs.Log(LogType.InfoImportant, "Test log\nInfo"); } else if (cmd == "test.log.infoimportant") { Engine.Instance.Logs.Log(LogType.InfoImportant, "Test log\nInfo Important"); } else if (cmd == "test.log.warning") { Engine.Instance.Logs.Log(LogType.Warning, "Test log\nWarning"); } else if (cmd == "test.log.error") { Engine.Instance.Logs.Log(LogType.Error, "Test log\nError"); } else if (cmd == "test.log.fatal") { Engine.Instance.Logs.Log(LogType.Fatal, "Test log\nFatal"); } else if (cmd == "test.netlock.update") { if (Engine.Instance.NetworkLockManager != null) { Engine.Instance.NetworkLockManager.OnUpdateIps(); } } return(null); }
public void Add(UiClient client) { Clients.Add(client); }
public Json ProcessCommand(Json data, UiClient sender) { string cmd = data["command"].Value as string; if (cmd == "exit") { Engine.Instance.Exit(); } else if (cmd == "mainaction.connect") { Engine.Instance.Connect(); } else if (cmd == "mainaction.disconnect") { Engine.Instance.Disconnect(); } else if (cmd == "system.report.start") { Report report = new Report(); report.Start(sender); } // TOCLEAN_OPENVPNMANAGEMENT /* * else if (cmd == "openvpn_management") * { * if (Engine.Instance.SendManagementCommand(data["management_command"].Value as string) == false) * Engine.Instance.Logs.Log(LogType.Warning, LanguageManager.GetText("OpenVpnManagementCommandFail")); * } */ else if (cmd == "tor_control") { string resultC = TorControl.SendCommand(data["control_command"].Value as string); foreach (string line in resultC.Split('\n')) { string l = line.Trim(); if (l != "") { Engine.Instance.Logs.Log(LogType.Verbose, l); } } } else if (cmd == "set_option") { string name = data["name"].Value as string; string value = data["value"].Value as string; if (Engine.Instance.Storage.Set(name, data["value"].Value)) { if (name == "tools.openvpn.path") { Software.Checking(); } } } else if (cmd == "ui.stats.pathprofile") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathProfile").Value); } else if (cmd == "ui.stats.pathdata") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathData").Value); } else if (cmd == "ui.stats.pathapp") { Platform.Instance.OpenDirectoryInFileManager(Engine.Instance.Stats.Get("PathApp").Value); } else if (cmd == "ui.start") { Json result = new Json(); result["manifest"].Value = Engine.Instance.Manifest; result["logs"].Value = Engine.Instance.Logs.GetJson(); return(result); } else if (cmd == "man") { string format = "text"; if (data.HasKey("format")) { format = data["format"].Value as string; } Json result = new Json(); result["layout"].Value = "text"; result["title"].Value = "MAN"; result["body"].Value = Engine.Instance.Storage.GetMan(format); return(result); } else if (cmd == "ui.show.os.info") { return(Engine.Instance.GenerateOsInfo().Clone()); } else if (cmd == "tor.guard") { Engine.Instance.Logs.LogVerbose("Tor Guard IPs:" + TorControl.GetGuardIps(true).ToString()); } else if (cmd == "tor.NEWNYM") { TorControl.SendNEWNYM(); } else if (cmd == "ip.exit") { Engine.Instance.Logs.LogVerbose(Engine.Instance.DiscoverExit().ToString()); } else if (cmd == "test.query") { Json result = new Json(); result["result"].Value = cmd; return(result); } else if (cmd == "test.logs") { Engine.Instance.Logs.Log(LogType.InfoImportant, "Test log\nInfo"); Engine.Instance.Logs.Log(LogType.InfoImportant, "Test log\nInfo Important"); Engine.Instance.Logs.Log(LogType.Warning, "Test log\nWarning\n" + DateTime.Now.ToString()); Engine.Instance.Logs.Log(LogType.Error, "Test log\nError"); //Engine.Instance.Logs.Log(LogType.Fatal, "Test log\nFatal"); } return(null); }