Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function generateIcecastConfig($options = null)
- {
- if (!$options) {
- $options = [];
- $options['location'] = 'Earth';
- $options['hostname'] = 'localhost';
- $options['admin'] = 'admin@site.com';
- $options['auth']['source-password'] = 'pass2019';
- $options['auth']['relay-password'] = 'pass2019';
- $options['auth']['admin-user'] = 'admin';
- $options['auth']['admin-password'] = 'pass2019';
- $options['port'] = 8000;
- $options['burst-size'] = 65536;
- $options['fallback-override'] = 0;
- $options['fileserve'] = 1;
- $options['chroot'] = 0;
- $options['on-connect'] = '/home/icecast/bin/stream-start';
- $options['on-disconnect'] = '/home/icecast/bin/stream-stop';
- $options['m1']['mount-name'] = '/liquidsoap';
- $options['m1']['username'] = 'source';
- $options['m1']['password'] = 'ls2019';
- $options['m1']['max-listeners'] = 10;
- $options['m1']['hidden'] = 0;
- $options['m1']['public'] = 0;
- $options['m2']['mount-name'] = '/live';
- $options['m2']['username'] = 'source';
- $options['m2']['password'] = 'live2019';
- $options['m2']['max-listeners'] = 10;
- $options['m2']['hidden'] = 1;
- $options['m2']['public'] = 0;
- $options['m3']['mount-name'] = '/mp3192';
- $options['m3']['username'] = 'source';
- $options['m3']['password'] = 'mp31922019';
- $options['m3']['max-listeners'] = 10;
- $options['m3']['hidden'] = 1;
- $options['m3']['public'] = 0;
- $options['paths']['basedir'] = '/usr/share/icecast2';
- $options['paths']['logdir'] = '/var/log/icecast2';
- $options['paths']['webroot'] = '/usr/share/icecast2/web';
- $options['paths']['alias-destination'] = '/status.xsl';
- $options['logging']['errorlog'] = 'error.log';
- $options['logging']['accesslog'] = 'access.log';
- $options['logging']['loglevel'] = 3;
- $options['logging']['logsize'] = 10000;
- }
- $xml = new DomDocument('1.0');
- $xml->formatOutput = true;
- $icecast = $xml->createElement("icecast");
- $xml->appendChild($icecast);
- // Location
- $location = $xml->createElement("location", $options['location']);
- $icecast->appendChild($location);
- // Admin
- $admin = $xml->createElement("admin", $options['admin']);
- $icecast->appendChild($admin);
- // Limits
- $limits = $xml->createElement("limits");
- $icecast->appendChild($limits);
- $clients = $xml->createElement("clients", 10);
- $limits->appendChild($clients);
- $sources = $xml->createElement("sources", 20);
- $limits->appendChild($sources);
- $queueSize = $xml->createElement("queue-size", 524288);
- $limits->appendChild($queueSize);
- $clientTimeout = $xml->createElement("client-timeout", 30);
- $limits->appendChild($clientTimeout);
- $headerTimeout = $xml->createElement("header-timeout", 15);
- $limits->appendChild($headerTimeout);
- $sourceTimeout = $xml->createElement("source-timeout", 10);
- $limits->appendChild($sourceTimeout);
- $burstOnConnect = $xml->createElement("burst-on-connect", 1);
- $limits->appendChild($burstOnConnect);
- $burstSize = $xml->createElement("burst-size", $options['burst-size']);
- $limits->appendChild($burstSize);
- // Authentication
- $authentication = $xml->createElement("authentication");
- $icecast->appendChild($authentication);
- $sourcePassword = $xml->createElement("source-password", $options['auth']['source-password']);
- $authentication->appendChild($sourcePassword);
- $relayPassword = $xml->createElement("relay-password", $options['auth']['relay-password']);
- $authentication->appendChild($relayPassword);
- $adminUser = $xml->createElement("admin-user", $options['auth']['admin-user']);
- $authentication->appendChild($adminUser);
- $adminPassword = $xml->createElement("admin-password", $options['auth']['admin-password']);
- $authentication->appendChild($adminPassword);
- // Hostname
- $hostname = $xml->createElement("hostname", $options['hostname']);
- $icecast->appendChild($hostname);
- // Listen Socket
- $listenSocket = $xml->createElement("listen-socket");
- $icecast->appendChild($listenSocket);
- $port = $xml->createElement("port", $options['port']);
- $listenSocket->appendChild($port);
- // HTTP Headers
- $httpHeaders = $xml->createElement("http-headers");
- $icecast->appendChild($httpHeaders);
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
- $httpHeadersHeader->setAttribute("value", "*");
- // Mount 1 (Liquid Soap)
- $mount1= $xml->createElement("mount");
- $icecast->appendChild($mount1);
- $mount1->setAttribute("type", "normal");
- $mountName = $xml->createElement("mount-name", $options['m1']['mount-name']);
- $mount1->appendChild($mountName);
- $username = $xml->createElement("username", $options['m1']['username']);
- $mount1->appendChild($username);
- $password = $xml->createElement("password", $options['m1']['password']);
- $mount1->appendChild($password);
- $maxListeners = $xml->createElement("max-listeners", $options['m1']['max-listeners']);
- $mount1->appendChild($maxListeners);
- $burstSize = $xml->createElement("burst-size", $options['burst-size']);
- $mount1->appendChild($burstSize);
- $fallbackOverride = $xml->createElement("fallback-override", $options['fallback-override']);
- $mount1->appendChild($fallbackOverride);
- $hidden = $xml->createElement("hidden", $options['m1']['hidden']);
- $mount1->appendChild($hidden);
- $public = $xml->createElement("public", $options['m1']['public']);
- $mount1->appendChild($public);
- // HTTP Headers
- $httpHeaders = $xml->createElement("http-headers");
- $mount1->appendChild($httpHeaders);
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
- $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", "baz");
- $httpHeadersHeader->setAttribute("value", "quux");
- $onConnect = $xml->createElement("on-connect", $options['on-connect']);
- $mount1->appendChild($onConnect);
- $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
- $mount1->appendChild($onDisconnect);
- // Mount 2 (Live)
- $mount2= $xml->createElement("mount");
- $icecast->appendChild($mount2);
- $mount2->setAttribute("type", "normal");
- $mountName = $xml->createElement("mount-name", $options['m2']['mount-name']);
- $mount2->appendChild($mountName);
- $username = $xml->createElement("username", $options['m2']['username']);
- $mount2->appendChild($username);
- $password = $xml->createElement("password", $options['m2']['password']);
- $mount2->appendChild($password);
- $maxListeners = $xml->createElement("max-listeners", $options['m2']['max-listeners']);
- $mount2->appendChild($maxListeners);
- $burstSize = $xml->createElement("burst-size", $options['burst-size']);
- $mount2->appendChild($burstSize);
- $hidden = $xml->createElement("hidden", $options['m2']['hidden']);
- $mount2->appendChild($hidden);
- $public = $xml->createElement("public", $options['m2']['public']);
- $mount2->appendChild($public);
- // HTTP Headers
- $httpHeaders = $xml->createElement("http-headers");
- $mount2->appendChild($httpHeaders);
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
- $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", "baz");
- $httpHeadersHeader->setAttribute("value", "quux");
- $onConnect = $xml->createElement("on-connect", $options['on-connect']);
- $mount2->appendChild($onConnect);
- $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
- $mount2->appendChild($onDisconnect);
- // Mount 3 (192k Output)
- $mount3= $xml->createElement("mount");
- $icecast->appendChild($mount3);
- $mount3->setAttribute("type", "normal");
- $mountName = $xml->createElement("mount-name", $options['m3']['mount-name']);
- $mount3->appendChild($mountName);
- $username = $xml->createElement("username", $options['m3']['username']);
- $mount3->appendChild($username);
- $password = $xml->createElement("password", $options['m3']['password']);
- $mount3->appendChild($password);
- $maxListeners = $xml->createElement("max-listeners", $options['m3']['max-listeners']);
- $mount3->appendChild($maxListeners);
- $burstSize = $xml->createElement("burst-size", $options['burst-size']);
- $mount3->appendChild($burstSize);
- $hidden = $xml->createElement("hidden", $options['m3']['hidden']);
- $mount3->appendChild($hidden);
- $public = $xml->createElement("public", $options['m3']['public']);
- $mount3->appendChild($public);
- // HTTP Headers
- $httpHeaders = $xml->createElement("http-headers");
- $mount3->appendChild($httpHeaders);
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
- $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
- $httpHeadersHeader = $xml->createElement("header");
- $httpHeaders->appendChild($httpHeadersHeader);
- $httpHeadersHeader->setAttribute("name", "baz");
- $httpHeadersHeader->setAttribute("value", "quux");
- $onConnect = $xml->createElement("on-connect", $options['on-connect']);
- $mount3->appendChild($onConnect);
- $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
- $mount3->appendChild($onDisconnect);
- // FileServe
- $fileServe = $xml->createElement("fileserve", $options['fileserve']);
- $icecast->appendChild($fileServe);
- // Paths
- $paths = $xml->createElement("paths");
- $icecast->appendChild($paths);
- $baseDir = $xml->createElement("basedir", $options['paths']['basedir']);
- $paths->appendChild($baseDir);
- $logDir = $xml->createElement("logdir", $options['paths']['logdir']);
- $paths->appendChild($logDir);
- $webRoot = $xml->createElement("webroot", $options['paths']['webroot']);
- $paths->appendChild($webRoot);
- $alias = $xml->createElement("alias");
- $paths->appendChild($alias);
- $alias->setAttribute("source", "/");
- $alias->setAttribute("destination", $options['paths']['alias-destination']);
- // Logging
- $logging = $xml->createElement("logging");
- $icecast->appendChild($logging);
- $accessLog = $xml->createElement("accesslog", $options['logging']['accesslog']);
- $logging->appendChild($accessLog);
- $errorLog = $xml->createElement("errorlog", $options['logging']['errorlog']);
- $logging->appendChild($errorLog);
- $logLevel = $xml->createElement("loglevel", $options['logging']['loglevel']);
- $logging->appendChild($logLevel);
- $logSize = $xml->createElement("logsize", $options['logging']['logsize']);
- $logging->appendChild($logSize);
- // Security
- $security = $xml->createElement("security");
- $icecast->appendChild($security);
- $chroot = $xml->createElement("chroot", $options['chroot']);
- $security->appendChild($chroot);
- return $xml->saveXML();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement