organizr-functions.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. array(
  141. 'type' => 'select',
  142. 'name' => 'branch',
  143. 'label' => 'Branch',
  144. 'value' => $GLOBALS['branch'],
  145. 'options' => getBranches()
  146. ),
  147. array(
  148. 'type' => 'button',
  149. 'label' => 'Force Install Branch',
  150. 'class' => 'popup-with-form getPlexTokenSSO',
  151. 'icon' => 'fa fa-paper-plane',
  152. 'text' => 'Retrieve'
  153. ),
  154. array(
  155. 'type' => 'select',
  156. 'name' => 'authType',
  157. 'label' => 'Authentication Type',
  158. 'value' => $GLOBALS['authType'],
  159. 'options' => getAuthTypes()
  160. ),
  161. array(
  162. 'type' => 'select',
  163. 'name' => 'authBackend',
  164. 'label' => 'Authentication Backend',
  165. 'value' => $GLOBALS['authBackend'],
  166. 'options' => getAuthBackends()
  167. ),
  168. array(
  169. 'type' => 'input',
  170. 'name' => 'plexToken',
  171. 'class' => 'plexAuth',
  172. 'label' => 'Plex Token',
  173. 'value' => $GLOBALS['plexToken'],
  174. 'placeholder' => 'Use Get Token Button'
  175. ),
  176. array(
  177. 'type' => 'button',
  178. 'label' => 'Get Plex Token',
  179. 'class' => 'popup-with-form getPlexTokenAuth plexAuth',
  180. 'icon' => 'fa fa-paper-plane',
  181. 'text' => 'Retrieve',
  182. 'href' => '#auth-plex-token-form',
  183. 'attr' => 'data-effect="mfp-3d-unfold"'
  184. ),
  185. array(
  186. 'type' => 'input',
  187. 'name' => 'plexID',
  188. 'class' => 'plexAuth',
  189. 'label' => 'Plex Machine',
  190. 'value' => $GLOBALS['plexID'],
  191. 'placeholder' => 'Use Get Plex Machine Button'
  192. ),
  193. array(
  194. 'type' => 'button',
  195. 'label' => 'Get Plex Machine',
  196. 'class' => 'popup-with-form getPlexMachineAuth plexAuth',
  197. 'icon' => 'fa fa-paper-plane',
  198. 'text' => 'Retrieve',
  199. 'href' => '#auth-plex-machine-form',
  200. 'attr' => 'data-effect="mfp-3d-unfold"'
  201. ),
  202. array(
  203. 'type' => 'input',
  204. 'name' => 'authBackendHost',
  205. 'class' => 'temp',
  206. 'label' => 'Host Address',
  207. 'value' => $GLOBALS['authBackendHost'],
  208. 'placeholder' => 'http{s) | ftp(s) | ldap(s) ://hostname:port'
  209. ),
  210. array(
  211. 'type' => 'input',
  212. 'name' => 'authBaseDN',
  213. 'class' => 'temp',
  214. 'label' => 'Host Base DN',
  215. 'value' => $GLOBALS['authBaseDN'],
  216. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  217. ),
  218. array(
  219. 'type' => 'input',
  220. 'name' => 'authUsername',
  221. 'class' => 'temp',
  222. 'label' => 'Host Username',
  223. 'value' => $GLOBALS['authUsername'],
  224. 'placeholder' => 'Username if required'
  225. ),
  226. array(
  227. 'type' => 'password',
  228. 'name' => 'authPassword',
  229. 'class' => 'temp',
  230. 'label' => 'Host Password',
  231. 'value' => $GLOBALS['authPassword'],
  232. 'placeholder' => 'Password if required'
  233. ),
  234. /*array(
  235. 'type' => 'button',
  236. 'label' => 'Send Test',
  237. 'class' => 'phpmSendTestEmail',
  238. 'icon' => 'fa fa-paper-plane',
  239. 'text' => 'Send'
  240. )*/
  241. );
  242. }
  243. function getSSO(){
  244. return array(
  245. array(
  246. 'type' => 'input',
  247. 'name' => 'plexToken',
  248. 'label' => 'Plex Token',
  249. 'value' => $GLOBALS['plexToken'],
  250. 'placeholder' => 'Use Get Token Button'
  251. ),
  252. array(
  253. 'type' => 'button',
  254. 'label' => 'Get Plex Token',
  255. 'class' => 'popup-with-form getPlexTokenSSO',
  256. 'icon' => 'fa fa-paper-plane',
  257. 'text' => 'Retrieve',
  258. 'href' => '#sso-plex-token-form',
  259. 'attr' => 'data-effect="mfp-3d-unfold"'
  260. ),
  261. array(
  262. 'type' => 'input',
  263. 'name' => 'plexID',
  264. 'label' => 'Plex Machine',
  265. 'value' => $GLOBALS['plexID'],
  266. 'placeholder' => 'Use Get Plex Machine Button'
  267. ),
  268. array(
  269. 'type' => 'button',
  270. 'label' => 'Get Plex Machine',
  271. 'class' => 'popup-with-form getPlexMachineSSO',
  272. 'icon' => 'fa fa-paper-plane',
  273. 'text' => 'Retrieve',
  274. 'href' => '#sso-plex-machine-form',
  275. 'attr' => 'data-effect="mfp-3d-unfold"'
  276. ),
  277. array(
  278. 'type' => 'html',
  279. 'label' => 'Plex Note',
  280. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  281. ),
  282. array(
  283. 'type' => 'switch',
  284. 'name' => 'ssoPlex',
  285. 'label' => 'Enable',
  286. 'value' => $GLOBALS['ssoPlex']
  287. ),
  288. array(
  289. 'type' => 'input',
  290. 'name' => 'ombiURL',
  291. 'label' => 'Ombi URL',
  292. 'value' => $GLOBALS['ombiURL'],
  293. 'placeholder' => 'http(s)://hostname'
  294. ),
  295. array(
  296. 'type' => 'switch',
  297. 'name' => 'ssoOmbi',
  298. 'label' => 'Enable',
  299. 'value' => $GLOBALS['ssoOmbi']
  300. ),
  301. array(
  302. 'type' => 'input',
  303. 'name' => 'tautulliURL',
  304. 'label' => 'Tautulli URL',
  305. 'value' => $GLOBALS['tautulliURL'],
  306. 'placeholder' => 'http(s)://hostname'
  307. ),
  308. array(
  309. 'type' => 'switch',
  310. 'name' => 'ssoTautulli',
  311. 'label' => 'Enable',
  312. 'value' => $GLOBALS['ssoTautulli']
  313. )
  314. /*array(
  315. 'type' => 'button',
  316. 'label' => 'Send Test',
  317. 'class' => 'phpmSendTestEmail',
  318. 'icon' => 'fa fa-paper-plane',
  319. 'text' => 'Send'
  320. )*/
  321. );
  322. }
  323. function loadAppearance(){
  324. $appearance = array();
  325. $appearance['logo'] = $GLOBALS['logo'];
  326. $appearance['title'] = $GLOBALS['title'];
  327. $appearance['useLogo'] = $GLOBALS['useLogo'];
  328. $appearance['headerColor'] = $GLOBALS['headerColor'];
  329. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  330. return $appearance;
  331. }
  332. function getCustomizeAppearance(){
  333. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  334. return array(
  335. 'config' => array(/*
  336. array(
  337. 'type' => 'select',
  338. 'name' => 'branch',
  339. 'label' => 'Organizr Branch',
  340. 'value' => $GLOBALS['branch'],
  341. 'options' => array(
  342. 'Master' => 'v2-master',
  343. 'Develop' => 'v2-develop'
  344. )
  345. ),*/
  346. array(
  347. 'type' => 'input',
  348. 'name' => 'logo',
  349. 'label' => 'Logo',
  350. 'value' => $GLOBALS['logo']
  351. ),
  352. array(
  353. 'type' => 'input',
  354. 'name' => 'loginWallpaper',
  355. 'label' => 'Login Wallpaper',
  356. 'value' => $GLOBALS['loginWallpaper']
  357. ),
  358. array(
  359. 'type' => 'input',
  360. 'name' => 'title',
  361. 'label' => 'Title',
  362. 'value' => $GLOBALS['title']
  363. ),
  364. array(
  365. 'type' => 'switch',
  366. 'name' => 'useLogo',
  367. 'label' => 'Use Logo instead of Title',
  368. 'value' => $GLOBALS['useLogo']
  369. ),
  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' => 'select',
  380. 'name' => 'theme',
  381. 'label' => 'Theme',
  382. 'class' => 'themeChanger',
  383. 'value' => $GLOBALS['theme'],
  384. 'options' => getThemes()
  385. ),
  386. array(
  387. 'type' => 'select',
  388. 'name' => 'style',
  389. 'label' => 'Style',
  390. 'class' => 'styleChanger',
  391. 'value' => $GLOBALS['style'],
  392. 'options' => array(
  393. array(
  394. 'name' => 'Light',
  395. 'value' => 'light'
  396. ),
  397. array(
  398. 'name' => 'Dark',
  399. 'value' => 'dark'
  400. )
  401. )
  402. )
  403. ),
  404. 'database' => array(
  405. )
  406. );
  407. }
  408. }
  409. function editAppearance($array){
  410. switch ($array['data']['value']) {
  411. case 'true':
  412. $array['data']['value'] = (bool) true;
  413. break;
  414. case 'false':
  415. $array['data']['value'] = (bool) false;
  416. break;
  417. default:
  418. $array['data']['value'] = $array['data']['value'];
  419. }
  420. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  421. switch ($array['data']['action']) {
  422. case 'editCustomizeAppearance':
  423. $newItem = array(
  424. $array['data']['name'] => $array['data']['value']
  425. );
  426. return (updateConfig($newItem)) ? true : false;
  427. break;
  428. default:
  429. # code...
  430. break;
  431. }
  432. }
  433. function updateConfigItem($array){
  434. switch ($array['data']['value']) {
  435. case 'true':
  436. $array['data']['value'] = (bool) true;
  437. break;
  438. case 'false':
  439. $array['data']['value'] = (bool) false;
  440. break;
  441. default:
  442. $array['data']['value'] = $array['data']['value'];
  443. }
  444. // Hash
  445. if($array['data']['type'] == 'password'){
  446. $array['data']['value'] = encrypt($array['data']['value']);
  447. }
  448. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  449. $newItem = array(
  450. $array['data']['name'] => $array['data']['value']
  451. );
  452. return (updateConfig($newItem)) ? true : false;
  453. }
  454. function getPlugins(){
  455. if(file_exists(dirname(__DIR__,1).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php')){
  456. $pluginList = array();
  457. foreach($GLOBALS['plugins'] as $plugin){
  458. foreach ($plugin as $key => $value) {
  459. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'].'-enabled'];
  460. }
  461. $pluginList = array_merge($pluginList, $plugin);
  462. }
  463. return $pluginList;
  464. }
  465. return false;
  466. }
  467. function editPlugins($array){
  468. switch ($array['data']['action']) {
  469. case 'enable':
  470. $newItem = array(
  471. $array['data']['configName'] => true
  472. );
  473. writeLog('success', 'Plugin Function - Enabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  474. return (updateConfig($newItem)) ? true : false;
  475. break;
  476. case 'disable':
  477. $newItem = array(
  478. $array['data']['configName'] => false
  479. );
  480. writeLog('success', 'Plugin Function - Disabled Plugin ['.$_POST['data']['name'].']', $GLOBALS['organizrUser']['username']);
  481. return (updateConfig($newItem)) ? true : false;
  482. break;
  483. default:
  484. # code...
  485. break;
  486. }
  487. }
  488. function auth(){
  489. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  490. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  491. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  492. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  493. $group = isset($_GET['group']) ? $_GET['group'] : 0;
  494. $currentIP = userIP();
  495. $currentUser = $GLOBALS['organizrUser']['username'];
  496. if ($whitelist) {
  497. if(in_array($currentIP, arrayIP($whitelist))) {
  498. !$debug ? exit(http_response_code(200)) : die("$currentIP Whitelist Authorized");
  499. }
  500. }
  501. if ($blacklist) {
  502. if(in_array($currentIP, arrayIP($blacklist))) {
  503. !$debug ? exit(http_response_code(401)) : die("$currentIP Blacklisted");
  504. }
  505. }
  506. if($group !== null){
  507. if(qualifyRequest($group)){
  508. !$debug ? exit(http_response_code(200)) : die("$currentUser on $currentIP Authorized");
  509. }else{
  510. !$debug ? exit(http_response_code(401)) : die("$currentUser on $currentIP Not Authorized");
  511. }
  512. }else{
  513. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  514. }
  515. }
  516. function logoOrText(){
  517. if($GLOBALS['useLogo'] == false){
  518. return '<h1>'.$GLOBALS['title'].'</h1>';
  519. }else{
  520. return '<img style="max-width: 350px;" src="'.$GLOBALS['logo'].'" alt="Home" />';
  521. }
  522. }
  523. function getImages(){
  524. $dirname = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  525. $path = 'plugins/images/tabs/';
  526. $images = scandir($dirname);
  527. $ignore = Array(".", "..", "._.DS_Store", ".DS_Store");
  528. $allIcons = array();
  529. foreach($images as $image){
  530. if(!in_array($image, $ignore)) {
  531. $allIcons[] = $path.$image;
  532. }
  533. }
  534. return $allIcons;
  535. }
  536. function editImages(){
  537. $array = array();
  538. $postCheck = array_filter($_POST);
  539. $filesCheck = array_filter($_FILES);
  540. if(!empty($postCheck)){
  541. if($_POST['data']['action'] == 'deleteImage'){
  542. if(file_exists(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])){
  543. writeLog('success', 'Image Manager Function - Deleted Image ['.$_POST['data']['imageName'].']', $GLOBALS['organizrUser']['username']);
  544. return (unlink(dirname(__DIR__,2).DIRECTORY_SEPARATOR.$_POST['data']['imagePath'])) ? true : false;
  545. }
  546. }
  547. }
  548. if(!empty($filesCheck)){
  549. ini_set('upload_max_filesize', '10M');
  550. ini_set('post_max_size', '10M');
  551. $tempFile = $_FILES['file']['tmp_name'];
  552. $targetPath = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'tabs'.DIRECTORY_SEPARATOR;
  553. $targetFile = $targetPath. $_FILES['file']['name'];
  554. return (move_uploaded_file($tempFile,$targetFile)) ? true : false;
  555. }
  556. return false;
  557. }
  558. function getThemes(){
  559. $themes = array();
  560. foreach (glob(dirname(__DIR__,2).DIRECTORY_SEPARATOR.'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename){
  561. $themes[] = array(
  562. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  563. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  564. );
  565. }
  566. return $themes;
  567. }
  568. function getBranches(){
  569. return array(
  570. array(
  571. 'name' => 'Develeop',
  572. 'value' => 'v2-develop'
  573. ),
  574. array(
  575. 'name' => 'Master',
  576. 'value' => 'v2-master'
  577. )
  578. );
  579. }
  580. function getAuthTypes(){
  581. return array(
  582. array(
  583. 'name' => 'Organizr DB',
  584. 'value' => 'internal'
  585. ),
  586. array(
  587. 'name' => 'Organizr DB + Backend',
  588. 'value' => 'both'
  589. ),
  590. array(
  591. 'name' => 'Backend Only',
  592. 'value' => 'external'
  593. )
  594. );
  595. }
  596. function getAuthBackends(){
  597. $backendOptions = array();
  598. $backendOptions[] = array(
  599. 'name' => 'Choose Backend',
  600. 'value' => false,
  601. 'disabled' => true
  602. );
  603. foreach (array_filter(get_defined_functions()['user'],function($v) { return strpos($v, 'plugin_auth_') === 0; }) as $value) {
  604. $name = str_replace('plugin_auth_','',$value);
  605. if (strpos($name, 'disabled') === false) {
  606. $backendOptions[] = array(
  607. 'name' => ucwords(str_replace('_',' ',$name)),
  608. 'value' => $name
  609. );
  610. } else {
  611. $backendOptions[] = array(
  612. 'name' => $value(),
  613. 'value' => 'none',
  614. 'disabled' => true,
  615. );
  616. }
  617. }
  618. ksort($backendOptions);
  619. return $backendOptions;
  620. }
  621. /*
  622. function sendEmail($email = null, $username = "Organizr User", $subject, $body, $cc = null, $bcc = null){
  623. try {
  624. $mail = new PHPMailer(true);
  625. $mail->isSMTP();
  626. $mail->Host = $GLOBALS['smtpHost'];
  627. $mail->SMTPAuth = $GLOBALS['smtpHostAuth'];
  628. $mail->Username = $GLOBALS['smtpHostUsername'];
  629. $mail->Password = $GLOBALS['smtpHostPassword'];
  630. $mail->SMTPSecure = $GLOBALS['smtpHostType'];
  631. $mail->Port = $GLOBALS['smtpHostPort'];
  632. $mail->setFrom($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  633. $mail->addReplyTo($GLOBALS['smtpHostSenderEmail'], $GLOBALS['smtpHostSenderName']);
  634. $mail->isHTML(true);
  635. if($email){
  636. $mail->addAddress($email, $username);
  637. }
  638. if($cc){
  639. $mail->addCC($cc);
  640. }
  641. if($bcc){
  642. if(strpos($bcc , ',') === false){
  643. $mail->addBCC($bcc);
  644. }else{
  645. $allEmails = explode(",",$bcc);
  646. foreach($allEmails as $gotEmail){
  647. $mail->addBCC($gotEmail);
  648. }
  649. }
  650. }
  651. $mail->Subject = $subject;
  652. $mail->Body = $body;
  653. $mail->send();
  654. writeLog('success', 'Mail Function - E-Mail Sent', $GLOBALS['organizrUser']['username']);
  655. return true;
  656. } catch (Exception $e) {
  657. writeLog('error', 'Mail Function - E-Mail Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  658. return false;
  659. }
  660. return false;
  661. }
  662. //EMAIL SHIT
  663. function sendTestEmail($to, $from, $host, $auth, $username, $password, $type, $port, $sendername){
  664. try {
  665. $mail = new PHPMailer(true);
  666. $mail->isSMTP();
  667. $mail->Host = $host;
  668. $mail->SMTPAuth = $auth;
  669. $mail->Username = $username;
  670. $mail->Password = $password;
  671. $mail->SMTPSecure = $type;
  672. $mail->Port = $port;
  673. $mail->setFrom($from, $sendername);
  674. $mail->addReplyTo($from, $sendername);
  675. $mail->isHTML(true);
  676. $mail->addAddress($to, "Organizr Admin");
  677. $mail->Subject = "Organizr Test E-Mail";
  678. $mail->Body = "This was just a test!";
  679. $mail->send();
  680. writeLog('success', 'Mail Function - E-Mail Test Sent', $GLOBALS['organizrUser']['username']);
  681. return true;
  682. } catch (Exception $e) {
  683. writeLog('error', 'Mail Function - E-Mail Test Failed['.$mail->ErrorInfo.']', $GLOBALS['organizrUser']['username']);
  684. return false;
  685. }
  686. return false;
  687. }
  688. */