organizr-functions.php 24 KB

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