ngxc.php 24 KB

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