Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }