ngxc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php
  2. $GLOBALS['plugins'][]['ngxc'] = array(
  3. 'name' => 'NGXConfigurator',
  4. 'author' => 'Vertig0ne',
  5. 'category' => 'Web Server',
  6. 'link' => 'https://github.com/vertig0ne/organizr-ngxc',
  7. 'idPrefix' => 'ngxc',
  8. 'configPrefix' => 'ngxc',
  9. 'version' => '0.2.0',
  10. 'image' => 'plugins/images/ngxc.png',
  11. 'settings' => true,
  12. 'homepage' => false,
  13. 'license' => 'personal,business'
  14. );
  15. ###############
  16. ## INTERNAL FUNCTIONS
  17. ###############
  18. function _ngxcTypeOptions()
  19. {
  20. $_ngxcTypes = array(
  21. 'none' => 'None',
  22. 'airsonic' => 'AirSonic',
  23. 'calibre-web' => 'Calibre-Web',
  24. 'calibre-webBlur' => 'Calibre-Web (Blur Theme)',
  25. 'deluge' => 'Deluge',
  26. 'guacamole' => 'Guacamole',
  27. 'jackett' => 'Jackett',
  28. 'lazylibrarian' => 'LazyLibrarian',
  29. 'lidarr' => 'Lidarr',
  30. 'mylar' => 'Mylar',
  31. 'netdata' => 'NetData',
  32. 'nowshowing' => 'NowShowing',
  33. 'nzbget' => 'NZBGet',
  34. 'nzbgetDark' => 'NZBGet (Dark Theme)',
  35. 'nzbhydra' => 'NZBHydra',
  36. 'ombi' => 'Ombi',
  37. 'plex' => 'Plex',
  38. 'qbittorrent' => 'qbittorrent',
  39. 'radarr' => 'Radarr',
  40. 'radarrDarker' => 'Radarr (Darkerr Theme)',
  41. 'rutorrent' => 'rUtorrent',
  42. 'sonarr' => 'Sonarr',
  43. 'sonarrDarker' => 'Sonarr (Darkerr Theme)',
  44. 'tautulli' => 'Tautulli',
  45. 'ubooquity' => 'Ubooquity',
  46. 'youtube-dl' => 'YouTube-DL Server'
  47. );
  48. $data = array();
  49. $t = 0;
  50. foreach ($_ngxcTypes as $key => $value) {
  51. $data[$t] = array(
  52. "name" => $value,
  53. "value" => $key
  54. );
  55. $t++;
  56. }
  57. return $data;
  58. }
  59. function _ngxcGetAllTabs()
  60. {
  61. return allTabs();
  62. }
  63. function _ngxcGetTabs()
  64. {
  65. $tabs = _ngxcGetAllTabs();
  66. $types = _ngxcTypeOptions();
  67. $data = array();
  68. foreach ($tabs["tabs"] as $tab) {
  69. if ($tab['name'] != "Homepage" && $tab['name'] != "Settings") {
  70. $name = strtoupper(str_replace(' ', '_', $tab['name']));
  71. $data[$tab['name']] = array(
  72. array(
  73. 'type' => 'select',
  74. 'name' => 'NGXC_' . $name . '_TYPE',
  75. 'label' => 'Type of Proxy',
  76. 'value' => isset($GLOBALS['NGXC_' . $name . '_TYPE']) ? $GLOBALS['NGXC_' . $name . '_TYPE'] : 'None',
  77. 'options' => $types
  78. ),
  79. array(
  80. 'type' => 'input',
  81. 'name' => 'NGXC_' . $name . '_URL',
  82. 'label' => 'Proxy URL',
  83. 'value' => isset($GLOBALS['NGXC_' . $name . '_URL']) ? $GLOBALS['NGXC_' . $name . '_URL'] : '',
  84. )
  85. );
  86. }
  87. }
  88. return $data;
  89. }
  90. function _ngxcWriteTabConfig($tab)
  91. {
  92. $name = strtoupper(str_replace(' ', '_', $tab["name"]));
  93. $nameLower = strtolower(str_replace(' ', '_', $tab["name"]));
  94. $type = $GLOBALS['NGXC_' . $name . '_TYPE'];
  95. $path = $tab["url"];
  96. $url = $GLOBALS['NGXC_' . $name . '_URL'];
  97. switch ($type) {
  98. case "sonarr":
  99. case "radarr":
  100. case "lidarr":
  101. return _ngxcWriteTabSonarrConfig($url, $path, $nameLower, $tab["group_id"]);
  102. break;
  103. case "sonarrDarker":
  104. case "radarrDarker":
  105. return _ngxcWriteTabSonarrConfig($url, $path, $nameLower, $tab["group_id"], true);
  106. break;
  107. case "airsonic":
  108. return _ngxcWriteTabAirSonicConfig($url, $path, $nameLower, $tab["group_id"]);
  109. break;
  110. case "calibre-web":
  111. return _ngxcWriteTabCalibreWebConfig($url, $path, $nameLower, $tab["group_id"]);
  112. break;
  113. case "calibre-webBlur":
  114. return _ngxcWriteTabCalibreWebConfig($url, $path, $nameLower, $tab["group_id"], true);
  115. break;
  116. case "deluge":
  117. return _ngxcWriteTabDelugeConfig($url, $path, $nameLower, $tab["group_id"]);
  118. break;
  119. case "guacamole":
  120. return _ngxcWriteTabGuacamoleConfig($url, $path, $nameLower, $tab["group_id"]);
  121. break;
  122. case "jackett":
  123. return _ngxcWriteTabJackettConfig($url, $path, $nameLower, $tab["group_id"]);
  124. break;
  125. case "mylar":
  126. case "lazylibrarian":
  127. return _ngxcWriteTabMylarConfig($url, $path, $nameLower, $tab["group_id"]);
  128. break;
  129. case "netdata":
  130. return _ngxcWriteTabNetdataConfig($url, $path, $nameLower, $tab["group_id"]);
  131. break;
  132. case "nowshowing":
  133. return _ngxcWriteTabNowshowingConfig($url, $path, $nameLower, $tab["group_id"]);
  134. break;
  135. case "nzbget":
  136. return _ngxcWriteTabNzbGetConfig($url, $path, $nameLower, $tab["group_id"]);
  137. break;
  138. case "nzbgetDark":
  139. return _ngxcWriteTabNzbGetConfig($url, $path, $nameLower, $tab["group_id"], true);
  140. break;
  141. case "nzbhydra":
  142. _ngxcWriteTabNzbHydraConfig($url, $path, $nameLower, $tab["group_id"]);
  143. break;
  144. case "ombi":
  145. return _ngxcWriteTabOmbiConfig($url, $path, $nameLower, $tab["group_id"]);
  146. break;
  147. case "plex":
  148. return _ngxcWriteTabPlexConfig($url, $path, $nameLower, $tab["group_id"]);
  149. break;
  150. case "qbittorrent":
  151. return _ngxcWriteTabQbittorrentConfig($url, $path, $nameLower, $tab["group_id"]);
  152. break;
  153. case "tautulli":
  154. return _ngxcWriteTabTautulliConfig($url, $path, $nameLower, $tab["group_id"]);
  155. break;
  156. case "transmission":
  157. return _ngxcWriteTabTransmissionConfig($url, $path, $nameLower, $tab["group_id"]);
  158. break;
  159. case "ubooquity":
  160. return _ngxcWriteTabUbooquityConfig($url, $path, $nameLower, $tab["group_id"]);
  161. break;
  162. case "rutorrent":
  163. return _ngxcWriteTabRutorrentConfig($url, $path, $nameLower, $tab["group_id"]);
  164. break;
  165. }
  166. }
  167. ###############
  168. ## CONFIGURATION WRITERS
  169. ###############
  170. function _ngxcWriteTabSonarrConfig($url, $path, $name, $group, $theme = false)
  171. {
  172. $data =
  173. "location $path {
  174. auth_request /auth-$group;
  175. proxy_pass $url/;
  176. proxy_set_header X-Real-IP \$remote_addr;
  177. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  178. proxy_set_header X-Forwarded-Proto \$scheme;
  179. proxy_http_version 1.1;
  180. proxy_no_cache \$cookie_session;";
  181. if ($theme) {
  182. $data .=
  183. "proxy_set_header Accept-Encoding \"\";
  184. sub_filter '</head>' '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://rawgit.com/iFelix18/Darkerr/master/darkerr.css\"></head>';
  185. sub_filter_once on;\n";
  186. }
  187. $data .=
  188. "location " . $path . "api {
  189. auth_request off;
  190. proxy_pass $url/api;
  191. }
  192. }";
  193. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  194. return $result;
  195. }
  196. function _ngxcWriteTabAirSonicConfig($url, $path, $name, $group)
  197. {
  198. $data = "
  199. location $path {
  200. auth_request /auth-$group;
  201. proxy_set_header X-Real-IP \$remote_addr;
  202. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  203. proxy_set_header X-Forwarded-Proto \$scheme;
  204. proxy_set_header X-Forwarded-Host \$http_host;
  205. proxy_set_header Host \$http_host;
  206. proxy_max_temp_file_size 0;
  207. proxy_pass $url/;
  208. proxy_redirect http:// https://;
  209. }";
  210. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  211. return $result;
  212. }
  213. function _ngxcWriteTabCalibreWebConfig($url, $path, $name, $group, $theme = false)
  214. {
  215. $data = "
  216. location $path {
  217. proxy_bind \$server_addr;
  218. proxy_pass $url;
  219. proxy_set_header Host \$http_host;
  220. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  221. proxy_set_header X-Scheme \$scheme;
  222. proxy_set_header X-Script-Name $path;
  223. ";
  224. if ($theme) {
  225. $data .= "
  226. set \$filter_output '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://rawgit.com/leram84/layer.Cake/dev/CSS/caliBlur-Demo.css\"></head>';
  227. if (\$http_user_agent ~* '(iPhone|iPod|android|blackberry)') {
  228. set \$filter_output '</head>';
  229. }
  230. if (\$request_uri ~* '(\/read\/)') {
  231. set \$filter_output '</head>';
  232. }
  233. proxy_set_header Accept-Encoding \"\";
  234. sub_filter '</head>' \$filter_output;
  235. sub_filter_once on;\n";
  236. }
  237. $data .= "}";
  238. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  239. return $result;
  240. }
  241. function _ngxcWriteTabDelugeConfig($url, $path, $name, $group)
  242. {
  243. $data = "
  244. location $path {
  245. auth_request /auth-$group;
  246. proxy_pass $url/;
  247. proxy_set_header X-Deluge-Base \"$path\";
  248. proxy_set_header Host \$host;
  249. proxy_set_header X-Real-IP \$remote_addr;
  250. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  251. proxy_set_header X-Forwarded-Proto https;
  252. proxy_redirect http:// \$scheme://;
  253. proxy_http_version 1.1;
  254. proxy_set_header Connection \"\";
  255. proxy_cache_bypass \$cookie_session;
  256. proxy_no_cache \$cookie_session;
  257. proxy_buffers 32 4k;
  258. add_header X-Frame-Options SAMEORIGIN;
  259. }";
  260. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  261. return $result;
  262. }
  263. function _ngxcWriteTabGuacamoleConfig($url, $path, $name, $group)
  264. {
  265. $data = "
  266. location $path {
  267. auth_request /auth-$group;
  268. proxy_pass $url/;
  269. proxy_buffering off;
  270. proxy_set_header Upgrade \$http_upgrade;
  271. proxy_set_header Connection \$http_connection;
  272. proxy_set_header X-Real-IP \$remote_addr;
  273. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  274. proxy_set_header X-Forwarded-Proto \$scheme;
  275. proxy_http_version 1.1;
  276. proxy_no_cache \$cookie_session;
  277. }";
  278. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  279. return $result;
  280. }
  281. function _ngxcWriteTabJackettConfig($url, $path, $name, $group)
  282. {
  283. $data = "
  284. location $path {
  285. auth_request /auth-$group;
  286. proxy_pass $url/;
  287. proxy_set_header Host \$host;
  288. proxy_set_header X-Real-IP \$remote_addr;
  289. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  290. proxy_set_header X-Forwarded-Proto https;
  291. proxy_redirect http:// \$scheme://;
  292. proxy_http_version 1.1;
  293. proxy_set_header Connection \"\";
  294. proxy_cache_bypass \$cookie_session;
  295. proxy_no_cache \$cookie_session;
  296. proxy_buffers 32 4k;
  297. }";
  298. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  299. return $result;
  300. }
  301. function _ngxcWriteTabMylarConfig($url, $path, $name, $group)
  302. {
  303. $data = "
  304. location $path {
  305. auth_request /auth-$group;
  306. proxy_pass $url/;
  307. proxy_set_header Host \$host;
  308. proxy_set_header X-Real-IP \$remote_addr;
  309. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  310. proxy_set_header X-Forwarded-Proto \$scheme;
  311. }";
  312. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  313. return $result;
  314. }
  315. function _ngxcWriteTabNetdataConfig($url, $path, $name, $group)
  316. {
  317. $data = "
  318. location $path {
  319. auth_request /auth-$group;
  320. proxy_redirect off;
  321. proxy_set_header Host \$host;
  322. proxy_set_header X-Forwarded-Host \$host;
  323. proxy_set_header X-Forwarded-Server \$host;
  324. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  325. proxy_http_version 1.1;
  326. proxy_pass_request_headers on;
  327. proxy_set_header Connection \"keep-alive\";
  328. proxy_store off;
  329. proxy_pass $url/;
  330. }";
  331. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  332. return $result;
  333. }
  334. function _ngxcWriteTabNowshowingConfig($url, $path, $name, $group)
  335. {
  336. $data = "
  337. location $path {
  338. auth_request /auth-$group;
  339. proxy_set_header Host \$host;
  340. proxy_set_header X-Forwarded-Host \$host;
  341. proxy_set_header X-Forwarded-Server \$host;
  342. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  343. proxy_http_version 1.1;
  344. proxy_pass_request_headers on;
  345. proxy_set_header Connection \"keep-alive\";
  346. proxy_pass $url/;
  347. }";
  348. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  349. return $result;
  350. }
  351. function _ngxcWriteTabNzbGetConfig($url, $path, $name, $group, $theme = false)
  352. {
  353. $data = "
  354. location $path {
  355. auth_request /auth-$group;
  356. proxy_pass $url/;
  357. proxy_set_header X-Real-IP \$remote_addr;
  358. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  359. proxy_set_header X-Forwarded-Proto \$scheme;
  360. proxy_http_version 1.1;
  361. proxy_no_cache \$cookie_session;
  362. proxy_set_header Accept-Encoding \"\";
  363. proxy_set_header Host \$host;
  364. ";
  365. if ($theme) {
  366. $data .= "
  367. sub_filter '</head>' '<link rel=\"stylesheet\" type=\"text/css\" href=\"https://rawgit.com/ydkmlt84/DarkerNZBget/develop/nzbget_custom_darkblue.css\"></head>';
  368. sub_filter_once on;
  369. ";
  370. }
  371. $data .= "
  372. }";
  373. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  374. return $result;
  375. }
  376. function _ngxcWriteTabNzbHydraConfig($url, $path, $name, $group)
  377. {
  378. $data = "
  379. location $path {
  380. auth_request /auth-$group;
  381. proxy_pass $url/;
  382. proxy_set_header X-Real-IP \$remote_addr;
  383. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  384. proxy_set_header X-Forwarded-Proto \$scheme;
  385. proxy_http_version 1.1;
  386. proxy_no_cache \$cookie_session;
  387. }";
  388. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  389. return $result;
  390. }
  391. function _ngxcWriteTabOmbiConfig($url, $path, $name, $group)
  392. {
  393. $data = "
  394. location $path {
  395. auth_request /auth-$group;
  396. proxy_pass $url/;
  397. proxy_cache_bypass \$http_upgrade;
  398. proxy_set_header Connection keep-alive;
  399. proxy_set_header Upgrade \$http_upgrade;
  400. proxy_set_header X-Forwarded-Host \$server_name;
  401. proxy_set_header X-Forwarded-Ssl on;
  402. proxy_set_header X-Real-IP \$remote_addr;
  403. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  404. proxy_set_header X-Forwarded-Proto \$scheme;
  405. proxy_http_version 1.1;
  406. proxy_no_cache \$cookie_session;
  407. proxy_set_header Host \$host;
  408. }
  409. location /dist/ {
  410. return 301 $path\$request_uri;
  411. }";
  412. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  413. return $result;
  414. }
  415. function _ngxcWriteTabPlexConfig($url, $path, $name, $group)
  416. {
  417. $data = "
  418. location $path {
  419. return 301 /web;
  420. }
  421. location ~ ^/(\?(?:.*)(X-Plex-Device=)|web|video|photo|library|web|status|system|updater|clients|:|playQueues)(.*) {
  422. proxy_pass $url;
  423. proxy_redirect $url /;
  424. proxy_set_header X-Real-IP \$remote_addr;
  425. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  426. proxy_redirect off;
  427. proxy_set_header Host \$host;
  428. proxy_http_version 1.1;
  429. proxy_set_header Upgrade \$http_upgrade;
  430. proxy_set_header Connection \"upgrade\";
  431. proxy_read_timeout 36000s;
  432. proxy_pass_request_headers on;
  433. }";
  434. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  435. return $result;
  436. }
  437. function _ngxcWriteTabQbittorrentConfig($url, $path, $name, $group)
  438. {
  439. $data = "
  440. location ~ $path(?<url>.*) {
  441. auth_request /auth-$group;
  442. proxy_pass $path\$url;
  443. proxy_set_header X-Forwarded-Host \$host;
  444. proxy_hide_header Referer;
  445. proxy_hide_header Origin;
  446. proxy_set_header Referer '';
  447. proxy_set_header Origin '';
  448. add_header X-Frame-Options \"SAMEORIGIN\";
  449. }";
  450. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  451. return $result;
  452. }
  453. function _ngxcWriteTabRutorrentConfig($url, $path, $name, $group)
  454. {
  455. $data = "
  456. location $path {
  457. auth_request /auth-$group;
  458. proxy_pass $url/;
  459. proxy_set_header Host \$server_name;
  460. proxy_set_header X-Real-IP \$remote_addr;
  461. proxy_set_header X-Forwarded-Host \$server_name;
  462. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  463. proxy_redirect off;
  464. }";
  465. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  466. return $result;
  467. }
  468. function _ngxcWriteTabTautulliConfig($url, $path, $name, $group)
  469. {
  470. $data = "
  471. location $path {
  472. auth_request /auth-$group;
  473. proxy_pass $url/;
  474. proxy_set_header X-Forwarded-Host \$server_name;
  475. proxy_set_header X-Real-IP \$remote_addr;
  476. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  477. proxy_set_header X-Forwarded-Proto \$scheme;
  478. proxy_http_version 1.1;
  479. proxy_no_cache \$cookie_session;
  480. location " . $path . "api/ {
  481. auth_request off;
  482. proxy_pass $url/api/;
  483. }
  484. }";
  485. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  486. return $result;
  487. }
  488. function _ngxcWriteTabTransmissionConfig($url, $path, $name, $group)
  489. {
  490. $data = "
  491. location $path {
  492. auth_request /auth-$group;
  493. proxy_set_header X-Real-IP \$remote_addr;
  494. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  495. proxy_set_header Host \$http_host;
  496. proxy_set_header X-NginX-Proxy true;
  497. proxy_http_version 1.1;
  498. proxy_set_header Connection \"\";
  499. proxy_pass_header X-Transmission-Session-Id;
  500. add_header Front-End-Https on;
  501. location " . $path . "rpc {
  502. proxy_pass $url/rpc;
  503. }
  504. location " . $path . "web {
  505. proxy_pass $url/web;
  506. }
  507. location " . $path . "upload {
  508. proxy_pass $url/upload;
  509. }
  510. location /transmission {
  511. return 301 https://\$server_name" . $path . "web;
  512. }
  513. }";
  514. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  515. return $result;
  516. }
  517. function _ngxcWriteTabUbooquityConfig($url, $path, $name, $group)
  518. {
  519. $data = "
  520. location $path {
  521. auth_request /auth-$group;
  522. proxy_pass $url/;
  523. proxy_set_header Host \$host;
  524. proxy_set_header X-Real-IP \$remote_addr;
  525. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  526. }";
  527. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/proxy' . '/' . $name . '.conf', $data) !== false);
  528. return $result;
  529. }
  530. ###############
  531. ## PUBLIC FUNCTIONS
  532. ###############
  533. function NGXCGetSettings()
  534. {
  535. $data = array(
  536. "Core" => array(
  537. array(
  538. 'type' => 'input',
  539. 'name' => 'NGXC_SAVE_PATH',
  540. 'label' => 'Configuration Save Path',
  541. 'value' => $GLOBALS['NGXC_SAVE_PATH'] ?: $GLOBALS['dbLocation']
  542. )
  543. )
  544. );
  545. $data = array_merge($data, _ngxcGetTabs());
  546. $data['Actions'] = array(
  547. array(
  548. 'type' => 'button',
  549. 'label' => 'Write Config',
  550. 'class' => 'ngxc-write-config',
  551. 'icon' => 'fa fa-save',
  552. 'text' => 'Write Config'
  553. )
  554. );
  555. return $data;
  556. }
  557. function NGXCWriteConfig()
  558. {
  559. if (!is_writable($GLOBALS['NGXC_SAVE_PATH'])) {
  560. return false;
  561. }
  562. if (!file_exists($GLOBALS['NGXC_SAVE_PATH'] . '/proxy')) {
  563. mkdir($GLOBALS['NGXC_SAVE_PATH'] . '/proxy', 0777, true);
  564. }
  565. $tabs = _ngxcGetAllTabs();
  566. $return = true;
  567. foreach ($tabs["tabs"] as $tab) {
  568. $res = _ngxcWriteTabConfig($tab);
  569. if ($res === false) $return = false;
  570. }
  571. $file_contents = "location ~ /auth-(.*) {
  572. internal;
  573. rewrite ^/auth-(.*) /api/?v1/auth&group=$1;
  574. }\n";
  575. $file_contents .= "include " . $GLOBALS['NGXC_SAVE_PATH'] . "/proxy/*.conf;\n";
  576. if ($return) {
  577. $result = (file_put_contents($GLOBALS['NGXC_SAVE_PATH'] . '/ngxc.conf', $file_contents) !== false);
  578. return (bool)$result;
  579. }
  580. return $return;
  581. }