organizr-functions.php 20 KB

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