예제 #1
0
        private static int AddPort(string[] args)
        {
            if (args.Length > 3)
            {
                Console.Error.WriteLine("Invalid number of arguments");
                return(1);
            }
            int newPort;

            if (args.Length > 1)
            {
                if (!Int32.TryParse(args[1], out newPort))
                {
                    Console.Error.WriteLine("Invalid new port " + args[2]);
                    return(4);
                }
            }
            else
            {
                Ares.Settings.BasicSettings basicSettings = new Ares.Settings.BasicSettings();
                bool foundSettings = basicSettings.ReadFromFile();
                Ares.Settings.Settings.Instance.InitializeWithoutSharedMemory(foundSettings ? basicSettings.GetSettingsDir() : null);
                newPort = Ares.Settings.Settings.Instance.WebTcpPort;
            }
            return(WrapExceptions(() =>
            {
                String newUrl = String.Format("http://+:{0}/", newPort);
                if (!WinSecurityHelpers.FindUrlPrefix(newUrl))
                {
                    WinSecurityHelpers.AddUrlPrefix(newUrl);
                }
                if (WinSecurityHelpers.FirewallEnabled)
                {
                    WinSecurityHelpers.AddFirewallRule(FW_RULE_NAME, newPort);
                }
                return 0;
            }, args.Length == 3 ? args[2] : String.Empty));
        }
예제 #2
0
        private static int ChangePort(string[] args)
        {
            if (args.Length != 4)
            {
                Console.Error.WriteLine("Invalid number of arguments");
                return(1);
            }
            int oldPort, newPort;

            if (!Int32.TryParse(args[1], out oldPort))
            {
                Console.Error.WriteLine("Invalid old port " + args[1]);
                return(3);
            }
            if (!Int32.TryParse(args[2], out newPort))
            {
                Console.Error.WriteLine("Invalid new port " + args[2]);
                return(4);
            }
            return(WrapExceptions(() =>
            {
                String oldUrl = String.Format("http://+:{0}/", oldPort);
                String newUrl = String.Format("http://+:{0}/", newPort);
                if (WinSecurityHelpers.FindUrlPrefix(oldUrl))
                {
                    WinSecurityHelpers.RemoveUrlPrefix(oldUrl);
                }
                if (!WinSecurityHelpers.FindUrlPrefix(newUrl))
                {
                    WinSecurityHelpers.AddUrlPrefix(newUrl);
                }
                if (WinSecurityHelpers.FirewallEnabled)
                {
                    WinSecurityHelpers.AddFirewallRule(FW_RULE_NAME, newPort);
                }
                return 0;
            }, args[3]));
        }
예제 #3
0
 private static int RemovePort(String[] args)
 {
     if (args.Length > 2)
     {
         Console.Error.WriteLine("Invalid number of arguments");
         return(1);
     }
     return(WrapExceptions(() =>
     {
         Ares.Settings.BasicSettings basicSettings = new Ares.Settings.BasicSettings();
         bool foundSettings = basicSettings.ReadFromFile();
         Ares.Settings.Settings.Instance.InitializeWithoutSharedMemory(foundSettings ? basicSettings.GetSettingsDir() : null);
         String oldUrl = String.Format("http://+:{0}/", Ares.Settings.Settings.Instance.WebTcpPort);
         if (WinSecurityHelpers.FindUrlPrefix(oldUrl))
         {
             WinSecurityHelpers.RemoveUrlPrefix(oldUrl);
         }
         if (WinSecurityHelpers.FirewallEnabled)
         {
             WinSecurityHelpers.RemoveFirewallRule(FW_RULE_NAME);
         }
         return 0;
     }, args.Length == 2 ? args[1] : String.Empty));
 }