organizr-functions.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. <?php
  2. function wizardConfig($array){
  3. foreach ($array['data'] as $items) {
  4. foreach ($items as $key => $value) {
  5. if($key == 'name'){
  6. $newKey = $value;
  7. }
  8. if($key == 'value'){
  9. $newValue = $value;
  10. }
  11. if(isset($newKey) && isset($newValue)){
  12. $$newKey = $newValue;
  13. }
  14. }
  15. }
  16. $location = cleanDirectory($location);
  17. $dbName = $dbName.'.db';
  18. $configVersion = $GLOBALS['installedVersion'];
  19. $configArray = array(
  20. 'dbName' => $dbName,
  21. 'dbLocation' => $location,
  22. 'license' => $license,
  23. 'organizrHash' => $hashKey,
  24. 'organizrAPI' => $api,
  25. 'registrationPassword' => $registrationPassword,
  26. );
  27. // Create Config
  28. if(createConfig($configArray)){
  29. // Call DB Create
  30. if(createDB($location,$dbName)){
  31. // Add in first user
  32. if(createFirstAdmin($location,$dbName,$username,$password,$email)){
  33. if(createToken($username,$email,gravatar($email),'Admin',0,$hashKey,1)){
  34. return true;
  35. }else{
  36. return 'token';
  37. }
  38. }else{
  39. return 'admin';
  40. }
  41. }else{
  42. return 'db';
  43. }
  44. }else{
  45. return 'config';
  46. }
  47. return false;
  48. }
  49. function register($array){
  50. // Grab username and password from login form
  51. foreach ($array['data'] as $items) {
  52. foreach ($items as $key => $value) {
  53. if($key == 'name'){
  54. $newKey = $value;
  55. }
  56. if($key == 'value'){
  57. $newValue = $value;
  58. }
  59. if(isset($newKey) && isset($newValue)){
  60. $$newKey = $newValue;
  61. }
  62. }
  63. }
  64. if($registrationPassword == $GLOBALS['registrationPassword']){
  65. $defaults = defaultUserGroup();
  66. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  67. if(createUser($username,$password,$defaults,$email)){
  68. writeLog('success', 'Registration Function - A User has registered', $username);
  69. if(createToken($username,$email,gravatar($email),$defaults['group'],$defaults['group_id'],$GLOBALS['organizrHash'],1)){
  70. writeLoginLog($username, 'success');
  71. writeLog('success', 'Login Function - A User has logged in', $username);
  72. return true;
  73. }
  74. }else{
  75. writeLog('error', 'Registration Function - An error occured', $username);
  76. return 'username taken';
  77. }
  78. }else{
  79. writeLog('warning', 'Registration Function - Wrong Password', $username);
  80. return 'mismatch';
  81. }
  82. }
  83. function editUser($array){
  84. return $array;
  85. }
  86. function logout(){
  87. coookie('delete','organizrToken');
  88. $GLOBALS['organizrUser'] = false;
  89. return true;
  90. }
  91. function qualifyRequest($accessLevelNeeded){
  92. if(getUserLevel() <= $accessLevelNeeded){
  93. return true;
  94. }else{
  95. return false;
  96. }
  97. }
  98. function getUserLevel(){
  99. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  100. // Check token or API key
  101. // If API key, return 0 for admin
  102. if(strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']){
  103. //DO API CHECK
  104. return 0;
  105. }elseif(isset($GLOBALS['organizrUser'])){
  106. return $GLOBALS['organizrUser']['groupID'];
  107. }
  108. // All else fails? return guest id
  109. return 999;
  110. }
  111. function organizrStatus(){
  112. $status = array();
  113. $dependenciesActive = array();
  114. $dependenciesInactive = array();
  115. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  116. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  117. foreach($extensions as $check){
  118. if(extension_loaded($check)){
  119. array_push($dependenciesActive,$check);
  120. }else{
  121. array_push($dependenciesInactive,$check);
  122. }
  123. }
  124. foreach($functions as $check){
  125. if(function_exists($check)){
  126. array_push($dependenciesActive,$check);
  127. }else{
  128. array_push($dependenciesInactive,$check);
  129. }
  130. }
  131. if(!file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
  132. $status['status'] = "wizard";//wizard - ok for test
  133. }
  134. if(count($dependenciesInactive)>0 || !is_writable(dirname(__DIR__,2))){
  135. $status['status'] = "dependencies";
  136. }
  137. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  138. $status['writable'] = is_writable(dirname(__DIR__,2)) ? 'yes' : 'no';
  139. $status['dependenciesActive'] = $dependenciesActive;
  140. $status['dependenciesInactive'] = $dependenciesInactive;
  141. $status['version'] = $GLOBALS['installedVersion'];
  142. $status['os'] = getOS();
  143. $status['php'] = phpversion();
  144. return $status;
  145. }
  146. function getSettingsMain(){
  147. return array(
  148. 'Github' => array(
  149. array(
  150. 'type' => 'select',
  151. 'name' => 'branch',
  152. 'label' => 'Branch',
  153. 'value' => $GLOBALS['branch'],
  154. 'options' => getBranches()
  155. ),
  156. array(
  157. 'type' => 'button',
  158. 'label' => 'Force Install Branch',
  159. 'class' => 'updateNow',
  160. 'icon' => 'fa fa-paper-plane',
  161. 'text' => 'Retrieve'
  162. )
  163. ),
  164. 'API' => array(
  165. array(
  166. 'type' => 'password-alt',
  167. 'name' => 'organizrAPI',
  168. 'label' => 'Organizr API',
  169. 'value' => $GLOBALS['organizrAPI']
  170. ),
  171. array(
  172. 'type' => 'button',
  173. 'label' => 'Generate New API Key',
  174. 'class' => 'newAPIKey',
  175. 'icon' => 'fa fa-paper-plane',
  176. 'text' => 'Generate'
  177. )
  178. ),
  179. 'Authentication' => array(
  180. array(
  181. 'type' => 'select',
  182. 'name' => 'authType',
  183. 'id' => 'authSelect',
  184. 'label' => 'Authentication Type',
  185. 'value' => $GLOBALS['authType'],
  186. 'options' => getAuthTypes()
  187. ),
  188. array(
  189. 'type' => 'select',
  190. 'name' => 'authBackend',
  191. 'id' => 'authBackendSelect',
  192. 'label' => 'Authentication Backend',
  193. 'class' => 'backendAuth switchAuth',
  194. 'value' => $GLOBALS['authBackend'],
  195. 'options' => getAuthBackends()
  196. ),
  197. array(
  198. 'type' => 'password-alt',
  199. 'name' => 'plexToken',
  200. 'class' => 'plexAuth switchAuth',
  201. 'label' => 'Plex Token',
  202. 'value' => $GLOBALS['plexToken'],
  203. 'placeholder' => 'Use Get Token Button'
  204. ),
  205. array(
  206. 'type' => 'button',
  207. 'label' => 'Get Plex Token',
  208. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  209. 'icon' => 'fa fa-paper-plane',
  210. 'text' => 'Retrieve',
  211. 'href' => '#auth-plex-token-form',
  212. 'attr' => 'data-effect="mfp-3d-unfold"'
  213. ),
  214. array(
  215. 'type' => 'password-alt',
  216. 'name' => 'plexID',
  217. 'class' => 'plexAuth switchAuth',
  218. 'label' => 'Plex Machine',
  219. 'value' => $GLOBALS['plexID'],
  220. 'placeholder' => 'Use Get Plex Machine Button'
  221. ),
  222. array(
  223. 'type' => 'button',
  224. 'label' => 'Get Plex Machine',
  225. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  226. 'icon' => 'fa fa-paper-plane',
  227. 'text' => 'Retrieve',
  228. 'href' => '#auth-plex-machine-form',
  229. 'attr' => 'data-effect="mfp-3d-unfold"'
  230. ),
  231. array(
  232. 'type' => 'input',
  233. 'name' => 'authBackendHost',
  234. 'class' => 'ldapAuth ftpAuth switchAuth',
  235. 'label' => 'Host Address',
  236. 'value' => $GLOBALS['authBackendHost'],
  237. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  238. ),
  239. array(
  240. 'type' => 'input',
  241. 'name' => 'authBaseDN',
  242. 'class' => 'ldapAuth switchAuth',
  243. 'label' => 'Host Base DN',
  244. 'value' => $GLOBALS['authBaseDN'],
  245. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  246. ),
  247. array(
  248. 'type' => 'input',
  249. 'name' => 'embyURL',
  250. 'class' => 'embyAuth switchAuth',
  251. 'label' => 'Emby URL',
  252. 'value' => $GLOBALS['embyURL'],
  253. 'placeholder' => 'http(s)://hostname:port'
  254. ),
  255. array(
  256. 'type' => 'password-alt',
  257. 'name' => 'embyToken',
  258. 'class' => 'embyAuth switchAuth',
  259. 'label' => 'Emby Token',
  260. 'value' => $GLOBALS['embyToken'],
  261. 'placeholder' => ''
  262. )
  263. /*array(
  264. 'type' => 'button',
  265. 'label' => 'Send Test',
  266. 'class' => 'phpmSendTestEmail',
  267. 'icon' => 'fa fa-paper-plane',
  268. 'text' => 'Send'
  269. )*/
  270. )
  271. );
  272. }
  273. function getSSO(){
  274. return array(
  275. 'Plex' => array(
  276. array(
  277. 'type' => 'password-alt',
  278. 'name' => 'plexToken',
  279. 'label' => 'Plex Token',
  280. 'value' => $GLOBALS['plexToken'],
  281. 'placeholder' => 'Use Get Token Button'
  282. ),
  283. array(
  284. 'type' => 'button',
  285. 'label' => 'Get Plex Token',
  286. 'class' => 'popup-with-form getPlexTokenSSO',
  287. 'icon' => 'fa fa-paper-plane',
  288. 'text' => 'Retrieve',
  289. 'href' => '#sso-plex-token-form',
  290. 'attr' => 'data-effect="mfp-3d-unfold"'
  291. ),
  292. array(
  293. 'type' => 'password-alt',
  294. 'name' => 'plexID',
  295. 'label' => 'Plex Machine',
  296. 'value' => $GLOBALS['plexID'],
  297. 'placeholder' => 'Use Get Plex Machine Button'
  298. ),
  299. array(
  300. 'type' => 'button',
  301. 'label' => 'Get Plex Machine',
  302. 'class' => 'popup-with-form getPlexMachineSSO',
  303. 'icon' => 'fa fa-paper-plane',
  304. 'text' => 'Retrieve',
  305. 'href' => '#sso-plex-machine-form',
  306. 'attr' => 'data-effect="mfp-3d-unfold"'
  307. ),
  308. array(
  309. 'type' => 'input',
  310. 'name' => 'plexAdmin',
  311. 'label' => 'Admin Username',
  312. 'value' => $GLOBALS['plexAdmin'],
  313. 'placeholder' => 'Admin username for Plex'
  314. ),
  315. array(
  316. 'type' => 'blank',
  317. 'label' => ''
  318. ),
  319. array(
  320. 'type' => 'html',
  321. 'label' => 'Plex Note',
  322. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  323. ),
  324. array(
  325. 'type' => 'switch',
  326. 'name' => 'ssoPlex',
  327. 'label' => 'Enable',
  328. 'value' => $GLOBALS['ssoPlex']
  329. )
  330. ),
  331. 'Ombi' => array(
  332. array(
  333. 'type' => 'input',
  334. 'name' => 'ombiURL',
  335. 'label' => 'Ombi URL',
  336. 'value' => $GLOBALS['ombiURL'],
  337. 'placeholder' => 'http(s)://hostname:port'
  338. ),
  339. array(
  340. 'type' => 'switch',
  341. 'name' => 'ssoOmbi',
  342. 'label' => 'Enable',
  343. 'value' => $GLOBALS['ssoOmbi']
  344. )
  345. ),
  346. 'Tautulli' => array(
  347. array(
  348. 'type' => 'input',
  349. 'name' => 'tautulliURL',
  350. 'label' => 'Tautulli URL',
  351. 'value' => $GLOBALS['tautulliURL'],
  352. 'placeholder' => 'http(s)://hostname:port'
  353. ),
  354. array(
  355. 'type' => 'switch',
  356. 'name' => 'ssoTautulli',
  357. 'label' => 'Enable',
  358. 'value' => $GLOBALS['ssoTautulli']
  359. )
  360. )
  361. );
  362. }
  363. function loadAppearance(){
  364. $appearance = array();
  365. $appearance['logo'] = $GLOBALS['logo'];
  366. $appearance['title'] = $GLOBALS['title'];
  367. $appearance['useLogo'] = $GLOBALS['useLogo'];
  368. $appearance['headerColor'] = $GLOBALS['headerColor'];
  369. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  370. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  371. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  372. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  373. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  374. $appearance['customCss'] = $GLOBALS['customCss'];
  375. return $appearance;
  376. }
  377. function getCustomizeAppearance(){
  378. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  379. return array(
  380. 'Top Bar' => array(
  381. array(
  382. 'type' => 'input',
  383. 'name' => 'logo',
  384. 'label' => 'Logo',
  385. 'value' => $GLOBALS['logo']
  386. ),
  387. array(
  388. 'type' => 'input',
  389. 'name' => 'title',
  390. 'label' => 'Title',
  391. 'value' => $GLOBALS['title']
  392. ),
  393. array(
  394. 'type' => 'switch',
  395. 'name' => 'useLogo',
  396. 'label' => 'Use Logo instead of Title',
  397. 'value' => $GLOBALS['useLogo']
  398. )
  399. ),
  400. 'Login Page' => array(
  401. array(
  402. 'type' => 'input',
  403. 'name' => 'loginWallpaper',
  404. 'label' => 'Login Wallpaper',
  405. 'value' => $GLOBALS['loginWallpaper']
  406. )
  407. ),
  408. 'Colors & Themes' => array(
  409. array(
  410. 'type' => 'input',
  411. 'name' => 'headerColor',
  412. 'label' => 'Nav Bar Color',
  413. 'value' => $GLOBALS['headerColor'],
  414. 'class' => 'colorpicker',
  415. 'disabled' => true
  416. ),
  417. array(
  418. 'type' => 'input',
  419. 'name' => 'headerTextColor',
  420. 'label' => 'Nav Bar Text Color',
  421. 'value' => $GLOBALS['headerTextColor'],
  422. 'class' => 'colorpicker',
  423. 'disabled' => true
  424. ),
  425. array(
  426. 'type' => 'input',
  427. 'name' => 'sidebarColor',
  428. 'label' => 'Side Bar Color',
  429. 'value' => $GLOBALS['sidebarColor'],
  430. 'class' => 'colorpicker',
  431. 'disabled' => true
  432. ),
  433. array(
  434. 'type' => 'input',
  435. 'name' => 'sidebarTextColor',
  436. 'label' => 'Side Bar Text Color',
  437. 'value' => $GLOBALS['sidebarTextColor'],
  438. 'class' => 'colorpicker',
  439. 'disabled' => true
  440. ),
  441. array(
  442. 'type' => 'select',
  443. 'name' => 'theme',
  444. 'label' => 'Theme',
  445. 'class' => 'themeChanger',
  446. 'value' => $GLOBALS['theme'],
  447. 'options' => getThemes()
  448. ),
  449. array(
  450. 'type' => 'select',
  451. 'name' => 'style',
  452. 'label' => 'Style',
  453. 'class' => 'styleChanger',
  454. 'value' => $GLOBALS['style'],
  455. 'options' => array(
  456. array(
  457. 'name' => 'Light',
  458. 'value' => 'light'
  459. ),
  460. array(
  461. 'name' => 'Dark',
  462. 'value' => 'dark'
  463. ),
  464. array(
  465. 'name' => 'Horizontal',
  466. 'value' => 'horizontal'
  467. )
  468. )
  469. ),
  470. array(
  471. 'type' => 'textbox',
  472. 'name' => 'customCss',
  473. 'class' => 'hidden cssTextarea',
  474. 'label' => '',
  475. 'value' => $GLOBALS['customCss'],
  476. 'placeholder' => 'No <style> tags needed',
  477. 'attr' => 'rows="10"',
  478. ),
  479. array(
  480. 'type' => 'html',
  481. 'override' => 12,
  482. 'label' => 'Custom CSS [Can replace colors from above]',
  483. 'html' => '<button type="button" class="hidden saveCss btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customCSSEditor" style="height:300px">'.$GLOBALS['customCss'].'</div>'
  484. ),
  485. )
  486. );
  487. }
  488. }
  489. function editAppearance($array){
  490. switch ($array['data']['value']) {
  491. case 'true':
  492. $array['data']['value'] = (bool) true;
  493. break;
  494. case 'false':
  495. $array['data']['value'] = (bool) false;
  496. break;
  497. default:
  498. $array['data']['value'] = $array['data']['value'];
  499. }
  500. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  501. switch ($array['data']['action']) {
  502. case 'editCustomizeAppearance':
  503. $newItem = array(
  504. $array['data']['name'] => $array['data']['value']
  505. );
  506. return (updateConfig($newItem)) ? true : false;
  507. break;
  508. default:
  509. # code...
  510. break;
  511. }
  512. }
  513. function updateConfigItem($array){
  514. switch ($array['data']['value']) {
  515. case 'true':
  516. $array['data']['value'] = (bool) true;
  517. break;
  518. case 'false':
  519. $array['data']['value'] = (bool) false;
  520. break;
  521. default:
  522. $array['data']['value'] = $array['data']['value'];
  523. }
  524. // Hash
  525. if($array['data']['type'] == 'password'){
  526. $array['data']['value'] = encrypt($array['data']['value']);
  527. }
  528. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  529. $newItem = array(
  530. $array['data']['name'] => $array['data']['value']
  531. );
  532. return (updateConfig($newItem)) ? true : false;
  533. }
  534. function getPlugins(){
  535. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  536. $pluginList = array();
  537. foreach($GLOBALS['plugins'] as $plugin){
  538. foreach ($plugin as $key => $value) {
  539. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  540. }
  541. $pluginList = array_merge($pluginList, $plugin);
  542. }
  543. return $pluginList;
  544. }
  545. return false;
  546. }
  547. function editPlugins($array){
  548. switch ($array['data']['action']) {
  549. case 'enable':
  550. $newItem = array(
  551. $array['data']['configName'] => true
  552. );
  553. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  554. return (updateConfig($newItem)) ? true : false;
  555. break;
  556. case 'disable':
  557. $newItem = array(
  558. $array['data']['configName'] => false
  559. );
  560. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  561. return (updateConfig($newItem)) ? true : false;
  562. break;
  563. default:
  564. # code...
  565. break;
  566. }
  567. }
  568. function auth(){
  569. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  570. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  571. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  572. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  573. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  574. $currentIP = userIP();
  575. if(isset($GLOBALS['organizrUser'])){
  576. $currentUser = $GLOBALS['organizrUser']['username'];
  577. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  578. }else{
  579. $currentUser = 'Guest';
  580. $currentGroup = getUserLevel();
  581. }
  582. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  583. if ($whitelist) {
  584. if(in_array($currentIP, arrayIP($whitelist))) {
  585. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  586. }
  587. }
  588. if ($blacklist) {
  589. if(in_array($currentIP, arrayIP($blacklist))) {
  590. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  591. }
  592. }
  593. if($group !== null){
  594. if(qualifyRequest($group)){
  595. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  596. }else{
  597. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  598. }
  599. }else{
  600. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  601. }
  602. }
  603. function logoOrText(){
  604. if($GLOBALS['useLogo'] == false){
  605. return '<h1>'.$GLOBALS['title'].'</h1>';
  606. }else{
  607. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  608. }
  609. }
  610. function getImages(){
  611. $dirname = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  612. $path = 'plugins/images/tabs/';
  613. $images = scandir($dirname);
  614. $ignore = Array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  615. $allIcons = array();
  616. foreach($images as $image){
  617. if(!in_array($image, $ignore)) {
  618. $allIcons[] = $path.$image;
  619. }
  620. }
  621. return $allIcons;
  622. }
  623. function editImages(){
  624. $array = array();
  625. $postCheck = array_filter($_POST);
  626. $filesCheck = array_filter($_FILES);
  627. if(!empty($postCheck)){
  628. if($_POST['data']['action'] == 'deleteImage'){
  629. if(file_exists(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])){
  630. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  631. return (unlink(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  632. }
  633. }
  634. }
  635. if(!empty($filesCheck)){
  636. ini_set('upload_max_filesize', '10M');
  637. ini_set('post_max_size', '10M');
  638. $tempFile = $_FILES['file']['tmp_name'];
  639. $targetPath = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  640. $targetFile = $targetPath. $_FILES['file']['name'];
  641. return (move_uploaded_file($tempFile,$targetFile)) ? true : false;
  642. }
  643. return false;
  644. }
  645. function getThemes(){
  646. $themes = array();
  647. foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename){
  648. $themes[] = array(
  649. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  650. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  651. );
  652. }
  653. return $themes;
  654. }
  655. function getBranches(){
  656. return array(
  657. array(
  658. 'name' => 'Develop',
  659. 'value' => 'v2-develop'
  660. ),
  661. array(
  662. 'name' => 'Master',
  663. 'value' => 'v2-master'
  664. )
  665. );
  666. }
  667. function getAuthTypes(){
  668. return array(
  669. array(
  670. 'name' => 'Organizr DB',
  671. 'value' => 'internal'
  672. ),
  673. array(
  674. 'name' => 'Organizr DB + Backend',
  675. 'value' => 'both'
  676. ),
  677. array(
  678. 'name' => 'Backend Only',
  679. 'value' => 'external'
  680. )
  681. );
  682. }
  683. function getAuthBackends(){
  684. $backendOptions = array();
  685. $backendOptions[] = array(
  686. 'name' => 'Choose Backend',
  687. 'value' => false,
  688. 'disabled' => true
  689. );
  690. foreach (array_filter(get_defined_functions()['user'],function($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) {
  691. $name = str_replace('plugin_auth_','',$value);
  692. if (strpos($name, 'disabled') === false) {
  693. $backendOptions[] = array(
  694. 'name' => ucwords(str_replace('_',' ',$name)),
  695. 'value' => $name
  696. );
  697. } else {
  698. $backendOptions[] = array(
  699. 'name' => $value(),
  700. 'value' => 'none',
  701. 'disabled' => true,
  702. );
  703. }
  704. }
  705. ksort($backendOptions);
  706. return $backendOptions;
  707. }
  708. function wizardPath($array){
  709. $path = $array['data']['path'];
  710. if(file_exists($path)){
  711. if(is_writable($path)){
  712. return true;
  713. }
  714. }else{
  715. if(is_writable(dirname($path, 1))){
  716. if(mkdir($path, 0760, true)) {
  717. return true;
  718. }
  719. }
  720. }
  721. return 'permissions';
  722. }
  723. function groupSelect(){
  724. $groups = allGroups();
  725. $select = array();
  726. foreach ($groups as $key => $value) {
  727. $select[] = array(
  728. 'name' => $value['group'],
  729. 'value' => $value['group_id']
  730. );
  731. }
  732. return $select;
  733. }
  734. function getImage() {
  735. $refresh = false;
  736. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  737. if (!file_exists($cacheDirectory)) {
  738. mkdir($cacheDirectory, 0777, true);
  739. }
  740. @$image_url = $_GET['img'];
  741. @$key = $_GET['key'];
  742. @$image_height = $_GET['height'];
  743. @$image_width = $_GET['width'];
  744. @$source = $_GET['source'];
  745. @$itemType = $_GET['type'];
  746. if(strpos($key, '$') !== false){
  747. $key = explode('$', $key)[0];
  748. $refresh = true;
  749. }
  750. switch ($source) {
  751. case 'plex':
  752. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  753. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  754. break;
  755. case 'emby':
  756. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  757. $imgParams = array();
  758. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  759. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  760. $image_src = $embyAddress . '/Items/'.$image_url.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  761. break;
  762. default:
  763. # code...
  764. break;
  765. }
  766. if(isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  767. $cachefile = $cacheDirectory.$key.'.jpg';
  768. $cachetime = 604800;
  769. // Serve from the cache if it is younger than $cachetime
  770. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  771. header("Content-type: image/jpeg");
  772. //@readfile($cachefile);
  773. echo @curl('get',$cachefile)['content'];
  774. exit;
  775. }
  776. ob_start(); // Start the output buffer
  777. header('Content-type: image/jpeg');
  778. //@readfile($image_src);
  779. echo @curl('get',$image_src)['content'];
  780. // Cache the output to a file
  781. $fp = fopen($cachefile, 'wb');
  782. fwrite($fp, ob_get_contents());
  783. fclose($fp);
  784. ob_end_flush(); // Send the output to the browser
  785. die();
  786. } else {
  787. die("Invalid Request");
  788. }
  789. }
  790. function cacheImage($url,$name){
  791. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  792. if (!file_exists($cacheDirectory)) {
  793. mkdir($cacheDirectory, 0777, true);
  794. }
  795. $cachefile = $cacheDirectory.$name.'.jpg';
  796. copy($url, $cachefile);
  797. }
  798. function downloader($array){
  799. switch ($array['data']['source']) {
  800. case 'sabnzbd':
  801. switch ($array['data']['action']) {
  802. case 'resume':
  803. case 'pause':
  804. sabnzbdAction($array['data']['action'],$array['data']['target']);
  805. break;
  806. default:
  807. # code...
  808. break;
  809. }
  810. break;
  811. case 'nzbget':
  812. break;
  813. default:
  814. # code...
  815. break;
  816. }
  817. }
  818. function sabnzbdAction($action=null, $target=null) {
  819. if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
  820. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  821. switch ($action) {
  822. case 'pause':
  823. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value='.$target.'&' : 'mode=pause';
  824. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  825. break;
  826. case 'resume':
  827. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value='.$target.'&' : 'mode=resume';
  828. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  829. break;
  830. default:
  831. # code...
  832. break;
  833. }
  834. try{
  835. $options = (localURL($url)) ? array('verify' => false ) : array();
  836. $response = Requests::get($url, array(), $options);
  837. if($response->success){
  838. $api['content'] = json_decode($response->body, true);
  839. }
  840. }catch( Requests_Exception $e ) {
  841. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  842. };
  843. $api['content'] = isset($api['content']) ? $api['content'] : false;
  844. return $api;
  845. }
  846. }
  847. /*
  848. function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  849. try {
  850. $mail = new PHPMailer(true);
  851. $mail->isSMTP();
  852. $mail->Host = $GLOBALS['smtpHost'];
  853. $mail->SMTPAuth = $GLOBALS['smtpHostAuth'];
  854. $mail->Username = $GLOBALS['smtpHostUsername'];
  855. $mail->Password = $GLOBALS['smtpHostPassword'];
  856. $mail->SMTPSecure = $GLOBALS['smtpHostType'];
  857. $mail->Port = $GLOBALS['smtpHostPort'];
  858. $mail->setFrom($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  859. $mail->addReplyTo($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  860. $mail->isHTML(true);
  861. if($email){
  862. $mail->addAddress($email, $username);
  863. }
  864. if($cc){
  865. $mail->addCC($cc);
  866. }
  867. if($bcc){
  868. if(strpos($bcc , ',') === false){
  869. $mail->addBCC($bcc);
  870. }else{
  871. $allEmails = explode(",",$bcc);
  872. foreach($allEmails as $gotEmail){
  873. $mail->addBCC($gotEmail);
  874. }
  875. }
  876. }
  877. $mail->Subject = $subject;
  878. $mail->Body = $body;
  879. $mail->send();
  880. writeLog('success', 'Mail Function - E-Mail Sent', $GLOBALS['organizrUser']['username']);
  881. return true;
  882. } catch (Exception $e) {
  883. writeLog('error', 'Mail Function - E-Mail Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  884. return false;
  885. }
  886. return false;
  887. }
  888. //EMAIL SHIT
  889. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  890. try {
  891. $mail = new PHPMailer(true);
  892. $mail->isSMTP();
  893. $mail->Host = $host;
  894. $mail->SMTPAuth = $auth;
  895. $mail->Username = $username;
  896. $mail->Password = $password;
  897. $mail->SMTPSecure = $type;
  898. $mail->Port = $port;
  899. $mail->setFrom($from, $sendername);
  900. $mail->addReplyTo($from, $sendername);
  901. $mail->isHTML(true);
  902. $mail->addAddress($to, "Organizr Admin");
  903. $mail->Subject = "Organizr Test E-Mail";
  904. $mail->Body = "This was just a test!";
  905. $mail->send();
  906. writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
  907. return true;
  908. } catch (Exception $e) {
  909. writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  910. return false;
  911. }
  912. return false;
  913. }
  914. */