insertBefore( $dom->ownerDocument->createElement($name, $value), $dom->firstChild ); return simplexml_import_dom($new, get_class($this)); } } function enableAutoSSL(){ # Make backup of original file copy('/usr/local/WowzaStreamingEngine/conf/VHost.xml', '/usr/local/WowzaStreamingEngine/conf/VHost.'.time().'.xml'); $xml = simplexml_load_file('/usr/local/WowzaStreamingEngine/conf/VHost.xml', 'my_node'); # Look for AutoSSL in description or port 1936 # Locate Default Streaming $defaultStreaming = null; foreach($xml->VHost->HostPortList->HostPort as $hostPort){ # Check Ports $ports = explode(",", $hostPort->Port); if ( in_array('1936', $ports) ){ output("Port 1936 already in use by a VHost."); output("Cannot continue AutoSSL configuration until port 1936 is available."); exit; } # Locate Default Streaming if ($hostPort->Name == 'Default Streaming' || in_array('1935',$ports) ){ $defaultStreaming = simplexml_load_string($hostPort->saveXML(),'my_node'); } } if ( !$defaultStreaming ){ output("Unable to locate default streaming VHost"); output("Cannot continue AutoSSL configuration."); } $defaultStreaming->Name = 'Somnode Secure Streaming'; $defaultStreaming->IpAddress = '*'; $defaultStreaming->Port = 1936; $defaultStreaming->addChild('SSLConfig'); $defaultStreaming->SSLConfig->addChild('KeyStorePath','/usr/local/WowzaStreamingEngine/conf/ssl/SomnodeAutoSSL.jks'); $defaultStreaming->SSLConfig->addChild('KeyStorePassword','secret'); $defaultStreaming->SSLConfig->addChild('DomainToKeyStoreMapPath','/usr/local/WowzaStreamingEngine/conf/ssl/jksmap.txt'); xml_adopt($xml->VHost->HostPortList,$defaultStreaming); saveXML($xml, '/usr/local/WowzaStreamingEngine/conf/VHost.xml'); # Update Plugin Config (Post Install Run) chdir('/usr/local/Somnode/htdocs/'); require_once('database.php'); if ( isset($db_prefix) ){ require_once('/usr/local/Somnode/htdocs/system/plugins/handler.php'); $handler = new \PluginHandler('WowzaMedia', 'server'); $config = $handler->config_load(1); $config['SecureStreamPort'] = '1936'; $handler->config_save($config); } echo "Complete"; } function disableAutoSSL(){ # Make backup of original file copy('/usr/local/WowzaStreamingEngine/conf/VHost.xml', '/usr/local/WowzaStreamingEngine/conf/VHost.'.time().'.xml'); $xml = simplexml_load_file('/usr/local/WowzaStreamingEngine/conf/VHost.xml', 'my_node'); for($i=0;$i < count($xml->VHost->HostPortList->HostPort); $i++){ $hostPort = $xml->VHost->HostPortList->HostPort[$i]; if ($hostPort->SSLConfig->KeyStorePath == '/usr/local/WowzaStreamingEngine/conf/ssl/SomnodeAutoSSL.jks'){ unset($xml->VHost->HostPortList->HostPort[$i]); } } saveXML($xml, '/usr/local/WowzaStreamingEngine/conf/VHost.xml'); # Update Plugin Config chdir('/usr/local/Somnode/htdocs/'); require_once('database.php'); if ( isset($db_prefix) ){ require_once('/usr/local/Somnode/htdocs/system/plugins/handler.php'); $handler = new \PluginHandler('WowzaMedia', 'server'); $config = $handler->config_load(1); $config['SecureStreamPort'] = ''; $handler->config_save($config); } echo "Complete"; } function saveXML(SimpleXMLElement $simpleXML, $file) { $dom = new DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($simpleXML->asXML()); $dom->save($file); } function output($message){ echo $message . "\r\n"; } function xml_adopt($root, $new, $namespace = null) { // first add the new node // NOTE: addChild does NOT escape "&" ampersands in (string)$new !!! // replace them or use htmlspecialchars(). see addchild docs comments. $node = $root->addChild($new->getName(), (string) $new, $namespace); // add any attributes for the new node foreach($new->attributes() as $attr => $value) { $node->addAttribute($attr, $value); } // get all namespaces, include a blank one $namespaces = array_merge(array(null), $new->getNameSpaces(true)); // add any child nodes, including optional namespace foreach($namespaces as $space) { foreach ($new->children($space) as $child) { xml_adopt($node, $child, $space); } } } function get_Somnode_domain(){ return trim(file_get_contents('/usr/local/Somnode/Somnode.domain')); }