Ejemplo n.º 1
0
        public static bool CommandAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 3 || url.Split('?')[1] != "command")
                return false;

            p.writeSuccess("text/html");
            string command = url.Split('?') [2].Replace("%20", " ");
            NINSS.API.Server.Instance.RunCommand(command);
            p.outputStream.WriteLine("true");
            return true;
        }
Ejemplo n.º 2
0
        public static bool ConfigAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 5 || url.Split('?')[1] != "config")
                return false;

            p.writeSuccess("text/html");
            NINSS.API.Config config = new NINSS.API.Config(url.Split('?')[2]);
            string name = url.Split('?')[3];
            string value = url.Split('?')[4].Replace("%20", " ");
            if(value == "get")
            {
                value = config.GetValue(name);
                if(value == null)
                    value = "null";
                p.outputStream.WriteLine(value);
            }
            else
            {
                config.SetValue(name, value);
                config.SaveConfig(url.Split('?')[2]);
                p.outputStream.WriteLine("true");
            }
            return true;
        }
Ejemplo n.º 3
0
 public void listen()
 {
     try
     {
         listener = new TcpListener(new IPEndPoint(ip, port));
         listener.Start();
         while (is_active)
         {
             TcpClient s = listener.AcceptTcpClient();
             HttpProcessor processor = new HttpProcessor(s, this);
             Thread thread = new Thread(new ThreadStart(processor.process));
             thread.Start();
             Thread.Sleep(1);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("WebUI Webserver error!\nMessage:\n"+e.Message+"\nStacktrace:\n"+e.StackTrace);
         if(e.InnerException != null)
             Console.WriteLine("InnerException:\nMessage:\n"+e.InnerException.Message+"\nStacktrace:\n"+e.InnerException.StackTrace);
     }
 }
Ejemplo n.º 4
0
 public abstract void HandleGETRequest(HttpProcessor p);
Ejemplo n.º 5
0
 public override void HandleGETRequest(HttpProcessor p)
 {
     string file = p.http_url.Trim(' ', '/');
     if (OnRequest != null)
     {
         foreach (RequestAction _action in OnRequest.GetInvocationList())
         {
             if (_action(file, p))
                 return;
         }
     }
     if (file == "")
     {
         file = "index.html";
     }
     file = AppDomain.CurrentDomain.BaseDirectory+"plugins\\WebUI\\"+file.Split('?')[0];
     if(!System.IO.File.Exists(file))
     {
         p.writeSuccess("text/html");
         p.outputStream.WriteLine("<html><body><h1>404 Not found!</h1></body></html>");
     }
     else
     {
         if (mineTypes.ContainsKey(file.Split('.') [file.Split('.').Length - 1]))
         {
             p.writeSuccess(mineTypes [file.Split('.') [file.Split('.').Length - 1]]);
         }
         else
         {
             p.writeSuccess("text/" + file.Split('.') [file.Split('.').Length - 1]);
         }
         foreach (string line in System.IO.File.ReadAllLines(file))
         {
             p.outputStream.WriteLine(line);
         }
     }
 }
Ejemplo n.º 6
0
        public static bool PluginsAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 2 || url.Split('?')[1] != "plugins")
                return false;

            string plugins = "";
            foreach (INinssPlugin plugin in NINSS.MainClass.pluginManager.Plugins)
            {
                plugins += plugin.Name + ",";
            }
            p.outputStream.WriteLine(plugins.Trim(','));
            return true;
        }
Ejemplo n.º 7
0
        public static bool LogAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 2 || url.Split('?')[1] != "log")
                return false;

            System.IO.File.Copy("logs\\latest.log", "plugins\\WebUI\\log.log");
            foreach (string line in System.IO.File.ReadAllLines("plugins\\WebUI\\log.log"))
            {
                p.outputStream.WriteLine(line);
            }
            System.IO.File.Delete("plugins\\WebUI\\log.log");
            return true;
        }
Ejemplo n.º 8
0
        public static bool ConfigsAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 2 || url.Split('?')[1] != "configlist")
                return false;

            string values = "";
            foreach (string file in System.IO.Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory+"plugins\\configs"))
            {
                values += file.Split('\\') [file.Split('\\').Length - 1].Replace(".xml", "") + ",";
            }
            p.outputStream.WriteLine(values.Trim(','));
            return true;
        }
Ejemplo n.º 9
0
        public static bool ConfigListAction(string url, HttpProcessor p)
        {
            if(url.Split('?').Length != 3 || url.Split('?')[1] != "configvalues")
                return false;

            p.writeSuccess("text/html");
            string values = "";
            foreach (string val in new NINSS.API.Config(url.Split('?')[2]).GetValues())
            {
                values += val + ",";
            }
            p.outputStream.WriteLine(values.Trim(','));
            return true;
        }