Ejemplo n.º 1
0
 public void DeployModuleFile(string fileName, sFreeSwitchModuleFile file)
 {
     CoreGenerator.Lock();
     if (fileName == "modules.conf.xml")
     {
         DeployModulesFile(file);
     }
     else if (fileName == "xml_curl.conf.xml")
     {
         DeployCurlFile(file);
     }
     CoreGenerator.UnLock();
 }
Ejemplo n.º 2
0
        internal static sFreeSwitchModuleFile FixSofiaFile(sFreeSwitchModuleFile file)
        {
            string confSection = file.ConfigurationSectionString;

            if (confSection.Contains("<profiles>"))
            {
                string pre = confSection.Substring(0, confSection.IndexOf("<profiles>"));
                confSection = pre + confSection.Substring(confSection.IndexOf("</profiles>") + "</profiles>".Length);
            }
            Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.sip_profile.st"));

            CoreGenerator.Lock();
            st.SetAttribute("profiles", CoreGenerator.Profiles);
            confSection = confSection.Replace("</configuration>", st.ToString() + "</configuration>");
            CoreGenerator.UnLock();
            return(new sFreeSwitchModuleFile(file.Name, file.Description, confSection));
        }
Ejemplo n.º 3
0
        public void DeployVarsFile(string content)
        {
            CoreGenerator.Lock();
            DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR);

            if (!di.Exists)
            {
                di.Create();
            }
            FileInfo fi = new FileInfo(di.FullName + Path.DirectorySeparatorChar + "vars.xml");

            if (fi.Exists)
            {
                fi.Delete();
            }
            StreamWriter sw = new StreamWriter(fi.OpenWrite());

            sw.Write(content);
            sw.Flush();
            sw.Close();
            CoreGenerator.UnLock();
        }
        public void HandleRequest(HttpRequest request, Site site)
        {
            bool found = false;

            request.ResponseHeaders.ContentType = "text/xml";
            string confPath = request.URL.AbsolutePath.Substring((EmbeddedHandlerFactory.BASE_PATH + BASE_PATH).Length);

            if (confPath.Contains("/"))
            {
                confPath = confPath.Substring(0, confPath.IndexOf('/'));
            }
            switch (confPath)
            {
            case CONFIGURATION_PATH:
                string fileName = request.Parameters["key_value"] + ".xml";
                CoreGenerator.Lock();
                if (CoreGenerator.Modules != null)
                {
                    for (int x = 0; x < CoreGenerator.Modules.Count; x++)
                    {
                        if (CoreGenerator.Modules[x].FileName == fileName)
                        {
                            sFreeSwitchModuleFile mod = CoreGenerator.Modules[x].File;
                            if (fileName == "sofia.conf.xml")
                            {
                                mod = VirtualConfigDeployer.FixSofiaFile(mod);
                            }
                            request.ResponseWriter.Write(String.Format(CONFIGURATION_FILE_TEMPLATE, request.Parameters["section"], mod.ToConfigurationString(request.Parameters["tag_name"])));
                            found = true;
                            break;
                        }
                    }
                }
                if (!found)
                {
                    request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                }
                CoreGenerator.UnLock();
                break;

            case DIRECTORY_PATH:
                ProcessDirectoryRequest(request);
                break;

            case DIALPLAN_PATH:
                string cont = VirtualConfigDeployer.GetCachedProfile(request.Parameters["variable_sofia_profile_name"]);
                if (cont != null)
                {
                    request.ResponseWriter.Write(cont);
                }
                else
                {
                    CoreGenerator.Lock();
                    Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.Context.st"));
                    for (int y = 0; y < CoreGenerator.Profiles.Count; y++)
                    {
                        if (CoreGenerator.Profiles[y].Name == request.Parameters["variable_sofia_profile_name"])
                        {
                            st.SetAttribute("context", CoreGenerator.Profiles[y].Context);
                            st.SetAttribute("contextName", request.Parameters["Caller-Context"]);
                            st.SetAttribute("destinationNumber", request.Parameters["Caller-Destination-Number"]);
                            System.Diagnostics.Debug.WriteLine(st.ToString());
                            request.ResponseWriter.Write(st.ToString());
                            VirtualConfigDeployer.CacheProfile(request.Parameters["variable_sofia_profile_name"], st.ToString());
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                    }
                    CoreGenerator.UnLock();
                }
                break;
            }
        }
        private void ProcessDirectoryRequest(HttpRequest request)
        {
            switch (request.Parameters["Event-Name"])
            {
            case "REQUEST_PARAMS":
                if (request.Parameters["purpose"] != null)
                {
                    switch (request.Parameters["purpose"])
                    {
                    case "gateways":
                        Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.domain.st"));
                        CoreGenerator.Lock();
                        st.SetAttribute("domains", CoreGenerator.Domains);
                        st.SetAttribute("section", request.Parameters["section"]);
                        request.ResponseWriter.Write(st.ToString());
                        CoreGenerator.UnLock();
                        break;

                    default:
                        request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                        break;
                    }
                }
                else
                {
                    sDeployedExtension ext = null;
                    sDeployedDomain    dom = null;
                    switch (request.Parameters["action"])
                    {
                    case "sip_auth":
                        CoreGenerator.Lock();
                        for (var x = 0; x < CoreGenerator.Extensions.Count; x++)
                        {
                            if ((CoreGenerator.Extensions[x].Number == request.Parameters["user"]) &&
                                (CoreGenerator.Extensions[x].DomainName == request.Parameters["domain"]))
                            {
                                ext = CoreGenerator.Extensions[x];
                                break;
                            }
                        }
                        if (ext != null)
                        {
                            for (int x = 0; x < CoreGenerator.Domains.Count; x++)
                            {
                                if (CoreGenerator.Domains[x].Name == ext.DomainName)
                                {
                                    dom = CoreGenerator.Domains[x];
                                    break;
                                }
                            }
                        }
                        CoreGenerator.UnLock();
                        if (ext == null)
                        {
                            request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                        }
                        else
                        {
                            Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.Extension.st"));
                            st.SetAttribute("ext", ext);
                            st.SetAttribute("domain", dom);
                            st.SetAttribute("section", request.Parameters["section"]);
                            request.ResponseWriter.Write(st.ToString());
                        }
                        break;

                    case "reverse-auth-lookup":
                        CoreGenerator.Lock();
                        for (var x = 0; x < CoreGenerator.Extensions.Count; x++)
                        {
                            if ((CoreGenerator.Extensions[x].Number == request.Parameters["user"]) &&
                                (CoreGenerator.Extensions[x].DomainName == request.Parameters["domain"]))
                            {
                                ext = CoreGenerator.Extensions[x];
                                break;
                            }
                        }
                        CoreGenerator.UnLock();
                        if (ext == null)
                        {
                            request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                        }
                        else
                        {
                            Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.ReverseAuth.st"));
                            st.SetAttribute("extension", ext);
                            st.SetAttribute("section", request.Parameters["section"]);
                            request.ResponseWriter.Write(st.ToString());
                        }
                        break;

                    default:
                        request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                        break;
                    }
                }
                break;

            case "GENERAL":
                if (request.Parameters["action"] == "message-count")
                {
                    string mcont = VirtualConfigDeployer.GetCachedMessageCount(request.Parameters["user"], request.Parameters["domain"]);
                    if (mcont != null)
                    {
                        request.ResponseWriter.Write(mcont);
                    }
                    else
                    {
                        sDeployedExtension ext = null;
                        sDeployedDomain    dom = null;
                        CoreGenerator.Lock();
                        for (var x = 0; x < CoreGenerator.Extensions.Count; x++)
                        {
                            if ((CoreGenerator.Extensions[x].Number == request.Parameters["user"]) &&
                                (CoreGenerator.Extensions[x].DomainName == request.Parameters["domain"]))
                            {
                                ext = CoreGenerator.Extensions[x];
                                break;
                            }
                        }
                        if (ext != null)
                        {
                            for (int x = 0; x < CoreGenerator.Domains.Count; x++)
                            {
                                if (CoreGenerator.Domains[x].Name == ext.DomainName)
                                {
                                    dom = CoreGenerator.Domains[x];
                                    break;
                                }
                            }
                        }
                        CoreGenerator.UnLock();
                        if (ext == null)
                        {
                            request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                        }
                        else
                        {
                            Template st = new Template(Utility.ReadEmbeddedResource("Org.Reddragonit.FreeSwitchConfig.UserModules.XmlCurl.resources.MessageCount.st"));
                            st.SetAttribute("ext", ext);
                            st.SetAttribute("domain", dom);
                            st.SetAttribute("section", request.Parameters["section"]);
                            request.ResponseWriter.Write(st.ToString());
                            VirtualConfigDeployer.CacheMessageCount(ext.Number, dom.Name, st.ToString());
                        }
                    }
                }
                else
                {
                    request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                }
                break;

            default:
                request.ResponseWriter.WriteLine(NOT_FOUND_RESPONSE);
                break;
            }
        }