private static void _ReloadConfigurations() { string ip = "127.0.0.1"; int port = 8021; string password = "******"; sFreeSwitchModuleFile swm = CoreGenerator.ReadCurrentModuleSettings("event_socket"); if (swm != null) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<?xml version=\"1.0\"?>" + swm.ConfigurationSectionString); foreach (XmlNode node in doc.GetElementsByTagName("param")) { if (!(node is XmlComment)) { switch (node.Attributes["name"].Value) { case "listen_port": port = int.Parse(node.Attributes["value"].Value); break; case "password": password = node.Attributes["value"].Value; break; } } } } TcpClient cl = new TcpClient(); cl.Connect(new IPEndPoint(IPAddress.Parse(ip), port)); cl.Client.Send(ASCIIEncoding.ASCII.GetBytes(string.Format(_RELOAD_CONFIGS_COMMAND, password))); cl.Close(); }
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(); }
public static sFreeSwitchModuleFile ReadCurrentModuleSettings(string moduleName) { sFreeSwitchModuleFile ret = null; Lock(); foreach (sDeployedModule dm in modules) { if (dm.File.Name == moduleName) { ret = dm.File; break; } } UnLock(); return(ret); }
public void DeployModuleFile(string fileName, sFreeSwitchModuleFile file) { DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + Constants.DEFAULT_AUTOLOAD_CONF_DIR); FileInfo fi = new FileInfo(di.FullName + Path.DirectorySeparatorChar + fileName); if (fi.Exists) { fi.Delete(); } if (file != null) { StreamWriter sw = new StreamWriter(fi.OpenWrite()); sw.Write(file.ConfigurationSectionString); sw.Flush(); sw.Close(); } }
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)); }
private void DeployModulesFile(sFreeSwitchModuleFile file) { string confSection = file.ConfigurationSectionString; confSection = confSection.Replace("<load module=\"mod_xml_curl\"/>", ""); confSection = confSection.Replace("<modules>", "<modules><load module=\"mod_xml_curl\"/>"); DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + Constants.DEFAULT_AUTOLOAD_CONF_DIR); if (!di.Exists) { di.Create(); } FileInfo fi = new FileInfo(di.FullName + Path.DirectorySeparatorChar + file.Name + ".xml"); StreamWriter sw = fi.CreateText(); sw.Write(confSection); sw.Flush(); sw.Close(); }
private void DeployCurlFile(sFreeSwitchModuleFile file) { string confSection = file.ConfigurationSectionString; string ip = (string)Settings.Current[Constants.SERVER_IP_SETTING_NAME]; int port = (int)Settings.Current[Constants.SERVER_PORT_SETTING_NAME]; ip = (ip == null ? "127.0.0.1" : (ip == "0.0.0.0" ? "127.0.0.1" : ip)); confSection = confSection.Replace("<bindings>", "<bindings>" + String.Format(CONFIGURATION_BINDING_TEMPLATE, new object[] { "configuration", ip, port, EmbeddedHandlerFactory.BASE_PATH + ConfigurationWebHandler.BASE_PATH + ConfigurationWebHandler.CONFIGURATION_PATH }) + String.Format(CONFIGURATION_BINDING_TEMPLATE, new object[] { "directory", ip, port, EmbeddedHandlerFactory.BASE_PATH + ConfigurationWebHandler.BASE_PATH + ConfigurationWebHandler.DIRECTORY_PATH }) + String.Format(CONFIGURATION_BINDING_TEMPLATE, new object[] { "dialplan", ip, port, EmbeddedHandlerFactory.BASE_PATH + ConfigurationWebHandler.BASE_PATH + ConfigurationWebHandler.DIALPLAN_PATH })); DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + Constants.DEFAULT_AUTOLOAD_CONF_DIR); if (!di.Exists) { di.Create(); } FileInfo fi = new FileInfo(di.FullName + Path.DirectorySeparatorChar + file.Name + ".xml"); StreamWriter sw = fi.CreateText(); sw.Write(confSection); sw.Flush(); sw.Close(); }
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; } }
public void LoadFromElement(XmlElement element) { _fileName = element.Attributes["filename"].Value; _file = new sFreeSwitchModuleFile((XmlElement)element.ChildNodes[0]); }
public sDeployedModule(string fileName, sFreeSwitchModuleFile file) { _fileName = fileName; _file = file; }