Exemplo n.º 1
0
        public UnitsModule()
            : base("/units")
        {
            Get["/"] = x => {
                List <UnitModel> units = Units.All;
                return(View["page-units", units]);
            };

            Post["/mgmt/enable/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Enable(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/disable/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Disable(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/start/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Start(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/stop/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Stop(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/restart/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Restart(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Post["/mgmt/reload/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Reload(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };

            Get["/mgmt/status/{unit}"] = x => {
                string       unit = x.unit;
                CommandModel r    = Systemctl.Status(unit);
                string       json = JsonConvert.SerializeObject(r.outputTable);
                return(json);
            };
        }
Exemplo n.º 2
0
        public UnitsModule()
        {
            this.RequiresAuthentication();

            Get["/units"] = x => {
                var units = Units.All;
                return(View["page-units", units]);
            };

            Get["/units/list"] = x => {
                return(JsonConvert.SerializeObject(Units.All.OrderBy(u => u.name)));
            };

            Post["/units/mgmt/enable/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Enable(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/disable/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Disable(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/start/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Start(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/stop/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Stop(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/restart/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Restart(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Post["/units/mgmt/reload/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Reload(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };

            Get["/units/mgmt/status/{unit}"] = x => {
                string unit = x.unit;
                var    r    = Systemctl.Status(unit);
                return(JsonConvert.SerializeObject(r.outputTable));
            };
        }
Exemplo n.º 3
0
        public AppsManagementModule()
        {
            Get["/apps/management"] = x => {
                var appsConfiguration = new AppsConfiguration();

                var model = new PageAppsManagementModel {
                    AppList = appsConfiguration.Get().Apps
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/apps/setup"] = x => {
                string app = Request.Form.AppName;
                if (string.IsNullOrEmpty(app))
                {
                    return(HttpStatusCode.InternalServerError);
                }
                var appsManagement = new AppsManagement();
                appsManagement.Setup(app);
                return(HttpStatusCode.OK);
            };

            Get["/apps/status/{unit}"] = x => {
                string unitName = x.unit;
                var    status   = Systemctl.Status(unitName);
                return(Response.AsJson(status));
            };

            Get["/apps/active/{unit}"] = x => {
                string unitName = x.unit;
                var    status   = Systemctl.IsActive(unitName);
                return(Response.AsJson(status ? "active" : "inactive"));
            };

            Post["/apps/restart"] = x => {
                string unitName = Request.Form.Name;
                Systemctl.Restart(unitName);
                return(HttpStatusCode.OK);
            };

            Post["/apps/stop"] = x => {
                string unitName = Request.Form.Name;
                Systemctl.Stop(unitName);
                return(HttpStatusCode.OK);
            };
        }
Exemplo n.º 4
0
        //public static void CreateUnits() {
        //    if (Units.CheckFiles() == false) {
        //        Units.SetAnthillaSp();
        //        Units.MountFramework();
        //        Units.LaunchAnthillaSp();
        //        Units.LaunchAnthillaServer();
        //    }
        //    Systemctl.DaemonReload();
        //}

        //private static void SetDirectories() {
        //    var app = Management.DetectApps().FirstOrDefault(a => a.Name == "anthillasp");
        //    if (app == null) {
        //        ConsoleLogger.Log("no appinfo detected");
        //    }
        //    else {
        //        var dirs = Management.GetWantedDirectories(app);
        //        if (dirs.Length <= 0) {
        //            ConsoleLogger.Log("no app directory found");
        //        }
        //        else {
        //            foreach (var dir in dirs) {
        //                Directory.CreateDirectory(dir.Trim());
        //                Directory.CreateDirectory(Mount.SetDirsPath(dir.Trim()));
        //                Mount.Dir(dir.Trim());
        //            }
        //        }
        //    }
        //}

        public static void Start()
        {
            if (!Systemctl.Status("app-anthillasp-01-prepare.service").output.Contains("Active: active (running)"))
            {
                Systemctl.Start("app-anthillasp-01-prepare.service");
            }

            if (!Systemctl.Status("app-anthillasp-02-mount.service").output.Contains("Active: active (running)"))
            {
                Systemctl.Start("app-anthillasp-02-mount.service");
            }

            if (!Systemctl.Status("app-anthillasp-03-srv-launcher.service").output.Contains("Active: active (running)"))
            {
                Systemctl.Start("app-anthillasp-03-srv-launcher.service");
            }

            if (!Systemctl.Status("app-anthillasp-04-wui-launcher.service").output.Contains("Active: active (running)"))
            {
                Systemctl.Start("app-anthillasp-04-wui-launcher.service");
            }
        }
Exemplo n.º 5
0
        private static string StatusNetworkdDir()
        {
            var r = Systemctl.Status("systemd-networkd");

            return(r.output);
        }
Exemplo n.º 6
0
 public static bool IsActiveAnthillaServer()
 {
     return(Systemctl.Status("app-anthillasp-03-srv-launcher.service").output.Contains("Active: active"));
 }
Exemplo n.º 7
0
 public static string AnthillaServer()
 {
     return(Systemctl.Status("app-anthillasp-03-srv-launcher.service").output);
 }
Exemplo n.º 8
0
 public static string AnthillaSp()
 {
     return(Systemctl.Status("app-anthillasp-04-wui-launcher.service").output);
 }
Exemplo n.º 9
0
 public static CommandModel StatusAnthillaAS()
 {
     return(Systemctl.Status("anthillaas.service"));
 }
Exemplo n.º 10
0
 public static CommandModel StatusAnthillaFirewall()
 {
     return(Systemctl.Status("anthillafirewall.service"));
 }
Exemplo n.º 11
0
 public static CommandModel StatusAnthillaStorage()
 {
     return(Systemctl.Status("anthillastorage.service"));
 }
Exemplo n.º 12
0
 public static CommandModel StatusAnthillaServer()
 {
     return(Systemctl.Status("anthillaserver.service"));
 }
Exemplo n.º 13
0
        public AppsModule()
            : base("/apps")
        {
            this.RequiresAuthentication();

            Get["/"] = x => {
                return(View["_page-apps"]);
            };

            Get["/launch"] = x => {
                ConsoleLogger.Log(">> App >> AnthillaSP");
                ConsoleLogger.Log(">> Check squashfs");
                var b = AnthillaSP.Setting.CheckSquash();
                if (b == false)
                {
                    ConsoleLogger.Warn(">> Squashfs does not exist!");
                    return(Response.AsJson(b));
                }
                else
                {
                    ConsoleLogger.Log(">> Mount squashfs in /framework/anthillasp");
                    AnthillaSP.Setting.MountSquash();
                    ConsoleLogger.Log(">> Create AnthillaSP units in /mnt/cdrom/Overlay/anthillasp/");
                    AnthillaSP.Setting.CreateUnits();
                    return(Response.AsJson(true));
                }
            };

            Get["/start/sp"] = x => {
                var start = Command.Launch("mono", "/framework/anthillasp/anthillasp/AnthillaSP.exe &").output;
                return(Response.AsJson(start));
            };

            Get["/start/server"] = x => {
                var start = Command.Launch("mono", "/framework/anthillasp/anthillaserver/AnthillaServer.exe &").output;
                return(Response.AsJson(start));
            };

            //Get["/start/sp"] = x => {
            //    var start = Systemctl.Start("anthillasp-launcher.service");
            //    return Response.AsJson(start);
            //};

            //Get["/start/server"] = x => {
            //    var start = Systemctl.Start("anthillaserver-launcher.service");
            //    return Response.AsJson(start);
            //};

            Get["/stop/sp"] = x => {
                var stop = Systemctl.Stop("anthillasp-launcher.service");
                return(Response.AsJson(stop));
            };

            Get["/stop/server"] = x => {
                var stop = Systemctl.Stop("anthillaserver-launcher.service");
                return(Response.AsJson(stop));
            };

            Get["/status/sp"] = x => {
                var status = Systemctl.Status("anthillasp-launcher.service");
                return(Response.AsJson(status));
            };

            Get["/status/server"] = x => {
                var status = Systemctl.Status("anthillaserver-launcher.service");
                return(Response.AsJson(status));
            };
        }