organizr-functions.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  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' => 'input',
  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' => 'input',
  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' => 'input',
  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' => 'input',
  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' => 'input',
  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' => 'input',
  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['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  370. return $appearance;
  371. }
  372. function getCustomizeAppearance(){
  373. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  374. return array(
  375. 'Top Bar' => array(
  376. array(
  377. 'type' => 'input',
  378. 'name' => 'logo',
  379. 'label' => 'Logo',
  380. 'value' => $GLOBALS['logo']
  381. ),
  382. array(
  383. 'type' => 'input',
  384. 'name' => 'title',
  385. 'label' => 'Title',
  386. 'value' => $GLOBALS['title']
  387. ),
  388. array(
  389. 'type' => 'switch',
  390. 'name' => 'useLogo',
  391. 'label' => 'Use Logo instead of Title',
  392. 'value' => $GLOBALS['useLogo']
  393. )
  394. ),
  395. 'Login Page' => array(
  396. array(
  397. 'type' => 'input',
  398. 'name' => 'loginWallpaper',
  399. 'label' => 'Login Wallpaper',
  400. 'value' => $GLOBALS['loginWallpaper']
  401. )
  402. ),
  403. 'Colors & Themes' => array(
  404. array(
  405. 'type' => 'input',
  406. 'name' => 'headerColor',
  407. 'label' => 'Nav Bar Color',
  408. 'value' => $GLOBALS['headerColor'],
  409. 'class' => 'colorpicker',
  410. 'disabled' => true
  411. ),
  412. array(
  413. 'type' => 'input',
  414. 'name' => 'headerTextColor',
  415. 'label' => 'Nav Bar Text Color',
  416. 'value' => $GLOBALS['headerTextColor'],
  417. 'class' => 'colorpicker',
  418. 'disabled' => true
  419. ),
  420. array(
  421. 'type' => 'input',
  422. 'name' => 'sidebarColor',
  423. 'label' => 'Side Bar Color',
  424. 'value' => $GLOBALS['sidebarColor'],
  425. 'class' => 'colorpicker',
  426. 'disabled' => true
  427. ),
  428. array(
  429. 'type' => 'input',
  430. 'name' => 'sidebarTextColor',
  431. 'label' => 'Side Bar Text Color',
  432. 'value' => $GLOBALS['sidebarTextColor'],
  433. 'class' => 'colorpicker',
  434. 'disabled' => true
  435. ),
  436. array(
  437. 'type' => 'select',
  438. 'name' => 'theme',
  439. 'label' => 'Theme',
  440. 'class' => 'themeChanger',
  441. 'value' => $GLOBALS['theme'],
  442. 'options' => getThemes()
  443. ),
  444. array(
  445. 'type' => 'select',
  446. 'name' => 'style',
  447. 'label' => 'Style',
  448. 'class' => 'styleChanger',
  449. 'value' => $GLOBALS['style'],
  450. 'options' => array(
  451. array(
  452. 'name' => 'Light',
  453. 'value' => 'light'
  454. ),
  455. array(
  456. 'name' => 'Dark',
  457. 'value' => 'dark'
  458. ),
  459. array(
  460. 'name' => 'Horizontal',
  461. 'value' => 'horizontal'
  462. )
  463. )
  464. )
  465. )
  466. );
  467. }
  468. }
  469. function editAppearance($array){
  470. switch ($array['data']['value']) {
  471. case 'true':
  472. $array['data']['value'] = (bool) true;
  473. break;
  474. case 'false':
  475. $array['data']['value'] = (bool) false;
  476. break;
  477. default:
  478. $array['data']['value'] = $array['data']['value'];
  479. }
  480. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  481. switch ($array['data']['action']) {
  482. case 'editCustomizeAppearance':
  483. $newItem = array(
  484. $array['data']['name'] => $array['data']['value']
  485. );
  486. return (updateConfig($newItem)) ? true : false;
  487. break;
  488. default:
  489. # code...
  490. break;
  491. }
  492. }
  493. function updateConfigItem($array){
  494. switch ($array['data']['value']) {
  495. case 'true':
  496. $array['data']['value'] = (bool) true;
  497. break;
  498. case 'false':
  499. $array['data']['value'] = (bool) false;
  500. break;
  501. default:
  502. $array['data']['value'] = $array['data']['value'];
  503. }
  504. // Hash
  505. if($array['data']['type'] == 'password'){
  506. $array['data']['value'] = encrypt($array['data']['value']);
  507. }
  508. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  509. $newItem = array(
  510. $array['data']['name'] => $array['data']['value']
  511. );
  512. return (updateConfig($newItem)) ? true : false;
  513. }
  514. function getPlugins(){
  515. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  516. $pluginList = array();
  517. foreach($GLOBALS['plugins'] as $plugin){
  518. foreach ($plugin as $key => $value) {
  519. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  520. }
  521. $pluginList = array_merge($pluginList, $plugin);
  522. }
  523. return $pluginList;
  524. }
  525. return false;
  526. }
  527. function editPlugins($array){
  528. switch ($array['data']['action']) {
  529. case 'enable':
  530. $newItem = array(
  531. $array['data']['configName'] => true
  532. );
  533. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  534. return (updateConfig($newItem)) ? true : false;
  535. break;
  536. case 'disable':
  537. $newItem = array(
  538. $array['data']['configName'] => false
  539. );
  540. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  541. return (updateConfig($newItem)) ? true : false;
  542. break;
  543. default:
  544. # code...
  545. break;
  546. }
  547. }
  548. function auth(){
  549. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  550. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  551. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  552. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  553. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  554. $currentIP = userIP();
  555. if(isset($GLOBALS['organizrUser'])){
  556. $currentUser = $GLOBALS['organizrUser']['username'];
  557. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  558. }else{
  559. $currentUser = 'Guest';
  560. $currentGroup = getUserLevel();
  561. }
  562. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  563. if ($whitelist) {
  564. if(in_array($currentIP, arrayIP($whitelist))) {
  565. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  566. }
  567. }
  568. if ($blacklist) {
  569. if(in_array($currentIP, arrayIP($blacklist))) {
  570. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  571. }
  572. }
  573. if($group !== null){
  574. if(qualifyRequest($group)){
  575. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  576. }else{
  577. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  578. }
  579. }else{
  580. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  581. }
  582. }
  583. function logoOrText(){
  584. if($GLOBALS['useLogo'] == false){
  585. return '<h1>'.$GLOBALS['title'].'</h1>';
  586. }else{
  587. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  588. }
  589. }
  590. function getImages(){
  591. $dirname = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  592. $path = 'plugins/images/tabs/';
  593. $images = scandir($dirname);
  594. $ignore = Array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  595. $allIcons = array();
  596. foreach($images as $image){
  597. if(!in_array($image, $ignore)) {
  598. $allIcons[] = $path.$image;
  599. }
  600. }
  601. return $allIcons;
  602. }
  603. function editImages(){
  604. $array = array();
  605. $postCheck = array_filter($_POST);
  606. $filesCheck = array_filter($_FILES);
  607. if(!empty($postCheck)){
  608. if($_POST['data']['action'] == 'deleteImage'){
  609. if(file_exists(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])){
  610. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  611. return (unlink(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  612. }
  613. }
  614. }
  615. if(!empty($filesCheck)){
  616. ini_set('upload_max_filesize', '10M');
  617. ini_set('post_max_size', '10M');
  618. $tempFile = $_FILES['file']['tmp_name'];
  619. $targetPath = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  620. $targetFile = $targetPath. $_FILES['file']['name'];
  621. return (move_uploaded_file($tempFile,$targetFile)) ? true : false;
  622. }
  623. return false;
  624. }
  625. function getThemes(){
  626. $themes = array();
  627. foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename){
  628. $themes[] = array(
  629. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  630. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  631. );
  632. }
  633. return $themes;
  634. }
  635. function getBranches(){
  636. return array(
  637. array(
  638. 'name' => 'Develop',
  639. 'value' => 'v2-develop'
  640. ),
  641. array(
  642. 'name' => 'Master',
  643. 'value' => 'v2-master'
  644. )
  645. );
  646. }
  647. function getAuthTypes(){
  648. return array(
  649. array(
  650. 'name' => 'Organizr DB',
  651. 'value' => 'internal'
  652. ),
  653. array(
  654. 'name' => 'Organizr DB + Backend',
  655. 'value' => 'both'
  656. ),
  657. array(
  658. 'name' => 'Backend Only',
  659. 'value' => 'external'
  660. )
  661. );
  662. }
  663. function getAuthBackends(){
  664. $backendOptions = array();
  665. $backendOptions[] = array(
  666. 'name' => 'Choose Backend',
  667. 'value' => false,
  668. 'disabled' => true
  669. );
  670. foreach (array_filter(get_defined_functions()['user'],function($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) {
  671. $name = str_replace('plugin_auth_','',$value);
  672. if (strpos($name, 'disabled') === false) {
  673. $backendOptions[] = array(
  674. 'name' => ucwords(str_replace('_',' ',$name)),
  675. 'value' => $name
  676. );
  677. } else {
  678. $backendOptions[] = array(
  679. 'name' => $value(),
  680. 'value' => 'none',
  681. 'disabled' => true,
  682. );
  683. }
  684. }
  685. ksort($backendOptions);
  686. return $backendOptions;
  687. }
  688. function wizardPath($array){
  689. $path = $array['data']['path'];
  690. if(file_exists($path)){
  691. if(is_writable($path)){
  692. return true;
  693. }
  694. }else{
  695. if(is_writable(dirname($path, 1))){
  696. if(mkdir($path, 0760, true)) {
  697. return true;
  698. }
  699. }
  700. }
  701. return 'permissions';
  702. }
  703. function groupSelect(){
  704. $groups = allGroups();
  705. $select = array();
  706. foreach ($groups as $key => $value) {
  707. $select[] = array(
  708. 'name' => $value['group'],
  709. 'value' => $value['group_id']
  710. );
  711. }
  712. return $select;
  713. }
  714. function getImage() {
  715. $refresh = false;
  716. $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
  717. if (!file_exists($cacheDirectory)) {
  718. mkdir($cacheDirectory, 0777, true);
  719. }
  720. @$image_url = $_GET['img'];
  721. @$key = $_GET['key'];
  722. @$image_height = $_GET['height'];
  723. @$image_width = $_GET['width'];
  724. @$source = $_GET['source'];
  725. @$itemType = $_GET['type'];
  726. if(strpos($key, '$') !== false){
  727. $key = explode('$', $key)[0];
  728. $refresh = true;
  729. }
  730. switch ($source) {
  731. case 'plex':
  732. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  733. $image_src = $plexAddress . '/photo/:/transcode?height='.$image_height.'&width='.$image_width.'&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  734. break;
  735. case 'emby':
  736. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  737. $imgParams = array();
  738. if (isset($_GET['height'])) { $imgParams['height'] = 'maxHeight='.$_GET['height']; }
  739. if (isset($_GET['width'])) { $imgParams['width'] = 'maxWidth='.$_GET['width']; }
  740. $image_src = $embyAddress . '/Items/'.$image_url.'/Images/'.$itemType.'?'.implode('&', $imgParams);
  741. break;
  742. default:
  743. # code...
  744. break;
  745. }
  746. if(isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  747. $cachefile = $cacheDirectory.$key.'.jpg';
  748. $cachetime = 604800;
  749. // Serve from the cache if it is younger than $cachetime
  750. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  751. header("Content-type: image/jpeg");
  752. //@readfile($cachefile);
  753. echo @curl('get',$cachefile)['content'];
  754. exit;
  755. }
  756. ob_start(); // Start the output buffer
  757. header('Content-type: image/jpeg');
  758. //@readfile($image_src);
  759. echo @curl('get',$image_src)['content'];
  760. // Cache the output to a file
  761. $fp = fopen($cachefile, 'wb');
  762. fwrite($fp, ob_get_contents());
  763. fclose($fp);
  764. ob_end_flush(); // Send the output to the browser
  765. die();
  766. } else {
  767. die("Invalid Request");
  768. }
  769. }
  770. function downloader($array){
  771. switch ($array['data']['source']) {
  772. case 'sabnzbd':
  773. switch ($array['data']['action']) {
  774. case 'resume':
  775. case 'pause':
  776. sabnzbdAction($array['data']['action'],$array['data']['target']);
  777. break;
  778. default:
  779. # code...
  780. break;
  781. }
  782. break;
  783. case 'nzbget':
  784. break;
  785. default:
  786. # code...
  787. break;
  788. }
  789. }
  790. function sabnzbdAction($action=null, $target=null) {
  791. if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
  792. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  793. switch ($action) {
  794. case 'pause':
  795. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value='.$target.'&' : 'mode=pause';
  796. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  797. break;
  798. case 'resume':
  799. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value='.$target.'&' : 'mode=resume';
  800. $url = $url.'/api?'.$id.'&output=json&apikey='.$GLOBALS['sabnzbdToken'];
  801. break;
  802. default:
  803. # code...
  804. break;
  805. }
  806. try{
  807. $options = (localURL($url)) ? array('verify' => false ) : array();
  808. $response = Requests::get($url, array(), $options);
  809. if($response->success){
  810. $api['content'] = json_decode($response->body, true);
  811. }
  812. }catch( Requests_Exception $e ) {
  813. writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
  814. };
  815. $api['content'] = isset($api['content']) ? $api['content'] : false;
  816. return $api;
  817. }
  818. }
  819. /*
  820. function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  821. try {
  822. $mail = new PHPMailer(true);
  823. $mail->isSMTP();
  824. $mail->Host = $GLOBALS['smtpHost'];
  825. $mail->SMTPAuth = $GLOBALS['smtpHostAuth'];
  826. $mail->Username = $GLOBALS['smtpHostUsername'];
  827. $mail->Password = $GLOBALS['smtpHostPassword'];
  828. $mail->SMTPSecure = $GLOBALS['smtpHostType'];
  829. $mail->Port = $GLOBALS['smtpHostPort'];
  830. $mail->setFrom($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  831. $mail->addReplyTo($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  832. $mail->isHTML(true);
  833. if($email){
  834. $mail->addAddress($email, $username);
  835. }
  836. if($cc){
  837. $mail->addCC($cc);
  838. }
  839. if($bcc){
  840. if(strpos($bcc , ',') === false){
  841. $mail->addBCC($bcc);
  842. }else{
  843. $allEmails = explode(",",$bcc);
  844. foreach($allEmails as $gotEmail){
  845. $mail->addBCC($gotEmail);
  846. }
  847. }
  848. }
  849. $mail->Subject = $subject;
  850. $mail->Body = $body;
  851. $mail->send();
  852. writeLog('success', 'Mail Function - E-Mail Sent', $GLOBALS['organizrUser']['username']);
  853. return true;
  854. } catch (Exception $e) {
  855. writeLog('error', 'Mail Function - E-Mail Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  856. return false;
  857. }
  858. return false;
  859. }
  860. //EMAIL SHIT
  861. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  862. try {
  863. $mail = new PHPMailer(true);
  864. $mail->isSMTP();
  865. $mail->Host = $host;
  866. $mail->SMTPAuth = $auth;
  867. $mail->Username = $username;
  868. $mail->Password = $password;
  869. $mail->SMTPSecure = $type;
  870. $mail->Port = $port;
  871. $mail->setFrom($from, $sendername);
  872. $mail->addReplyTo($from, $sendername);
  873. $mail->isHTML(true);
  874. $mail->addAddress($to, "Organizr Admin");
  875. $mail->Subject = "Organizr Test E-Mail";
  876. $mail->Body = "This was just a test!";
  877. $mail->send();
  878. writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
  879. return true;
  880. } catch (Exception $e) {
  881. writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  882. return false;
  883. }
  884. return false;
  885. }
  886. */