organizr-functions.php 23 KB

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