Esempio n. 1
0
        private void RoutingList_ContextMenu_Add_Click(object sender, EventArgs e)
        {
            AddStaticRouteWizard Wizard = new AddStaticRouteWizard(Data);

            if (Wizard.ShowDialog().GetValueOrDefault())
            {
                var Result = (AddStaticRouteWizardData)Wizard.DataContext;

                StaticRoutingData NewRoute = new StaticRoutingData();
                NewRoute.Name = Result.RouteNameValue;

                switch (Result.RouteType)
                {
                case StaticRouteType.All:
                case StaticRouteType.DNSLog:
                case StaticRouteType.IP:
                case StaticRouteType.Netmask:
                    NewRoute.Type = RoutingType.Netmask;
                    break;

                case StaticRouteType.Organization:
                    NewRoute.Type = RoutingType.Organisation;
                    break;

                case StaticRouteType.ASN:
                    NewRoute.Type = RoutingType.ASN;
                    break;
                }
                NewRoute.Destination = Result.FilterValue;
                NewRoute.Interface   = Result.RouterData.Interfaces[Result.SelectedInterface].Interface;
                NewRoute.Action      = Result.RouteAction;

                Data.StaticRoutes.Add(NewRoute);
            }
        }
Esempio n. 2
0
        private ListViewItem CreateLVIFromStaticRoutingRule(StaticRoutingData Route, ListViewItem ExistingItem = null)
        {
            ListViewItem Item = ExistingItem != null ? ExistingItem : new ListViewItem();

            Item.SubItems.Clear();
            Item.Tag  = Route;
            Item.Text = Route.Name;
            Item.SubItems.Add(Route.Action.ToString());
            Item.SubItems.Add(Route.Type.ToString());
            Item.SubItems.Add(Route.Destination);
            Item.SubItems.Add(Route.Interface);

            return(Item);
        }
        public RouterData()
        {
            StaticRoutes.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
                delegate(object Sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs EventArgs)
            {
                if (EventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    foreach (var ItemObj in EventArgs.NewItems)
                    {
                        StaticRoutingData Item = (StaticRoutingData)ItemObj;

                        string[] Splits = Item.Destination.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

                        foreach (string Value in Splits)
                        {
                            if (Item.Type == RoutingType.Organisation)
                            {
                                VyattaConfigRouting.AddStaticRoutesForOrganization(ConfigRoot, Value.Trim(), this, Item.Interface, Item.Name);
                            }
                            else if (Item.Type == RoutingType.ASN)
                            {
                                int ASN = 0;
                                int.TryParse(Value.Trim(), out ASN);

                                VyattaConfigRouting.AddStaticRoutesForASN(ConfigRoot, ASN, this, Item.Interface, Item.Name);
                            }
                            else if (Item.Type == RoutingType.Netmask)
                            {
                                VyattaConfigRouting.AddStaticRoute(ConfigRoot, this, Value.Trim(), Item.Interface, Item.Name);
                            }
                            else
                            {
                                throw new Exception("Unimplemented type");
                            }
                        }
                    }
                }
                else if (EventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
                {
                    foreach (var ItemObj in EventArgs.OldItems)
                    {
                        StaticRoutingData Item = (StaticRoutingData)ItemObj;
                        VyattaConfigRouting.DeleteGeneratedStaticRoutes(ConfigRoot, Item.Name);
                    }
                }
            }
                );
        }
