public static string Shell(string path, string[] arguments) { SystemShell s = new SystemShell(); s.Path = path; s.Arguments.AddRange(arguments); s.Run(); return(s.Output); }
public virtual void OnUpdateVersion() { string finalPath = GetPath(); if (finalPath != "") { string argument = GetVersionArgument(); Version = SystemShell.Shell1(finalPath, argument).Trim(); if ((Version.StartsWithInv("Error:")) || (Version == "")) { throw new Exception(Version); } } }
public static string ShellCmd(string command) // TOCLEAN, Avoid when possible { if (command == "") { return(""); } string path; string[] arguments; Platform.Instance.ShellCommandDirect(command, out path, out arguments); SystemShell s = new SystemShell(); s.Path = path; s.Arguments.AddRange(arguments); s.WaitEnd = true; s.ExceptionIfFail = false; s.Run(); return(s.Output); }
public Json ToJson() { Json j = new Json(); j["url"].Value = Url; j["postfields"].Value = ""; foreach (string k in Parameters.Keys) { if (j["postfields"].ValueString != "") { j["postfields"].Value += "&"; } j["postfields"].Value += Uri.EscapeUriString(k) + "=" + Uri.EscapeUriString(Parameters[k]); } j["iplayer"].Value = IpLayer; j["resolve-single"].Value = ForceResolve; j["timeout"].Value = Engine.Instance.Storage.GetInt("http.timeout"); j["cacert"].Value = SystemShell.EscapePath(Engine.Instance.LocateResource("cacert.pem")); j["useragent"].Value = Constants.Name + "/" + Constants.VersionDesc; // Don't use proxy if connected to the VPN, or in special cases (checking) during connection. bool bypassProxy = BypassProxy; if (bypassProxy == false) { bypassProxy = Engine.Instance.IsConnected(); } j["proxy"].Value = ""; j["proxyauth"].Value = ""; j["proxyuserpwd"].Value = ""; if (bypassProxy == false) { string proxyMode = Engine.Instance.Storage.GetLower("proxy.mode"); string proxyWhen = Engine.Instance.Storage.GetLower("proxy.when"); string proxyHost = Engine.Instance.Storage.Get("proxy.host"); int proxyPort = Engine.Instance.Storage.GetInt("proxy.port"); string proxyAuth = Engine.Instance.Storage.Get("proxy.auth").ToLowerInvariant(); string proxyLogin = Engine.Instance.Storage.Get("proxy.login"); string proxyPassword = Engine.Instance.Storage.Get("proxy.password"); if ((proxyWhen == "none") || (proxyWhen == "openvpn")) { proxyMode = "none"; } if (proxyMode == "detect") { throw new Exception(LanguageManager.GetText("ProxyDetectDeprecated")); } if (proxyMode == "tor") { proxyMode = "socks"; proxyAuth = "none"; proxyLogin = ""; proxyPassword = ""; } if (proxyMode == "http") { j["proxy"].Value = "http://" + proxyHost + ":" + proxyPort.ToString(); } else if (proxyMode == "socks") { // curl support different types of proxy. OpenVPN not, only socks5. So, it's useless to support other kind of proxy here. j["proxy"].Value = "socks5://" + proxyHost + ":" + proxyPort.ToString(); } if ((proxyMode != "none") && (proxyAuth != "none")) { j["proxyauth"].Value = proxyAuth; if ((proxyLogin != "") && (proxyPassword != "")) { j["proxyuserpwd"].Value = proxyLogin + ":" + proxyPassword; } } } return(j); }
public void Save() { string path = GetProfilePath(); bool remember = GetBool("remember"); lock (this) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = xmlDoc.CreateElement("eddie"); xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement); XmlElement optionsNode = xmlDoc.CreateElement("options"); rootNode.AppendChild(optionsNode); xmlDoc.AppendChild(rootNode); foreach (Option option in Options.Values) { bool skip = false; if ((remember == false) && (option.Code == "login")) { skip = true; } if ((remember == false) && (option.Code == "password")) { skip = true; } if (option.CommandLineOnly) { skip = true; } if ((option.Value == "") || (option.Value == option.Default)) { skip = true; } if (skip == false) { XmlElement itemNode = xmlDoc.CreateElement("option"); itemNode.SetAttribute("name", option.Code); itemNode.SetAttribute("value", option.Value); optionsNode.AppendChild(itemNode); } } XmlElement providersNode = xmlDoc.CreateElement("providers"); rootNode.AppendChild(providersNode); foreach (Provider provider in Engine.Instance.ProvidersManager.Providers) { XmlNode providerNode = xmlDoc.ImportNode(provider.Storage.DocumentElement, true); providersNode.AppendChild(providerNode); } if (Engine.Instance.ProvidersManager.Providers.Count == 1) { if (Engine.Instance.ProvidersManager.Providers[0].GetCode() == "AirVPN") { // Move providers->AirVPN to root. XmlElement xmlAirVPN = Utils.XmlGetFirstElementByTagName(providersNode, "AirVPN"); if (xmlAirVPN != null) { foreach (XmlElement xmlChild in xmlAirVPN.ChildNodes) { Utils.XmlCopyElement(xmlChild, xmlDoc.DocumentElement); } providersNode.RemoveChild(xmlAirVPN); } if (providersNode.ChildNodes.Count == 0) { providersNode.ParentNode.RemoveChild(providersNode); } } } xmlDoc.Save(path); } if (Platform.Instance.IsUnixSystem()) { Platform.Instance.ShellCmd("chmod 600 \"" + SystemShell.EscapePath(path) + "\""); } }