コード例 #1
0
 /*
  * This function processes a given request for an embedded file.
  * It finds the file from the list, sets the response type appropriately.
  * If its uncompresssed css or js, checks the cache, if not compresses it,
  * and caches it.  It then writes the given file out to the response stream.
  */
 void IRequestHandler.ProcessRequest(HttpRequest request, Site site)
 {
     request.ResponseHeaders["Cache-Control"] = "Private";
     if (request.Headers["If-Modified-Since"] != null && DateTime.Parse(request.Headers["If-Modified-Since"]) >= site.StartTimestamp)
         request.ResponseStatus = HttpStatusCodes.Not_Modified;
     else
     {
         sEmbeddedFile file = site.EmbeddedFiles[request.URL.AbsolutePath];
         Stream str = null;
         switch (file.FileType)
         {
             case EmbeddedFileTypes.Compressed_Css:
                 string comCss = Utility.ReadEmbeddedResource(file.DLLPath);
                 if (comCss == null)
                     request.ResponseStatus = HttpStatusCodes.Not_Found;
                 else
                 {
                     request.ResponseHeaders.ContentType = "text/css";
                     request.ResponseWriter.Write(comCss);
                 }
                 break;
             case EmbeddedFileTypes.Compressed_Javascript:
                 string comJs = Utility.ReadEmbeddedResource(file.DLLPath);
                 if (comJs == null)
                     request.ResponseStatus = HttpStatusCodes.Not_Found;
                 else
                 {
                     request.ResponseHeaders.ContentType = "text/javascript";
                     request.ResponseWriter.Write(comJs);
                 }
                 break;
             case EmbeddedFileTypes.Css:
                 bool loadCss = true;
                 Monitor.Enter(_lock);
                 if (_compressedCache.ContainsKey(file.DLLPath))
                 {
                     loadCss = false;
                     request.ResponseHeaders.ContentType = "text/css";
                     request.ResponseWriter.Write(_compressedCache[file.DLLPath].Value);
                 }
                 Monitor.Exit(_lock);
                 if (loadCss)
                 {
                     string css = Utility.ReadEmbeddedResource(file.DLLPath);
                     if (css == null)
                         request.ResponseStatus = HttpStatusCodes.Not_Found;
                     else
                     {
                         request.ResponseHeaders.ContentType = "text/css";
                         Monitor.Enter(_lock);
                         if (site.CompressCSS)
                             css = CSSMinifier.Minify(css);
                         if (!_compressedCache.ContainsKey(file.DLLPath))
                         {
                             _compressedCache.Add(file.DLLPath, new CachedItemContainer(css));
                         }
                         Monitor.Exit(_lock);
                         request.ResponseWriter.Write(css);
                     }
                 }
                 break;
             case EmbeddedFileTypes.Javascript:
                 bool loadJS = true;
                 Monitor.Enter(_lock);
                 if (_compressedCache.ContainsKey(file.DLLPath))
                 {
                     loadJS = false;
                     request.ResponseHeaders.ContentType = "text/javascript";
                     request.ResponseWriter.Write(_compressedCache[file.DLLPath].Value);
                 }
                 Monitor.Exit(_lock);
                 if (loadJS)
                 {
                     string js = Utility.ReadEmbeddedResource(file.DLLPath);
                     if (js == null)
                         request.ResponseStatus = HttpStatusCodes.Not_Found;
                     else
                     {
                         request.ResponseHeaders.ContentType = "text/javascript";
                         if (site.CompressJS)
                             js = JSMinifier.Minify(js);
                         Monitor.Enter(_lock);
                         if (!_compressedCache.ContainsKey(file.DLLPath))
                         {
                             _compressedCache.Add(file.DLLPath, new CachedItemContainer(js));
                         }
                         Monitor.Exit(_lock);
                         request.ResponseWriter.Write(js);
                     }
                 }
                 break;
             case EmbeddedFileTypes.Image:
                 str = Utility.LocateEmbededResource(file.DLLPath);
                 if (str == null)
                     request.ResponseStatus = HttpStatusCodes.Not_Found;
                 else
                 {
                     request.ResponseHeaders.ContentType = "image/" + file.ImageType.Value.ToString();
                     request.UseResponseStream(str);
                 }
                 break;
             case EmbeddedFileTypes.Text:
                 str = Utility.LocateEmbededResource(file.DLLPath);
                 if (str == null)
                     request.ResponseStatus = HttpStatusCodes.Not_Found;
                 else
                     request.UseResponseStream(str);
                 break;
         }
     }
 }