Esempio n. 4
0
        public Main(RouterData Data)
        {
            this.Data = Data;

            InitializeComponent();

            RoutingList.Items.Clear();

            foreach (var Item in Data.StaticRoutes)
            {
                RoutingList.Items.Add(CreateLVIFromStaticRoutingRule(Item));
            }
            RoutingList.Refresh();

            Data.StaticRoutes.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
                delegate(object Sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs EventArgs)
            {
                if (EventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    foreach (var ItemObj in EventArgs.NewItems)
                    {
                        StaticRoutingData Item = (StaticRoutingData)ItemObj;

                        RoutingList.Items.Add(CreateLVIFromStaticRoutingRule(Item));
                    }
                }
                else if (EventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
                {
                    foreach (var ItemObj in EventArgs.OldItems)
                    {
                        StaticRoutingData Item = (StaticRoutingData)ItemObj;

                        foreach (var ListItemObj in RoutingList.Items)
                        {
                            var ListViewItem = ListItemObj as ListViewItem;
                            if (ListViewItem.Tag.Equals(Item))
                            {
                                RoutingList.Items.Remove(ListViewItem);
                                break;
                            }
                        }
                    }
                }

                RefreshDiff();
            }
                );
        }
Esempio n. 5
0
        public bool DoWork(Util.UpdateStatusDelegate SetStatus, Util.ShouldCancelDelegate ShouldCancel)
        {
            if (ShouldCancel())
            {
                return(false);
            }

            SetStatus("Deleting previous auto-generated rules...", 16);
            VyattaConfigRouting.DeleteGeneratedStaticRoutes(Data.ConfigRoot);

            if (ShouldCancel())
            {
                return(false);
            }

            SetStatus("Generating Netflix static routing...", 32);
            //VyattaConfigRouting.AddStaticRoutesForOrganization( Data.ConfigRoot, "Netflix", Data, "Internet", "Netflix" );
            {
                StaticRoutingData NewRoute = new StaticRoutingData();
                NewRoute.Destination = "Netflix";
                NewRoute.Interface   = "eth0";
                NewRoute.Name        = "Netflix";
                NewRoute.Type        = RoutingType.Organisation;
                NewRoute.Action      = StaticRouteAction.ToInterface;

                Data.StaticRoutes.Add(NewRoute);
            }

            if (ShouldCancel())
            {
                return(false);
            }

            SetStatus("Generating BBC static routing...", 48);
            //VyattaConfigRouting.AddStaticRoutesForOrganization( Data.ConfigRoot, "BBC", Data, "Internet", "BBC" );
            {
                StaticRoutingData NewRoute = new StaticRoutingData();
                NewRoute.Destination = "BBC";
                NewRoute.Interface   = "eth0";
                NewRoute.Name        = "BBC";
                NewRoute.Type        = RoutingType.Organisation;
                NewRoute.Action      = StaticRouteAction.ToInterface;

                Data.StaticRoutes.Add(NewRoute);
            }

            if (ShouldCancel())
            {
                return(false);
            }

            SetStatus("Generating Valve static routing...", 56);
            //VyattaConfigRouting.AddStaticRoutesForOrganization( Data.ConfigRoot, "Valve", Data, "Internet", "Valve" );
            {
                StaticRoutingData NewRoute = new StaticRoutingData();
                NewRoute.Destination = "Valve";
                NewRoute.Interface   = "eth0";
                NewRoute.Name        = "Valve";
                NewRoute.Type        = RoutingType.Organisation;
                NewRoute.Action      = StaticRouteAction.ToInterface;

                Data.StaticRoutes.Add(NewRoute);
            }

            if (ShouldCancel())
            {
                return(false);
            }

            SetStatus("Generating Nest static routing...", 80);
            //VyattaConfigRouting.AddStaticRoutesForOrganization( Data.ConfigRoot, "Nest", Data, "Internet", "Nest" );
            {
                StaticRoutingData NewRoute = new StaticRoutingData();
                NewRoute.Destination = "Nest";
                NewRoute.Interface   = "eth0";
                NewRoute.Name        = "Nest";
                NewRoute.Type        = RoutingType.Organisation;
                NewRoute.Action      = StaticRouteAction.ToInterface;

                Data.StaticRoutes.Add(NewRoute);
            }

            SetStatus("Saving new config...", 90);
            Data.NewConfigLines = VyattaConfigUtil.WriteToStringLines(Data.ConfigRoot);

            return(true);
        }