Example #1
0
        public StorageModule()
        {
            this.RequiresAuthentication();

            Get["/storage"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.VolumesInfo    = Volumes.BlocksFromDd();
                vmod.IsOsRemovable  = InstallCheck.IsOsRemovable;
                vmod.Mounts         = antdlib.MountPoint.MountRepository.Get();
                vmod.CurrentContext = Request.Path;
                vmod.CCTable        = CCTableRepository.GetAllByContext(Request.Path);
                vmod.Count          = CCTableRepository.GetAllByContext(Request.Path).ToArray().Length;
                return(View["_page-storage", vmod]);
            };

            Get["/storage/reload/volumes"] = x => {
                Volumes.PopulateBlocks();
                return(Response.AsJson(true));
            };

            Post["/storage/install"] = x => {
                new InstallOperativeSystem((string)Request.Form.DiskName).SetDiskAndInstall();
                return(Response.AsJson(true));
            };

            Post["/rsync/add"] = x => {
                var source      = (string)Request.Form.Source;
                var destination = (string)Request.Form.Destination;
                var options     = (string)Request.Form.Options;
                var type        = (string)Request.Form.Type.Value;
                Rsync.Create(source, destination, options, type);
                return(Response.AsRedirect("/"));
            };
        }
Example #2
0
        public HypervisorModule()
        {
            this.RequiresAuthentication();

            Get["/hypervisor"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.CurrentContext = Request.Path;
                vmod.CCTable        = CCTableRepository.GetAllByContext(Request.Path);
                vmod.Count          = CCTableRepository.GetAllByContext(Request.Path).ToArray().Length;
                return(View["_page-hypervisor", vmod]);
            };
        }
Example #3
0
        public MailModule()
        {
            this.RequiresAuthentication();

            Get["/mail"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.CurrentContext = Request.Path;
                vmod.CCTable        = CCTableRepository.GetAllByContext(Request.Path);
                vmod.Count          = CCTableRepository.GetAllByContext(Request.Path).ToArray().Length;
                dynamic smtp = new ExpandoObject();
                smtp.Url      = Smtp.Settings.Url;
                smtp.Port     = Smtp.Settings.Port;
                smtp.Account  = Smtp.Settings.Account;
                smtp.Password = Smtp.Settings.Password;
                vmod.SMTP     = smtp;
                dynamic imap = new ExpandoObject();
                imap.Url      = Imap.Settings.Url;
                imap.Port     = Imap.Settings.Port;
                imap.Account  = Imap.Settings.Account;
                imap.Password = Imap.Settings.Password;
                vmod.IMAP     = imap;
                return(View["_page-mail", vmod]);
            };

            Post["/mail/smtp/config"] = x => {
                string url = Request.Form.Url;
                Smtp.Settings.SetUrl(url);
                string port = Request.Form.Port;
                Smtp.Settings.SetPort(port);
                string account = Request.Form.Account;
                Smtp.Settings.SetAccount(account);
                string passwd = Request.Form.Password;
                Smtp.Settings.SetPassword(passwd);
                return(Response.AsRedirect("/"));
            };

            Post["/mail/imap/config"] = x => {
                string url = Request.Form.Url;
                Imap.Settings.SetUrl(url);
                string port = Request.Form.Port;
                Imap.Settings.SetPort(port);
                string account = Request.Form.Account;
                Imap.Settings.SetAccount(account);
                string passwd = Request.Form.Password;
                Imap.Settings.SetPassword(passwd);
                return(Response.AsRedirect("/"));
            };
        }
