| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744 |
- <?php
- function checkPlexAdminFilled()
- {
- if ($GLOBALS['plexAdmin'] == '') {
- return false;
- } else {
- if ((strpos($GLOBALS['plexAdmin'], '@') !== false)) {
- return 'email';
- } else {
- return 'username';
- }
- }
- }
- 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,
- 'alias' => ($GLOBALS['ombiAlias']) ? true : false,
- 'ombiDefaultFilterAvailable' => $GLOBALS['ombiDefaultFilterAvailable'] ? true : false,
- 'ombiDefaultFilterUnavailable' => $GLOBALS['ombiDefaultFilterUnavailable'] ? true : false,
- 'ombiDefaultFilterApproved' => $GLOBALS['ombiDefaultFilterApproved'] ? true : false,
- 'ombiDefaultFilterUnapproved' => $GLOBALS['ombiDefaultFilterUnapproved'] ? true : false,
- 'ombiDefaultFilterDenied' => $GLOBALS['ombiDefaultFilterDenied'] ? true : false
- ),
- 'options' => array(
- 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
- 'healthChecksTags' => $GLOBALS['healthChecksTags'],
- 'titles' => array(
- 'tautulli' => $GLOBALS['tautulliHeader']
- )
- ),
- 'media' => array(
- 'jellyfin' => (strpos($GLOBALS['embyURL'], 'jellyfin') !== false) ? true : false
- )
- ),
- 'sso' => array(
- 'misc' => array(
- 'oAuthLogin' => isset($_COOKIE['oAuth']) ? true : false,
- 'rememberMe' => $GLOBALS['rememberMe'],
- 'rememberMeDays' => $GLOBALS['rememberMeDays']
- ),
- 'plex' => array(
- 'enabled' => ($GLOBALS['ssoPlex']) ? true : false,
- 'cookie' => isset($_COOKIE['mpt']) ? true : false,
- 'machineID' => (strlen($GLOBALS['plexID']) == 40) ? true : false,
- 'token' => ($GLOBALS['plexToken'] !== '') ? true : false,
- 'plexAdmin' => checkPlexAdminFilled(),
- 'strict' => ($GLOBALS['plexStrictFriends']) ? true : false,
- 'oAuthEnabled' => ($GLOBALS['plexoAuth']) ? true : false,
- 'backend' => ($GLOBALS['authBackend'] == 'plex') ? true : false,
- ),
- 'ombi' => array(
- 'enabled' => ($GLOBALS['ssoOmbi']) ? true : false,
- 'cookie' => isset($_COOKIE['Auth']) ? true : false,
- 'url' => ($GLOBALS['ombiURL'] !== '') ? $GLOBALS['ombiURL'] : false,
- 'api' => ($GLOBALS['ombiToken'] !== '') ? true : false,
- ),
- 'tautulli' => array(
- 'enabled' => ($GLOBALS['ssoTautulli']) ? true : false,
- 'cookie' => !empty($tautulli) ? true : false,
- 'url' => ($GLOBALS['tautulliURL'] !== '') ? $GLOBALS['tautulliURL'] : false,
- ),
- ),
- 'ping' => array(
- 'onlineSound' => $GLOBALS['pingOnlineSound'],
- 'offlineSound' => $GLOBALS['pingOfflineSound'],
- 'statusSounds' => $GLOBALS['statusSounds'],
- '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,
- 'oAuthLogin' => isset($_COOKIE['oAuth']) ? true : false,
- 'local' => (isLocal()) ? true : false,
- 'ip' => userIP()
- ),
- 'login' => array(
- 'rememberMe' => $GLOBALS['rememberMe'],
- 'rememberMeDays' => $GLOBALS['rememberMeDays'],
- 'wanDomain' => $GLOBALS['wanDomain'],
- 'localAddress' => $GLOBALS['localAddress'],
- 'enableLocalAddressForward' => $GLOBALS['enableLocalAddressForward'],
- ),
- 'misc' => array(
- 'installedPlugins' => qualifyRequest(1) ? $GLOBALS['installedPlugins'] : '',
- 'installedThemes' => qualifyRequest(1) ? $GLOBALS['installedThemes'] : '',
- 'return' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : false,
- 'authDebug' => $GLOBALS['authDebug'],
- 'minimalLoginScreen' => $GLOBALS['minimalLoginScreen'],
- 'unsortedTabs' => $GLOBALS['unsortedTabs'],
- 'authType' => $GLOBALS['authType'],
- 'authBackend' => $GLOBALS['authBackend'],
- 'newMessageSound' => (isset($GLOBALS['CHAT-newMessageSound-include'])) ? $GLOBALS['CHAT-newMessageSound-include'] : '',
- 'uuid' => $GLOBALS['uuid'],
- 'docker' => qualifyRequest(1) ? $GLOBALS['docker'] : '',
- 'githubCommit' => qualifyRequest(1) ? $GLOBALS['commit'] : '',
- 'schema' => qualifyRequest(1) ? getSchema() : '',
- 'debugArea' => qualifyRequest($GLOBALS['debugAreaAuth']),
- 'debugErrors' => $GLOBALS['debugErrors'],
- 'sandbox' => $GLOBALS['sandbox'],
- ),
- 'menuLink' => array(
- 'githubMenuLink' => $GLOBALS['githubMenuLink'],
- 'organizrSupportMenuLink' => $GLOBALS['organizrSupportMenuLink'],
- 'organizrDocsMenuLink' => $GLOBALS['organizrDocsMenuLink']
- )
- );
- }
- 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 = dbExtension($dbName);
- $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'], $GLOBALS['rememberMeDays'])) {
- 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'],
- 'image' => gravatar($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 clearTautulliTokens()
- {
- foreach (array_keys($_COOKIE) as $k => $v) {
- if (strpos($v, 'tautulli') !== false) {
- coookie('delete', $v);
- }
- }
- }
- function logout()
- {
- coookie('delete', $GLOBALS['cookieName']);
- coookie('delete', 'mpt');
- coookie('delete', 'Auth');
- coookie('delete', 'oAuth');
- clearTautulliTokens();
- revokeToken(array('data' => array('token' => $GLOBALS['organizrUser']['token'])));
- $GLOBALS['organizrUser'] = false;
- return true;
- }
- function qualifyRequest($accessLevelNeeded)
- {
- if (getUserLevel() <= $accessLevelNeeded && getUserLevel() !== null) {
- return true;
- } else {
- return false;
- }
- }
- function isApprovedRequest($method)
- {
- $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
- if (isset($_POST['data']['formKey'])) {
- $formKey = $_POST['data']['formKey'];
- } elseif (isset(getallheaders()['Formkey'])) {
- $formKey = getallheaders()['Formkey'];
- } elseif (isset(getallheaders()['formkey'])) {
- $formKey = getallheaders()['formkey'];
- } elseif (isset(getallheaders()['formKey'])) {
- $formKey = getallheaders()['formKey'];
- } elseif (isset(getallheaders()['FormKey'])) {
- $formKey = getallheaders()['FormKey'];
- } else {
- $formKey = false;
- }
- // Check token or API key
- // If API key, return 0 for admin
- if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
- //DO API CHECK
- return true;
- } elseif ($method == 'POST') {
- if (checkFormKey($formKey)) {
- return true;
- } else {
- writeLog('error', 'API ERROR: Unable to authenticate Form Key: ' . $formKey, $GLOBALS['organizrUser']['username']);
- }
- } else {
- return true;
- }
- 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", "filter");
- $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 pathsWritable($paths)
- {
- $results = array();
- foreach ($paths as $k => $v) {
- $results[$k] = is_writable($v);
- }
- return $results;
- }
- function getSettingsMain()
- {
- return array(
- 'Github' => array(
- array(
- 'type' => 'select',
- 'name' => 'branch',
- 'label' => 'Branch',
- 'value' => $GLOBALS['branch'],
- 'options' => getBranches(),
- 'disabled' => $GLOBALS['docker'],
- 'help' => ($GLOBALS['docker']) ? 'Since you are using the Official Docker image, Change the image to change the branch' : 'Choose which branch to download from'
- ),
- array(
- 'type' => 'button',
- 'name' => 'force-install-branch',
- 'label' => 'Force Install Branch',
- 'class' => 'updateNow',
- 'icon' => 'fa fa-download',
- 'text' => 'Retrieve',
- 'attr' => ($GLOBALS['docker']) ? 'title="You can just restart your docker to update"' : '',
- 'help' => ($GLOBALS['docker']) ? 'Since you are using the official Docker image, you can just restart your Docker container to update Organizr' : 'This will re-download all of the source files for Organizr'
- )
- ),
- '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' => 'plexAdmin',
- 'label' => 'Admin Username',
- 'class' => 'plexAuth switchAuth',
- 'value' => $GLOBALS['plexAdmin'],
- 'placeholder' => 'Admin username for Plex'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'plexoAuth',
- 'label' => 'Enable Plex oAuth',
- 'class' => 'plexAuth switchAuth',
- 'value' => $GLOBALS['plexoAuth']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'plexStrictFriends',
- 'label' => 'Strict Plex Friends ',
- 'class' => 'plexAuth switchAuth',
- 'value' => $GLOBALS['plexStrictFriends'],
- 'help' => 'Enabling this will only allow Friends that have shares to the Machine ID entered above to login, Having this disabled will allow all Friends on your Friends list to login'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ignoreTFALocal',
- 'label' => 'Ignore External 2FA on Local Subnet',
- 'value' => $GLOBALS['ignoreTFALocal'],
- 'help' => 'Enabling this will bypass external 2FA security if user is on local Subnet'
- ),
- 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' => 'select',
- 'name' => 'ldapType',
- 'id' => 'ldapType',
- 'label' => 'LDAP Backend Type',
- 'class' => 'ldapAuth switchAuth',
- 'value' => $GLOBALS['ldapType'],
- 'options' => getLDAPOptions()
- ),
- array(
- 'type' => 'input',
- 'name' => 'authBackendHostPrefix',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Account Prefix',
- 'id' => 'authBackendHostPrefix-input',
- 'value' => $GLOBALS['authBackendHostPrefix'],
- 'placeholder' => 'Account prefix - i.e. Controller\ from Controller\Username for AD - uid= for OpenLDAP'
- ),
- array(
- 'type' => 'input',
- 'name' => 'authBackendHostSuffix',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Account Suffix',
- 'id' => 'authBackendHostSuffix-input',
- 'value' => $GLOBALS['authBackendHostSuffix'],
- 'placeholder' => 'Account suffix - start with comma - ,ou=people,dc=domain,dc=tld'
- ),
- array(
- 'type' => 'input',
- 'name' => 'ldapBindUsername',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Bind Username',
- 'value' => $GLOBALS['ldapBindUsername'],
- 'placeholder' => ''
- ),
- array(
- 'type' => 'password',
- 'name' => 'ldapBindPassword',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Password',
- 'value' => $GLOBALS['ldapBindPassword']
- ),
- array(
- 'type' => 'html',
- 'class' => 'ldapAuth switchAuth',
- 'label' => 'Account DN',
- 'html' => '<span id="accountDN" class="ldapAuth switchAuth">' . $GLOBALS['authBackendHostPrefix'] . 'TestAcct' . $GLOBALS['authBackendHostSuffix'] . '</span>'
- ),
- array(
- 'type' => 'button',
- 'name' => 'test-button-ldap',
- 'label' => 'Test Connection',
- 'icon' => 'fa fa-flask',
- 'class' => 'ldapAuth switchAuth',
- 'text' => 'Test Connection',
- 'attr' => 'onclick="testAPIConnection(\'ldap\')"',
- 'help' => 'Remember! Please save before using the test button!'
- ),
- array(
- 'type' => 'button',
- 'name' => 'test-button-ldap-login',
- 'label' => 'Test Login',
- 'icon' => 'fa fa-flask',
- 'class' => 'ldapAuth switchAuth',
- 'text' => 'Test Login',
- 'attr' => 'onclick="showLDAPLoginTest()"'
- ),
- array(
- 'type' => 'input',
- 'name' => 'embyURL',
- 'class' => 'embyAuth switchAuth',
- 'label' => 'Emby URL',
- 'value' => $GLOBALS['embyURL'],
- 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
- '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' => 'loginAttempts',
- 'label' => 'Max Login Attempts',
- 'value' => $GLOBALS['loginAttempts'],
- 'placeholder' => ''
- ),
- array(
- 'type' => 'select',
- 'name' => 'loginLockout',
- 'label' => 'Login Lockout Seconds',
- 'value' => $GLOBALS['loginLockout'],
- 'options' => optionTime()
- ),
- array(
- 'type' => 'number',
- 'name' => 'lockoutTimeout',
- 'label' => 'Inactivity Timer [Minutes]',
- 'value' => $GLOBALS['lockoutTimeout'],
- 'placeholder' => ''
- ),
- 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' => 'switch',
- 'name' => 'lockoutSystem',
- 'label' => 'Inactivity Lock',
- 'value' => $GLOBALS['lockoutSystem']
- ),
- array(
- 'type' => 'select',
- 'name' => 'debugAreaAuth',
- 'label' => 'Minimum Authentication for Debug Area',
- 'value' => $GLOBALS['debugAreaAuth'],
- 'options' => groupSelect()
- ),
- 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'
- ),
- array(
- 'type' => 'select2',
- 'class' => 'select2-multiple',
- 'id' => 'sandbox-select',
- 'name' => 'sandbox',
- 'label' => 'iFrame Sandbox',
- 'value' => $GLOBALS['sandbox'],
- 'help' => 'WARNING! This can potentially mess up your iFrames',
- 'options' => array(
- array(
- 'name' => 'Allow Presentation',
- 'value' => 'allow-presentation'
- ),
- array(
- 'name' => 'Allow Forms',
- 'value' => 'allow-forms'
- ),
- array(
- 'name' => 'Allow Same Origin',
- 'value' => 'allow-same-origin'
- ),
- array(
- 'name' => 'Allow Pointer Lock',
- 'value' => 'allow-pointer-lock'
- ),
- array(
- 'name' => 'Allow Scripts',
- 'value' => 'allow-scripts'
- ), array(
- 'name' => 'Allow Popups',
- 'value' => 'allow-popups'
- ),
- array(
- 'name' => 'Allow Modals',
- 'value' => 'allow-modals'
- ),
- array(
- 'name' => 'Allow Top Navigation',
- 'value' => 'allow-top-navigation'
- ),
- array(
- 'name' => 'Allow Downloads',
- 'value' => 'allow-downloads'
- ),
- )
- ),
- array(
- 'type' => 'switch',
- 'name' => 'traefikAuthEnable',
- 'label' => 'Enable Traefik Auth Redirect',
- 'help' => 'This will enable the webserver to forward errors so traefik will accept them',
- 'value' => $GLOBALS['traefikAuthEnable']
- ),
- ),
- 'Performance' => array(
- array(
- 'type' => 'switch',
- 'name' => 'performanceDisableIconDropdown',
- 'label' => 'Disable Icon Dropdown',
- 'help' => 'Disable select dropdown boxes on new and edit tab forms',
- 'value' => $GLOBALS['performanceDisableIconDropdown'],
- ),
- array(
- 'type' => 'switch',
- 'name' => 'performanceDisableImageDropdown',
- 'label' => 'Disable Image Dropdown',
- 'help' => 'Disable select dropdown boxes on new and edit tab forms',
- 'value' => $GLOBALS['performanceDisableImageDropdown'],
- ),
- ),
- 'Login' => array(
- array(
- 'type' => 'password-alt',
- 'name' => 'registrationPassword',
- 'label' => 'Registration Password',
- 'help' => 'Sets the password for the Registration form on the login screen',
- 'value' => $GLOBALS['registrationPassword'],
- ),
- array(
- 'type' => 'switch',
- 'name' => 'hideRegistration',
- 'label' => 'Hide Registration',
- 'help' => 'Enable this to hide the Registration button on the login screen',
- 'value' => $GLOBALS['hideRegistration'],
- ),
- array(
- 'type' => 'number',
- 'name' => 'rememberMeDays',
- 'label' => 'Remember Me Length',
- 'help' => 'Number of days cookies and tokens will be valid for',
- 'value' => $GLOBALS['rememberMeDays'],
- 'placeholder' => '',
- 'attr' => 'min="1"'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'rememberMe',
- 'label' => 'Remember Me',
- 'help' => 'Default status of Remember Me button on login screen',
- 'value' => $GLOBALS['rememberMe'],
- ),
- array(
- 'type' => 'input',
- 'name' => 'localIPFrom',
- 'label' => 'Override Local IP From',
- 'value' => $GLOBALS['localIPFrom'],
- 'placeholder' => 'i.e. 123.123.123.123',
- 'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
- ),
- array(
- 'type' => 'input',
- 'name' => 'localIPTo',
- 'label' => 'Override Local IP To',
- 'value' => $GLOBALS['localIPTo'],
- 'placeholder' => 'i.e. 123.123.123.123',
- 'help' => 'IPv4 only at the moment - This will set your login as local if your IP falls within the From and To'
- ),
- array(
- 'type' => 'input',
- 'name' => 'wanDomain',
- 'label' => 'WAN Domain',
- 'value' => $GLOBALS['wanDomain'],
- 'placeholder' => 'only domain and tld - i.e. domain.com',
- 'help' => 'Enter domain if you wish to be forwarded to a local address - Local Address filled out on next item'
- ),
- array(
- 'type' => 'input',
- 'name' => 'localAddress',
- 'label' => 'Local Address',
- 'value' => $GLOBALS['localAddress'],
- 'placeholder' => 'http://home.local',
- 'help' => 'Full local address of organizr install - i.e. http://home.local or http://192.168.0.100'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'enableLocalAddressForward',
- 'label' => 'Enable Local Address Forward',
- 'help' => 'Enables the local address forward if on local address and accessed from WAN Domain',
- 'value' => $GLOBALS['enableLocalAddressForward'],
- ),
- ),
- 'Auth Proxy' => array(
- array(
- 'type' => 'switch',
- 'name' => 'authProxyEnabled',
- 'label' => 'Auth Proxy',
- 'help' => 'Enable option to set Auth Proxy Header Login',
- 'value' => $GLOBALS['authProxyEnabled'],
- ),
- array(
- 'type' => 'input',
- 'name' => 'authProxyHeaderName',
- 'label' => 'Auth Proxy Header Name',
- 'value' => $GLOBALS['authProxyHeaderName'],
- 'placeholder' => 'i.e. X-Forwarded-User',
- 'help' => 'Please choose a unique value for added security'
- ),
- array(
- 'type' => 'input',
- 'name' => 'authProxyWhitelist',
- 'label' => 'Auth Proxy Whitelist',
- 'value' => $GLOBALS['authProxyWhitelist'],
- 'placeholder' => 'i.e. 10.0.0.0/24 or 10.0.0.20',
- 'help' => 'IPv4 only at the moment - This must be set to work, will accept subnet or IP address'
- ),
- ),
- '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' => 'switch',
- 'name' => 'statusSounds',
- 'label' => 'Enable Notify Sounds',
- 'value' => $GLOBALS['statusSounds'],
- 'help' => 'Will play a sound if the server goes down and will play sound if comes back up.',
- ),
- 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']
- )
- ),
- 'Tautulli' => array(
- array(
- 'type' => 'input',
- 'name' => 'tautulliURL',
- 'label' => 'Tautulli URL',
- 'value' => $GLOBALS['tautulliURL'],
- 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ssoTautulli',
- 'label' => 'Enable',
- 'value' => $GLOBALS['ssoTautulli']
- )
- ),
- 'Ombi' => array(
- array(
- 'type' => 'input',
- 'name' => 'ombiURL',
- 'label' => 'Ombi URL',
- 'value' => $GLOBALS['ombiURL'],
- 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'ombiToken',
- 'label' => 'Token',
- 'value' => $GLOBALS['ombiToken']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'ssoOmbi',
- 'label' => 'Enable',
- 'value' => $GLOBALS['ssoOmbi']
- )
- )
- );
- }
- function loadAppearance()
- {
- $appearance = array();
- $appearance['logo'] = $GLOBALS['logo'];
- $appearance['title'] = $GLOBALS['title'];
- $appearance['useLogo'] = $GLOBALS['useLogo'];
- $appearance['useLogoLogin'] = $GLOBALS['useLogoLogin'];
- $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['loginLogo'] = $GLOBALS['loginLogo'];
- $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'],
- 'help' => 'Also sets the title of your site'
- ),
- array(
- 'type' => 'input',
- 'name' => 'description',
- 'label' => 'Meta Description',
- 'value' => $GLOBALS['description'],
- 'help' => 'Used to set the description for SEO meta tags'
- ),
- ),
- 'Login Page' => array(
- array(
- 'type' => 'input',
- 'name' => 'loginLogo',
- 'label' => 'Login Logo',
- 'value' => $GLOBALS['loginLogo'],
- ),
- array(
- 'type' => 'input',
- 'name' => 'loginWallpaper',
- 'label' => 'Login Wallpaper',
- 'value' => $GLOBALS['loginWallpaper'],
- 'help' => 'You may enter multiple URL\'s using the CSV format. i.e. link#1,link#2,link#3'
- ),
- array(
- 'type' => 'switch',
- 'name' => 'useLogoLogin',
- 'label' => 'Use Logo instead of Title on Login Page',
- 'value' => $GLOBALS['useLogoLogin']
- ),
- 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' => 'switch',
- 'name' => 'debugErrors',
- 'label' => 'Show Debug Errors',
- 'value' => $GLOBALS['debugErrors']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'githubMenuLink',
- 'label' => 'Show GitHub Repo Link',
- 'value' => $GLOBALS['githubMenuLink']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'organizrSupportMenuLink',
- 'label' => 'Show Organizr Support Link',
- 'value' => $GLOBALS['organizrSupportMenuLink']
- ),
- array(
- 'type' => 'switch',
- 'name' => 'organizrDocsMenuLink',
- 'label' => 'Show Organizr Docs Link',
- 'value' => $GLOBALS['organizrDocsMenuLink']
- ),
- array(
- 'type' => 'select',
- 'name' => 'unsortedTabs',
- 'label' => 'Unsorted Tab Placement',
- 'value' => $GLOBALS['unsortedTabs'],
- 'options' => array(
- array(
- 'name' => 'Top',
- 'value' => 'top'
- ),
- array(
- 'name' => 'Bottom',
- 'value' => 'bottom'
- )
- )
- ),
- array(
- 'type' => 'input',
- 'name' => 'gaTrackingID',
- 'label' => 'Google Analytics Tracking ID',
- 'placeholder' => 'e.g. UA-XXXXXXXXX-X',
- 'value' => $GLOBALS['gaTrackingID']
- )
- ),
- '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>
- <span lang="en">To revert back to default, save with no value defined in the relevant field.</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">' . htmlentities($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">' . htmlentities($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">' . htmlentities($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">' . htmlentities($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) {
- $v['value'] = $v['value'] ?? '';
- 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 (isEncrypted($v['value']) || $v['value'] == '') {
- $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)
- {
- $array['data']['value'] = $array['data']['value'] ?? '';
- 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 [' . $array['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 [' . $array['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 = 0;
- $groupParam = $_GET['group'];
- $redirect = false;
- if (isset($groupParam)) {
- if (is_numeric($groupParam)) {
- $group = (int)$groupParam;
- } else {
- $group = getTabGroup($groupParam);
- }
- }
- $currentIP = userIP();
- $unlocked = ($GLOBALS['organizrUser']['locked'] == '1') ? false : true;
- if (isset($GLOBALS['organizrUser'])) {
- $currentUser = $GLOBALS['organizrUser']['username'];
- $currentGroup = $GLOBALS['organizrUser']['groupID'];
- $currentEmail = $GLOBALS['organizrUser']['email'];
- } else {
- $currentUser = 'Guest';
- $currentGroup = getUserLevel();
- $currentEmail = 'guest@guest.com';
- }
- $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 ((isset($_SERVER['HTTP_X_FORWARDED_SERVER']) && $_SERVER['HTTP_X_FORWARDED_SERVER'] == 'traefik') || $GLOBALS['traefikAuthEnable']) {
- $redirect = 'Location: ' . getServerPath();
- }
- if (qualifyRequest($group) && $unlocked) {
- header("X-Organizr-User: $currentUser");
- header("X-Organizr-Email: $currentEmail");
- !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
- } else {
- !$debug ? (!$redirect ? exit(http_response_code(401)) : exit(http_response_code(401) . header($redirect))) : die("$userInfo Not Authorized");
- }
- } else {
- !$debug ? (!$redirect ? exit(http_response_code(401)) : exit(http_response_code(401) . header($redirect))) : die("Not Authorized Due To No Parameters Set");
- }
- }
- function getTabGroup($tab)
- {
- try {
- $connect = new Dibi\Connection([
- 'driver' => 'sqlite3',
- 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],]);
- $row = $connect->fetch('SELECT group_id FROM tabs WHERE name LIKE %~like~', $tab);
- return $row ? $row['group_id'] : 0;
- } catch (\Dibi\Exception $e) {
- writeLog('error', 'Tab Group Function - Error Fetching Tab Group', $tab);
- return 0;
- }
- }
- function logoOrText()
- {
- if ($GLOBALS['useLogoLogin'] == false) {
- return '<h1>' . $GLOBALS['title'] . '</h1>';
- } else {
- return '<img class="loginLogo" src="' . $GLOBALS['loginLogo'] . '" 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 checkoAuth()
- {
- return ($GLOBALS['plexoAuth'] && $GLOBALS['authType'] !== 'internal') ? true : false;
- }
- function checkoAuthOnly()
- {
- return ($GLOBALS['plexoAuth'] && $GLOBALS['authType'] == 'external') ? true : false;
- }
- function showoAuth()
- {
- $buttons = '';
- if ($GLOBALS['plexoAuth'] && $GLOBALS['authType'] !== 'internal') {
- $buttons .= '<a href="javascript:void(0)" onclick="oAuthStart(\'plex\')" class="btn btn-lg btn-block text-uppercase waves-effect waves-light bg-plex text-muted" data-toggle="tooltip" title="" data-original-title="Login with Plex"> <span>Login</span><i aria-hidden="true" class="mdi mdi-plex m-l-5"></i> </a>';
- }
- return ($buttons) ? '
- <div class="panel">
- <div class="panel-heading bg-org" id="plex-login-heading" role="tab">
- <a class="panel-title" data-toggle="collapse" href="#plex-login-collapse" data-parent="#login-panels" aria-expanded="false" aria-controls="organizr-login-collapse">
- <img class="lazyload loginTitle" data-src="plugins/images/tabs/plex.png">
- <span class="text-uppercase fw300" lang="en">Login with Plex</span>
- </a>
- </div>
- <div class="panel-collapse collapse in" id="plex-login-collapse" aria-labelledby="plex-login-heading" role="tabpanel">
- <div class="panel-body">
- <div class="row">
- <div class="col-xs-12 col-sm-12 col-md-12 text-center">
- <div class="social m-b-0">' . $buttons . '</div>
- </div>
- </div>
- </div>
- </div>
- </div>
- ' : '';
- }
- function getImages()
- {
- $allIconsPrep = array();
- $allIcons = array();
- $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id", "index.html");
- $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
- $path = 'plugins/images/tabs/';
- $images = scandir($dirname);
- foreach ($images as $image) {
- if (!in_array($image, $ignore)) {
- $allIconsPrep[$image] = array(
- 'path' => $path,
- 'name' => $image
- );
- }
- }
- $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'userTabs' . DIRECTORY_SEPARATOR;
- $path = 'plugins/images/userTabs/';
- $images = scandir($dirname);
- foreach ($images as $image) {
- if (!in_array($image, $ignore)) {
- $allIconsPrep[$image] = array(
- 'path' => $path,
- 'name' => $image
- );
- }
- }
- ksort($allIconsPrep);
- foreach ($allIconsPrep as $item) {
- $allIcons[] = $item['path'] . $item['name'];
- }
- 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);
- $approvedPath = 'plugins/images/userTabs/';
- if (!empty($postCheck)) {
- $removeImage = $approvedPath . pathinfo($_POST['data']['imagePath'], PATHINFO_BASENAME);
- if ($_POST['data']['action'] == 'deleteImage' && approvedFileExtension($removeImage)) {
- if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $removeImage)) {
- writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
- return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $removeImage)) ? true : false;
- }
- }
- }
- if (!empty($filesCheck) && approvedFileExtension($_FILES['file']['name']) && strpos($_FILES['file']['type'], 'image/') !== false) {
- 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 . 'userTabs' . DIRECTORY_SEPARATOR;
- $targetFile = $targetPath . $_FILES['file']['name'];
- return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
- }
- return false;
- }
- function approvedFileExtension($filename)
- {
- $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- switch ($ext) {
- case 'gif':
- case 'png':
- case 'jpeg':
- case 'jpg':
- case 'svg':
- return true;
- break;
- default:
- 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 getLDAPOptions()
- {
- return array(
- array(
- 'name' => 'Active Directory',
- 'value' => '1'
- ),
- array(
- 'name' => 'OpenLDAP',
- 'value' => '2'
- ),
- array(
- 'name' => 'First IPA',
- 'value' => '3'
- ),
- );
- }
- 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'];
- $options = array('verify' => false);
- $response = Requests::get($cachefile, array(), $options);
- if ($response->success) {
- echo $response->body;
- }
- exit;
- }
- ob_start(); // Start the output buffer
- header('Content-type: image/jpeg');
- //@readfile($image_src);
- //echo @curl('get', $image_src)['content'];
- $options = array('verify' => false);
- $response = Requests::get($image_src, array(), $options);
- if ($response->success) {
- echo $response->body;
- }
- // 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, $extension = 'jpg')
- {
- $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 . '.' . $extension;
- $cachetime = 604800;
- if ((file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) || !file_exists($cachefile)) {
- @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 'jdownloader':
- switch ($array['data']['action']) {
- case 'start':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'stop':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'resume':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'pause':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'update':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'retry':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- case 'remove':
- jdownloaderAction($array['data']['action'], $array['data']['target']);
- break;
- default:
- # code...
- break;
- }
- break;
- case 'nzbget':
- break;
- default:
- # code...
- break;
- }
- }
- function jdownloaderAction($action = null, $target = null)
- {
- if ($GLOBALS['homepageJdownloaderEnabled'] && !empty($GLOBALS['jdownloaderURL']) && qualifyRequest($GLOBALS['homepageJdownloaderAuth'])) {
- $url = qualifyURL($GLOBALS['jdownloaderURL']);
- # This ensures compatibility with RSScrawler
- $url = str_replace('/myjd', '', $url);
- if (substr($url, -1) == '/') {
- $url = substr_replace($url, "", -1);
- }
- switch ($action) {
- case 'start':
- $url = $url . '/myjd_start/';
- break;
- case 'stop':
- $url = $url . '/myjd_stop/';
- break;
- case 'resume':
- $url = $url . '/myjd_pause/false';
- break;
- case 'pause':
- $url = $url . '/myjd_pause/true';
- break;
- case 'update':
- $url = $url . '/myjd_update';
- break;
- case 'retry':
- # code...
- break;
- case 'remove':
- # code...
- break;
- default:
- # code...
- break;
- }
- try {
- $options = (localURL($url)) ? array('verify' => false) : array();
- $response = Requests::post($url, array(), $options);
- if ($response->success) {
- $api['content'] = json_decode($response->body, true);
- }
- } catch (Requests_Exception $e) {
- writeLog('error', 'JDownloader Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- };
- $api['content'] = isset($api['content']) ? $api['content'] : false;
- return $api;
- }
- }
- 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 embyJoinAPI($array)
- {
- return embyJoin($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' => $GLOBALS['uuid'],
- );
- $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 embyJoin($username, $email, $password)
- {
- try {
- #create user in emby.
- $headers = array(
- "Accept" => "application/json"
- );
- $data = array();
- $url = $GLOBALS['embyURL'] . '/emby/Users/New?name=' . $username . '&api_key=' . $GLOBALS['embyToken'];
- $response = Requests::Post($url, $headers, json_encode($data), array());
- $response = $response->body;
- //return($response);
- $response = json_decode($response, true);
- //return($response);
- $userID = $response["Id"];
- //return($userID);
- #authenticate as user to update password.
- //randomizer four digits of DeviceId
- // I dont think ther would be security problems with hardcoding deviceID but randomizing it would mitigate any issue.
- $deviceIdSeceret = rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9) . "" . rand(0, 9);
- //hardcoded device id with the first three digits random 0-9,0-9,0-9,0-9
- $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
- $headers = array(
- "Accept" => "application/json",
- "Content-Type" => "application/json",
- "X-Emby-Authorization" => $embyAuthHeader
- );
- $data = array(
- "Pw" => "",
- "Username" => $username
- );
- $url = $GLOBALS['embyURL'] . '/emby/Users/AuthenticateByName';
- $response = Requests::Post($url, $headers, json_encode($data), array());
- $response = $response->body;
- $response = json_decode($response, true);
- $userToken = $response["AccessToken"];
- #update password
- $embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", Token="' . $userToken . '", DeviceId="' . $deviceIdSeceret . 'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
- $headers = array(
- "Accept" => "application/json",
- "Content-Type" => "application/json",
- "X-Emby-Authorization" => $embyAuthHeader
- );
- $data = array(
- "CurrentPw" => "",
- "NewPw" => $password,
- "Id" => $userID
- );
- $url = $GLOBALS['embyURL'] . '/emby/Users/' . $userID . '/Password';
- Requests::Post($url, $headers, json_encode($data), array());
- #update config
- $headers = array(
- "Accept" => "application/json",
- "Content-Type" => "application/json"
- );
- $url = $GLOBALS['embyURL'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $GLOBALS['embyToken'];
- $response = Requests::Post($url, $headers, getEmbyTemplateUserJson(), array());
- #add emby.media
- try {
- #seperate because this is not required
- $headers = array(
- "Accept" => "application/json",
- "X-Emby-Authorization" => $embyAuthHeader
- );
- $data = array(
- "ConnectUsername " => $email
- );
- $url = $GLOBALS['embyURL'] . '/emby/Users/' . $userID . '/Connect/Link';
- Requests::Post($url, $headers, json_encode($data), array());
- } catch (Requests_Exception $e) {
- writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- }
- return (true);
- //return( "USERID:".$userID);
- } catch (Requests_Exception $e) {
- writeLog('error', 'Emby create 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;
- }
- }
- /*loads users from emby and returns a correctly formated policy for a new user.
- */
- function getEmbyTemplateUserJson()
- {
- $headers = array(
- "Accept" => "application/json"
- );
- $data = array();
- $url = $GLOBALS['embyURL'] . '/emby/Users?api_key=' . $GLOBALS['embyToken'];
- $response = Requests::Get($url, $headers, array());
- $response = $response->body;
- $response = json_decode($response, true);
- //error_Log("response ".json_encode($response));
- writeLog('error', 'userList:' . json_encode($response), 'SYSTEM');
- //$correct stores the template users object
- $correct = null;
- foreach ($response as $element) {
- if ($element['Name'] == $GLOBALS['INVITES-EmbyTemplate']) {
- $correct = $element;
- }
- }
- writeLog('error', 'Correct user:' . json_encode($correct), 'SYSTEM');
- if ($correct == null) {
- //return empty JSON if user incorectly configured template
- return "{}";
- }
- //select policy section and remove possibly dangeours rows.
- $policy = $correct['Policy'];
- //writeLog('error', 'policy update'.$policy, 'SYSTEM');
- unset($policy['AuthenticationProviderId']);
- unset($policy['InvalidLoginAttemptCount']);
- unset($policy['DisablePremiumFeatures']);
- unset($policy['DisablePremiumFeatures']);
- return (json_encode($policy));
- }
- 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;
- }
- function guestHash($start, $end)
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- $ip = md5($ip);
- return substr($ip, $start, $end);
- }
- function importUserButtons()
- {
- $emptyButtons = '
- <div class="col-md-12">
- <div class="white-box bg-org">
- <h3 class="box-title m-0" lang="en">Currently User import is available for Plex only.</h3> </div>
- </div>
- ';
- $buttons = '';
- if (!empty($GLOBALS['plexToken'])) {
- $buttons .= '<button class="btn bg-plex text-muted waves-effect waves-light importUsersButton" onclick="importUsers(\'plex\')" type="button"><span class="btn-label"><i class="mdi mdi-plex"></i></span><span lang="en">Import Plex Users</span></button>';
- }
- return ($buttons !== '') ? $buttons : $emptyButtons;
- }
- function settingsDocker()
- {
- $type = ($GLOBALS['docker']) ? 'Official Docker' : 'Native';
- return '<li><div class="bg-info"><i class="mdi mdi-flag mdi-24px text-white"></i></div><span class="text-muted hidden-xs m-t-10" lang="en">Install Type</span> ' . $type . '</li>';
- }
- function settingsPathChecks()
- {
- $items = '';
- $type = (array_search(false, pathsWritable($GLOBALS['paths']))) ? 'Not Writable' : 'Writable';
- $result = '<li class="mouse" onclick="toggleWritableFolders();"><div class="bg-info"><i class="mdi mdi-folder mdi-24px text-white"></i></div><span class="text-muted hidden-xs m-t-10" lang="en">Organizr Paths</span> ' . $type . '</li>';
- foreach (pathsWritable($GLOBALS['paths']) as $k => $v) {
- $items .= '<li class="folders-writable hidden"><div class="bg-info"><i class="mdi mdi-folder mdi-24px text-white"></i></div><span class="text-muted hidden-xs m-t-10" lang="en">' . $k . '</span> ' . (($v) ? 'Writable' : 'Not Writable') . '</li>';
- }
- return $result . $items;
- }
- function dockerUpdate()
- {
- $dockerUpdate = null;
- chdir('/etc/cont-init.d/');
- if (file_exists('./30-install')) {
- $dockerUpdate = shell_exec('./30-install');
- } elseif (file_exists('./40-install')) {
- $dockerUpdate = shell_exec('./40-install');
- }
- return $dockerUpdate ?? 'Update Failed';
- }
- function windowsUpdate()
- {
- $branch = ($GLOBALS['branch'] == 'v2-master') ? '-m' : '-d';
- ini_set('max_execution_time', 0);
- set_time_limit(0);
- $logFile = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'log.txt';
- $windowsScript = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'windows-update.bat ' . $branch . ' > ' . $logFile . ' 2>&1';
- $windowsUpdate = shell_exec($windowsScript);
- return ($windowsUpdate) ? $windowsUpdate : 'Update Complete - check log.txt for output';
- }
- function checkHostPrefix($s)
- {
- if (empty($s)) {
- return $s;
- }
- return (substr($s, -1, 1) == '\\') ? $s : $s . '\\';
- }
- function analyzeIP($ip)
- {
- if (strpos($ip, '/') !== false) {
- $explodeIP = explode('/', $ip);
- $prefix = $explodeIP[1];
- $start_ip = $explodeIP[0];
- $ip_count = 1 << (32 - $prefix);
- $start_ip_long = ip2long($start_ip);
- $last_ip_long = ip2long($start_ip) + $ip_count - 1;
- } elseif (substr_count($ip, '.') == 3) {
- $start_ip_long = ip2long($ip);
- $last_ip_long = ip2long($ip);
- }
- return (isset($start_ip_long) && isset($last_ip_long)) ? array('from' => $start_ip_long, 'to' => $last_ip_long) : false;
- }
- function authProxyRangeCheck($from, $to)
- {
- $approved = false;
- $userIP = ip2long($_SERVER['REMOTE_ADDR']);
- $low = $from;
- $high = $to;
- if ($userIP <= $high && $low <= $userIP) {
- $approved = true;
- }
- return $approved;
- }
|