コード例 #2
0
 public void ProcessRequest(HttpRequest request, Site site)
 {
     if (request.URL.AbsolutePath == _fileIconPath)
     {
         request.UseResponseStream(_browserImages[_fileIconPath]);
         request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension("png");
         return;
     }
     else if (request.URL.AbsolutePath == _folderIconPath)
     {
         request.UseResponseStream(_browserImages[_folderIconPath]);
         request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension("png");
         return;
     }
     else if (request.URL.AbsolutePath == _downloadIconPath)
     {
         request.UseResponseStream(_browserImages[_downloadIconPath]);
         request.ResponseHeaders.ContentLength = HttpUtility.GetContentTypeForExtension("png");
         return;
     }
     IDirectoryFolder idf = (IDirectoryFolder)request["IFolder"];
     string path = request.URL.AbsolutePath;
     path = path.Substring(((string)request["IFolderPath"]).Length);
     if (path.StartsWith("/"))
         path = path.Substring(1);
     IDirectoryFile ifile = null;
     IDirectoryFolder ifold = null;
     if (path == "" || path == "/")
         ifold = idf;
     else
         LocateObjectForPath((path.EndsWith("/") ? path : path + "/"), idf, out ifold, out ifile);
     if (request.Parameters["DownloadPath"] != null)
     {
         path = (path.EndsWith("/") ? path.Substring(0,path.Length-1) : path);
         if (ifile != null)
         {
             request.UseResponseStream(ifile.ContentStream);
             request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension(path.Substring(path.LastIndexOf(".")));
         }
         else
         {
             ZipFile zf = new ZipFile(path.Substring(path.LastIndexOf("/") + 1));
             string basePath = Utility.TraceFullDirectoryPath(ifold);
             zf.AddDirectory(ifold,basePath.Substring(0,basePath.Length-ifold.Name.Length));
             request.UseResponseStream(zf.ToStream());
             request.ResponseHeaders.ContentType = zf.ContentType;
             request.ResponseHeaders["Content-Disposition"] = "attachment; filename=" + zf.Name+"."+zf.Extension;
         }
     }
     else
     {
         if (ifile != null)
         {
             request.UseResponseStream(ifile.ContentStream);
             request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension(path.Substring(path.LastIndexOf(".")));
         }
         else if (ifold != null)
         {
             request.ResponseHeaders.ContentType = "text/html";
             request.ResponseWriter.Write(RenderFolderBrowser(ifold,site,request));
         }
         else
         {
             request.ResponseStatus = HttpStatusCodes.Not_Found;
             request.ResponseWriter.WriteLine("<h1>Unable to locate the folder at the path " + request.URL.AbsolutePath + "</h1>");
         }
     }
 }
コード例 #3
0
 public void HandleRequest(HttpRequest request, Site site)
 {
     File f = new File(HttpUtility.UrlDecode(request.URL.AbsolutePath.Substring(request.URL.AbsolutePath.IndexOf("RelativeFiles/") + "RelativeFiles/".Length).Replace("/",Path.DirectorySeparatorChar.ToString())));
     request.ResponseHeaders.ContentType = HttpUtility.GetContentTypeForExtension(f.FileName.Substring(f.FileName.IndexOf(".") + 1));
     request.UseResponseStream(new FileStream(f.ActualPath, FileMode.Open, FileAccess.Read, FileShare.Read));
 }