Example #4
0
        public CCTableModule()
            : base("/cctable")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.list = CCTableRepository.GetAll();
                return(View["_page-cctable", vmod]);
            };

            Post["/"] = x => {
                string tbl = (string)this.Request.Form.Alias;
                if (tbl != "")
                {
                    CCTableRepository.CreateTable(tbl);
                }
                return(Response.AsRedirect("/cctable"));
            };

            Post["/row"] = x => {
                string table        = (string)this.Request.Form.TableGuid;
                string tableName    = (string)this.Request.Form.TableName;
                string label        = (string)this.Request.Form.Label;
                string inputType    = (string)this.Request.Form.InputType.Value;
                string inputValue   = (string)this.Request.Form.InputLabel;
                string inputCommand = (string)this.Request.Form.InputCommand;
                string notes        = (string)this.Request.Form.Notes;
                CCTableRepository.CreateRow(table, tableName, label, inputType, inputValue, inputCommand, notes);

                string command       = this.Request.Form.CCTableCommand;
                string inputid       = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace();
                string inputlocation = "CCTable" + this.Request.Form.TableName;
                CommandDB.Create(inputid, command, command, inputlocation, notes);

                return(Response.AsRedirect("/cctable"));
            };

            Get["/delete/table/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTable(guid);
                return(Response.AsJson("CCTable deleted"));
            };
        }
