Esempio n. 1
0
        public override void onPageInitialize()
        {
            HttpHead.AddCSS("https://blaze-games.com/codemirror/codemirror.css");
            HttpHead.AddCSS("https://blaze-games.com/codemirror/ambiance.css");
            HttpHead.AddCSS("https://blaze-games.com/codemirror/dialog.css");
            HttpHead.AddCSS("https://blaze-games.com/datatable/datatable.css");
            HttpHead.AddCSS("https://blaze-games.com/datatable/ui_custom.css");

            HttpHead.AddJS("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/codemirror.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/clike.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/css.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/xml.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/htmlmixed.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/javascript.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/continuecomment.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/dialog.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/search.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/searchcursor.js");
            HttpHead.AddJS("https://blaze-games.com/datatable/datatable.js");

            if (Utilities.POST("Act") == "GetInfo" && Utilities.POST("ID") != "")
            {
                string PageInfo = "";
                Page InfoPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);

                if (!InfoPage.Exists)
                    PageInfo += "No page found!";
                else
                {
                    TimeSpan LastUpdate = DateTime.Now - InfoPage.LastUpdate;
                    PageInfo += "ID: " + InfoPage.ID + "\r\n";
                    PageInfo += "Url: " + InfoPage.Url + "\r\n";
                    PageInfo += "Last Update: " + Utilities.GetTimeSpan(LastUpdate);
                }

                Http.Response.Write(PageInfo);
                Http.Response.End();
            }

            if (Utilities.POST("Act") == "CompileAll")
            {
                MySqlCommand PageFetchQuery = new MySqlCommand("SELECT ID FROM pages ORDER BY LastUpdate DESC", SqlConnection);
                MySqlDataReader PageFetchReader = PageFetchQuery.ExecuteReader();
                List<int> Pages = new List<int>();

                while (PageFetchReader.Read())
                {
                    int ID = PageFetchReader.GetInt32("ID");
                    Pages.Add(ID);
                }

                PageFetchReader.Close();

                foreach (int PageID in Pages)
                {
                    Page page = new Page(PageID, SqlConnection);
                    if(page.Locked)
                        Http.Response.Write(PageID + " locked.\r\n");
                    else if (page.Compile() == null)
                        Http.Response.Write(PageID + " compiled.\r\n");
                    else
                        Http.Response.Write(PageID + " compile failed.\r\n");
                }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "UpdatePage")
            {
                try
                {
                    if (Utilities.POST("ID") != "" && Utilities.POST("Url") != "" && Utilities.POST("Domain") != "" && Utilities.POST("References") != "" && Utilities.POST("MinimumAuthorization") != "" && Utilities.POST("RequireSecure") != "" && Utilities.POST("Code") != "")
                    {
                        Page EditPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                        if (EditPage.Exists)
                        {
                            if (EditPage.IsEditing != LoggedInMember.ID)
                                Http.Response.Write("4");
                            else
                            {
                                EditPage.Url = Utilities.POST("Url").ToLower();
                                EditPage.Domain = Utilities.POST("Domain").ToLower();
                                EditPage.References = Utilities.POST("References").Split(',');
                                EditPage.MinimumAuthorization = Convert.ToInt32(Utilities.POST("MinimumAuthorization"));
                                EditPage.RequireSecure = Convert.ToBoolean(Utilities.POST("RequireSecure"));
                                EditPage.Code = Utilities.POST("Code");
                                EditPage.PageCSS = Utilities.POST("Code_CSS");
                                EditPage.PageJS = Utilities.POST("Code_JS");
                                EditPage.PageHTML = Utilities.POST("Code_HTML");

                                if (EditPage.Compile() == null)
                                    Http.Response.Write("0");
                                else 
                                    Http.Response.Write("3");
                            }
                        }
                        else
                            Http.Response.Write("1");

                    }
                    else
                        Http.Response.Write("2");
                }
                catch (Exception ex) { Http.Response.Write(ex.Message); }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "CreatePage")
            {
                if (Utilities.POST("Url") != "" && Utilities.POST("References") != "" && Utilities.POST("MinimumAuthorization") != "" && Utilities.POST("RequireSecure") != "" && Utilities.POST("Code") != "")
                {
                    Page CreatedPage = Page.Create(SqlConnection, Utilities.POST("Url").ToLower(), Utilities.POST("Domain").ToLower(), Utilities.POST("Code"), Utilities.POST("References").Split(','), Convert.ToInt32(Utilities.POST("MinimumAuthorization")), Convert.ToBoolean(Utilities.POST("RequireSecure")), Utilities.POST("Code_CSS"), Utilities.POST("Code_JS"), Utilities.POST("Code_HTML"));
                    Http.Response.Write(CreatedPage.ID.ToString());
                }
                else
                    Http.Response.Write("0");

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "DeletePage" && Utilities.POST("ID") != "")
            {
                Page DeletePage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                DeletePage.Delete();
                Http.Response.End();
            }

            if (Utilities.POST("Act") == "UnlockPage" && Utilities.POST("ID") != "")
            {
                Page EditPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                if (EditPage.Exists && EditPage.IsEditing != 0)
                {
                    EditPage.IsEditing = 0;
                    EditPage.Save();
                }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "VerifyCode")
            {
                if (Utilities.POST("Code") != "" && Utilities.POST("References") != "" && Utilities.POST("Type") != "")
                {
                    if (Utilities.POST("Type") == "text/x-csharp")
                    {
                        CodeDomProvider CodeCompiler = CodeDomProvider.CreateProvider("CSharp");
                        CompilerParameters CodeParameters = new CompilerParameters();
                        CodeParameters.CompilerOptions = "/lib:C:\\inetpub\\wwwroot\\bin";
                        CodeParameters.GenerateInMemory = false;

                        CodeParameters.ReferencedAssemblies.AddRange(Utilities.POST("References").Split(','));
                        CodeParameters.WarningLevel = 4;


                        /* Build the assembly */
                        string Code = Utilities.POST("Code");
                        BlazeGames_CodeCompiler BGxCodeCompiler = new BlazeGames_CodeCompiler();
                        Code = BGxCodeCompiler.CompileToCSharp(Code);

                        CompilerResults CodeCompiled = CodeCompiler.CompileAssemblyFromSource(CodeParameters, Code);

                        /* Check for errors */
                        if (CodeCompiled.Errors.HasErrors)
                        {
                            foreach (CompilerError Error in CodeCompiled.Errors)
                            {
                                if (Error.IsWarning)
                                    Http.Response.Write("2:");
                                else
                                    Http.Response.Write("1:");

                                Http.Response.Write(Error.Line + ":");
                                Http.Response.Write(Error.Column + ":");
                                Http.Response.Write(Error.ErrorText + "\r\n");
                            }
                        }
                        else
                            Http.Response.Write("0");
                    }
                    else if (Utilities.POST("Type") == "text/x-html")
                        Http.Response.Write("0");
                    else
                        Http.Response.Write("3");
                }
                else
                    Http.Response.Write("3");
                Http.Response.End();
            }
        }
