Exemplo n.º 1
0
 public static string GetFreeEmail(string name = null)
 {
     return(GetUserName(name) + "@" + HOSTS.Rand());
 }
Exemplo n.º 2
0
        public static void FinaliseApplyPolicy(List <PortMappingPolicy> Add, List <PortMappingPolicy> Remove)
        {
            Add    = DeDup(Add);
            Remove = DeDup(Remove);

            foreach (PortMappingPolicy rm in Remove)
            {
                bool DontRemove = false;
                //check if this policy is in "add" (to prevent connection breaking)
                foreach (PortMappingPolicy ad in Add)
                {
                    if (rm.BindTo0000 == ad.BindTo0000 && rm.ClientPort == ad.ClientPort &&
                        rm.EditHOSTS == ad.EditHOSTS && rm.HOSTSEntry == ad.HOSTSEntry &&
                        rm.ID == ad.ID && rm.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected)
                    {
                        DontRemove = true;
                        break;
                    }
                }
                if (DontRemove == true)
                {
                    continue;
                }

                PortMappings_ConnectionNode RMC = null;

                foreach (PortMappings_ConnectionNode C in Connections)
                {
                    if (C.RunningPort == rm.ClientPort && C.PolicyID == rm.ID)
                    {
                        RMC = C;
                        break;
                    }
                }

                if (RMC != null)
                {
                    Connections.Remove(RMC);
                    RMC.StopConnection();
                }
            }

            for (int i = 0; i < Add.Count; i++)
            {
                bool BadPort         = false;
                PortMappingPolicy ad = Add[i];
                for (int j = 0; j < Add.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    if (ad.ClientPort == Add[j].ClientPort)
                    {
                        FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " conflicts with Policy ID " + ad.ID + " and " + Add[j].ID, EventLogEntryType.Error);
                        BadPort = true;
                        break;
                    }
                }
                if (BadPort == true)
                {
                    continue;
                }

                foreach (PortMappings_ConnectionNode cc in Connections)
                {
                    if (ad.ID == cc.PolicyID)
                    {
                        if (cc.PolicyData.BindTo0000 == ad.BindTo0000 && cc.PolicyData.ClientPort == ad.ClientPort &&
                            cc.PolicyData.EditHOSTS == ad.EditHOSTS && cc.PolicyData.HOSTSEntry == ad.HOSTSEntry &&
                            cc.PolicyData.NoBindIfSDCServerIsDetected == ad.NoBindIfSDCServerIsDetected)
                        {
                            //no changes - continue
                            BadPort = true;
                            break;
                        }
                        else
                        {
                            //remove connection
                            Connections.Remove(cc);
                            cc.StopConnection();
                            break;
                        }
                    }
                }
                if (BadPort == true)
                {
                    continue;
                }

                if (NetworkUtilities.PortAvailable(ad.ClientPort) == false)
                {
                    FoxEventLog.WriteEventLog("Portmapping: Port " + ad.ClientPort + " from Policy ID " + ad.ID + " is unavailable.", EventLogEntryType.Error);
                    continue;
                }

                if (ad.NoBindIfSDCServerIsDetected == true)
                {
                    bool FoundSDCS = false;
                    using (RegistryKey reg = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\FoxSDCS"))
                    {
                        if (reg != null)
                        {
                            FoundSDCS = true;
                        }
                    }
                    if (FoundSDCS == true)
                    {
                        continue;
                    }
                }

                if (ad.EditHOSTS == true)
                {
                    if (string.IsNullOrWhiteSpace(ad.HOSTSEntry) == false)
                    {
                        foreach (string HOSTS in ad.HOSTSEntry.Split('|'))
                        {
                            if (string.IsNullOrWhiteSpace(HOSTS) == true)
                            {
                                continue;
                            }
                            HostsEdit.AppendIntoHOSTSFile(HOSTS.Trim(), "127.0.0.1");
                        }
                    }
                }

                PortMappings_ConnectionNode C = new PortMappings_ConnectionNode(ad);
                C.StartConnection();
                Connections.Add(C);
            }
        }