Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.34 KB | None | 0 0
  1. public function generateIcecastConfig($options = null)
  2. {
  3. if (!$options) {
  4. $options = [];
  5. $options['location'] = 'Earth';
  6. $options['hostname'] = 'localhost';
  7. $options['admin'] = 'admin@site.com';
  8. $options['auth']['source-password'] = 'pass2019';
  9. $options['auth']['relay-password'] = 'pass2019';
  10. $options['auth']['admin-user'] = 'admin';
  11. $options['auth']['admin-password'] = 'pass2019';
  12. $options['port'] = 8000;
  13. $options['burst-size'] = 65536;
  14. $options['fallback-override'] = 0;
  15. $options['fileserve'] = 1;
  16. $options['chroot'] = 0;
  17. $options['on-connect'] = '/home/icecast/bin/stream-start';
  18. $options['on-disconnect'] = '/home/icecast/bin/stream-stop';
  19. $options['m1']['mount-name'] = '/liquidsoap';
  20. $options['m1']['username'] = 'source';
  21. $options['m1']['password'] = 'ls2019';
  22. $options['m1']['max-listeners'] = 10;
  23. $options['m1']['hidden'] = 0;
  24. $options['m1']['public'] = 0;
  25. $options['m2']['mount-name'] = '/live';
  26. $options['m2']['username'] = 'source';
  27. $options['m2']['password'] = 'live2019';
  28. $options['m2']['max-listeners'] = 10;
  29. $options['m2']['hidden'] = 1;
  30. $options['m2']['public'] = 0;
  31. $options['m3']['mount-name'] = '/mp3192';
  32. $options['m3']['username'] = 'source';
  33. $options['m3']['password'] = 'mp31922019';
  34. $options['m3']['max-listeners'] = 10;
  35. $options['m3']['hidden'] = 1;
  36. $options['m3']['public'] = 0;
  37. $options['paths']['basedir'] = '/usr/share/icecast2';
  38. $options['paths']['logdir'] = '/var/log/icecast2';
  39. $options['paths']['webroot'] = '/usr/share/icecast2/web';
  40. $options['paths']['alias-destination'] = '/status.xsl';
  41. $options['logging']['errorlog'] = 'error.log';
  42. $options['logging']['accesslog'] = 'access.log';
  43. $options['logging']['loglevel'] = 3;
  44. $options['logging']['logsize'] = 10000;
  45. }
  46.  
  47. $xml = new DomDocument('1.0');
  48. $xml->formatOutput = true;
  49. $icecast = $xml->createElement("icecast");
  50. $xml->appendChild($icecast);
  51.  
  52. // Location
  53. $location = $xml->createElement("location", $options['location']);
  54. $icecast->appendChild($location);
  55.  
  56. // Admin
  57. $admin = $xml->createElement("admin", $options['admin']);
  58. $icecast->appendChild($admin);
  59.  
  60. // Limits
  61. $limits = $xml->createElement("limits");
  62. $icecast->appendChild($limits);
  63.  
  64. $clients = $xml->createElement("clients", 10);
  65. $limits->appendChild($clients);
  66.  
  67. $sources = $xml->createElement("sources", 20);
  68. $limits->appendChild($sources);
  69.  
  70. $queueSize = $xml->createElement("queue-size", 524288);
  71. $limits->appendChild($queueSize);
  72.  
  73. $clientTimeout = $xml->createElement("client-timeout", 30);
  74. $limits->appendChild($clientTimeout);
  75.  
  76. $headerTimeout = $xml->createElement("header-timeout", 15);
  77. $limits->appendChild($headerTimeout);
  78.  
  79. $sourceTimeout = $xml->createElement("source-timeout", 10);
  80. $limits->appendChild($sourceTimeout);
  81.  
  82. $burstOnConnect = $xml->createElement("burst-on-connect", 1);
  83. $limits->appendChild($burstOnConnect);
  84.  
  85. $burstSize = $xml->createElement("burst-size", $options['burst-size']);
  86. $limits->appendChild($burstSize);
  87.  
  88. // Authentication
  89. $authentication = $xml->createElement("authentication");
  90. $icecast->appendChild($authentication);
  91.  
  92. $sourcePassword = $xml->createElement("source-password", $options['auth']['source-password']);
  93. $authentication->appendChild($sourcePassword);
  94.  
  95. $relayPassword = $xml->createElement("relay-password", $options['auth']['relay-password']);
  96. $authentication->appendChild($relayPassword);
  97.  
  98. $adminUser = $xml->createElement("admin-user", $options['auth']['admin-user']);
  99. $authentication->appendChild($adminUser);
  100.  
  101. $adminPassword = $xml->createElement("admin-password", $options['auth']['admin-password']);
  102. $authentication->appendChild($adminPassword);
  103.  
  104. // Hostname
  105. $hostname = $xml->createElement("hostname", $options['hostname']);
  106. $icecast->appendChild($hostname);
  107.  
  108. // Listen Socket
  109. $listenSocket = $xml->createElement("listen-socket");
  110. $icecast->appendChild($listenSocket);
  111.  
  112. $port = $xml->createElement("port", $options['port']);
  113. $listenSocket->appendChild($port);
  114.  
  115. // HTTP Headers
  116. $httpHeaders = $xml->createElement("http-headers");
  117. $icecast->appendChild($httpHeaders);
  118. $httpHeadersHeader = $xml->createElement("header");
  119. $httpHeaders->appendChild($httpHeadersHeader);
  120. $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
  121. $httpHeadersHeader->setAttribute("value", "*");
  122.  
  123. // Mount 1 (Liquid Soap)
  124. $mount1= $xml->createElement("mount");
  125. $icecast->appendChild($mount1);
  126. $mount1->setAttribute("type", "normal");
  127.  
  128. $mountName = $xml->createElement("mount-name", $options['m1']['mount-name']);
  129. $mount1->appendChild($mountName);
  130.  
  131. $username = $xml->createElement("username", $options['m1']['username']);
  132. $mount1->appendChild($username);
  133.  
  134. $password = $xml->createElement("password", $options['m1']['password']);
  135. $mount1->appendChild($password);
  136.  
  137. $maxListeners = $xml->createElement("max-listeners", $options['m1']['max-listeners']);
  138. $mount1->appendChild($maxListeners);
  139.  
  140. $burstSize = $xml->createElement("burst-size", $options['burst-size']);
  141. $mount1->appendChild($burstSize);
  142.  
  143. $fallbackOverride = $xml->createElement("fallback-override", $options['fallback-override']);
  144. $mount1->appendChild($fallbackOverride);
  145.  
  146. $hidden = $xml->createElement("hidden", $options['m1']['hidden']);
  147. $mount1->appendChild($hidden);
  148.  
  149. $public = $xml->createElement("public", $options['m1']['public']);
  150. $mount1->appendChild($public);
  151.  
  152. // HTTP Headers
  153. $httpHeaders = $xml->createElement("http-headers");
  154. $mount1->appendChild($httpHeaders);
  155.  
  156. $httpHeadersHeader = $xml->createElement("header");
  157. $httpHeaders->appendChild($httpHeadersHeader);
  158. $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
  159. $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
  160. $httpHeadersHeader = $xml->createElement("header");
  161. $httpHeaders->appendChild($httpHeadersHeader);
  162. $httpHeadersHeader->setAttribute("name", "baz");
  163. $httpHeadersHeader->setAttribute("value", "quux");
  164.  
  165. $onConnect = $xml->createElement("on-connect", $options['on-connect']);
  166. $mount1->appendChild($onConnect);
  167. $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
  168. $mount1->appendChild($onDisconnect);
  169.  
  170. // Mount 2 (Live)
  171. $mount2= $xml->createElement("mount");
  172. $icecast->appendChild($mount2);
  173. $mount2->setAttribute("type", "normal");
  174.  
  175. $mountName = $xml->createElement("mount-name", $options['m2']['mount-name']);
  176. $mount2->appendChild($mountName);
  177.  
  178. $username = $xml->createElement("username", $options['m2']['username']);
  179. $mount2->appendChild($username);
  180.  
  181. $password = $xml->createElement("password", $options['m2']['password']);
  182. $mount2->appendChild($password);
  183.  
  184. $maxListeners = $xml->createElement("max-listeners", $options['m2']['max-listeners']);
  185. $mount2->appendChild($maxListeners);
  186.  
  187. $burstSize = $xml->createElement("burst-size", $options['burst-size']);
  188. $mount2->appendChild($burstSize);
  189.  
  190. $hidden = $xml->createElement("hidden", $options['m2']['hidden']);
  191. $mount2->appendChild($hidden);
  192.  
  193. $public = $xml->createElement("public", $options['m2']['public']);
  194. $mount2->appendChild($public);
  195.  
  196. // HTTP Headers
  197. $httpHeaders = $xml->createElement("http-headers");
  198. $mount2->appendChild($httpHeaders);
  199.  
  200. $httpHeadersHeader = $xml->createElement("header");
  201. $httpHeaders->appendChild($httpHeadersHeader);
  202. $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
  203. $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
  204. $httpHeadersHeader = $xml->createElement("header");
  205. $httpHeaders->appendChild($httpHeadersHeader);
  206. $httpHeadersHeader->setAttribute("name", "baz");
  207. $httpHeadersHeader->setAttribute("value", "quux");
  208.  
  209. $onConnect = $xml->createElement("on-connect", $options['on-connect']);
  210. $mount2->appendChild($onConnect);
  211. $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
  212. $mount2->appendChild($onDisconnect);
  213.  
  214. // Mount 3 (192k Output)
  215. $mount3= $xml->createElement("mount");
  216. $icecast->appendChild($mount3);
  217. $mount3->setAttribute("type", "normal");
  218.  
  219. $mountName = $xml->createElement("mount-name", $options['m3']['mount-name']);
  220. $mount3->appendChild($mountName);
  221.  
  222. $username = $xml->createElement("username", $options['m3']['username']);
  223. $mount3->appendChild($username);
  224.  
  225. $password = $xml->createElement("password", $options['m3']['password']);
  226. $mount3->appendChild($password);
  227.  
  228. $maxListeners = $xml->createElement("max-listeners", $options['m3']['max-listeners']);
  229. $mount3->appendChild($maxListeners);
  230.  
  231. $burstSize = $xml->createElement("burst-size", $options['burst-size']);
  232. $mount3->appendChild($burstSize);
  233.  
  234. $hidden = $xml->createElement("hidden", $options['m3']['hidden']);
  235. $mount3->appendChild($hidden);
  236.  
  237. $public = $xml->createElement("public", $options['m3']['public']);
  238. $mount3->appendChild($public);
  239.  
  240. // HTTP Headers
  241. $httpHeaders = $xml->createElement("http-headers");
  242. $mount3->appendChild($httpHeaders);
  243.  
  244. $httpHeadersHeader = $xml->createElement("header");
  245. $httpHeaders->appendChild($httpHeadersHeader);
  246. $httpHeadersHeader->setAttribute("name", 'Access-Control-Allow-Origin');
  247. $httpHeadersHeader->setAttribute("value", "http://webplayer.example.org");
  248. $httpHeadersHeader = $xml->createElement("header");
  249. $httpHeaders->appendChild($httpHeadersHeader);
  250. $httpHeadersHeader->setAttribute("name", "baz");
  251. $httpHeadersHeader->setAttribute("value", "quux");
  252.  
  253. $onConnect = $xml->createElement("on-connect", $options['on-connect']);
  254. $mount3->appendChild($onConnect);
  255. $onDisconnect = $xml->createElement("on-disconnect", $options['on-disconnect']);
  256. $mount3->appendChild($onDisconnect);
  257.  
  258. // FileServe
  259. $fileServe = $xml->createElement("fileserve", $options['fileserve']);
  260. $icecast->appendChild($fileServe);
  261.  
  262. // Paths
  263. $paths = $xml->createElement("paths");
  264. $icecast->appendChild($paths);
  265.  
  266. $baseDir = $xml->createElement("basedir", $options['paths']['basedir']);
  267. $paths->appendChild($baseDir);
  268.  
  269. $logDir = $xml->createElement("logdir", $options['paths']['logdir']);
  270. $paths->appendChild($logDir);
  271.  
  272. $webRoot = $xml->createElement("webroot", $options['paths']['webroot']);
  273. $paths->appendChild($webRoot);
  274.  
  275. $alias = $xml->createElement("alias");
  276. $paths->appendChild($alias);
  277. $alias->setAttribute("source", "/");
  278. $alias->setAttribute("destination", $options['paths']['alias-destination']);
  279.  
  280. // Logging
  281. $logging = $xml->createElement("logging");
  282. $icecast->appendChild($logging);
  283.  
  284. $accessLog = $xml->createElement("accesslog", $options['logging']['accesslog']);
  285. $logging->appendChild($accessLog);
  286.  
  287. $errorLog = $xml->createElement("errorlog", $options['logging']['errorlog']);
  288. $logging->appendChild($errorLog);
  289.  
  290. $logLevel = $xml->createElement("loglevel", $options['logging']['loglevel']);
  291. $logging->appendChild($logLevel);
  292.  
  293. $logSize = $xml->createElement("logsize", $options['logging']['logsize']);
  294. $logging->appendChild($logSize);
  295.  
  296. // Security
  297. $security = $xml->createElement("security");
  298. $icecast->appendChild($security);
  299.  
  300. $chroot = $xml->createElement("chroot", $options['chroot']);
  301. $security->appendChild($chroot);
  302.  
  303. return $xml->saveXML();
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement