organizr-functions.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. }
  36. }
  37. }
  38. }
  39. return false;
  40. }
  41. function register($array){
  42. // Grab username and password from login form
  43. foreach ($array['data'] as $items) {
  44. foreach ($items as $key => $value) {
  45. if($key == 'name'){
  46. $newKey = $value;
  47. }
  48. if($key == 'value'){
  49. $newValue = $value;
  50. }
  51. if(isset($newKey) && isset($newValue)){
  52. $$newKey = $newValue;
  53. }
  54. }
  55. }
  56. if($registrationPassword == $GLOBALS['registrationPassword']){
  57. $defaults = defaultUserGroup();
  58. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  59. if(createUser($username,$password,$defaults,$email)){
  60. writeLog('success', 'Registration Function - A User has registered', $username);
  61. if(createToken($username,$email,gravatar($email),$defaults['group'],$defaults['group_id'],$GLOBALS['organizrHash'],1)){
  62. writeLoginLog($username, 'success');
  63. writeLog('success', 'Login Function - A User has logged in', $username);
  64. return true;
  65. }
  66. }else{
  67. writeLog('error', 'Registration Function - An error occured', $username);
  68. return 'username taken';
  69. }
  70. }else{
  71. writeLog('warning', 'Registration Function - Wrong Password', $username);
  72. return 'mismatch';
  73. }
  74. }
  75. function editUser($array){
  76. return $array;
  77. }
  78. function logout(){
  79. coookie('delete','organizrToken');
  80. $GLOBALS['organizrUser'] = false;
  81. return true;
  82. }
  83. function qualifyRequest($accessLevelNeeded){
  84. if(getUserLevel() <= $accessLevelNeeded){
  85. return true;
  86. }else{
  87. return false;
  88. }
  89. }
  90. function getUserLevel(){
  91. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  92. // Check token or API key
  93. // If API key, return 0 for admin
  94. if(strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']){
  95. //DO API CHECK
  96. return 0;
  97. }elseif(isset($GLOBALS['organizrUser'])){
  98. return $GLOBALS['organizrUser']['groupID'];
  99. }
  100. // All else fails? return guest id
  101. return 999;
  102. }
  103. function organizrStatus(){
  104. $status = array();
  105. $dependenciesActive = array();
  106. $dependenciesInactive = array();
  107. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  108. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  109. foreach($extensions as $check){
  110. if(extension_loaded($check)){
  111. array_push($dependenciesActive,$check);
  112. }else{
  113. array_push($dependenciesInactive,$check);
  114. }
  115. }
  116. foreach($functions as $check){
  117. if(function_exists($check)){
  118. array_push($dependenciesActive,$check);
  119. }else{
  120. array_push($dependenciesInactive,$check);
  121. }
  122. }
  123. if(!file_exists('config'.DIRECTORY_SEPARATOR.'config.php')){
  124. $status['status'] = "wizard";//wizard - ok for test
  125. }
  126. if(count($dependenciesInactive)>0 || !is_writable(dirname(__DIR__,2))){
  127. $status['status'] = "dependencies";
  128. }
  129. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  130. $status['writable'] = is_writable(dirname(__DIR__,2)) ? 'yes' : 'no';
  131. $status['dependenciesActive'] = $dependenciesActive;
  132. $status['dependenciesInactive'] = $dependenciesInactive;
  133. $status['version'] = $GLOBALS['installedVersion'];
  134. $status['os'] = getOS();
  135. $status['php'] = phpversion();
  136. return $status;
  137. }
  138. function getSettingsMain(){
  139. return array(
  140. 'Github' => array(
  141. array(
  142. 'type' => 'select',
  143. 'name' => 'branch',
  144. 'label' => 'Branch',
  145. 'value' => $GLOBALS['branch'],
  146. 'options' => getBranches()
  147. ),
  148. array(
  149. 'type' => 'button',
  150. 'label' => 'Force Install Branch',
  151. 'class' => 'updateNow',
  152. 'icon' => 'fa fa-paper-plane',
  153. 'text' => 'Retrieve'
  154. )
  155. ),
  156. 'Authentication' => array(
  157. array(
  158. 'type' => 'select',
  159. 'name' => 'authType',
  160. 'id' => 'authSelect',
  161. 'label' => 'Authentication Type',
  162. 'value' => $GLOBALS['authType'],
  163. 'options' => getAuthTypes()
  164. ),
  165. array(
  166. 'type' => 'select',
  167. 'name' => 'authBackend',
  168. 'id' => 'authBackendSelect',
  169. 'label' => 'Authentication Backend',
  170. 'class' => 'backendAuth switchAuth',
  171. 'value' => $GLOBALS['authBackend'],
  172. 'options' => getAuthBackends()
  173. ),
  174. array(
  175. 'type' => 'input',
  176. 'name' => 'plexToken',
  177. 'class' => 'plexAuth switchAuth',
  178. 'label' => 'Plex Token',
  179. 'value' => $GLOBALS['plexToken'],
  180. 'placeholder' => 'Use Get Token Button'
  181. ),
  182. array(
  183. 'type' => 'button',
  184. 'label' => 'Get Plex Token',
  185. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  186. 'icon' => 'fa fa-paper-plane',
  187. 'text' => 'Retrieve',
  188. 'href' => '#auth-plex-token-form',
  189. 'attr' => 'data-effect="mfp-3d-unfold"'
  190. ),
  191. array(
  192. 'type' => 'input',
  193. 'name' => 'plexID',
  194. 'class' => 'plexAuth switchAuth',
  195. 'label' => 'Plex Machine',
  196. 'value' => $GLOBALS['plexID'],
  197. 'placeholder' => 'Use Get Plex Machine Button'
  198. ),
  199. array(
  200. 'type' => 'button',
  201. 'label' => 'Get Plex Machine',
  202. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  203. 'icon' => 'fa fa-paper-plane',
  204. 'text' => 'Retrieve',
  205. 'href' => '#auth-plex-machine-form',
  206. 'attr' => 'data-effect="mfp-3d-unfold"'
  207. ),
  208. array(
  209. 'type' => 'input',
  210. 'name' => 'authBackendHost',
  211. 'class' => 'ldapAuth ftpAuth switchAuth',
  212. 'label' => 'Host Address',
  213. 'value' => $GLOBALS['authBackendHost'],
  214. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  215. ),
  216. array(
  217. 'type' => 'input',
  218. 'name' => 'authBaseDN',
  219. 'class' => 'ldapAuth switchAuth',
  220. 'label' => 'Host Base DN',
  221. 'value' => $GLOBALS['authBaseDN'],
  222. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  223. ),
  224. array(
  225. 'type' => 'input',
  226. 'name' => 'embyURL',
  227. 'class' => 'embyAuth switchAuth',
  228. 'label' => 'Emby URL',
  229. 'value' => $GLOBALS['embyURL'],
  230. 'placeholder' => ''
  231. ),
  232. array(
  233. 'type' => 'input',
  234. 'name' => 'embyToken',
  235. 'class' => 'embyAuth switchAuth',
  236. 'label' => 'Emby Token',
  237. 'value' => $GLOBALS['embyToken'],
  238. 'placeholder' => ''
  239. )
  240. /*array(
  241. 'type' => 'button',
  242. 'label' => 'Send Test',
  243. 'class' => 'phpmSendTestEmail',
  244. 'icon' => 'fa fa-paper-plane',
  245. 'text' => 'Send'
  246. )*/
  247. )
  248. );
  249. }
  250. function getSSO(){
  251. return array(
  252. 'Plex' => array(
  253. array(
  254. 'type' => 'input',
  255. 'name' => 'plexToken',
  256. 'label' => 'Plex Token',
  257. 'value' => $GLOBALS['plexToken'],
  258. 'placeholder' => 'Use Get Token Button'
  259. ),
  260. array(
  261. 'type' => 'button',
  262. 'label' => 'Get Plex Token',
  263. 'class' => 'popup-with-form getPlexTokenSSO',
  264. 'icon' => 'fa fa-paper-plane',
  265. 'text' => 'Retrieve',
  266. 'href' => '#sso-plex-token-form',
  267. 'attr' => 'data-effect="mfp-3d-unfold"'
  268. ),
  269. array(
  270. 'type' => 'input',
  271. 'name' => 'plexID',
  272. 'label' => 'Plex Machine',
  273. 'value' => $GLOBALS['plexID'],
  274. 'placeholder' => 'Use Get Plex Machine Button'
  275. ),
  276. array(
  277. 'type' => 'button',
  278. 'label' => 'Get Plex Machine',
  279. 'class' => 'popup-with-form getPlexMachineSSO',
  280. 'icon' => 'fa fa-paper-plane',
  281. 'text' => 'Retrieve',
  282. 'href' => '#sso-plex-machine-form',
  283. 'attr' => 'data-effect="mfp-3d-unfold"'
  284. ),
  285. array(
  286. 'type' => 'html',
  287. 'label' => 'Plex Note',
  288. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  289. ),
  290. array(
  291. 'type' => 'switch',
  292. 'name' => 'ssoPlex',
  293. 'label' => 'Enable',
  294. 'value' => $GLOBALS['ssoPlex']
  295. )
  296. ),
  297. 'Ombu' => array(
  298. array(
  299. 'type' => 'input',
  300. 'name' => 'ombiURL',
  301. 'label' => 'Ombi URL',
  302. 'value' => $GLOBALS['ombiURL'],
  303. 'placeholder' => 'http(s)://hostname'
  304. ),
  305. array(
  306. 'type' => 'switch',
  307. 'name' => 'ssoOmbi',
  308. 'label' => 'Enable',
  309. 'value' => $GLOBALS['ssoOmbi']
  310. )
  311. ),
  312. 'Tautulli' => array(
  313. array(
  314. 'type' => 'input',
  315. 'name' => 'tautulliURL',
  316. 'label' => 'Tautulli URL',
  317. 'value' => $GLOBALS['tautulliURL'],
  318. 'placeholder' => 'http(s)://hostname'
  319. ),
  320. array(
  321. 'type' => 'switch',
  322. 'name' => 'ssoTautulli',
  323. 'label' => 'Enable',
  324. 'value' => $GLOBALS['ssoTautulli']
  325. )
  326. )
  327. );
  328. }
  329. function loadAppearance(){
  330. $appearance = array();
  331. $appearance['logo'] = $GLOBALS['logo'];
  332. $appearance['title'] = $GLOBALS['title'];
  333. $appearance['useLogo'] = $GLOBALS['useLogo'];
  334. $appearance['headerColor'] = $GLOBALS['headerColor'];
  335. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  336. return $appearance;
  337. }
  338. function getCustomizeAppearance(){
  339. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  340. return array(
  341. 'Top Bar' => array(
  342. array(
  343. 'type' => 'input',
  344. 'name' => 'logo',
  345. 'label' => 'Logo',
  346. 'value' => $GLOBALS['logo']
  347. ),
  348. array(
  349. 'type' => 'input',
  350. 'name' => 'title',
  351. 'label' => 'Title',
  352. 'value' => $GLOBALS['title']
  353. ),
  354. array(
  355. 'type' => 'switch',
  356. 'name' => 'useLogo',
  357. 'label' => 'Use Logo instead of Title',
  358. 'value' => $GLOBALS['useLogo']
  359. )
  360. ),
  361. 'Login Page' => array(
  362. array(
  363. 'type' => 'input',
  364. 'name' => 'loginWallpaper',
  365. 'label' => 'Login Wallpaper',
  366. 'value' => $GLOBALS['loginWallpaper']
  367. )
  368. ),
  369. 'Colors & Themes' => array(
  370. array(
  371. 'type' => 'input',
  372. 'name' => 'headerColor',
  373. 'label' => 'Nav Bar Color',
  374. 'value' => $GLOBALS['headerColor'],
  375. 'class' => 'colorpicker',
  376. 'disabled' => true
  377. ),
  378. array(
  379. 'type' => 'input',
  380. 'name' => 'headerTextColor',
  381. 'label' => 'Nav Bar Text Color',
  382. 'value' => $GLOBALS['headerTextColor'],
  383. 'class' => 'colorpicker',
  384. 'disabled' => true
  385. ),
  386. array(
  387. 'type' => 'input',
  388. 'name' => 'sidebarColor',
  389. 'label' => 'Side Bar Color',
  390. 'value' => $GLOBALS['sidebarColor'],
  391. 'class' => 'colorpicker',
  392. 'disabled' => true
  393. ),
  394. array(
  395. 'type' => 'input',
  396. 'name' => 'sidebarTextColor',
  397. 'label' => 'Side Bar Text Color',
  398. 'value' => $GLOBALS['sidebarTextColor'],
  399. 'class' => 'colorpicker',
  400. 'disabled' => true
  401. ),
  402. array(
  403. 'type' => 'select',
  404. 'name' => 'theme',
  405. 'label' => 'Theme',
  406. 'class' => 'themeChanger',
  407. 'value' => $GLOBALS['theme'],
  408. 'options' => getThemes()
  409. ),
  410. array(
  411. 'type' => 'select',
  412. 'name' => 'style',
  413. 'label' => 'Style',
  414. 'class' => 'styleChanger',
  415. 'value' => $GLOBALS['style'],
  416. 'options' => array(
  417. array(
  418. 'name' => 'Light',
  419. 'value' => 'light'
  420. ),
  421. array(
  422. 'name' => 'Dark',
  423. 'value' => 'dark'
  424. )
  425. )
  426. )
  427. )
  428. );
  429. }
  430. }
  431. function editAppearance($array){
  432. switch ($array['data']['value']) {
  433. case 'true':
  434. $array['data']['value'] = (bool) true;
  435. break;
  436. case 'false':
  437. $array['data']['value'] = (bool) false;
  438. break;
  439. default:
  440. $array['data']['value'] = $array['data']['value'];
  441. }
  442. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  443. switch ($array['data']['action']) {
  444. case 'editCustomizeAppearance':
  445. $newItem = array(
  446. $array['data']['name'] => $array['data']['value']
  447. );
  448. return (updateConfig($newItem)) ? true : false;
  449. break;
  450. default:
  451. # code...
  452. break;
  453. }
  454. }
  455. function updateConfigItem($array){
  456. switch ($array['data']['value']) {
  457. case 'true':
  458. $array['data']['value'] = (bool) true;
  459. break;
  460. case 'false':
  461. $array['data']['value'] = (bool) false;
  462. break;
  463. default:
  464. $array['data']['value'] = $array['data']['value'];
  465. }
  466. // Hash
  467. if($array['data']['type'] == 'password'){
  468. $array['data']['value'] = encrypt($array['data']['value']);
  469. }
  470. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  471. $newItem = array(
  472. $array['data']['name'] => $array['data']['value']
  473. );
  474. return (updateConfig($newItem)) ? true : false;
  475. }
  476. function getPlugins(){
  477. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  478. $pluginList = array();
  479. foreach($GLOBALS['plugins'] as $plugin){
  480. foreach ($plugin as $key => $value) {
  481. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  482. }
  483. $pluginList = array_merge($pluginList, $plugin);
  484. }
  485. return $pluginList;
  486. }
  487. return false;
  488. }
  489. function editPlugins($array){
  490. switch ($array['data']['action']) {
  491. case 'enable':
  492. $newItem = array(
  493. $array['data']['configName'] => true
  494. );
  495. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  496. return (updateConfig($newItem)) ? true : false;
  497. break;
  498. case 'disable':
  499. $newItem = array(
  500. $array['data']['configName'] => false
  501. );
  502. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  503. return (updateConfig($newItem)) ? true : false;
  504. break;
  505. default:
  506. # code...
  507. break;
  508. }
  509. }
  510. function auth(){
  511. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  512. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  513. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  514. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  515. $group = isset($_GET['group']) ? $_GET['group'] : 0;
  516. $currentIP = userIP();
  517. $currentUser = $GLOBALS['organizrUser']['username'];
  518. if ($whitelist) {
  519. if(in_array($currentIP, arrayIP($whitelist))) {
  520. !$debug ? exit(http_response_code(200)) : die("$currentIP Whitelist Authorized");
  521. }
  522. }
  523. if ($blacklist) {
  524. if(in_array($currentIP, arrayIP($blacklist))) {
  525. !$debug ? exit(http_response_code(401)) : die("$currentIP Blacklisted");
  526. }
  527. }
  528. if($group !== null){
  529. if(qualifyRequest($group)){
  530. !$debug ? exit(http_response_code(200)) : die("$currentUser on $currentIP Authorized");
  531. }else{
  532. !$debug ? exit(http_response_code(401)) : die("$currentUser on $currentIP Not Authorized");
  533. }
  534. }else{
  535. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  536. }
  537. }
  538. function logoOrText(){
  539. if($GLOBALS['useLogo'] == false){
  540. return '<h1>'.$GLOBALS['title'].'</h1>';
  541. }else{
  542. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  543. }
  544. }
  545. function getImages(){
  546. $dirname = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  547. $path = 'plugins/images/tabs/';
  548. $images = scandir($dirname);
  549. $ignore = Array(".", "..", "._.DS_Store", ".DS_Store");
  550. $allIcons = array();
  551. foreach($images as $image){
  552. if(!in_array($image, $ignore)) {
  553. $allIcons[] = $path.$image;
  554. }
  555. }
  556. return $allIcons;
  557. }
  558. function editImages(){
  559. $array = array();
  560. $postCheck = array_filter($_POST);
  561. $filesCheck = array_filter($_FILES);
  562. if(!empty($postCheck)){
  563. if($_POST['data']['action'] == 'deleteImage'){
  564. if(file_exists(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])){
  565. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  566. return (unlink(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  567. }
  568. }
  569. }
  570. if(!empty($filesCheck)){
  571. ini_set('upload_max_filesize', '10M');
  572. ini_set('post_max_size', '10M');
  573. $tempFile = $_FILES['file']['tmp_name'];
  574. $targetPath = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  575. $targetFile = $targetPath. $_FILES['file']['name'];
  576. return (move_uploaded_file($tempFile,$targetFile)) ? true : false;
  577. }
  578. return false;
  579. }
  580. function getThemes(){
  581. $themes = array();
  582. foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename){
  583. $themes[] = array(
  584. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  585. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  586. );
  587. }
  588. return $themes;
  589. }
  590. function getBranches(){
  591. return array(
  592. array(
  593. 'name' => 'Develop',
  594. 'value' => 'v2-develop'
  595. ),
  596. array(
  597. 'name' => 'Master',
  598. 'value' => 'v2-master'
  599. )
  600. );
  601. }
  602. function getAuthTypes(){
  603. return array(
  604. array(
  605. 'name' => 'Organizr DB',
  606. 'value' => 'internal'
  607. ),
  608. array(
  609. 'name' => 'Organizr DB + Backend',
  610. 'value' => 'both'
  611. ),
  612. array(
  613. 'name' => 'Backend Only',
  614. 'value' => 'external'
  615. )
  616. );
  617. }
  618. function getAuthBackends(){
  619. $backendOptions = array();
  620. $backendOptions[] = array(
  621. 'name' => 'Choose Backend',
  622. 'value' => false,
  623. 'disabled' => true
  624. );
  625. foreach (array_filter(get_defined_functions()['user'],function($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) {
  626. $name = str_replace('plugin_auth_','',$value);
  627. if (strpos($name, 'disabled') === false) {
  628. $backendOptions[] = array(
  629. 'name' => ucwords(str_replace('_',' ',$name)),
  630. 'value' => $name
  631. );
  632. } else {
  633. $backendOptions[] = array(
  634. 'name' => $value(),
  635. 'value' => 'none',
  636. 'disabled' => true,
  637. );
  638. }
  639. }
  640. ksort($backendOptions);
  641. return $backendOptions;
  642. }
  643. /*
  644. function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  645. try {
  646. $mail = new PHPMailer(true);
  647. $mail->isSMTP();
  648. $mail->Host = $GLOBALS['smtpHost'];
  649. $mail->SMTPAuth = $GLOBALS['smtpHostAuth'];
  650. $mail->Username = $GLOBALS['smtpHostUsername'];
  651. $mail->Password = $GLOBALS['smtpHostPassword'];
  652. $mail->SMTPSecure = $GLOBALS['smtpHostType'];
  653. $mail->Port = $GLOBALS['smtpHostPort'];
  654. $mail->setFrom($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  655. $mail->addReplyTo($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  656. $mail->isHTML(true);
  657. if($email){
  658. $mail->addAddress($email, $username);
  659. }
  660. if($cc){
  661. $mail->addCC($cc);
  662. }
  663. if($bcc){
  664. if(strpos($bcc , ',') === false){
  665. $mail->addBCC($bcc);
  666. }else{
  667. $allEmails = explode(",",$bcc);
  668. foreach($allEmails as $gotEmail){
  669. $mail->addBCC($gotEmail);
  670. }
  671. }
  672. }
  673. $mail->Subject = $subject;
  674. $mail->Body = $body;
  675. $mail->send();
  676. writeLog('success', 'Mail Function - E-Mail Sent', $GLOBALS['organizrUser']['username']);
  677. return true;
  678. } catch (Exception $e) {
  679. writeLog('error', 'Mail Function - E-Mail Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  680. return false;
  681. }
  682. return false;
  683. }
  684. //EMAIL SHIT
  685. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  686. try {
  687. $mail = new PHPMailer(true);
  688. $mail->isSMTP();
  689. $mail->Host = $host;
  690. $mail->SMTPAuth = $auth;
  691. $mail->Username = $username;
  692. $mail->Password = $password;
  693. $mail->SMTPSecure = $type;
  694. $mail->Port = $port;
  695. $mail->setFrom($from, $sendername);
  696. $mail->addReplyTo($from, $sendername);
  697. $mail->isHTML(true);
  698. $mail->addAddress($to, "Organizr Admin");
  699. $mail->Subject = "Organizr Test E-Mail";
  700. $mail->Body = "This was just a test!";
  701. $mail->send();
  702. writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
  703. return true;
  704. } catch (Exception $e) {
  705. writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  706. return false;
  707. }
  708. return false;
  709. }
  710. */