コード例 #4
0
        public void ProcessRequest(HttpRequest request, Org.Reddragonit.EmbeddedWebServer.Interfaces.Site site)
        {
            request.SetTimeout(20 * 60 * 1000);
            if (request.Parameters["FileType"] == "Backup")
            {
                string fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm") + "_";
                switch (request.Parameters["Level"])
                {
                    case "Database":
                        fileName += "database";
                        break;
                    case "Voicemail":
                        fileName += "voicemail";
                        break;
                    case "Recordings":
                        fileName += "recordings";
                        break;
                    case "Sounds":
                        fileName += "sounds";
                        break;
                    case "Script":
                        fileName += "scripts";
                        break;
                    default:
                        fileName += "complete";
                        break;

                }
                request.ResponseHeaders.ContentType = "application/octet-stream";
                request.ResponseHeaders["content-disposition"] = "attachment; filename=" + fileName + ".fscbak";
                ZipFile zf = new ZipFile(fileName);
                DirectoryInfo di;
                byte[] tmp;
                if ((request.Parameters["Level"] == "Database") || (request.Parameters["Level"] == "Complete"))
                {
                    Stream ms = new MemoryStream();
                    Org.Reddragonit.Dbpro.Backup.BackupManager.BackupDataToStream(Org.Reddragonit.Dbpro.Connections.ConnectionPoolManager.GetPool(typeof(Org.Reddragonit.FreeSwitchConfig.DataCore.DB.Phones.Extension)), ref ms);
                    zf.AddFile("database.rdpbk", ((MemoryStream)ms).ToArray());
                }
                //backup voicemail
                if ((request.Parameters["Level"] == "Voicemail") || (request.Parameters["Level"] == "Complete"))
                {
                    di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_VOICEMAIL_PATH);
                    ImportZipDirectory("voicemail", zf, di);
                    Log.Trace("Issueing voicemail backup command...");
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("DELETE FROM voicemail_msgs;");
                    foreach (Dictionary<string, string> row in Utility.SelectFromFreeswitchDB(VM_DB, VM_SELECT_QUERY))
                    {
                        sb.Append("INSERT INTO voicemail_msgs VALUES(");
                        sb.Append("'" + row["created_epoch"] + "',");
                        sb.Append("'" + row["read_epoch"] + "',");
                        sb.Append("'" + row["username"] + "',");
                        sb.Append("'" + row["domain"] + "',");
                        sb.Append("'" + row["uuid"] + "',");
                        sb.Append("'" + row["cid_name"] + "',");
                        sb.Append("'" + row["cid_number"] + "',");
                        sb.Append("'" + row["in_folder"] + "',");
                        sb.Append("'" + row["file_path"] + "',");
                        sb.Append("'" + row["message_len"] + "',");
                        sb.Append("'" + row["flags"] + "',");
                        if (row.ContainsKey("read_flags") && row["read_flags"] != null)
                            sb.Append("'" + row["read_flags"] + "',");
                        else
                            sb.Append("null,");
                        if (row.ContainsKey("forwarded_by") && row["forwarded_by"] != null)
                            sb.Append("'" + row["forwarded_by"] + "'");
                        else
                            sb.Append("null");
                        sb.AppendLine(");");
                    }
                    zf.AddFile("voicemail_restore.sql", ASCIIEncoding.ASCII.GetBytes(sb.ToString()));
                }
                //backup scripts
                if ((request.Parameters["Level"] == "Script") || (request.Parameters["Level"] == "Complete"))
                {
                    di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_SCRIPTS_DIRECTORY);
                    ImportZipDirectory("scripts", zf, di);
                }
                //backup sounds
                if ((request.Parameters["Level"] == "Sounds") || (request.Parameters["Level"] == "Complete"))
                {
                    di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_SOUNDS_DIRECTORY);
                    ImportZipDirectory("sounds", zf, di);
                }
                //backup recordings
                if ((request.Parameters["Level"] == "Recordings") || (request.Parameters["Level"] == "Complete"))
                {
                    di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar+ Constants.DEFAULT_RECORDINGS_DIRECTORY);
                    ImportZipDirectory("recordings", zf, di);
                }

                //flush and close the final zip stream
                request.UseResponseStream(zf.ToStream());
            }
            else if (request.Parameters["clazz"] != null)
            {
                Type t = Org.Reddragonit.FreeSwitchConfig.DataCore.Utility.LocateType(request.Parameters["clazz"]);
                if (t != null)
                {
                    System.Reflection.MethodInfo mi = null;
                    foreach (System.Reflection.MethodInfo m in t.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
                    {
                        if (m.Name == request.Parameters["MethodName"] && m.GetParameters().Length == 0)
                        {
                            mi = m;
                            break;
                        }
                    }
                    if (mi == null)
                    {
                        request.ResponseStatus = HttpStatusCodes.Not_Found;
                        request.ResponseWriter.Write("Unable to locate static public method " + request.Parameters["MethodName"] + " in class type " + request.Parameters["clazz"]);
                    }
                    else
                    {
                        mi.Invoke(null, new object[0]);
                    }
                }
                else
                {
                    request.ResponseStatus = HttpStatusCodes.Not_Found;
                    request.ResponseWriter.Write("Unable to locate clazz type " + request.Parameters["clazz"]);
                }
            }
            else
            {
                request.ResponseStatus = HttpStatusCodes.Not_Found;
            }
        }