Esempio n. 2
0
        public override void onPageInitialize()
        {
            HttpHead.AddCSS("https://blaze-games.com/codemirror/codemirror.css");
            HttpHead.AddCSS("https://blaze-games.com/codemirror/ambiance.css");
            HttpHead.AddCSS("https://blaze-games.com/codemirror/dialog.css");
            HttpHead.AddCSS("https://blaze-games.com/datatable/datatable.css");
            HttpHead.AddCSS("https://blaze-games.com/datatable/ui_custom.css");

            HttpHead.AddJS("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/codemirror.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/clike.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/css.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/xml.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/htmlmixed.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/javascript.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/continuecomment.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/dialog.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/search.js");
            HttpHead.AddJS("https://blaze-games.com/codemirror/searchcursor.js");
            HttpHead.AddJS("https://blaze-games.com/datatable/datatable.js");

            if (Utilities.POST("Act") == "GetInfo" && Utilities.POST("ID") != "")
            {
                string PageInfo = "";
                Page   InfoPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);

                if (!InfoPage.Exists)
                {
                    PageInfo += "No page found!";
                }
                else
                {
                    TimeSpan LastUpdate = DateTime.Now - InfoPage.LastUpdate;
                    PageInfo += "ID: " + InfoPage.ID + "\r\n";
                    PageInfo += "Url: " + InfoPage.Url + "\r\n";
                    PageInfo += "Last Update: " + Utilities.GetTimeSpan(LastUpdate);
                }

                Http.Response.Write(PageInfo);
                Http.Response.End();
            }

            if (Utilities.POST("Act") == "CompileAll")
            {
                MySqlCommand    PageFetchQuery  = new MySqlCommand("SELECT ID FROM pages ORDER BY LastUpdate DESC", SqlConnection);
                MySqlDataReader PageFetchReader = PageFetchQuery.ExecuteReader();
                List <int>      Pages           = new List <int>();

                while (PageFetchReader.Read())
                {
                    int ID = PageFetchReader.GetInt32("ID");
                    Pages.Add(ID);
                }

                PageFetchReader.Close();

                foreach (int PageID in Pages)
                {
                    Page page = new Page(PageID, SqlConnection);
                    if (page.Locked)
                    {
                        Http.Response.Write(PageID + " locked.\r\n");
                    }
                    else if (page.Compile() == null)
                    {
                        Http.Response.Write(PageID + " compiled.\r\n");
                    }
                    else
                    {
                        Http.Response.Write(PageID + " compile failed.\r\n");
                    }
                }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "UpdatePage")
            {
                try
                {
                    if (Utilities.POST("ID") != "" && Utilities.POST("Url") != "" && Utilities.POST("Domain") != "" && Utilities.POST("References") != "" && Utilities.POST("MinimumAuthorization") != "" && Utilities.POST("RequireSecure") != "" && Utilities.POST("Code") != "")
                    {
                        Page EditPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                        if (EditPage.Exists)
                        {
                            if (EditPage.IsEditing != LoggedInMember.ID)
                            {
                                Http.Response.Write("4");
                            }
                            else
                            {
                                EditPage.Url                  = Utilities.POST("Url").ToLower();
                                EditPage.Domain               = Utilities.POST("Domain").ToLower();
                                EditPage.References           = Utilities.POST("References").Split(',');
                                EditPage.MinimumAuthorization = Convert.ToInt32(Utilities.POST("MinimumAuthorization"));
                                EditPage.RequireSecure        = Convert.ToBoolean(Utilities.POST("RequireSecure"));
                                EditPage.Code                 = Utilities.POST("Code");
                                EditPage.PageCSS              = Utilities.POST("Code_CSS");
                                EditPage.PageJS               = Utilities.POST("Code_JS");
                                EditPage.PageHTML             = Utilities.POST("Code_HTML");

                                if (EditPage.Compile() == null)
                                {
                                    Http.Response.Write("0");
                                }
                                else
                                {
                                    Http.Response.Write("3");
                                }
                            }
                        }
                        else
                        {
                            Http.Response.Write("1");
                        }
                    }
                    else
                    {
                        Http.Response.Write("2");
                    }
                }
                catch (Exception ex) { Http.Response.Write(ex.Message); }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "CreatePage")
            {
                if (Utilities.POST("Url") != "" && Utilities.POST("References") != "" && Utilities.POST("MinimumAuthorization") != "" && Utilities.POST("RequireSecure") != "" && Utilities.POST("Code") != "")
                {
                    Page CreatedPage = Page.Create(SqlConnection, Utilities.POST("Url").ToLower(), Utilities.POST("Domain").ToLower(), Utilities.POST("Code"), Utilities.POST("References").Split(','), Convert.ToInt32(Utilities.POST("MinimumAuthorization")), Convert.ToBoolean(Utilities.POST("RequireSecure")), Utilities.POST("Code_CSS"), Utilities.POST("Code_JS"), Utilities.POST("Code_HTML"));
                    Http.Response.Write(CreatedPage.ID.ToString());
                }
                else
                {
                    Http.Response.Write("0");
                }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "DeletePage" && Utilities.POST("ID") != "")
            {
                Page DeletePage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                DeletePage.Delete();
                Http.Response.End();
            }

            if (Utilities.POST("Act") == "UnlockPage" && Utilities.POST("ID") != "")
            {
                Page EditPage = new Page(Convert.ToInt32(Utilities.POST("ID")), SqlConnection);
                if (EditPage.Exists && EditPage.IsEditing != 0)
                {
                    EditPage.IsEditing = 0;
                    EditPage.Save();
                }

                Http.Response.End();
            }

            if (Utilities.POST("Act") == "VerifyCode")
            {
                if (Utilities.POST("Code") != "" && Utilities.POST("References") != "" && Utilities.POST("Type") != "")
                {
                    if (Utilities.POST("Type") == "text/x-csharp")
                    {
                        CodeDomProvider    CodeCompiler   = CodeDomProvider.CreateProvider("CSharp");
                        CompilerParameters CodeParameters = new CompilerParameters();
                        CodeParameters.CompilerOptions  = "/lib:C:\\inetpub\\wwwroot\\bin";
                        CodeParameters.GenerateInMemory = false;

                        CodeParameters.ReferencedAssemblies.AddRange(Utilities.POST("References").Split(','));
                        CodeParameters.WarningLevel = 4;


                        /* Build the assembly */
                        string Code = Utilities.POST("Code");
                        BlazeGames_CodeCompiler BGxCodeCompiler = new BlazeGames_CodeCompiler();
                        Code = BGxCodeCompiler.CompileToCSharp(Code);

                        CompilerResults CodeCompiled = CodeCompiler.CompileAssemblyFromSource(CodeParameters, Code);

                        /* Check for errors */
                        if (CodeCompiled.Errors.HasErrors)
                        {
                            foreach (CompilerError Error in CodeCompiled.Errors)
                            {
                                if (Error.IsWarning)
                                {
                                    Http.Response.Write("2:");
                                }
                                else
                                {
                                    Http.Response.Write("1:");
                                }

                                Http.Response.Write(Error.Line + ":");
                                Http.Response.Write(Error.Column + ":");
                                Http.Response.Write(Error.ErrorText + "\r\n");
                            }
                        }
                        else
                        {
                            Http.Response.Write("0");
                        }
                    }
                    else if (Utilities.POST("Type") == "text/x-html")
                    {
                        Http.Response.Write("0");
                    }
                    else
                    {
                        Http.Response.Write("3");
                    }
                }
                else
                {
                    Http.Response.Write("3");
                }
                Http.Response.End();
            }
        }