Example #5
0
        public CcTableModule()
        {
            this.RequiresAuthentication();

            Get["/cctable/cctable"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.list = CCTableRepository.GetAll();
                return(View["_page-cctable", vmod]);
            };

            Post["/cctable/cctable"] = x => {
                var tbl     = (string)Request.Form.Alias;
                var context = (string)Request.Form.Context;
                var tblType = (string)Request.Form.TableType;
                if (tbl.RemoveWhiteSpace().Length > 0)
                {
                    CCTableRepository.CreateTable(tbl, tblType, context);
                }
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row"] = x => {
                var    tableGuid     = (string)Request.Form.TableGuid;
                var    tableName     = (string)Request.Form.TableName;
                var    label         = (string)Request.Form.Label;
                var    inputType     = (string)Request.Form.InputType.Value;
                var    inputLabel    = (string)Request.Form.InputLabel;
                var    notes         = (string)Request.Form.Notes;
                var    osi           = (string)Request.Form.FlagOSI.Value;
                var    func          = (string)Request.Form.FlagFunction.Value;
                var    vOsi          = CCTableRepository.GetOsiLevel(osi);
                var    vFunc         = CCTableRepository.GetCommandFunction(func);
                var    inputId       = "New" + tableName.UppercaseAllFirstLetters().RemoveWhiteSpace() + label.UppercaseAllFirstLetters().RemoveWhiteSpace();
                string inputLocation = "CCTable" + Request.Form.TableName;
                string command;
                var    commandGet = (string)Request.Form.InputCommand;
                switch (inputType)
                {
                case "hidden":
                    command = Request.Form.CCTableCommandNone;
                    CCTableRepository.CreateRowForDirectCommand(tableGuid, tableName, label, inputLabel, command, notes, vOsi, vFunc, inputId, inputLocation);
                    break;

                case "text":
                    command = Request.Form.CCTableCommandText;
                    CCTableRepository.CreateRowForTextInputCommand(tableGuid, tableName, label, inputLabel, command, commandGet, notes, vOsi, vFunc, inputId, inputLocation);
                    break;

                case "checkbox":
                    string commandTrue  = Request.Form.CCTableCommandBooleanTrue;
                    string commandFalse = Request.Form.CCTableCommandBooleanFalse;
                    CCTableRepository.CreateRowForBooleanPairCommand(tableGuid, tableName, label, inputLabel, commandTrue, commandFalse, notes, vOsi, vFunc, inputId, inputLocation);
                    break;
                }

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/dataview"] = x => {
                var table     = (string)Request.Form.TableGuid;
                var tableName = (string)Request.Form.TableName;
                var label     = (string)Request.Form.Label;

                var commandString = (string)Request.Form.Command;
                var resultString  = (string)Request.Form.Result;
                ConsoleLogger.Log(commandString);
                if (commandString != "")
                {
                    var thisResult = resultString == "" ? Terminal.Execute(commandString) : resultString;
                    CCTableRepository.CreateRowDataView(table, tableName, label, commandString, thisResult);
                }
                ConsoleLogger.Log(commandString);

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/mapdata"] = x => {
                var rowGuid    = (string)Request.Form.ItemGuid;
                var labelArray = (string)Request.Form.MapLabel;
                var indexArray = (string)Request.Form.MapLabelIndex;
                CCTableRepository.SaveMapData(rowGuid, labelArray, indexArray);
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/row/refresh"] = x => {
                var guid = (string)Request.Form.Guid;
                CCTableRepository.Refresh(guid);
                return(Response.AsJson(true));
            };

            Get["/cctable/delete/table/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTable(guid);
                return(Response.AsJson("CCTable deleted"));
            };

            Get["/cctable/delete/row/{guid}"] = x => {
                string guid = x.guid;
                CCTableRepository.DeleteTableRow(guid);
                return(Response.AsJson("CCTable Row deleted"));
            };

            Get["/cctable/edit/row/{guid}/{cmd*}"] = x => {
                string guid = x.guid;
                string cmd  = x.cmd;
                CCTableRepository.EditTableRow(guid, cmd);
                return(Response.AsJson("CCTable Row deleted"));
            };

            Post["/cctable/Launch"] = x => {
                var commandType  = (string)Request.Form.Type;
                var rowGuid      = (string)Request.Form.RowGuid;
                var newValue     = (string)Request.Form.NewValue;
                var boolSelected = (string)Request.Form.BoolSelected;

                var row = CCTableRepository.GetRow(rowGuid);

                switch (commandType)
                {
                case "direct":
                    Terminal.Execute(row.CommandDirect);
                    break;

                case "text":
                    Terminal.Execute(row.CommandSet.Replace("{Value}", newValue));
                    break;

                case "bool":
                    if (boolSelected == "true")
                    {
                        Terminal.Execute(row.CommandTrue);
                    }
                    else if (boolSelected == "false")
                    {
                        Terminal.Execute(row.CommandFalse);
                    }
                    else
                    {
                        Terminal.Execute("echo COMMAND NOT FOUND");
                    }
                    break;
                }

                return(Response.AsJson(true));
            };

            Post["/cctable/row/conf"] = x => {
                var table     = (string)Request.Form.TableGuid;
                var tableName = (string)Request.Form.TableName;
                var file      = (string)Request.Form.File;

                var type = file.EndsWith(".conf") ? CCTableFlags.ConfType.File : CCTableFlags.ConfType.Directory;
                if (file != "")
                {
                    CCTableRepository.CreateRowConf(table, tableName, file, type);
                }
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Get["/cctable/conf/files"] = x => Response.AsJson(CCTableRepository.GetEtcConfs());

            Post["/cctable/update/conf"] = x => {
                var file = (string)Request.Form.FileName;
                var text = (string)Request.Form.FileText;
                CCTableRepository.UpdateConfFile(file, text);
                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };

            Post["/cctable/map/conf"] = x => {
                var  guid               = Guid.NewGuid().ToString();
                var  commentInput       = ((string)Request.Form.CharComment).ToCharArray();
                var  comment            = commentInput.Length > 0 ? commentInput[0] : ' ';
                var  filePath           = (string)Request.Form.FilePath;
                bool hasInclude         = Request.Form.PermitsInclude.HasValue;
                var  include            = (string)Request.Form.VerbInclude;
                bool hasSection         = Request.Form.PermitsSection.HasValue;
                var  sectionOpenInput   = ((string)Request.Form.CharSectionOpen).ToCharArray();
                var  sectionOpen        = sectionOpenInput.Length > 0 ? sectionOpenInput[0] : ' ';
                var  sectionCloseInput  = ((string)Request.Form.CharSectionClose).ToCharArray();
                var  sectionClose       = sectionCloseInput.Length > 0 ? sectionCloseInput[0] : ' ';
                var  dataSeparatorInput = ((string)Request.Form.CharKevValueSeparator).ToCharArray();
                var  dataSeparator      = dataSeparatorInput.Length > 0 ? dataSeparatorInput[0] : ' ';
                bool hasBlock           = Request.Form.PermitsBlock.HasValue;
                var  blockOpenInput     = ((string)Request.Form.CharBlockOpen).ToCharArray();
                var  blockOpen          = blockOpenInput.Length > 0 ? blockOpenInput[0] : ' ';
                var  blockCloseInput    = ((string)Request.Form.CharBlockClose).ToCharArray();
                var  blockClose         = blockCloseInput.Length > 0 ? blockCloseInput[0] : ' ';
                var  endOfLineInput     = ((string)Request.Form.CharEndOfLine).ToCharArray();
                var  endOfLine          = endOfLineInput.Length > 0 ? endOfLineInput[0] : '\n';

                CCTableConf.Mapping.Repository.Create(guid, filePath, comment, hasInclude, include, hasSection, sectionOpen, sectionClose, dataSeparator, hasBlock, blockOpen, blockClose, endOfLine);

                var number  = (string)Request.Form.LineNumber;
                var numbers = number.Split(new[] { "," }, StringSplitOptions.None).ToIntArray();
                var type    = (string)Request.Form.LineType;
                var types   = type.Split(new[] { "," }, StringSplitOptions.None).ToArray();
                //linee e typi dovrebbero essere uguali
                if (numbers.Length == types.Length)
                {
                    var l = (numbers.Length + types.Length) / 2;
                    for (var i = 0; i < l; i++)
                    {
                        var ti = CCTableConf.Mapping.Repository.ConvertToDataType(types[i]);
                        CCTableConf.Mapping.Repository.AddLine(guid, numbers[i], ti);
                    }
                }

                var context  = (string)Request.Form.Context;
                var redirect = context.RemoveWhiteSpace().Length > 0 ? context : "/cctable";
                return(Response.AsRedirect(redirect));
            };
        }
Example #6
0
        public HomeModule()
        {
            this.RequiresAuthentication();
            Before += x => {
                if (CCTableRepository.GetByContext(CctableContextName) == null)
                {
                    CCTableRepository.CreateTable("System Configuration", "4", CctableContextName);
                }
                return(null);
            };

            Get["/"] = x => {
                dynamic viewModel = new ExpandoObject();

                viewModel.AntdContext = new[] {
                    "Info",
                    "Config",
                    "Network",
                    "DnsClient",
                    "Firewall",
                    "DnsServer",
                    "Proxy",
                    "Storage",
                    "Mount",
                    "Rsync",
                    "Users",
                    "Samba",
                };

                viewModel.Meminfo = Meminfo.GetMappedModel();
                if (SystemInfo.Get() == null)
                {
                    viewModel.VersionOS  = "";
                    viewModel.VersionAOS = "";
                }
                else
                {
                    viewModel.VersionOS  = SystemInfo.Get().VersionOs;
                    viewModel.VersionAOS = SystemInfo.Get().VersionAos;
                }

                viewModel.ActiveKernel               = Terminal.Execute("ls -la /mnt/cdrom/Kernel | grep active | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.RecoveryKernel             = Terminal.Execute("ls -la /mnt/cdrom/Kernel | grep recovery | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.ActiveSystem               = Terminal.Execute("ls -la /mnt/cdrom/System | grep active | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.RecoverySystem             = Terminal.Execute("ls -la /mnt/cdrom/System | grep recovery | awk '{print $9 \" : \" $11;}'").Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                viewModel.Cpuinfo                    = Cpuinfo.Get();
                viewModel.NetworkPhysicalIf          = NetworkInterface.Physical;
                viewModel.NetworkVirtualIf           = NetworkInterface.Virtual;
                viewModel.NetworkBondIf              = NetworkInterface.Bond;
                viewModel.NetworkBridgeIf            = NetworkInterface.Bridge;
                viewModel.FirewallCommands           = NfTables.GetNftCommandsBundle();
                viewModel.FirewallMacAddressEnabled  = MacAddressDiscovery.GetEnabled();
                viewModel.FirewallMacAddressDisabled = MacAddressDiscovery.GetDisabled();
                viewModel.FirewallMacAddressNew      = MacAddressDiscovery.GetNew();
                viewModel.DhcpdStatus                = antdlib.Svcs.Dhcp.DhcpConfig.IsActive;
                var dhcpdModel = antdlib.Svcs.Dhcp.DhcpConfig.MapFile.Get();
                if (dhcpdModel != null)
                {
                    viewModel.DhcpdGetGlobal        = dhcpdModel.DhcpGlobal;
                    viewModel.DhcpdGetPrefix6       = dhcpdModel.DhcpPrefix6;
                    viewModel.DhcpdGetRange         = dhcpdModel.DhcpRange;
                    viewModel.DhcpdGetRange6        = dhcpdModel.DhcpRange6;
                    viewModel.DhcpdGetKeys          = dhcpdModel.DhcpKey;
                    viewModel.DhcpdGetSubnet        = dhcpdModel.DhcpSubnet;
                    viewModel.DhcpdGetSubnet6       = dhcpdModel.DhcpSubnet6;
                    viewModel.DhcpdGetHost          = dhcpdModel.DhcpHost;
                    viewModel.DhcpdGetFailover      = dhcpdModel.DhcpFailover;
                    viewModel.DhcpdGetSharedNetwork = dhcpdModel.DhcpSharedNetwork;
                    viewModel.DhcpdGetGroup         = dhcpdModel.DhcpGroup;
                    viewModel.DhcpdGetClass         = dhcpdModel.DhcpClass;
                    viewModel.DhcpdGetSubclass      = dhcpdModel.DhcpSubclass;
                    viewModel.DhcpdGetLogging       = dhcpdModel.DhcpLogging;
                }
                //viewModel.SambaStatus = antdlib.Svcs.Samba.SambaConfig.IsActive;
                //viewModel.SambaStructure = antdlib.Svcs.Samba.SambaConfig.SimpleStructure;
                //var sambaModel = antdlib.Svcs.Samba.SambaConfig.MapFile.Get();
                //if (sambaModel != null) {
                //    viewModel.SambaGetData = sambaModel.Data;
                //    viewModel.SambaGetShare = sambaModel.Share;
                //}

                viewModel.Mounts           = MountRepository.Get();
                viewModel.RsyncDirectories = Rsync.GetAll();
                viewModel.RsyncOptions     = new List <Tuple <string, string> > {
                    new Tuple <string, string>("--checksum", "skip based on checksum"),
                    new Tuple <string, string>("--archive", "archive mode"),
                    new Tuple <string, string>("--recursive", "recurse into directories"),
                    new Tuple <string, string>("--update", "skip files that are newer on the receiver"),
                    new Tuple <string, string>("--links", "copy symlinks as symlinks"),
                    new Tuple <string, string>("--copy-links", "transform symlink into referent file/dir"),
                    new Tuple <string, string>("--copy-dirlinks", "transform symlink to dir into referent dir"),
                    new Tuple <string, string>("--keep-dirlinks", "treat symlinked dir on receiver as dir"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--hard-links", "preserve hard links"),
                    new Tuple <string, string>("--perms", "preserve permissions"),
                    new Tuple <string, string>("--executability", "preserve executability"),
                    new Tuple <string, string>("--acls", "preserve ACLs"),
                    new Tuple <string, string>("--xattrs", "preserve extended attributes"),
                    new Tuple <string, string>("--owner", "preserve owner"),
                    new Tuple <string, string>("--group", "preserve group"),
                    new Tuple <string, string>("--times", "preserve modification times")
                };

                viewModel.UserEntities = UserEntity.Repository.GetAll();

                //todo check next parameters
                viewModel.SSHPort    = "22";
                viewModel.AuthStatus = ApplicationSetting.TwoFactorAuth();

                viewModel.CCTableContext = CctableContextName;
                var table = CCTableRepository.GetByContext2(CctableContextName);
                viewModel.CommandDirect = table.Content.Where(_ => _.CommandType == CCTableCommandType.Direct);
                viewModel.CommandText   = table.Content.Where(_ => _.CommandType == CCTableCommandType.TextInput);
                viewModel.CommandBool   = table.Content.Where(_ => _.CommandType == CCTableCommandType.BooleanPair);
                return(View["antd/page-antd", viewModel]);
            };

            Get["/log"] = x => {
                dynamic viewModel = new ExpandoObject();
                viewModel.AntdContext = new[] {
                    "AntdLog",
                    "SystemLog",
                    "LogReport",
                };

                viewModel.LOGS       = Logger.GetAll();
                viewModel.LogReports = Journalctl.Report.Get();
                return(View["antd/page-log", viewModel]);
            };

            Get["/ca"] = x => {
                dynamic viewModel = new ExpandoObject();
                viewModel.AntdContext = new[] {
                    "Manage",
                };

                viewModel.SslStatus       = "Enabled";
                viewModel.SslStatusAction = "Disable";
                if (ApplicationSetting.Ssl() == "no")
                {
                    viewModel.SslStatus       = "Disabled";
                    viewModel.SslStatusAction = "Enable";
                }
                viewModel.CertificatePath = ApplicationSetting.CertificatePath();
                viewModel.CaStatus        = "Enabled";
                if (ApplicationSetting.CertificateAuthority() == "no")
                {
                    viewModel.CaStatus = "Disabled";
                }
                viewModel.CaIsActive   = CertificateAuthority.IsActive;
                viewModel.Certificates = CertificateRepository.GetAll();

                return(View["antd/page-ca", viewModel]);
            };

            Get["/cfg"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.ValueBundle           = ConfigManagement.GetValuesBundle();
                vmod.EnabledCommandBundle  = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled).OrderBy(_ => _.Index);
                vmod.DisabledCommandBundle = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled == false).OrderBy(_ => _.Index);
                return(View["antd/page-cfg", vmod]);
            };
        }
Example #7
0
        public ServicesModule()
        {
            this.RequiresAuthentication();

            Get["/services"] = x => {
                dynamic vmod = new ExpandoObject();
                vmod.CurrentContext = Request.Path;
                vmod.CCTable        = CCTableRepository.GetAllByContext(Request.Path);
                vmod.Count          = CCTableRepository.GetAllByContext(Request.Path).ToArray().Length;
                return(View["_page-services", vmod]);
            };

            #region SAMBA
            Post["/services/activate/samba"] = x => {
                SambaConfig.SetReady();
                SambaConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/refresh/samba"] = x => {
                SambaConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/reloadconfig/samba"] = x => {
                SambaConfig.ReloadConfig();
                return(Response.AsJson(true));
            };

            Post["/services/update/samba"] = x => {
                var parameters = this.Bind <List <ServiceSamba> >();
                SambaConfig.WriteFile.SaveGlobalConfig(parameters);
                Thread.Sleep(1000);
                SambaConfig.WriteFile.DumpGlobalConfig();
                Thread.Sleep(1000);
                SambaConfig.WriteFile.RewriteSmbconf();
                return(Response.AsRedirect("/"));
            };

            Post["/services/update/sambashares"] = x => {
                var    parameters = this.Bind <List <ServiceSamba> >();
                string file       = Request.Form.ShareFile;
                string name       = Request.Form.ShareName;
                string query      = Request.Form.ShareQueryName;
                SambaConfig.WriteFile.SaveShareConfig(file, name, query, parameters);
                Thread.Sleep(1000);
                SambaConfig.WriteFile.DumpShare(name);
                Thread.Sleep(1000);
                SambaConfig.WriteFile.RewriteSmbconf();
                return(Response.AsRedirect("/"));
            };

            Post["/services/samba/addparam"] = x => {
                string key   = Request.Form.NewParameterKey;
                string value = Request.Form.NewParameterValue;
                SambaConfig.WriteFile.AddParameterToGlobal(key, value);
                Thread.Sleep(1000);
                SambaConfig.WriteFile.RewriteSmbconf();
                return(Response.AsRedirect("/"));
            };

            Post["/services/samba/addshare"] = x => {
                string name      = Request.Form.NewShareName;
                string directory = Request.Form.NewShareDirectory;
                SambaConfig.WriteFile.AddShare(name, directory);
                Thread.Sleep(1000);
                SambaConfig.WriteFile.RewriteSmbconf();
                return(Response.AsRedirect("/"));
            };
            #endregion SAMBA

            #region BIND
            Post["/services/activate/bind"] = x => {
                BindConfig.SetReady();
                BindConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/refresh/bind"] = x => {
                BindConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/reloadconfig/bind"] = x => {
                BindConfig.ReloadConfig();
                return(Response.AsJson(true));
            };

            Post["/services/update/bind/{section}"] = x => {
                var section    = (string)x.section;
                var parameters = this.Bind <List <ServiceBind> >();
                if (section == "acl")
                {
                    BindConfig.WriteFile.SaveAcls(parameters);
                }
                else
                {
                    BindConfig.WriteFile.SaveGlobalConfig(section, parameters);
                }
                Thread.Sleep(1000);
                BindConfig.WriteFile.DumpGlobalConfig();
                return(Response.AsRedirect("/"));
            };

            Post["/services/update/bind/zone/{zone}"] = x => {
                var zoneName   = (string)x.zone;
                var parameters = this.Bind <List <ServiceBind> >();
                BindConfig.WriteFile.SaveZoneConfig(zoneName, parameters);
                Thread.Sleep(1000);
                BindConfig.WriteFile.DumpGlobalConfig();
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addacl"] = x => {
                string k = Request.Form.NewAclKey;
                string v = Request.Form.NewAclValue;
                BindConfig.MapFile.AddAcl(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addkey"] = x => {
                string name = Request.Form.NewKeyName;
                BindConfig.MapFile.AddKey(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addmasters"] = x => {
                string name = Request.Form.NewMastersName;
                BindConfig.MapFile.AddMasters(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addserver"] = x => {
                string name = Request.Form.NewServerName;
                BindConfig.MapFile.AddServer(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addview"] = x => {
                string name = Request.Form.NewViewName;
                BindConfig.MapFile.AddView(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/bind/addzone"] = x => {
                string name = Request.Form.NewZoneName;
                BindConfig.MapFile.AddZone(name);
                return(Response.AsRedirect("/"));
            };
            #endregion BIND

            #region DHCP
            Post["/services/activate/dhcp"] = x => {
                DhcpConfig.SetReady();
                DhcpConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/refresh/dhcp"] = x => {
                DhcpConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/reloadconfig/dhcp"] = x => {
                DhcpConfig.ReloadConfig();
                return(Response.AsJson(true));
            };

            Post["/services/update/dhcp/{section}"] = x => {
                var parameters = this.Bind <List <ServiceDhcp> >();
                var section    = (string)x.section;
                if (section == "global")
                {
                    DhcpConfig.WriteFile.SaveGlobal(parameters);
                }
                if (section == "prefix6")
                {
                    DhcpConfig.WriteFile.SavePrefix6(parameters);
                }
                if (section == "range6")
                {
                    DhcpConfig.WriteFile.SaveRange6(parameters);
                }
                if (section == "range")
                {
                    DhcpConfig.WriteFile.SaveRange(parameters);
                }
                else
                {
                    DhcpConfig.WriteFile.SaveConfigFor(section, parameters);
                }
                Thread.Sleep(1000);
                DhcpConfig.WriteFile.DumpGlobalConfig();
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addglobal"] = x => {
                string k = Request.Form.NewKey;
                string v = Request.Form.NewValue;
                DhcpConfig.MapFile.AddGlobal(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addrange"] = x => {
                string k = Request.Form.NewKey;
                string v = Request.Form.NewValue;
                DhcpConfig.MapFile.AddGlobal(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addprefix6"] = x => {
                string k = Request.Form.NewKey;
                string v = Request.Form.NewValue;
                DhcpConfig.MapFile.AddPrefix6(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addrange6"] = x => {
                string k = Request.Form.NewKey;
                string v = Request.Form.NewValue;
                DhcpConfig.MapFile.AddRange6(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addrange"] = x => {
                string k = Request.Form.NewKey;
                string v = Request.Form.NewValue;
                DhcpConfig.MapFile.AddRange(k, v);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addkey"] = x => {
                string name = Request.Form.NewKeyName;
                DhcpConfig.MapFile.AddKey(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addsubnet"] = x => {
                string name = Request.Form.NewSubnet6Name;
                DhcpConfig.MapFile.AddSubnet6(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addsubnet"] = x => {
                string name = Request.Form.NewSubnetName;
                DhcpConfig.MapFile.AddSubnet(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addhost"] = x => {
                string name = Request.Form.NewHostName;
                DhcpConfig.MapFile.AddHost(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addclass"] = x => {
                string name = Request.Form.NewClassName;
                DhcpConfig.MapFile.AddClass(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addsubclass"] = x => {
                string name = Request.Form.NewSubclassName;
                DhcpConfig.MapFile.AddSubclass(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addfailover"] = x => {
                string name = Request.Form.NewFailoverName;
                DhcpConfig.MapFile.AddFailover(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addlogging"] = x => {
                string name = Request.Form.NewLoggingName;
                DhcpConfig.MapFile.AddLogging(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addgroup"] = x => {
                string name = Request.Form.NewGroupName;
                DhcpConfig.MapFile.AddGroup(name);
                return(Response.AsRedirect("/"));
            };

            Post["/services/dhcp/addkey"] = x => {
                string name = Request.Form.NewKeyName;
                DhcpConfig.MapFile.AddKey(name);
                return(Response.AsRedirect("/"));
            };
            #endregion DHCP

            #region SSH
            Post["/services/activate/ssh"] = x => {
                SshConfig.SetReady();
                SshConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/refresh/ssh"] = x => {
                SshConfig.MapFile.Render();
                return(Response.AsJson(true));
            };

            Post["/services/reloadconfig/ssh"] = x => {
                SshConfig.ReloadConfig();
                return(Response.AsJson(true));
            };

            Post["/services/update/ssh/{section}"] = x => {
                //var parameters = this.Bind<List<ServiceSsh>>();
                //var section = (string)x.section;
                //if (section == "global") {
                //    SshConfig.WriteFile.SaveGlobal(parameters);
                //}
                //if (section == "prefix6") {
                //    SshConfig.WriteFile.SavePrefix6(parameters);
                //}
                //if (section == "range6") {
                //    SshConfig.WriteFile.SaveRange6(parameters);
                //}
                //if (section == "range") {
                //    SshConfig.WriteFile.SaveRange(parameters);
                //}
                //else {
                //    SshConfig.WriteFile.SaveConfigFor(section, parameters);
                //}
                //Thread.Sleep(1000);
                SshConfig.WriteFile.DumpGlobalConfig();
                return(Response.AsRedirect("/"));
            };

            //Post["/services/ssh/addkey"] = x => {
            //    string name = Request.Form.NewKeyName;
            //    SshConfig.Keys.PropagateKeys(name);
            //    return Response.AsRedirect("/");
            //};
            #endregion SSH
        }