public ActionResult BrowseDirectory(string pp)
        {
            ManagementConsoleAuthentication.VerifyTokenCookie(this);

            pp = pp ?? string.Empty;
            var physicalPath = Encoding.UTF8.GetString(EncryptedBase64.FromEncryptedBase64String(pp));

            if (string.IsNullOrEmpty(physicalPath))
            {
                physicalPath = Server.MapPath("~");
            }

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            sb.Append("<h2>" + HttpUtility.HtmlEncode(physicalPath) + "</h2>");
            sb.Append("<a href=\"" + Url.Action("ZipDirectory", new { pp = EncryptedBase64.ToEncryptedBase64String(Encoding.UTF8.GetBytes(physicalPath)) }) + "\">zip</a>");
            sb.Append("<table>");
            // Directories
            var directories = from d in Directory.GetDirectories(physicalPath)
                              orderby d ascending
                              select d;

            foreach (var directory in directories)
            {
                sb.Append("<tr><td>D</td><td><a href=\"");
                sb.Append(Url.Action("BrowseDirectory", new { pp = EncryptedBase64.ToEncryptedBase64String(Encoding.UTF8.GetBytes(directory)) }));
                sb.Append("\">");
                sb.Append(HttpUtility.HtmlEncode(Path.GetFileName(directory)));
                sb.Append("</a></td></tr>");
            }
            sb.Append("</table>");

            // Files
            sb.Append("<table>");
            // Directories
            var files = from d in Directory.GetFiles(physicalPath)
                        orderby d ascending
                        select d;

            foreach (var file in files)
            {
                sb.Append("<tr><td>F</td><td><a href=\"");
                sb.Append(Url.Action("DownloadFile", new { pp = EncryptedBase64.ToEncryptedBase64String(Encoding.UTF8.GetBytes(file)) }));
                sb.Append("\">");
                sb.Append(HttpUtility.HtmlEncode(Path.GetFileName(file)));
                sb.Append("</a></td></tr>");
            }
            sb.Append("</table>");
            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
        public ActionResult SignIn()
        {
            var sb = new StringBuilder();

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            sb.Append("<form method=\"post\" action=\"");
            sb.Append(Url.Action("GetPortal"));
            sb.Append("\" >PIN:<input id=\"pin\" name=\"pin\" type=\"password\" /><input type=\"submit\" value=\"SignIn\" /></form>");
            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
示例#3
0
        public ActionResult GetTables(string ask, string csk, string eb64cs)
        {
            ManagementConsoleAuthentication.VerifyTokenCookie(this);

            string connectionString;

            if (!string.IsNullOrEmpty(ask))
            {
                connectionString = ConfigurationCenter.Global[ask];
            }
            else if (!string.IsNullOrEmpty(csk))
            {
                connectionString = WebConfigurationManager.ConnectionStrings[csk].ConnectionString;
            }
            else
            {
                connectionString = Encoding.UTF8.GetString(EncryptedBase64.FromEncryptedBase64String(eb64cs));
            }

            var tables = new List <string>();

            DbHelper.ExecuteReader(
                connectionString,
                "SELECT [name] FROM sys.tables",
                reader =>
            {
                tables.Add((string)reader[0]);
            }
                );

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            sb.Append("<h3>Tables</h3><br/>");
            sb.Append("<table>");
            foreach (var table in tables)
            {
                sb.Append("<tr><td><a href=\"");
                sb.Append(Url.Action("GetRows", new { ask = ask, csk = csk, eb64cs = eb64cs, t = table }));
                sb.Append("\">");
                sb.Append(HttpUtility.HtmlEncode(table));
                sb.Append("</a></td></tr>");
            }
            sb.Append("</table><br/>");
            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
        public ActionResult GetPortal(string pin)
        {
            var sb = new StringBuilder();

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());

            sb.Append("<a href=\"");
            sb.Append(Url.Action("DisplayCacheHits", "CacheManagement"));
            sb.Append("\">Cache</a><br/>");

            sb.Append("<a href=\"");
            sb.Append(Url.Action("BrowseDirectory", "FilesManagement"));
            sb.Append("\">File</a><br/>");

            sb.Append("<a href=\"");
            sb.Append(Url.Action("BrowseConnections", "DBManagement"));
            sb.Append("\">DB</a><br/>");

            sb.Append("<a href=\"");
            sb.Append(Url.Action("BrowseSettings", "SettingsManagement"));
            sb.Append("\">Setting</a><br/>");

            sb.Append("<a href=\"");
            sb.Append(Url.Action("BrowseLiveActions", "ActionManagement"));
            sb.Append("\">LiveActions</a><br/>");

            sb.Append("<a href=\"");
            sb.Append(Url.Action("BrowseRequests", "RequestTracker"));
            sb.Append("\">RequestTracker</a><br/>");

            sb.Append("</body></html>");

            var cookie = ManagementConsoleAuthentication.GenerateTokenCookie(pin);

            this.HttpContext.Response.Cookies.Add(cookie);

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
        public ActionResult BrowseSettings()
        {
            ManagementConsoleAuthentication.VerifyTokenCookie(this);

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            // Local
            sb.Append("<h3>Local</h3><br/>");
            sb.Append("<table>");
            foreach (var key in ConfigurationCenter.Local.DiscoverAllKeys())
            {
                sb.Append("<tr><td>");
                sb.Append(HttpUtility.HtmlEncode(key));
                sb.Append("</td><td>");
                sb.Append(ConfigurationCenter.Local[key] ?? "(null)");
                sb.Append("</td></tr>");
            }
            sb.Append("</table><br/>");

            // Global
            sb.Append("<h3>Global</h3><br/>");
            sb.Append("<table>");
            foreach (var key in ConfigurationCenter.Global.DiscoverAllKeys())
            {
                sb.Append("<tr><td>");
                sb.Append(HttpUtility.HtmlEncode(key));
                sb.Append("</td><td>");
                sb.Append(ConfigurationCenter.Global[key] ?? "(null)");
                sb.Append("</td></tr>");
            }
            sb.Append("</table><br/>");

            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
示例#6
0
        public ActionResult BrowseConnections()
        {
            ManagementConsoleAuthentication.VerifyTokenCookie(this);

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            sb.Append("<h3>AppSettings</h3><br/>");
            sb.Append("<table>");
            foreach (var key in ConfigurationCenter.Global.DiscoverAllKeys())
            {
                sb.Append("<tr><td><a href=\"");
                sb.Append(Url.Action("GetTables", new { ask = key })); // ask: app setting key
                sb.Append("\">");
                sb.Append(HttpUtility.HtmlEncode(key));
                sb.Append("</a></td></tr>");
            }
            sb.Append("</table><br/>");

            // Files
            sb.Append("<h3>Conn</h3><br/>");
            sb.Append("<table>");
            for (int i = 0; i < WebConfigurationManager.ConnectionStrings.Count; i++)
            {
                var v = WebConfigurationManager.ConnectionStrings[i].Name;
                sb.Append("<tr><td><a href=\"");
                sb.Append(Url.Action("GetTables", new { csk = v })); // csk: connection string key
                sb.Append("\">");
                sb.Append(HttpUtility.HtmlEncode(v));
                sb.Append("</a></td></tr>");
            }
            sb.Append("</table><br/>");
            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }
示例#7
0
        public ActionResult GetRows(string ask, string csk, string eb64cs, string t)
        {
            ManagementConsoleAuthentication.VerifyTokenCookie(this);

            string connectionString;

            if (!string.IsNullOrEmpty(ask))
            {
                connectionString = ConfigurationCenter.Global[ask];
            }
            else if (!string.IsNullOrEmpty(csk))
            {
                connectionString = WebConfigurationManager.ConnectionStrings[csk].ConnectionString;
            }
            else
            {
                connectionString = Encoding.UTF8.GetString(EncryptedBase64.FromEncryptedBase64String(eb64cs));
            }

            // To avoid sql injection
            t = t.Replace("\'", string.Empty);
            t = t.Replace("\"", string.Empty);
            t = t.Replace(" ", string.Empty);

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("<html><body>");
            sb.Append(ManagementUtility.BuildHeaderHtml());
            sb.Append("<h3>" + HttpUtility.HtmlEncode(t) + "</h3><br/>");
            sb.Append("<table>");

            DataTable schema = null;

            DbHelper.ExecuteReader(
                connectionString,
                "SELECT * FROM " + t,
                reader =>
            {
                if (schema == null)
                {
                    schema = reader.GetSchemaTable();
                    sb.Append("<tr>");
                    foreach (DataRow row in schema.Rows)
                    {
                        sb.Append("<td>");
                        sb.Append(row["ColumnName"].ToString());
                        sb.Append("</td>");
                    }
                    sb.Append("</tr>");
                }

                sb.Append("<tr>");
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    sb.Append("<td>");
                    sb.Append(reader[i].ToString());
                    sb.Append("</td>");
                }
                sb.Append("</tr>");
            }
                );

            sb.Append("</table><br/>");
            sb.Append("</body></html>");

            return(File(Encoding.UTF8.GetBytes(sb.ToString()), "text/html"));
        }