Beispiel #1
0
        public void Save(VpnConfigurationModel model)
        {
            var text = JsonConvert.SerializeObject(model, Formatting.Indented);

            FileWithAcl.WriteAllText(_cfgFile, text, "644", "root", "wheel");
            ConsoleLogger.Log("[vpn] configuration saved");
        }
Beispiel #2
0
        public void Save(VpnConfigurationModel model)
        {
            var text = JsonConvert.SerializeObject(model, Formatting.Indented);

            if (File.Exists(_cfgFile))
            {
                File.Copy(_cfgFile, _cfgFileBackup, true);
            }
            File.WriteAllText(_cfgFile, text);
            ConsoleLogger.Log("[vpn] configuration saved");
        }
Beispiel #3
0
 public VpnConfiguration()
 {
     IoDir.CreateDirectory(Parameter.AntdCfgServices);
     if (!File.Exists(_cfgFile))
     {
         _serviceModel = new VpnConfigurationModel();
     }
     else
     {
         try {
             var text = File.ReadAllText(_cfgFile);
             var obj  = JsonConvert.DeserializeObject <VpnConfigurationModel>(text);
             _serviceModel = obj;
         }
         catch (Exception) {
             _serviceModel = new VpnConfigurationModel();
         }
     }
 }
Beispiel #4
0
        public AntdVpnModule()
        {
            Get["/vpn"] = x => {
                var vpnConfiguration = new VpnConfiguration();
                var vpnIsActive      = vpnConfiguration.IsActive();
                var model            = new PageVpnModel {
                    VpnIsActive    = vpnIsActive,
                    VpnLocalPoint  = vpnConfiguration.Get()?.LocalPoint,
                    VpnRemoteHost  = vpnConfiguration.Get()?.RemoteHost,
                    VpnRemotePoint = vpnConfiguration.Get()?.RemotePoint
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/vpn/set"] = x => {
                var vpnConfiguration = new VpnConfiguration();
                vpnConfiguration.Set();
                return(HttpStatusCode.OK);
            };

            Post["/vpn/restart"] = x => {
                var vpnConfiguration = new VpnConfiguration();
                vpnConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/vpn/stop"] = x => {
                var vpnConfiguration = new VpnConfiguration();
                vpnConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/vpn/enable"] = x => {
                var dhcpdConfiguration = new VpnConfiguration();
                dhcpdConfiguration.Enable();
                dhcpdConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/vpn/disable"] = x => {
                var dhcpdConfiguration = new VpnConfiguration();
                dhcpdConfiguration.Disable();
                dhcpdConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/vpn/options"] = x => {
                string remoteHost    = Request.Form.RemoteHost;
                string remoteAddress = Request.Form.RemoteAddress;
                string remoteRange   = Request.Form.RemoteRange;
                string localAddress  = Request.Form.LocalAddress;
                string localRange    = Request.Form.LocalRange;
                var    model         = new VpnConfigurationModel {
                    RemoteHost  = remoteHost,
                    RemotePoint = new VpnPointModel {
                        Address = remoteAddress, Range = remoteRange
                    },
                    LocalPoint = new VpnPointModel {
                        Address = localAddress, Range = localRange
                    }
                };
                var vpnConfiguration = new VpnConfiguration();
                vpnConfiguration.Save(model);
                return(HttpStatusCode.OK);
            };
        }