| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843 |
- <?php
- function organizrSpecialSettings()
- {
- $refreshSearch = "Refresh";
- $tautulliSearch = "tautulli_token";
- $tautulli = array_filter($_COOKIE, function ($k) use ($tautulliSearch) {
- return stripos($k, $tautulliSearch) !== false;
- }, ARRAY_FILTER_USE_KEY);
- return array(
- 'homepage' => array(
- 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
- return stripos($k, $refreshSearch) !== false;
- }, ARRAY_FILTER_USE_KEY),
- 'search' => array(
- 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
- 'type' => $GLOBALS['mediaSearchType'],
- ),
- 'ombi' => array(
- 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && qualifyRequest($GLOBALS['homepageOmbiRequestAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
- 'authView' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
- 'authRequest' => (qualifyRequest($GLOBALS['homepageOmbiRequestAuth'])) ? true : false,
- 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
- 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
- ),
- 'options' => array(
- 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
- )
- ),
- 'sso' => array(
- 'plex' => array(
- 'enabled' => ($GLOBALS['ssoPlex']) ? true : false,
- 'cookie' => isset($_COOKIE['mpt']) ? true : false,
- ),
- 'ombi' => array(
- 'enabled' => ($GLOBALS['ssoOmbi']) ? true : false,
- 'cookie' => isset($_COOKIE['Auth']) ? true : false,
- ),
- 'tautulli' => array(
- 'enabled' => ($GLOBALS['ssoTautulli']) ? true : false,
- 'cookie' => !empty($tautulli) ? true : false,
- ),
- ),
- 'ping' => array(
- 'onlineSound' => $GLOBALS['pingOnlineSound'],
- 'offlineSound' => $GLOBALS['pingOfflineSound'],
- 'auth' => $GLOBALS['pingAuth'],
- 'authMessage' => $GLOBALS['pingAuthMessage'],
- 'authMs' => $GLOBALS['pingAuthMs'],
- 'ms' => $GLOBALS['pingMs'],
- 'adminRefresh' => $GLOBALS['adminPingRefresh'],
- 'everyoneRefresh' => $GLOBALS['otherPingRefresh'],
- ),
- 'notifications' => array(
- 'backbone' => $GLOBALS['notificationBackbone'],
- 'position' => $GLOBALS['notificationPosition']
- ),
- 'lockout' => array(
- 'enabled' => $GLOBALS['lockoutSystem'],
- 'timer' => $GLOBALS['lockoutTimeout'],
- 'minGroup' => $GLOBALS['lockoutMinAuth'],
- 'maxGroup' => $GLOBALS['lockoutMaxAuth']
- ),
- 'user' => array(
- 'agent' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null
- ),
- 'misc' => array(
- 'installedPlugins' => $GLOBALS['installedPlugins'],
- 'installedThemes' => $GLOBALS['installedThemes'],
- 'return' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false,
- 'authDebug' => $GLOBALS['authDebug'],
- 'minimalLoginScreen' => $GLOBALS['minimalLoginScreen'],
- 'unsortedTabs' => $GLOBALS['unsortedTabs']
- )
- );
- }
- function wizardConfig($array)
- {
- foreach ($array['data'] as $items) {
- foreach ($items as $key => $value) {
- if ($key == 'name') {
- $newKey = $value;
- }
- if ($key == 'value') {
- $newValue = $value;
- }
- if (isset($newKey) && isset($newValue)) {
- $$newKey = $newValue;
- }
- }
- }
- $location = cleanDirectory($location);
- $dbName = $dbName . '.db';
- $configVersion = $GLOBALS['installedVersion'];
- $configArray = array(
- 'dbName' => $dbName,
- 'dbLocation' => $location,
- 'license' => $license,
- 'organizrHash' => $hashKey,
- 'organizrAPI' => $api,
- 'registrationPassword' => $registrationPassword,
- );
- // Create Config
- $GLOBALS['dbLocation'] = $location;
- $GLOBALS['dbName'] = $dbName;
- if (createConfig($configArray)) {
- // Call DB Create
- if (createDB($location, $dbName)) {
- // Add in first user
- if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
- if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
- return true;
- } else {
- return 'token';
- }
- } else {
- return 'admin';
- }
- } else {
- return 'db';
- }
- } else {
- return 'config';
- }
- return false;
- }
- function register($array)
- {
- // Grab username and password from login form
- foreach ($array['data'] as $items) {
- foreach ($items as $key => $value) {
- if ($key == 'name') {
- $newKey = $value;
- }
- if ($key == 'value') {
- $newValue = $value;
- }
- if (isset($newKey) && isset($newValue)) {
- $$newKey = $newValue;
- }
- }
- }
- if ($registrationPassword == $GLOBALS['registrationPassword']) {
- $defaults = defaultUserGroup();
- writeLog('success', 'Registration Function - Registration Password Verified', $username);
- if (createUser($username, $password, $defaults, $email)) {
- writeLog('success', 'Registration Function - A User has registered', $username);
- if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
- writeLoginLog($username, 'success');
- writeLog('success', 'Login Function - A User has logged in', $username);
- return true;
- }
- } else {
- writeLog('error', 'Registration Function - An error occured', $username);
- return 'username taken';
- }
- } else {
- writeLog('warning', 'Registration Function - Wrong Password', $username);
- return 'mismatch';
- }
- }
- function removeFile($array)
- {
- $filePath = $array['data']['path'];
- $fileName = $array['data']['name'];
- if (file_exists($filePath)) {
- if (unlink($filePath)) {
- writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
- return true;
- } else {
- writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
- return false;
- }
- } else {
- writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
- return false;
- }
- }
- function recover($array)
- {
- $email = $array['data']['email'];
- $newPassword = randString(10);
- try {
- $connect = new Dibi\Connection([
- 'driver' => 'sqlite3',
- 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
- ]);
- $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
- if ($isUser) {
- $connect->query('
- UPDATE users SET', [
- 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
- ], '
- WHERE email=? COLLATE NOCASE', $email);
- if ($GLOBALS['PHPMAILER-enabled']) {
- $emailTemplate = array(
- 'type' => 'reset',
- 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
- 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
- 'user' => $isUser['username'],
- 'password' => $newPassword,
- 'inviteCode' => null,
- );
- $emailTemplate = phpmEmailTemplate($emailTemplate);
- $sendEmail = array(
- 'to' => $email,
- 'user' => $isUser['username'],
- 'subject' => $emailTemplate['subject'],
- 'body' => phpmBuildEmail($emailTemplate),
- );
- phpmSendEmail($sendEmail);
- }
- writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
- return true;
- } else {
- writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
- return 'an error occured';
- }
- } catch (Dibi\Exception $e) {
- writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
- return 'an error occured';
- }
- }
- function unlock($array)
- {
- if ($array['data']['password'] == '') {
- return 'Password Not Set';
- }
- try {
- $connect = new Dibi\Connection([
- 'driver' => 'sqlite3',
- 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
- ]);
- $result = $connect->fetch('SELECT * FROM users WHERE id = ?', $GLOBALS['organizrUser']['userID']);
- if (!password_verify($array['data']['password'], $result['password'])) {
- return 'Password Incorrect';
- }
- $connect->query('
- UPDATE users SET', [
- 'locked' => ''
- ], '
- WHERE id=?', $GLOBALS['organizrUser']['userID']);
- writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
- return true;
- } catch (Dibi\Exception $e) {
- writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
- return 'an error occured';
- }
- }
- function lock()
- {
- if ($GLOBALS['organizrUser']['userID'] == '999') {
- return 'Not Allowed on Guest';
- }
- try {
- $connect = new Dibi\Connection([
- 'driver' => 'sqlite3',
- 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
- ]);
- $connect->query('
- UPDATE users SET', [
- 'locked' => '1'
- ], '
- WHERE id=?', $GLOBALS['organizrUser']['userID']);
- writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
- return true;
- } catch (Dibi\Exception $e) {
- writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
- return 'an error occured';
- }
- }
- function editUser($array)
- {
- if ($array['data']['username'] == '' && $array['data']['username'] == '') {
- return 'Username/email not set';
- }
- try {
- $connect = new Dibi\Connection([
- 'driver' => 'sqlite3',
- 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
- ]);
- if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
- $connect->query('
- UPDATE users SET', [
- 'username' => $array['data']['username'],
- 'email' => $array['data']['email'],
- ], '
- WHERE id=?', $GLOBALS['organizrUser']['userID']);
- if (!empty($array['data']['password'])) {
- $connect->query('
- UPDATE users SET', [
- 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
- ], '
- WHERE id=?', $GLOBALS['organizrUser']['userID']);
- }
- writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
- return true;
- } else {
- return 'Username/Email Already Taken';
- }
- } catch (Dibi\Exception $e) {
- writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
- return 'an error occured';
- }
- }
- function logout()
- {
- coookie('delete', $GLOBALS['cookieName']);
- coookie('delete', 'mpt');
- coookie('delete', 'Auth');
- $GLOBALS['organizrUser'] = false;
- return true;
- }
- function qualifyRequest($accessLevelNeeded)
- {
- if (getUserLevel() <= $accessLevelNeeded) {
- return true;
- } else {
- return false;
- }
- }
- function getUserLevel()
- {
- // Grab token
- //$requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
- $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
- // Check token or API key
- // If API key, return 0 for admin
- if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
- //DO API CHECK
- return 0;
- } elseif (isset($GLOBALS['organizrUser'])) {
- return $GLOBALS['organizrUser']['groupID'];
- }
- // All else fails? return guest id
- return 999;
- }
- function organizrStatus()
- {
- $status = array();
- $dependenciesActive = array();
- $dependenciesInactive = array();
- $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
- $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
- foreach ($extensions as $check) {
- if (extension_loaded($check)) {
- array_push($dependenciesActive, $check);
- } else {
- array_push($dependenciesInactive, $check);
- }
- }
- foreach ($functions as $check) {
- if (function_exists($check)) {
- array_push($dependenciesActive, $check);
- } else {
- array_push($dependenciesInactive, $check);
- }
- }
- if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
- $status['status'] = "wizard";//wizard - ok for test
- }
- if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0)) {
- $status['status'] = "dependencies";
- }
- $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
- $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
- $status['minVersion'] = (version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0) ? 'yes' : 'no';
- $status['dependenciesActive'] = $dependenciesActive;
- $status['dependenciesInactive'] = $dependenciesInactive;
- $status['version'] = $GLOBALS['installedVersion'];
- $status['os'] = getOS();
- $status['php'] = phpversion();
- return $status;
- }
- function getSettingsMain()
- {
- return array(
- 'Github' => array(
- array(
- 'type' => 'select',
- 'name' => 'branch',
- 'label' => 'Branch',
- 'value' => $GLOBALS['branch'],
- 'options' => getBranches()
- ),
- array(
- 'type' => 'button',
- 'label' => 'Force Install Branch',
- 'class' => 'updateNow',
- 'icon' => 'fa fa-download',
- 'text' => 'Retrieve'
- )
- ),
- 'API' => array(
- array(
- 'type' => 'password-alt',
- 'name' => 'organizrAPI',
- 'label' => 'Organizr API',
- 'value' => $GLOBALS['organizrAPI']
- ),
- array(
- 'type' => 'button',
- 'label' => 'Generate New API Key',
- 'class' => 'newAPIKey',
- 'icon' => 'fa fa-refresh',
- 'text' => 'Generate'
- )
- ),
- 'Authentication' => array(
- array(
- 'type' => 'select',
- 'name' => 'authType',
- 'id' => 'authSelect',
- 'label' => 'Authentication Type',
- 'value' => $GLOBALS['authType'],
- 'options' => getAuthTypes()
- ),
- array(
- 'type' => 'select',
- 'name' => 'authBackend',
- 'id' => 'authBackendSelect',
- 'label' => 'Authentication Backend',
- 'class' => 'backendAuth switchAuth',
- 'value' => $GLOBALS['authBackend'],
- 'options' => getAuthBackends()
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'plexToken',
- 'class' => 'plexAuth switchAuth',
- 'label' => 'Plex Token',
- 'value' => $GLOBALS['plexToken'],
- 'placeholder' => 'Use Get Token Button'
- ),
- array(
- 'type' => 'button',
- 'label' => 'Get Plex Token',
- 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
- 'icon' => 'fa fa-ticket',
- 'text' => 'Retrieve',
- 'href' => '#auth-plex-token-form',
- 'attr' => 'data-effect="mfp-3d-unfold"'
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'plexID',
- 'class' => 'plexAuth switchAuth',
- 'label' => 'Plex Machine',
- 'value' => $GLOBALS['plexID'],
- 'placeholder' => 'Use Get Plex Machine Button'
- ),
- array(
- 'type' => 'button',
- 'label' => 'Get Plex Machine',
- 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
- 'icon' => 'fa fa-id-badge',
- 'text' => 'Retrieve',
- 'href' => '#auth-plex-machine-form',
- 'attr' => 'data-effect="mfp-3d-unfold"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'authBackendHost',
- 'class' => 'ldapAuth ftpAuth switchAuth',
- 'label' => 'Host Address',
- 'value' => $GLOBALS['authBackendHost'],
- 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
- ),
- array(
- 'type' => 'input',
- 'name' => 'authBaseDN',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Host Base DN',
- 'value' => $GLOBALS['authBaseDN'],
- 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
- ),
- array(
- 'type' => 'input',
- 'name' => 'embyURL',
- 'class' => 'embyAuth switchAuth',
- 'label' => 'Emby URL',
- 'value' => $GLOBALS['embyURL'],
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'embyToken',
- 'class' => 'embyAuth switchAuth',
- 'label' => 'Emby Token',
- 'value' => $GLOBALS['embyToken'],
- 'placeholder' => ''
- ),
- /*array(
- 'type' => 'button',
- 'label' => 'Send Test',
- 'class' => 'phpmSendTestEmail',
- 'icon' => 'fa fa-paper-plane',
- 'text' => 'Send'
- )*/
- ),
- 'Security' => array(
- array(
- 'type' => 'number',
- 'name' => 'lockoutTimeout',
- 'label' => 'Inactivity Timer [Minutes]',
- 'value' => $GLOBALS['lockoutTimeout'],
- 'placeholder' => ''
- ),
- array(
- 'type' => 'switch',
- 'name' => 'lockoutSystem',
- 'label' => 'Inactivity Lock',
- 'value' => $GLOBALS['lockoutSystem']
- ),
- array(
- 'type' => 'select',
- 'name' => 'lockoutMinAuth',
- 'label' => 'Lockout Groups From',
- 'value' => $GLOBALS['lockoutMinAuth'],
- 'options' => groupSelect()
- ),
- array(
- 'type' => 'select',
- 'name' => 'lockoutMaxAuth',
- 'label' => 'Lockout Groups To',
- 'value' => $GLOBALS['lockoutMaxAuth'],
- 'options' => groupSelect()
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'registrationPassword',
- 'label' => 'Registration Password',
- 'value' => $GLOBALS['registrationPassword'],
- ),
- array(
- 'type' => 'switch',
- 'name' => 'hideRegistration',
- 'label' => 'Hide Registration',
- 'value' => $GLOBALS['hideRegistration'],
- ),
- array(
- 'type' => 'switch',
- 'name' => 'authDebug',
- 'label' => 'Nginx Auth Debug',
- 'help' => 'Important! Do not keep this enabled for too long as this opens up Authentication while testing.',
- 'value' => $GLOBALS['authDebug'],
- 'class' => 'authDebug'
- )
- ),
- 'Ping' => array(
- array(
- 'type' => 'select',
- 'name' => 'pingAuth',
- 'label' => 'Minimum Authentication',
- 'value' => $GLOBALS['pingAuth'],
- 'options' => groupSelect()
- ),
- array(
- 'type' => 'select',
- 'name' => 'pingAuthMessage',
- 'label' => 'Minimum Authentication for Message and Sound',
- 'value' => $GLOBALS['pingAuthMessage'],
- 'options' => groupSelect()
- ),
- array(
- 'type' => 'select',
- 'name' => 'pingOnlineSound',
- 'label' => 'Online Sound',
- 'value' => $GLOBALS['pingOnlineSound'],
- 'options' => getSounds()
- ),
- array(
- 'type' => 'select',
- 'name' => 'pingOfflineSound',
- 'label' => 'Offline Sound',
- 'value' => $GLOBALS['pingOfflineSound'],
- 'options' => getSounds()
- ),
- array(
- 'type' => 'switch',
- 'name' => 'pingMs',
- 'label' => 'Show Ping Time',
- 'value' => $GLOBALS['pingMs']
- ),
- array(
- 'type' => 'select',
- 'name' => 'pingAuthMs',
- 'label' => 'Minimum Authentication for Time Display',
- 'value' => $GLOBALS['pingAuthMs'],
- 'options' => groupSelect()
- ),
- array(
- 'type' => 'select',
- 'name' => 'adminPingRefresh',
- 'label' => 'Admin Refresh Seconds',
- 'value' => $GLOBALS['adminPingRefresh'],
- 'options' => optionTime()
- ),
- array(
- 'type' => 'select',
- 'name' => 'otherPingRefresh',
- 'label' => 'Everyone Refresh Seconds',
- 'value' => $GLOBALS['otherPingRefresh'],
- 'options' => optionTime()
- ),
- )
- );
- }
- function getSSO()
- {
- return array(
- 'FYI' => array(
- array(
- 'type' => 'html',
- 'label' => 'Important Information',
- 'override' => 12,
- 'html' => '
- <div class="row">
- <div class="col-lg-12">
- <div class="panel panel-info">
- <div class="panel-heading">
- <span lang="en">Notice</span>
- </div>
- <div class="panel-wrapper collapse in" aria-expanded="true">
- <div class="panel-body">
- <span lang="en">This is not the same as database authentication - i.e. Plex Authentication | Emby Authentication | FTP Authentication<br/>Click Main on the sub-menu above.</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- '
- )
- ),
- 'Plex' => array(
- array(
- 'type' => 'password-alt',
- 'name' => 'plexToken',
- 'label' => 'Plex Token',
- 'value' => $GLOBALS['plexToken'],
- 'placeholder' => 'Use Get Token Button'
- ),
- array(
- 'type' => 'button',
- 'label' => 'Get Plex Token',
- 'class' => 'popup-with-form getPlexTokenSSO',
- 'icon' => 'fa fa-ticket',
- 'text' => 'Retrieve',
- 'href' => '#sso-plex-token-form',
- 'attr' => 'data-effect="mfp-3d-unfold"'
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'plexID',
- 'label' => 'Plex Machine',
- 'value' => $GLOBALS['plexID'],
- 'placeholder' => 'Use Get Plex Machine Button'
- ),
- array(
- 'type' => 'button',
- 'label' => 'Get Plex Machine',
- 'class' => 'popup-with-form getPlexMachineSSO',
- 'icon' => 'fa fa-id-badge',
- 'text' => 'Retrieve',
- 'href' => '#sso-plex-machine-form',
- 'attr' => 'data-effect="mfp-3d-unfold"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'plexAdmin',
- 'label' => 'Admin Username',
- 'value' => $GLOBALS['plexAdmin'],
- 'placeholder' => 'Admin username for Plex'
- ),
- array(
- 'type' => 'blank',
- 'label' => ''
- ),
- array(
- 'type' => 'html',
- 'label' => 'Plex Note',
- 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ssoPlex',
- 'label' => 'Enable',
- 'value' => $GLOBALS['ssoPlex']
- )
- ),
- 'Ombi' => array(
- array(
- 'type' => 'input',
- 'name' => 'ombiURL',
- 'label' => 'Ombi URL',
- 'value' => $GLOBALS['ombiURL'],
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ssoOmbi',
- 'label' => 'Enable',
- 'value' => $GLOBALS['ssoOmbi']
- )
- ),
- 'Tautulli' => array(
- array(
- 'type' => 'input',
- 'name' => 'tautulliURL',
- 'label' => 'Tautulli URL',
- 'value' => $GLOBALS['tautulliURL'],
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ssoTautulli',
- 'label' => 'Enable',
- 'value' => $GLOBALS['ssoTautulli']
- )
- )
- );
- }
- function loadAppearance()
- {
- $appearance = array();
- $appearance['logo'] = $GLOBALS['logo'];
- $appearance['title'] = $GLOBALS['title'];
- $appearance['useLogo'] = $GLOBALS['useLogo'];
- $appearance['headerColor'] = $GLOBALS['headerColor'];
- $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
- $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
- $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
- $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
- $appearance['accentColor'] = $GLOBALS['accentColor'];
- $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
- $appearance['buttonColor'] = $GLOBALS['buttonColor'];
- $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
- $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
- $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
- $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
- $appearance['customCss'] = $GLOBALS['customCss'];
- $appearance['customThemeCss'] = $GLOBALS['customThemeCss'];
- $appearance['customJava'] = $GLOBALS['customJava'];
- $appearance['customThemeJava'] = $GLOBALS['customThemeJava'];
- return $appearance;
- }
- function getCustomizeAppearance()
- {
- if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
- return array(
- 'Top Bar' => array(
- array(
- 'type' => 'input',
- 'name' => 'logo',
- 'label' => 'Logo',
- 'value' => $GLOBALS['logo']
- ),
- array(
- 'type' => 'input',
- 'name' => 'title',
- 'label' => 'Title',
- 'value' => $GLOBALS['title']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'useLogo',
- 'label' => 'Use Logo instead of Title',
- 'value' => $GLOBALS['useLogo']
- )
- ),
- 'Login Page' => array(
- array(
- 'type' => 'input',
- 'name' => 'loginWallpaper',
- 'label' => 'Login Wallpaper',
- 'value' => $GLOBALS['loginWallpaper']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'minimalLoginScreen',
- 'label' => 'Minimal Login Screen',
- 'value' => $GLOBALS['minimalLoginScreen']
- )
- ),
- 'Options' => array(
- array(
- 'type' => 'switch',
- 'name' => 'alternateHomepageHeaders',
- 'label' => 'Alternate Homepage Titles',
- 'value' => $GLOBALS['alternateHomepageHeaders']
- ),
- array(
- 'type' => 'select',
- 'name' => 'unsortedTabs',
- 'label' => 'Unsorted Tab Placement',
- 'value' => $GLOBALS['unsortedTabs'],
- 'options' => array(
- array(
- 'name' => 'Top',
- 'value' => 'top'
- ),
- array(
- 'name' => 'Bottom',
- 'value' => 'bottom'
- )
- )
- )
- ),
- 'Colors & Themes' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Custom CSS [Can replace colors from above]',
- 'html' => '
- <div class="row">
- <div class="col-lg-12">
- <div class="panel panel-info">
- <div class="panel-heading">
- <span lang="en">Notice</span>
- </div>
- <div class="panel-wrapper collapse in" aria-expanded="true">
- <div class="panel-body">
- <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- ',
- ),
- array(
- 'type' => 'blank',
- 'label' => ''
- ),
- array(
- 'type' => 'input',
- 'name' => 'headerColor',
- 'label' => 'Nav Bar Color',
- 'value' => $GLOBALS['headerColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'headerTextColor',
- 'label' => 'Nav Bar Text Color',
- 'value' => $GLOBALS['headerTextColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'sidebarColor',
- 'label' => 'Side Bar Color',
- 'value' => $GLOBALS['sidebarColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'sidebarTextColor',
- 'label' => 'Side Bar Text Color',
- 'value' => $GLOBALS['sidebarTextColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'accentColor',
- 'label' => 'Accent Color',
- 'value' => $GLOBALS['accentColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'accentTextColor',
- 'label' => 'Accent Text Color',
- 'value' => $GLOBALS['accentTextColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'buttonColor',
- 'label' => 'Button Color',
- 'value' => $GLOBALS['buttonColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'buttonTextColor',
- 'label' => 'Button Text Color',
- 'value' => $GLOBALS['buttonTextColor'],
- 'class' => 'pick-a-color',
- 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
- ),/*
- array(
- 'type' => 'input',
- 'name' => 'buttonHoverColor',
- 'label' => 'Button Hover Color',
- 'value' => $GLOBALS['buttonHoverColor'],
- 'class' => 'pick-a-color',
- 'disabled' => true
- ),
- array(
- 'type' => 'input',
- 'name' => 'buttonTextHoverColor',
- 'label' => 'Button Hover Text Color',
- 'value' => $GLOBALS['buttonTextHoverColor'],
- 'class' => 'pick-a-color',
- 'disabled' => true
- ),*/
- array(
- 'type' => 'select',
- 'name' => 'theme',
- 'label' => 'Theme',
- 'class' => 'themeChanger',
- 'value' => $GLOBALS['theme'],
- 'options' => getThemes()
- ),
- array(
- 'type' => 'select',
- 'name' => 'style',
- 'label' => 'Style',
- 'class' => 'styleChanger',
- 'value' => $GLOBALS['style'],
- 'options' => array(
- array(
- 'name' => 'Light',
- 'value' => 'light'
- ),
- array(
- 'name' => 'Dark',
- 'value' => 'dark'
- ),
- array(
- 'name' => 'Horizontal',
- 'value' => 'horizontal'
- )
- )
- )
- ),
- 'Notifications' => array(
- array(
- 'type' => 'select',
- 'name' => 'notificationBackbone',
- 'class' => 'notifyChanger',
- 'label' => 'Type',
- 'value' => $GLOBALS['notificationBackbone'],
- 'options' => optionNotificationTypes()
- ),
- array(
- 'type' => 'select',
- 'name' => 'notificationPosition',
- 'class' => 'notifyPositionChanger',
- 'label' => 'Position',
- 'value' => $GLOBALS['notificationPosition'],
- 'options' => optionNotificationPositions()
- ),
- array(
- 'type' => 'html',
- 'label' => 'Test Message',
- 'html' => '
- <div class="btn-group m-r-10 dropup">
- <button aria-expanded="false" data-toggle="dropdown" class="btn btn-info btn-outline dropdown-toggle waves-effect waves-light" type="button">
- <i class="fa fa-comment m-r-5"></i>
- <span>Test </span>
- </button>
- <ul role="menu" class="dropdown-menu">
- <li><a onclick="message(\'Test Message\',\'This is a success Message\',activeInfo.settings.notifications.position,\'#FFF\',\'success\',\'5000\');">Success</a></li>
- <li><a onclick="message(\'Test Message\',\'This is a info Message\',activeInfo.settings.notifications.position,\'#FFF\',\'info\',\'5000\');">Info</a></li>
- <li><a onclick="message(\'Test Message\',\'This is a warning Message\',activeInfo.settings.notifications.position,\'#FFF\',\'warning\',\'5000\');">Warning</a></li>
- <li><a onclick="message(\'Test Message\',\'This is a error Message\',activeInfo.settings.notifications.position,\'#FFF\',\'error\',\'5000\');">Error</a></li>
- </ul>
- </div>
- '
- )
- ),
- 'FavIcon' => array(
- array(
- 'type' => 'textbox',
- 'name' => 'favIcon',
- 'class' => '',
- 'label' => 'Fav Icon Code',
- 'value' => $GLOBALS['favIcon'],
- 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
- 'attr' => 'rows="10"',
- ),
- array(
- 'type' => 'html',
- 'label' => 'Instructions',
- 'html' => '
- <div class="panel panel-default">
- <div class="panel-heading">
- <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
- </div>
- <div class="panel-wrapper collapse in">
- <div class="panel-body">
- <ul class="list-icons">
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Select your Favicon picture"</li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> At bottom of page on "Favicon Generator Options" under "Path" choose "I cannot or I do not want to place favicon files at the root of my web site."</li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Generate your Favicons and HTML code"</li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Download and unzip file and place in <code>plugins/images/faviconCustom</code></li>
- <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
- </ul>
- </div>
- </div>
- </div>
- '
- ),
- ),
- 'Custom CSS' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Custom CSS [Can replace colors from above]',
- 'html' => '<button type="button" class="hidden saveCss btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customCSSEditor" style="height:300px">' . $GLOBALS['customCss'] . '</div>'
- ),
- array(
- 'type' => 'textbox',
- 'name' => 'customCss',
- 'class' => 'hidden cssTextarea',
- 'label' => '',
- 'value' => $GLOBALS['customCss'],
- 'placeholder' => 'No <style> tags needed',
- 'attr' => 'rows="10"',
- ),
- ),
- 'Theme CSS' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Theme CSS [Can replace colors from above]',
- 'html' => '<button type="button" class="hidden saveCssTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeCSSEditor" style="height:300px">' . $GLOBALS['customThemeCss'] . '</div>'
- ),
- array(
- 'type' => 'textbox',
- 'name' => 'customThemeCss',
- 'class' => 'hidden cssThemeTextarea',
- 'label' => '',
- 'value' => $GLOBALS['customThemeCss'],
- 'placeholder' => 'No <style> tags needed',
- 'attr' => 'rows="10"',
- ),
- ),
- 'Custom Javascript' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Custom Javascript',
- 'html' => '<button type="button" class="hidden saveJava btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customJavaEditor" style="height:300px">' . $GLOBALS['customJava'] . '</div>'
- ),
- array(
- 'type' => 'textbox',
- 'name' => 'customJava',
- 'class' => 'hidden javaTextarea',
- 'label' => '',
- 'value' => $GLOBALS['customJava'],
- 'placeholder' => 'No <script> tags needed',
- 'attr' => 'rows="10"',
- ),
- ),
- 'Theme Javascript' => array(
- array(
- 'type' => 'html',
- 'override' => 12,
- 'label' => 'Theme Javascript',
- 'html' => '<button type="button" class="hidden saveJavaTheme btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customThemeJavaEditor" style="height:300px">' . $GLOBALS['customThemeJava'] . '</div>'
- ),
- array(
- 'type' => 'textbox',
- 'name' => 'customThemeJava',
- 'class' => 'hidden javaThemeTextarea',
- 'label' => '',
- 'value' => $GLOBALS['customThemeJava'],
- 'placeholder' => 'No <script> tags needed',
- 'attr' => 'rows="10"',
- ),
- ),
- );
- }
- }
- function editAppearance($array)
- {
- switch ($array['data']['value']) {
- case 'true':
- $array['data']['value'] = (bool)true;
- break;
- case 'false':
- $array['data']['value'] = (bool)false;
- break;
- default:
- $array['data']['value'] = $array['data']['value'];
- }
- //return gettype($array['data']['value']).' - '.$array['data']['value'];
- switch ($array['data']['action']) {
- case 'editCustomizeAppearance':
- $newItem = array(
- $array['data']['name'] => $array['data']['value']
- );
- return (updateConfig($newItem)) ? true : false;
- break;
- default:
- # code...
- break;
- }
- }
- function updateConfigMultiple($array)
- {
- return (updateConfig($array['data']['payload'])) ? true : false;
- }
- function updateConfigMultipleForm($array)
- {
- $newItem = array();
- foreach ($array['data']['payload'] as $k => $v) {
- switch ($v['value']) {
- case 'true':
- $v['value'] = (bool)true;
- break;
- case 'false':
- $v['value'] = (bool)false;
- break;
- default:
- $v['value'] = $v['value'];
- }
- // Hash
- if ($v['type'] == 'password') {
- if (strpos($v['value'], '==') !== false) {
- $v['value'] = $v['value'];
- } else {
- $v['value'] = encrypt($v['value']);
- }
- }
- $newItem[$v['name']] = $v['value'];
- }
- //return $newItem;
- return (updateConfig($newItem)) ? true : false;
- }
- function updateConfigItem($array)
- {
- switch ($array['data']['value']) {
- case 'true':
- $array['data']['value'] = (bool)true;
- break;
- case 'false':
- $array['data']['value'] = (bool)false;
- break;
- default:
- $array['data']['value'] = $array['data']['value'];
- }
- // Hash
- if ($array['data']['type'] == 'password') {
- $array['data']['value'] = encrypt($array['data']['value']);
- }
- $newItem = array(
- $array['data']['name'] => $array['data']['value']
- );
- return (updateConfig($newItem)) ? true : false;
- }
- function getPlugins()
- {
- if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
- $pluginList = [];
- foreach ($GLOBALS['plugins'] as $plugin) {
- foreach ($plugin as $key => $value) {
- if (strpos($value['license'], $GLOBALS['license']) !== false) {
- $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
- $pluginList[$key] = $plugin[$key];
- }
- }
- }
- return $pluginList;
- }
- return false;
- }
- function editPlugins($array)
- {
- switch ($array['data']['action']) {
- case 'enable':
- $newItem = array(
- $array['data']['configName'] => true
- );
- writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
- return (updateConfig($newItem)) ? true : false;
- break;
- case 'disable':
- $newItem = array(
- $array['data']['configName'] => false
- );
- writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
- return (updateConfig($newItem)) ? true : false;
- break;
- default:
- # code...
- break;
- }
- }
- function auth()
- {
- $debug = $GLOBALS['authDebug']; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
- $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
- $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
- $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
- $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
- $currentIP = userIP();
- $unlocked = ($GLOBALS['organizrUser']['locked'] == '1') ? false : true;
- if (isset($GLOBALS['organizrUser'])) {
- $currentUser = $GLOBALS['organizrUser']['username'];
- $currentGroup = $GLOBALS['organizrUser']['groupID'];
- } else {
- $currentUser = 'Guest';
- $currentGroup = getUserLevel();
- }
- $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
- if ($whitelist) {
- if (in_array($currentIP, arrayIP($whitelist))) {
- !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
- }
- }
- if ($blacklist) {
- if (in_array($currentIP, arrayIP($blacklist))) {
- !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
- }
- }
- if ($group !== null) {
- if (qualifyRequest($group) && $unlocked) {
- !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
- } else {
- !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
- }
- } else {
- !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
- }
- }
- function logoOrText()
- {
- if ($GLOBALS['useLogo'] == false) {
- return '<h1>' . $GLOBALS['title'] . '</h1>';
- } else {
- return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
- }
- }
- function showLogin()
- {
- if ($GLOBALS['hideRegistration'] == false) {
- return '<p><span lang="en">Don\'t have an account?</span><a href="#" class="text-primary m-l-5 to-register"><b lang="en">Sign Up</b></a></p>';
- }
- }
- function getImages()
- {
- $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
- $path = 'plugins/images/tabs/';
- $images = scandir($dirname);
- $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
- $allIcons = array();
- foreach ($images as $image) {
- if (!in_array($image, $ignore)) {
- $allIcons[] = $path . $image;
- }
- }
- return $allIcons;
- }
- function imageSelect($form)
- {
- $i = 1;
- $images = getImages();
- $return = '<select class="form-control tabIconImageList" id="' . $form . '-chooseImage" name="chooseImage"><option lang="en">Select or type Icon</option>';
- foreach ($images as $image) {
- $i++;
- $return .= '<option value="' . $image . '">' . basename($image) . '</option>';
- }
- return $return . '</select>';
- }
- function editImages()
- {
- $array = array();
- $postCheck = array_filter($_POST);
- $filesCheck = array_filter($_FILES);
- if (!empty($postCheck)) {
- if ($_POST['data']['action'] == 'deleteImage') {
- if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
- writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
- return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
- }
- }
- }
- if (!empty($filesCheck)) {
- ini_set('upload_max_filesize', '10M');
- ini_set('post_max_size', '10M');
- $tempFile = $_FILES['file']['tmp_name'];
- $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
- $targetFile = $targetPath . $_FILES['file']['name'];
- return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
- }
- return false;
- }
- function getThemes()
- {
- $themes = array();
- foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
- $themes[] = array(
- 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
- 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
- );
- }
- return $themes;
- }
- function getSounds()
- {
- $sounds = array();
- foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
- $sounds[] = array(
- 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
- 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3')
- );
- }
- foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
- $sounds[] = array(
- 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
- 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3')
- );
- }
- return $sounds;
- }
- function getBranches()
- {
- return array(
- array(
- 'name' => 'Develop',
- 'value' => 'v2-develop'
- ),
- array(
- 'name' => 'Master',
- 'value' => 'v2-master'
- )
- );
- }
- function getAuthTypes()
- {
- return array(
- array(
- 'name' => 'Organizr DB',
- 'value' => 'internal'
- ),
- array(
- 'name' => 'Organizr DB + Backend',
- 'value' => 'both'
- ),
- array(
- 'name' => 'Backend Only',
- 'value' => 'external'
- )
- );
- }
- function getAuthBackends()
- {
- $backendOptions = array();
- $backendOptions[] = array(
- 'name' => 'Choose Backend',
- 'value' => false,
- 'disabled' => true
- );
- foreach (array_filter(get_defined_functions()['user'], function ($v) {
- return strpos($v, 'plugin_auth_') === 0;
- }) as $value) {
- $name = str_replace('plugin_auth_', '', $value);
- if (strpos($name, 'disabled') === false) {
- $backendOptions[] = array(
- 'name' => ucwords(str_replace('_', ' ', $name)),
- 'value' => $name
- );
- } else {
- $backendOptions[] = array(
- 'name' => $value(),
- 'value' => 'none',
- 'disabled' => true,
- );
- }
- }
- ksort($backendOptions);
- return $backendOptions;
- }
- function wizardPath($array)
- {
- $path = $array['data']['path'];
- if (file_exists($path)) {
- if (is_writable($path)) {
- return true;
- }
- } else {
- if (is_writable(dirname($path, 1))) {
- if (mkdir($path, 0760, true)) {
- return true;
- }
- }
- }
- return 'permissions';
- }
- function groupSelect()
- {
- $groups = allGroups();
- $select = array();
- foreach ($groups as $key => $value) {
- $select[] = array(
- 'name' => $value['group'],
- 'value' => $value['group_id']
- );
- }
- return $select;
- }
- function getImage()
- {
- $refresh = false;
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- if (!file_exists($cacheDirectory)) {
- mkdir($cacheDirectory, 0777, true);
- }
- @$image_url = $_GET['img'];
- @$key = $_GET['key'];
- @$image_height = $_GET['height'];
- @$image_width = $_GET['width'];
- @$source = $_GET['source'];
- @$itemType = $_GET['type'];
- if (strpos($key, '$') !== false) {
- $key = explode('$', $key)[0];
- $refresh = true;
- }
- switch ($source) {
- case 'plex':
- $plexAddress = qualifyURL($GLOBALS['plexURL']);
- $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
- break;
- case 'emby':
- $embyAddress = qualifyURL($GLOBALS['embyURL']);
- $imgParams = array();
- if (isset($_GET['height'])) {
- $imgParams['height'] = 'maxHeight=' . $_GET['height'];
- }
- if (isset($_GET['width'])) {
- $imgParams['width'] = 'maxWidth=' . $_GET['width'];
- }
- $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
- break;
- default:
- # code...
- break;
- }
- if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
- $cachefile = $cacheDirectory . $key . '.jpg';
- $cachetime = 604800;
- // Serve from the cache if it is younger than $cachetime
- if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
- header("Content-type: image/jpeg");
- //@readfile($cachefile);
- echo @curl('get', $cachefile)['content'];
- exit;
- }
- ob_start(); // Start the output buffer
- header('Content-type: image/jpeg');
- //@readfile($image_src);
- echo @curl('get', $image_src)['content'];
- // Cache the output to a file
- $fp = fopen($cachefile, 'wb');
- fwrite($fp, ob_get_contents());
- fclose($fp);
- ob_end_flush(); // Send the output to the browser
- die();
- } else {
- die("Invalid Request");
- }
- }
- function cacheImage($url, $name)
- {
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- if (!file_exists($cacheDirectory)) {
- mkdir($cacheDirectory, 0777, true);
- }
- $cachefile = $cacheDirectory . $name . '.jpg';
- copy($url, $cachefile);
- }
- function downloader($array)
- {
- switch ($array['data']['source']) {
- case 'sabnzbd':
- switch ($array['data']['action']) {
- case 'resume':
- case 'pause':
- sabnzbdAction($array['data']['action'], $array['data']['target']);
- break;
- default:
- # code...
- break;
- }
- break;
- case 'nzbget':
- break;
- default:
- # code...
- break;
- }
- }
- function sabnzbdAction($action = null, $target = null)
- {
- if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
- $url = qualifyURL($GLOBALS['sabnzbdURL']);
- switch ($action) {
- case 'pause':
- $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
- $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
- break;
- case 'resume':
- $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
- $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
- break;
- default:
- # code...
- break;
- }
- try {
- $options = (localURL($url)) ? array('verify' => false) : array();
- $response = Requests::get($url, array(), $options);
- if ($response->success) {
- $api['content'] = json_decode($response->body, true);
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- // Deluge API isn't working ATM - will get with dev.
- function delugeAction($action = null, $target = null)
- {
- if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
- $url = qualifyURL($GLOBALS['delugeURL']);
- try {
- $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
- switch ($action) {
- case 'pause':
- $torrents = $deluge->pauseTorrent($target);
- break;
- case 'pauseAll':
- $torrents = $deluge->pauseAllTorrents();
- break;
- case 'resume':
- $torrents = $deluge->resumeTorrent($target);
- break;
- case 'resumeAll':
- $torrents = $deluge->resumeAllTorrents();
- break;
- default:
- # code...
- break;
- }
- $api['content'] = $torrents;
- } catch (Excecption $e) {
- writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- }
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- return false;
- }
- function getOrgUsers()
- {
- $result = allUsers();
- if (is_array($result) || is_object($result)) {
- foreach ($result['users'] as $k => $v) {
- $return[$v['username']] = $v['email'];
- }
- return $return;
- }
- }
- function convertPlexName($user, $type)
- {
- $array = userList('plex');
- switch ($type) {
- case "username":
- case "u":
- $plexUser = array_search($user, $array['users']);
- break;
- case "id":
- if (array_key_exists(strtolower($user), $array['users'])) {
- $plexUser = $array['users'][strtolower($user)];
- }
- break;
- default:
- $plexUser = false;
- }
- return (!empty($plexUser) ? $plexUser : null);
- }
- function userList($type = null)
- {
- switch ($type) {
- case 'plex':
- if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
- $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
- try {
- $headers = array(
- "Accept" => "application/json",
- "X-Plex-Token" => $GLOBALS['plexToken']
- );
- $response = Requests::get($url, $headers, array());
- libxml_use_internal_errors(true);
- if ($response->success) {
- $libraryList = array();
- $plex = simplexml_load_string($response->body);
- foreach ($plex->SharedServer as $child) {
- if (!empty($child['username'])) {
- $username = (string)strtolower($child['username']);
- $email = (string)strtolower($child['email']);
- $libraryList['users'][$username] = (string)$child['id'];
- $libraryList['emails'][$email] = (string)$child['id'];
- $libraryList['both'][$username] = $email;
- }
- }
- $libraryList = array_change_key_case($libraryList, CASE_LOWER);
- return $libraryList;
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- }
- break;
- default:
- # code...
- break;
- }
- return false;
- }
- function libraryList($type = null)
- {
- switch ($type) {
- case 'plex':
- if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
- $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'];
- try {
- $headers = array(
- "Accept" => "application/json",
- "X-Plex-Token" => $GLOBALS['plexToken']
- );
- $response = Requests::get($url, $headers, array());
- libxml_use_internal_errors(true);
- if ($response->success) {
- $libraryList = array();
- $plex = simplexml_load_string($response->body);
- foreach ($plex->Server->Section as $child) {
- $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
- }
- $libraryList = array_change_key_case($libraryList, CASE_LOWER);
- return $libraryList;
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- }
- break;
- default:
- # code...
- break;
- }
- return false;
- }
- function plexJoinAPI($array)
- {
- return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
- }
- function plexJoin($username, $email, $password)
- {
- try {
- $url = 'https://plex.tv/users.json';
- $headers = array(
- 'Accept' => 'application/json',
- 'Content-Type' => 'application/x-www-form-urlencoded',
- 'X-Plex-Product' => 'Organizr',
- 'X-Plex-Version' => '2.0',
- 'X-Plex-Client-Identifier' => '01010101-10101010',
- );
- $data = array(
- 'user[email]' => $email,
- 'user[username]' => $username,
- 'user[password]' => $password,
- );
- $response = Requests::post($url, $headers, $data, array());
- $json = json_decode($response->body, true);
- $errors = (!empty($json['errors']) ? true : false);
- $success = (!empty($json['user']) ? true : false);
- //Use This for later
- $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
- $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
- $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
- $errorMessage = "";
- if ($errors) {
- if ($usernameError) {
- $errorMessage .= "[Username Error: " . $usernameError . "]";
- }
- if ($emailError) {
- $errorMessage .= "[Email Error: " . $emailError . "]";
- }
- if ($passwordError) {
- $errorMessage .= "[Password Error: " . $passwordError . "]";
- }
- }
- return (!empty($success) && empty($errors) ? true : $errorMessage);
- } catch (Requests_Exception $e) {
- writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- return false;
- }
- function checkFrame($array, $url)
- {
- if (array_key_exists("x-frame-options", $array)) {
- if ($array['x-frame-options'] == "deny") {
- return false;
- } elseif ($array['x-frame-options'] == "sameorgin") {
- $digest = parse_url($url);
- $host = (isset($digest['host']) ? $digest['host'] : '');
- if (getServer() == $host) {
- return true;
- } else {
- return false;
- }
- }
- } else {
- if (!$array) {
- return false;
- }
- return true;
- }
- }
- function frameTest($url)
- {
- $array = array_change_key_case(get_headers(qualifyURL($url), 1));
- $url = qualifyURL($url);
- if (checkFrame($array, $url)) {
- return true;
- } else {
- return false;
- }
- }
- function ping($pings)
- {
- if (qualifyRequest($GLOBALS['pingAuth'])) {
- $type = gettype($pings);
- $ping = new Ping("");
- $ping->setTtl(128);
- $ping->setTimeout(2);
- switch ($type) {
- case "array":
- $results = [];
- foreach ($pings as $k => $v) {
- if (strpos($v, ':') !== false) {
- $domain = explode(':', $v)[0];
- $port = explode(':', $v)[1];
- $ping->setHost($domain);
- $ping->setPort($port);
- $latency = $ping->ping('fsockopen');
- } else {
- $ping->setHost($v);
- $latency = $ping->ping();
- }
- if ($latency || $latency === 0) {
- $results[$v] = $latency;
- } else {
- $results[$v] = false;
- }
- }
- break;
- case "string":
- if (strpos($pings, ':') !== false) {
- $domain = explode(':', $pings)[0];
- $port = explode(':', $pings)[1];
- $ping->setHost($domain);
- $ping->setPort($port);
- $latency = $ping->ping('fsockopen');
- } else {
- $ping->setHost($pings);
- $latency = $ping->ping();
- }
- if ($latency || $latency === 0) {
- $results = $latency;
- } else {
- $results = false;
- }
- break;
- }
- return $results;
- }
- return false;
- }
|