4
0

organizr-functions.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  1. <?php
  2. function organizrSpecialSettings()
  3. {
  4. $refreshSearch = "Refresh";
  5. $tautulliSearch = "tautulli_token";
  6. $tautulli = array_filter($_COOKIE, function ($k) use ($tautulliSearch) {
  7. return stripos($k, $tautulliSearch) !== false;
  8. }, ARRAY_FILTER_USE_KEY);
  9. return array(
  10. 'homepage' => array(
  11. 'refresh' => array_filter($GLOBALS, function ($k) use ($refreshSearch) {
  12. return stripos($k, $refreshSearch) !== false;
  13. }, ARRAY_FILTER_USE_KEY),
  14. 'search' => array(
  15. 'enabled' => (qualifyRequest($GLOBALS['mediaSearchAuth']) && $GLOBALS['mediaSearch'] == true && $GLOBALS['plexToken']) ? true : false,
  16. 'type' => $GLOBALS['mediaSearchType'],
  17. ),
  18. 'ombi' => array(
  19. 'enabled' => (qualifyRequest($GLOBALS['homepageOmbiAuth']) && qualifyRequest($GLOBALS['homepageOmbiRequestAuth']) && $GLOBALS['homepageOmbiEnabled'] == true && $GLOBALS['ssoOmbi'] && isset($_COOKIE['Auth'])) ? true : false,
  20. 'authView' => (qualifyRequest($GLOBALS['homepageOmbiAuth'])) ? true : false,
  21. 'authRequest' => (qualifyRequest($GLOBALS['homepageOmbiRequestAuth'])) ? true : false,
  22. 'sso' => ($GLOBALS['ssoOmbi']) ? true : false,
  23. 'cookie' => (isset($_COOKIE['Auth'])) ? true : false,
  24. ),
  25. 'options' => array(
  26. 'alternateHomepageHeaders' => $GLOBALS['alternateHomepageHeaders'],
  27. )
  28. ),
  29. 'sso' => array(
  30. 'plex' => array(
  31. 'enabled' => ($GLOBALS['ssoPlex']) ? true : false,
  32. 'cookie' => isset($_COOKIE['mpt']) ? true : false,
  33. ),
  34. 'ombi' => array(
  35. 'enabled' => ($GLOBALS['ssoOmbi']) ? true : false,
  36. 'cookie' => isset($_COOKIE['Auth']) ? true : false,
  37. ),
  38. 'tautulli' => array(
  39. 'enabled' => ($GLOBALS['ssoTautulli']) ? true : false,
  40. 'cookie' => !empty($tautulli) ? true : false,
  41. ),
  42. ),
  43. 'ping' => array(
  44. 'onlineSound' => $GLOBALS['pingOnlineSound'],
  45. 'offlineSound' => $GLOBALS['pingOfflineSound'],
  46. 'auth' => $GLOBALS['pingAuth'],
  47. 'authMessage' => $GLOBALS['pingAuthMessage'],
  48. 'authMs' => $GLOBALS['pingAuthMs'],
  49. 'ms' => $GLOBALS['pingMs'],
  50. 'adminRefresh' => $GLOBALS['adminPingRefresh'],
  51. 'everyoneRefresh' => $GLOBALS['otherPingRefresh'],
  52. ),
  53. 'notifications' => array(
  54. 'backbone' => $GLOBALS['notificationBackbone'],
  55. 'position' => $GLOBALS['notificationPosition']
  56. ),
  57. 'lockout' => array(
  58. 'enabled' => $GLOBALS['lockoutSystem'],
  59. 'timer' => $GLOBALS['lockoutTimeout'],
  60. 'minGroup' => $GLOBALS['lockoutMinAuth'],
  61. 'maxGroup' => $GLOBALS['lockoutMaxAuth']
  62. ),
  63. 'user' => array(
  64. 'agent' => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null
  65. )
  66. );
  67. }
  68. function wizardConfig($array)
  69. {
  70. foreach ($array['data'] as $items) {
  71. foreach ($items as $key => $value) {
  72. if ($key == 'name') {
  73. $newKey = $value;
  74. }
  75. if ($key == 'value') {
  76. $newValue = $value;
  77. }
  78. if (isset($newKey) && isset($newValue)) {
  79. $$newKey = $newValue;
  80. }
  81. }
  82. }
  83. $location = cleanDirectory($location);
  84. $dbName = $dbName . '.db';
  85. $configVersion = $GLOBALS['installedVersion'];
  86. $configArray = array(
  87. 'dbName' => $dbName,
  88. 'dbLocation' => $location,
  89. 'license' => $license,
  90. 'organizrHash' => $hashKey,
  91. 'organizrAPI' => $api,
  92. 'registrationPassword' => $registrationPassword,
  93. );
  94. // Create Config
  95. $GLOBALS['dbLocation'] = $location;
  96. $GLOBALS['dbName'] = $dbName;
  97. if (createConfig($configArray)) {
  98. // Call DB Create
  99. if (createDB($location, $dbName)) {
  100. // Add in first user
  101. if (createFirstAdmin($location, $dbName, $username, $password, $email)) {
  102. if (createToken($username, $email, gravatar($email), 'Admin', 0, $hashKey, 1)) {
  103. return true;
  104. } else {
  105. return 'token';
  106. }
  107. } else {
  108. return 'admin';
  109. }
  110. } else {
  111. return 'db';
  112. }
  113. } else {
  114. return 'config';
  115. }
  116. return false;
  117. }
  118. function register($array)
  119. {
  120. // Grab username and password from login form
  121. foreach ($array['data'] as $items) {
  122. foreach ($items as $key => $value) {
  123. if ($key == 'name') {
  124. $newKey = $value;
  125. }
  126. if ($key == 'value') {
  127. $newValue = $value;
  128. }
  129. if (isset($newKey) && isset($newValue)) {
  130. $$newKey = $newValue;
  131. }
  132. }
  133. }
  134. if ($registrationPassword == $GLOBALS['registrationPassword']) {
  135. $defaults = defaultUserGroup();
  136. writeLog('success', 'Registration Function - Registration Password Verified', $username);
  137. if (createUser($username, $password, $defaults, $email)) {
  138. writeLog('success', 'Registration Function - A User has registered', $username);
  139. if (createToken($username, $email, gravatar($email), $defaults['group'], $defaults['group_id'], $GLOBALS['organizrHash'], 1)) {
  140. writeLoginLog($username, 'success');
  141. writeLog('success', 'Login Function - A User has logged in', $username);
  142. return true;
  143. }
  144. } else {
  145. writeLog('error', 'Registration Function - An error occured', $username);
  146. return 'username taken';
  147. }
  148. } else {
  149. writeLog('warning', 'Registration Function - Wrong Password', $username);
  150. return 'mismatch';
  151. }
  152. }
  153. function removeFile($array)
  154. {
  155. $filePath = $array['data']['path'];
  156. $fileName = $array['data']['name'];
  157. if (file_exists($filePath)) {
  158. if (unlink($filePath)) {
  159. writeLog('success', 'Log Management Function - Log: ' . $fileName . ' has been purged/deleted', 'SYSTEM');
  160. return true;
  161. } else {
  162. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' - Error Occured', 'SYSTEM');
  163. return false;
  164. }
  165. } else {
  166. writeLog('error', 'Log Management Function - Log: ' . $fileName . ' does not exist', 'SYSTEM');
  167. return false;
  168. }
  169. }
  170. function recover($array)
  171. {
  172. $email = $array['data']['email'];
  173. $newPassword = randString(10);
  174. try {
  175. $connect = new Dibi\Connection([
  176. 'driver' => 'sqlite3',
  177. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  178. ]);
  179. $isUser = $connect->fetch('SELECT * FROM users WHERE email = ? COLLATE NOCASE', $email);
  180. if ($isUser) {
  181. $connect->query('
  182. UPDATE users SET', [
  183. 'password' => password_hash($newPassword, PASSWORD_BCRYPT)
  184. ], '
  185. WHERE email=? COLLATE NOCASE', $email);
  186. if ($GLOBALS['PHPMAILER-enabled']) {
  187. $emailTemplate = array(
  188. 'type' => 'reset',
  189. 'body' => $GLOBALS['PHPMAILER-emailTemplateResetPassword'],
  190. 'subject' => $GLOBALS['PHPMAILER-emailTemplateResetPasswordSubject'],
  191. 'user' => $isUser['username'],
  192. 'password' => $newPassword,
  193. 'inviteCode' => null,
  194. );
  195. $emailTemplate = phpmEmailTemplate($emailTemplate);
  196. $sendEmail = array(
  197. 'to' => $email,
  198. 'user' => $isUser['username'],
  199. 'subject' => $emailTemplate['subject'],
  200. 'body' => phpmBuildEmail($emailTemplate),
  201. );
  202. phpmSendEmail($sendEmail);
  203. }
  204. writeLog('success', 'User Management Function - User: ' . $isUser['username'] . '\'s password was reset', $isUser['username']);
  205. return true;
  206. } else {
  207. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  208. return 'an error occured';
  209. }
  210. } catch (Dibi\Exception $e) {
  211. writeLog('error', 'User Management Function - Error - User: ' . $email . ' An error Occured', $email);
  212. return 'an error occured';
  213. }
  214. }
  215. function unlock($array)
  216. {
  217. if ($array['data']['password'] == '') {
  218. return 'Password Not Set';
  219. }
  220. try {
  221. $connect = new Dibi\Connection([
  222. 'driver' => 'sqlite3',
  223. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  224. ]);
  225. $result = $connect->fetch('SELECT * FROM users WHERE id = ?', $GLOBALS['organizrUser']['userID']);
  226. if (!password_verify($array['data']['password'], $result['password'])) {
  227. return 'Password Incorrect';
  228. }
  229. $connect->query('
  230. UPDATE users SET', [
  231. 'locked' => ''
  232. ], '
  233. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  234. writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
  235. return true;
  236. } catch (Dibi\Exception $e) {
  237. writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  238. return 'an error occured';
  239. }
  240. }
  241. function lock()
  242. {
  243. if ($GLOBALS['organizrUser']['userID'] == '999') {
  244. return 'Not Allowed on Guest';
  245. }
  246. try {
  247. $connect = new Dibi\Connection([
  248. 'driver' => 'sqlite3',
  249. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  250. ]);
  251. $connect->query('
  252. UPDATE users SET', [
  253. 'locked' => '1'
  254. ], '
  255. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  256. writeLog('success', 'User Lockout Function - User: ' . $GLOBALS['organizrUser']['username'] . '\'s account unlocked', $GLOBALS['organizrUser']['username']);
  257. return true;
  258. } catch (Dibi\Exception $e) {
  259. writeLog('error', 'User Management Function - Error - User: ' . $GLOBALS['organizrUser']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  260. return 'an error occured';
  261. }
  262. }
  263. function editUser($array)
  264. {
  265. if ($array['data']['username'] == '' && $array['data']['username'] == '') {
  266. return 'Username/email not set';
  267. }
  268. try {
  269. $connect = new Dibi\Connection([
  270. 'driver' => 'sqlite3',
  271. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  272. ]);
  273. if (!usernameTakenExcept($array['data']['username'], $array['data']['email'], $GLOBALS['organizrUser']['userID'])) {
  274. $connect->query('
  275. UPDATE users SET', [
  276. 'username' => $array['data']['username'],
  277. 'email' => $array['data']['email'],
  278. ], '
  279. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  280. if (!empty($array['data']['password'])) {
  281. $connect->query('
  282. UPDATE users SET', [
  283. 'password' => password_hash($array['data']['password'], PASSWORD_BCRYPT)
  284. ], '
  285. WHERE id=?', $GLOBALS['organizrUser']['userID']);
  286. }
  287. writeLog('success', 'User Management Function - User: ' . $array['data']['username'] . '\'s info was changed', $GLOBALS['organizrUser']['username']);
  288. return true;
  289. } else {
  290. return 'Username/Email Already Taken';
  291. }
  292. } catch (Dibi\Exception $e) {
  293. writeLog('error', 'User Management Function - Error - User: ' . $array['data']['username'] . ' An error Occured', $GLOBALS['organizrUser']['username']);
  294. return 'an error occured';
  295. }
  296. }
  297. function logout()
  298. {
  299. coookie('delete', $GLOBALS['cookieName']);
  300. coookie('delete', 'mpt');
  301. coookie('delete', 'Auth');
  302. $GLOBALS['organizrUser'] = false;
  303. return true;
  304. }
  305. function qualifyRequest($accessLevelNeeded)
  306. {
  307. if (getUserLevel() <= $accessLevelNeeded) {
  308. return true;
  309. } else {
  310. return false;
  311. }
  312. }
  313. function getUserLevel()
  314. {
  315. // Grab token
  316. //$requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : false;
  317. $requesterToken = isset(getallheaders()['Token']) ? getallheaders()['Token'] : (isset($_GET['apikey']) ? $_GET['apikey'] : false);
  318. // Check token or API key
  319. // If API key, return 0 for admin
  320. if (strlen($requesterToken) == 20 && $requesterToken == $GLOBALS['organizrAPI']) {
  321. //DO API CHECK
  322. return 0;
  323. } elseif (isset($GLOBALS['organizrUser'])) {
  324. return $GLOBALS['organizrUser']['groupID'];
  325. }
  326. // All else fails? return guest id
  327. return 999;
  328. }
  329. function organizrStatus()
  330. {
  331. $status = array();
  332. $dependenciesActive = array();
  333. $dependenciesInactive = array();
  334. $extensions = array("PDO_SQLITE", "PDO", "SQLITE3", "zip", "cURL", "openssl", "simplexml", "json", "session");
  335. $functions = array("hash", "fopen", "fsockopen", "fwrite", "fclose", "readfile");
  336. foreach ($extensions as $check) {
  337. if (extension_loaded($check)) {
  338. array_push($dependenciesActive, $check);
  339. } else {
  340. array_push($dependenciesInactive, $check);
  341. }
  342. }
  343. foreach ($functions as $check) {
  344. if (function_exists($check)) {
  345. array_push($dependenciesActive, $check);
  346. } else {
  347. array_push($dependenciesInactive, $check);
  348. }
  349. }
  350. if (!file_exists('config' . DIRECTORY_SEPARATOR . 'config.php')) {
  351. $status['status'] = "wizard";//wizard - ok for test
  352. }
  353. if (count($dependenciesInactive) > 0 || !is_writable(dirname(__DIR__, 2)) || !(version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0)) {
  354. $status['status'] = "dependencies";
  355. }
  356. $status['status'] = (!empty($status['status'])) ? $status['status'] : $status['status'] = "ok";
  357. $status['writable'] = is_writable(dirname(__DIR__, 2)) ? 'yes' : 'no';
  358. $status['minVersion'] = (version_compare(PHP_VERSION, $GLOBALS['minimumPHP']) >= 0) ? 'yes' : 'no';
  359. $status['dependenciesActive'] = $dependenciesActive;
  360. $status['dependenciesInactive'] = $dependenciesInactive;
  361. $status['version'] = $GLOBALS['installedVersion'];
  362. $status['os'] = getOS();
  363. $status['php'] = phpversion();
  364. return $status;
  365. }
  366. function getSettingsMain()
  367. {
  368. return array(
  369. 'Github' => array(
  370. array(
  371. 'type' => 'select',
  372. 'name' => 'branch',
  373. 'label' => 'Branch',
  374. 'value' => $GLOBALS['branch'],
  375. 'options' => getBranches()
  376. ),
  377. array(
  378. 'type' => 'button',
  379. 'label' => 'Force Install Branch',
  380. 'class' => 'updateNow',
  381. 'icon' => 'fa fa-download',
  382. 'text' => 'Retrieve'
  383. )
  384. ),
  385. 'API' => array(
  386. array(
  387. 'type' => 'password-alt',
  388. 'name' => 'organizrAPI',
  389. 'label' => 'Organizr API',
  390. 'value' => $GLOBALS['organizrAPI']
  391. ),
  392. array(
  393. 'type' => 'button',
  394. 'label' => 'Generate New API Key',
  395. 'class' => 'newAPIKey',
  396. 'icon' => 'fa fa-refresh',
  397. 'text' => 'Generate'
  398. )
  399. ),
  400. 'Authentication' => array(
  401. array(
  402. 'type' => 'select',
  403. 'name' => 'authType',
  404. 'id' => 'authSelect',
  405. 'label' => 'Authentication Type',
  406. 'value' => $GLOBALS['authType'],
  407. 'options' => getAuthTypes()
  408. ),
  409. array(
  410. 'type' => 'select',
  411. 'name' => 'authBackend',
  412. 'id' => 'authBackendSelect',
  413. 'label' => 'Authentication Backend',
  414. 'class' => 'backendAuth switchAuth',
  415. 'value' => $GLOBALS['authBackend'],
  416. 'options' => getAuthBackends()
  417. ),
  418. array(
  419. 'type' => 'password-alt',
  420. 'name' => 'plexToken',
  421. 'class' => 'plexAuth switchAuth',
  422. 'label' => 'Plex Token',
  423. 'value' => $GLOBALS['plexToken'],
  424. 'placeholder' => 'Use Get Token Button'
  425. ),
  426. array(
  427. 'type' => 'button',
  428. 'label' => 'Get Plex Token',
  429. 'class' => 'popup-with-form getPlexTokenAuth plexAuth switchAuth',
  430. 'icon' => 'fa fa-ticket',
  431. 'text' => 'Retrieve',
  432. 'href' => '#auth-plex-token-form',
  433. 'attr' => 'data-effect="mfp-3d-unfold"'
  434. ),
  435. array(
  436. 'type' => 'password-alt',
  437. 'name' => 'plexID',
  438. 'class' => 'plexAuth switchAuth',
  439. 'label' => 'Plex Machine',
  440. 'value' => $GLOBALS['plexID'],
  441. 'placeholder' => 'Use Get Plex Machine Button'
  442. ),
  443. array(
  444. 'type' => 'button',
  445. 'label' => 'Get Plex Machine',
  446. 'class' => 'popup-with-form getPlexMachineAuth plexAuth switchAuth',
  447. 'icon' => 'fa fa-id-badge',
  448. 'text' => 'Retrieve',
  449. 'href' => '#auth-plex-machine-form',
  450. 'attr' => 'data-effect="mfp-3d-unfold"'
  451. ),
  452. array(
  453. 'type' => 'input',
  454. 'name' => 'authBackendHost',
  455. 'class' => 'ldapAuth ftpAuth switchAuth',
  456. 'label' => 'Host Address',
  457. 'value' => $GLOBALS['authBackendHost'],
  458. 'placeholder' => 'http{s) | ftp(s) | ldap(s)://hostname:port'
  459. ),
  460. array(
  461. 'type' => 'input',
  462. 'name' => 'authBaseDN',
  463. 'class' => 'ldapAuth switchAuth',
  464. 'label' => 'Host Base DN',
  465. 'value' => $GLOBALS['authBaseDN'],
  466. 'placeholder' => 'cn=%s,dc=sub,dc=domain,dc=com'
  467. ),
  468. array(
  469. 'type' => 'input',
  470. 'name' => 'embyURL',
  471. 'class' => 'embyAuth switchAuth',
  472. 'label' => 'Emby URL',
  473. 'value' => $GLOBALS['embyURL'],
  474. 'placeholder' => 'http(s)://hostname:port'
  475. ),
  476. array(
  477. 'type' => 'password-alt',
  478. 'name' => 'embyToken',
  479. 'class' => 'embyAuth switchAuth',
  480. 'label' => 'Emby Token',
  481. 'value' => $GLOBALS['embyToken'],
  482. 'placeholder' => ''
  483. ),
  484. /*array(
  485. 'type' => 'button',
  486. 'label' => 'Send Test',
  487. 'class' => 'phpmSendTestEmail',
  488. 'icon' => 'fa fa-paper-plane',
  489. 'text' => 'Send'
  490. )*/
  491. ),
  492. 'Security' => array(
  493. array(
  494. 'type' => 'number',
  495. 'name' => 'lockoutTimeout',
  496. 'label' => 'Inactivity Timer [Minutes]',
  497. 'value' => $GLOBALS['lockoutTimeout'],
  498. 'placeholder' => ''
  499. ),
  500. array(
  501. 'type' => 'switch',
  502. 'name' => 'lockoutSystem',
  503. 'label' => 'Inactivity Lock',
  504. 'value' => $GLOBALS['lockoutSystem']
  505. ),
  506. array(
  507. 'type' => 'select',
  508. 'name' => 'lockoutMinAuth',
  509. 'label' => 'Lockout Groups From',
  510. 'value' => $GLOBALS['lockoutMinAuth'],
  511. 'options' => groupSelect()
  512. ),
  513. array(
  514. 'type' => 'select',
  515. 'name' => 'lockoutMaxAuth',
  516. 'label' => 'Lockout Groups To',
  517. 'value' => $GLOBALS['lockoutMaxAuth'],
  518. 'options' => groupSelect()
  519. ),
  520. array(
  521. 'type' => 'password-alt',
  522. 'name' => 'registrationPassword',
  523. 'label' => 'Registration Password',
  524. 'value' => $GLOBALS['registrationPassword'],
  525. ),
  526. array(
  527. 'type' => 'switch',
  528. 'name' => 'hideRegistration',
  529. 'label' => 'Hide Registration',
  530. 'value' => $GLOBALS['hideRegistration']
  531. )
  532. ),
  533. 'Ping' => array(
  534. array(
  535. 'type' => 'select',
  536. 'name' => 'pingAuth',
  537. 'label' => 'Minimum Authentication',
  538. 'value' => $GLOBALS['pingAuth'],
  539. 'options' => groupSelect()
  540. ),
  541. array(
  542. 'type' => 'select',
  543. 'name' => 'pingAuthMessage',
  544. 'label' => 'Minimum Authentication for Message and Sound',
  545. 'value' => $GLOBALS['pingAuthMessage'],
  546. 'options' => groupSelect()
  547. ),
  548. array(
  549. 'type' => 'select',
  550. 'name' => 'pingOnlineSound',
  551. 'label' => 'Online Sound',
  552. 'value' => $GLOBALS['pingOnlineSound'],
  553. 'options' => getSounds()
  554. ),
  555. array(
  556. 'type' => 'select',
  557. 'name' => 'pingOfflineSound',
  558. 'label' => 'Offline Sound',
  559. 'value' => $GLOBALS['pingOfflineSound'],
  560. 'options' => getSounds()
  561. ),
  562. array(
  563. 'type' => 'switch',
  564. 'name' => 'pingMs',
  565. 'label' => 'Show Ping Time',
  566. 'value' => $GLOBALS['pingMs']
  567. ),
  568. array(
  569. 'type' => 'select',
  570. 'name' => 'pingAuthMs',
  571. 'label' => 'Minimum Authentication for Time Display',
  572. 'value' => $GLOBALS['pingAuthMs'],
  573. 'options' => groupSelect()
  574. ),
  575. array(
  576. 'type' => 'select',
  577. 'name' => 'adminPingRefresh',
  578. 'label' => 'Admin Refresh Seconds',
  579. 'value' => $GLOBALS['adminPingRefresh'],
  580. 'options' => optionTime()
  581. ),
  582. array(
  583. 'type' => 'select',
  584. 'name' => 'otherPingRefresh',
  585. 'label' => 'Everyone Refresh Seconds',
  586. 'value' => $GLOBALS['otherPingRefresh'],
  587. 'options' => optionTime()
  588. ),
  589. )
  590. );
  591. }
  592. function getSSO()
  593. {
  594. return array(
  595. 'FYI' => array(
  596. array(
  597. 'type' => 'html',
  598. 'label' => 'Important Information',
  599. 'override' => 12,
  600. 'html' => '
  601. <div class="row">
  602. <div class="col-lg-12">
  603. <div class="panel panel-info">
  604. <div class="panel-heading">
  605. <span lang="en">Notice</span>
  606. </div>
  607. <div class="panel-wrapper collapse in" aria-expanded="true">
  608. <div class="panel-body">
  609. <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>
  610. </div>
  611. </div>
  612. </div>
  613. </div>
  614. </div>
  615. '
  616. )
  617. ),
  618. 'Plex' => array(
  619. array(
  620. 'type' => 'password-alt',
  621. 'name' => 'plexToken',
  622. 'label' => 'Plex Token',
  623. 'value' => $GLOBALS['plexToken'],
  624. 'placeholder' => 'Use Get Token Button'
  625. ),
  626. array(
  627. 'type' => 'button',
  628. 'label' => 'Get Plex Token',
  629. 'class' => 'popup-with-form getPlexTokenSSO',
  630. 'icon' => 'fa fa-ticket',
  631. 'text' => 'Retrieve',
  632. 'href' => '#sso-plex-token-form',
  633. 'attr' => 'data-effect="mfp-3d-unfold"'
  634. ),
  635. array(
  636. 'type' => 'password-alt',
  637. 'name' => 'plexID',
  638. 'label' => 'Plex Machine',
  639. 'value' => $GLOBALS['plexID'],
  640. 'placeholder' => 'Use Get Plex Machine Button'
  641. ),
  642. array(
  643. 'type' => 'button',
  644. 'label' => 'Get Plex Machine',
  645. 'class' => 'popup-with-form getPlexMachineSSO',
  646. 'icon' => 'fa fa-id-badge',
  647. 'text' => 'Retrieve',
  648. 'href' => '#sso-plex-machine-form',
  649. 'attr' => 'data-effect="mfp-3d-unfold"'
  650. ),
  651. array(
  652. 'type' => 'input',
  653. 'name' => 'plexAdmin',
  654. 'label' => 'Admin Username',
  655. 'value' => $GLOBALS['plexAdmin'],
  656. 'placeholder' => 'Admin username for Plex'
  657. ),
  658. array(
  659. 'type' => 'blank',
  660. 'label' => ''
  661. ),
  662. array(
  663. 'type' => 'html',
  664. 'label' => 'Plex Note',
  665. 'html' => '<span lang="en">Please make sure both Token and Machine are filled in</span>'
  666. ),
  667. array(
  668. 'type' => 'switch',
  669. 'name' => 'ssoPlex',
  670. 'label' => 'Enable',
  671. 'value' => $GLOBALS['ssoPlex']
  672. )
  673. ),
  674. 'Ombi' => array(
  675. array(
  676. 'type' => 'input',
  677. 'name' => 'ombiURL',
  678. 'label' => 'Ombi URL',
  679. 'value' => $GLOBALS['ombiURL'],
  680. 'placeholder' => 'http(s)://hostname:port'
  681. ),
  682. array(
  683. 'type' => 'switch',
  684. 'name' => 'ssoOmbi',
  685. 'label' => 'Enable',
  686. 'value' => $GLOBALS['ssoOmbi']
  687. )
  688. ),
  689. 'Tautulli' => array(
  690. array(
  691. 'type' => 'input',
  692. 'name' => 'tautulliURL',
  693. 'label' => 'Tautulli URL',
  694. 'value' => $GLOBALS['tautulliURL'],
  695. 'placeholder' => 'http(s)://hostname:port'
  696. ),
  697. array(
  698. 'type' => 'switch',
  699. 'name' => 'ssoTautulli',
  700. 'label' => 'Enable',
  701. 'value' => $GLOBALS['ssoTautulli']
  702. )
  703. )
  704. );
  705. }
  706. function loadAppearance()
  707. {
  708. $appearance = array();
  709. $appearance['logo'] = $GLOBALS['logo'];
  710. $appearance['title'] = $GLOBALS['title'];
  711. $appearance['useLogo'] = $GLOBALS['useLogo'];
  712. $appearance['headerColor'] = $GLOBALS['headerColor'];
  713. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  714. $appearance['sidebarColor'] = $GLOBALS['sidebarColor'];
  715. $appearance['headerTextColor'] = $GLOBALS['headerTextColor'];
  716. $appearance['sidebarTextColor'] = $GLOBALS['sidebarTextColor'];
  717. $appearance['accentColor'] = $GLOBALS['accentColor'];
  718. $appearance['accentTextColor'] = $GLOBALS['accentTextColor'];
  719. $appearance['buttonColor'] = $GLOBALS['buttonColor'];
  720. $appearance['buttonTextColor'] = $GLOBALS['buttonTextColor'];
  721. $appearance['buttonTextHoverColor'] = $GLOBALS['buttonTextHoverColor'];
  722. $appearance['buttonHoverColor'] = $GLOBALS['buttonHoverColor'];
  723. $appearance['loginWallpaper'] = $GLOBALS['loginWallpaper'];
  724. $appearance['customCss'] = $GLOBALS['customCss'];
  725. return $appearance;
  726. }
  727. function getCustomizeAppearance()
  728. {
  729. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  730. return array(
  731. 'Top Bar' => array(
  732. array(
  733. 'type' => 'input',
  734. 'name' => 'logo',
  735. 'label' => 'Logo',
  736. 'value' => $GLOBALS['logo']
  737. ),
  738. array(
  739. 'type' => 'input',
  740. 'name' => 'title',
  741. 'label' => 'Title',
  742. 'value' => $GLOBALS['title']
  743. ),
  744. array(
  745. 'type' => 'switch',
  746. 'name' => 'useLogo',
  747. 'label' => 'Use Logo instead of Title',
  748. 'value' => $GLOBALS['useLogo']
  749. )
  750. ),
  751. 'Login Page' => array(
  752. array(
  753. 'type' => 'input',
  754. 'name' => 'loginWallpaper',
  755. 'label' => 'Login Wallpaper',
  756. 'value' => $GLOBALS['loginWallpaper']
  757. )
  758. ),
  759. 'Options' => array(
  760. array(
  761. 'type' => 'switch',
  762. 'name' => 'alternateHomepageHeaders',
  763. 'label' => 'Alternate Homepage Titles',
  764. 'value' => $GLOBALS['alternateHomepageHeaders']
  765. )
  766. ),
  767. 'Colors & Themes' => array(
  768. array(
  769. 'type' => 'html',
  770. 'override' => 12,
  771. 'label' => 'Custom CSS [Can replace colors from above]',
  772. 'html' => '
  773. <div class="row">
  774. <div class="col-lg-12">
  775. <div class="panel panel-info">
  776. <div class="panel-heading">
  777. <span lang="en">Notice</span>
  778. </div>
  779. <div class="panel-wrapper collapse in" aria-expanded="true">
  780. <div class="panel-body">
  781. <span lang="en">The value of #987654 is just a placeholder, you can change to any value you like.</span>
  782. </div>
  783. </div>
  784. </div>
  785. </div>
  786. </div>
  787. ',
  788. ),
  789. array(
  790. 'type' => 'blank',
  791. 'label' => ''
  792. ),
  793. array(
  794. 'type' => 'input',
  795. 'name' => 'headerColor',
  796. 'label' => 'Nav Bar Color',
  797. 'value' => $GLOBALS['headerColor'],
  798. 'class' => 'pick-a-color',
  799. 'attr' => 'data-original="' . $GLOBALS['headerColor'] . '"'
  800. ),
  801. array(
  802. 'type' => 'input',
  803. 'name' => 'headerTextColor',
  804. 'label' => 'Nav Bar Text Color',
  805. 'value' => $GLOBALS['headerTextColor'],
  806. 'class' => 'pick-a-color',
  807. 'attr' => 'data-original="' . $GLOBALS['headerTextColor'] . '"'
  808. ),
  809. array(
  810. 'type' => 'input',
  811. 'name' => 'sidebarColor',
  812. 'label' => 'Side Bar Color',
  813. 'value' => $GLOBALS['sidebarColor'],
  814. 'class' => 'pick-a-color',
  815. 'attr' => 'data-original="' . $GLOBALS['sidebarColor'] . '"'
  816. ),
  817. array(
  818. 'type' => 'input',
  819. 'name' => 'sidebarTextColor',
  820. 'label' => 'Side Bar Text Color',
  821. 'value' => $GLOBALS['sidebarTextColor'],
  822. 'class' => 'pick-a-color',
  823. 'attr' => 'data-original="' . $GLOBALS['sidebarTextColor'] . '"'
  824. ),
  825. array(
  826. 'type' => 'input',
  827. 'name' => 'accentColor',
  828. 'label' => 'Accent Color',
  829. 'value' => $GLOBALS['accentColor'],
  830. 'class' => 'pick-a-color',
  831. 'attr' => 'data-original="' . $GLOBALS['accentColor'] . '"'
  832. ),
  833. array(
  834. 'type' => 'input',
  835. 'name' => 'accentTextColor',
  836. 'label' => 'Accent Text Color',
  837. 'value' => $GLOBALS['accentTextColor'],
  838. 'class' => 'pick-a-color',
  839. 'attr' => 'data-original="' . $GLOBALS['accentTextColor'] . '"'
  840. ),
  841. array(
  842. 'type' => 'input',
  843. 'name' => 'buttonColor',
  844. 'label' => 'Button Color',
  845. 'value' => $GLOBALS['buttonColor'],
  846. 'class' => 'pick-a-color',
  847. 'attr' => 'data-original="' . $GLOBALS['buttonColor'] . '"'
  848. ),
  849. array(
  850. 'type' => 'input',
  851. 'name' => 'buttonTextColor',
  852. 'label' => 'Button Text Color',
  853. 'value' => $GLOBALS['buttonTextColor'],
  854. 'class' => 'pick-a-color',
  855. 'attr' => 'data-original="' . $GLOBALS['buttonTextColor'] . '"'
  856. ),/*
  857. array(
  858. 'type' => 'input',
  859. 'name' => 'buttonHoverColor',
  860. 'label' => 'Button Hover Color',
  861. 'value' => $GLOBALS['buttonHoverColor'],
  862. 'class' => 'pick-a-color',
  863. 'disabled' => true
  864. ),
  865. array(
  866. 'type' => 'input',
  867. 'name' => 'buttonTextHoverColor',
  868. 'label' => 'Button Hover Text Color',
  869. 'value' => $GLOBALS['buttonTextHoverColor'],
  870. 'class' => 'pick-a-color',
  871. 'disabled' => true
  872. ),*/
  873. array(
  874. 'type' => 'select',
  875. 'name' => 'theme',
  876. 'label' => 'Theme',
  877. 'class' => 'themeChanger',
  878. 'value' => $GLOBALS['theme'],
  879. 'options' => getThemes()
  880. ),
  881. array(
  882. 'type' => 'select',
  883. 'name' => 'style',
  884. 'label' => 'Style',
  885. 'class' => 'styleChanger',
  886. 'value' => $GLOBALS['style'],
  887. 'options' => array(
  888. array(
  889. 'name' => 'Light',
  890. 'value' => 'light'
  891. ),
  892. array(
  893. 'name' => 'Dark',
  894. 'value' => 'dark'
  895. ),
  896. array(
  897. 'name' => 'Horizontal',
  898. 'value' => 'horizontal'
  899. )
  900. )
  901. )
  902. ),
  903. 'Notifications' => array(
  904. array(
  905. 'type' => 'select',
  906. 'name' => 'notificationBackbone',
  907. 'class' => 'notifyChanger',
  908. 'label' => 'Type',
  909. 'value' => $GLOBALS['notificationBackbone'],
  910. 'options' => optionNotificationTypes()
  911. ),
  912. array(
  913. 'type' => 'select',
  914. 'name' => 'notificationPosition',
  915. 'class' => 'notifyPositionChanger',
  916. 'label' => 'Position',
  917. 'value' => $GLOBALS['notificationPosition'],
  918. 'options' => optionNotificationPositions()
  919. ),
  920. array(
  921. 'type' => 'html',
  922. 'label' => 'Test Message',
  923. 'html' => '
  924. <div class="btn-group m-r-10 dropup">
  925. <button aria-expanded="false" data-toggle="dropdown" class="btn btn-info btn-outline dropdown-toggle waves-effect waves-light" type="button">
  926. <i class="fa fa-comment m-r-5"></i>
  927. <span>Test </span>
  928. </button>
  929. <ul role="menu" class="dropdown-menu">
  930. <li><a onclick="message(\'Test Message\',\'This is a success Message\',activeInfo.settings.notifications.position,\'#FFF\',\'success\',\'5000\');">Success</a></li>
  931. <li><a onclick="message(\'Test Message\',\'This is a info Message\',activeInfo.settings.notifications.position,\'#FFF\',\'info\',\'5000\');">Info</a></li>
  932. <li><a onclick="message(\'Test Message\',\'This is a warning Message\',activeInfo.settings.notifications.position,\'#FFF\',\'warning\',\'5000\');">Warning</a></li>
  933. <li><a onclick="message(\'Test Message\',\'This is a error Message\',activeInfo.settings.notifications.position,\'#FFF\',\'error\',\'5000\');">Error</a></li>
  934. </ul>
  935. </div>
  936. '
  937. )
  938. ),
  939. 'FavIcon' => array(
  940. array(
  941. 'type' => 'textbox',
  942. 'name' => 'favIcon',
  943. 'class' => '',
  944. 'label' => 'Fav Icon Code',
  945. 'value' => $GLOBALS['favIcon'],
  946. 'placeholder' => 'Paste Contents from https://realfavicongenerator.net/',
  947. 'attr' => 'rows="10"',
  948. ),
  949. array(
  950. 'type' => 'html',
  951. 'label' => 'Instructions',
  952. 'html' => '
  953. <div class="panel panel-default">
  954. <div class="panel-heading">
  955. <a href="https://realfavicongenerator.net/" target="_blank"><span class="label label-info m-l-5">Visit FavIcon Site</span></a>
  956. </div>
  957. <div class="panel-wrapper collapse in">
  958. <div class="panel-body">
  959. <ul class="list-icons">
  960. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Select your Favicon picture"</li>
  961. <li lang="en"><i class="fa fa-caret-right text-info"></i> Choose your image to use</li>
  962. <li lang="en"><i class="fa fa-caret-right text-info"></i> Edit settings to your liking</li>
  963. <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>
  964. <li lang="en"><i class="fa fa-caret-right text-info"></i> Enter this path <code>plugins/images/faviconCustom</code></li>
  965. <li lang="en"><i class="fa fa-caret-right text-info"></i> Click "Generate your Favicons and HTML code"</li>
  966. <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>
  967. <li lang="en"><i class="fa fa-caret-right text-info"></i> Copy code and paste inside left box</li>
  968. </ul>
  969. </div>
  970. </div>
  971. </div>
  972. '
  973. ),
  974. ),
  975. 'Custom CSS' => array(
  976. array(
  977. 'type' => 'html',
  978. 'override' => 12,
  979. 'label' => 'Custom CSS [Can replace colors from above]',
  980. 'html' => '<button type="button" class="hidden saveCss btn btn-info btn-circle pull-right m-r-5 m-l-10"><i class="fa fa-save"></i> </button><div id="customCSSEditor" style="height:300px">' . $GLOBALS['customCss'] . '</div>'
  981. ),
  982. array(
  983. 'type' => 'textbox',
  984. 'name' => 'customCss',
  985. 'class' => 'hidden cssTextarea',
  986. 'label' => '',
  987. 'value' => $GLOBALS['customCss'],
  988. 'placeholder' => 'No <style> tags needed',
  989. 'attr' => 'rows="10"',
  990. ),
  991. )
  992. );
  993. }
  994. }
  995. function editAppearance($array)
  996. {
  997. switch ($array['data']['value']) {
  998. case 'true':
  999. $array['data']['value'] = (bool)true;
  1000. break;
  1001. case 'false':
  1002. $array['data']['value'] = (bool)false;
  1003. break;
  1004. default:
  1005. $array['data']['value'] = $array['data']['value'];
  1006. }
  1007. //return gettype($array['data']['value']).' - '.$array['data']['value'];
  1008. switch ($array['data']['action']) {
  1009. case 'editCustomizeAppearance':
  1010. $newItem = array(
  1011. $array['data']['name'] => $array['data']['value']
  1012. );
  1013. return (updateConfig($newItem)) ? true : false;
  1014. break;
  1015. default:
  1016. # code...
  1017. break;
  1018. }
  1019. }
  1020. function updateConfigMultiple($array)
  1021. {
  1022. return (updateConfig($array['data']['payload'])) ? true : false;
  1023. }
  1024. function updateConfigMultipleForm($array)
  1025. {
  1026. $newItem = array();
  1027. foreach ($array['data']['payload'] as $k => $v) {
  1028. switch ($v['value']) {
  1029. case 'true':
  1030. $v['value'] = (bool)true;
  1031. break;
  1032. case 'false':
  1033. $v['value'] = (bool)false;
  1034. break;
  1035. default:
  1036. $v['value'] = $v['value'];
  1037. }
  1038. // Hash
  1039. if ($v['type'] == 'password') {
  1040. if (strpos($v['value'], '==') !== false) {
  1041. $v['value'] = $v['value'];
  1042. } else {
  1043. $v['value'] = encrypt($v['value']);
  1044. }
  1045. }
  1046. $newItem[$v['name']] = $v['value'];
  1047. }
  1048. //return $newItem;
  1049. return (updateConfig($newItem)) ? true : false;
  1050. }
  1051. function updateConfigItem($array)
  1052. {
  1053. switch ($array['data']['value']) {
  1054. case 'true':
  1055. $array['data']['value'] = (bool)true;
  1056. break;
  1057. case 'false':
  1058. $array['data']['value'] = (bool)false;
  1059. break;
  1060. default:
  1061. $array['data']['value'] = $array['data']['value'];
  1062. }
  1063. // Hash
  1064. if ($array['data']['type'] == 'password') {
  1065. $array['data']['value'] = encrypt($array['data']['value']);
  1066. }
  1067. $newItem = array(
  1068. $array['data']['name'] => $array['data']['value']
  1069. );
  1070. return (updateConfig($newItem)) ? true : false;
  1071. }
  1072. function getPlugins()
  1073. {
  1074. if (file_exists(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php')) {
  1075. $pluginList = [];
  1076. foreach ($GLOBALS['plugins'] as $plugin) {
  1077. foreach ($plugin as $key => $value) {
  1078. if (strpos($value['license'], $GLOBALS['license']) !== false) {
  1079. $plugin[$key]['enabled'] = $GLOBALS[$value['configPrefix'] . '-enabled'];
  1080. $pluginList[$key] = $plugin[$key];
  1081. }
  1082. }
  1083. }
  1084. return $pluginList;
  1085. }
  1086. return false;
  1087. }
  1088. function editPlugins($array)
  1089. {
  1090. switch ($array['data']['action']) {
  1091. case 'enable':
  1092. $newItem = array(
  1093. $array['data']['configName'] => true
  1094. );
  1095. writeLog('success', 'Plugin Function - Enabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  1096. return (updateConfig($newItem)) ? true : false;
  1097. break;
  1098. case 'disable':
  1099. $newItem = array(
  1100. $array['data']['configName'] => false
  1101. );
  1102. writeLog('success', 'Plugin Function - Disabled Plugin [' . $_POST['data']['name'] . ']', $GLOBALS['organizrUser']['username']);
  1103. return (updateConfig($newItem)) ? true : false;
  1104. break;
  1105. default:
  1106. # code...
  1107. break;
  1108. }
  1109. }
  1110. function auth()
  1111. {
  1112. $debug = false; // CAREFUL WHEN SETTING TO TRUE AS THIS OPENS AUTH UP
  1113. $ban = isset($_GET['ban']) ? strtoupper($_GET['ban']) : "";
  1114. $whitelist = isset($_GET['whitelist']) ? $_GET['whitelist'] : false;
  1115. $blacklist = isset($_GET['blacklist']) ? $_GET['blacklist'] : false;
  1116. $group = isset($_GET['group']) ? (int)$_GET['group'] : (int)0;
  1117. $currentIP = userIP();
  1118. $unlocked = ($GLOBALS['organizrUser']['locked'] == '1') ? false : true;
  1119. if (isset($GLOBALS['organizrUser'])) {
  1120. $currentUser = $GLOBALS['organizrUser']['username'];
  1121. $currentGroup = $GLOBALS['organizrUser']['groupID'];
  1122. } else {
  1123. $currentUser = 'Guest';
  1124. $currentGroup = getUserLevel();
  1125. }
  1126. $userInfo = "User: $currentUser | Group: $currentGroup | IP: $currentIP | Requesting Access to Group $group | Result: ";
  1127. if ($whitelist) {
  1128. if (in_array($currentIP, arrayIP($whitelist))) {
  1129. !$debug ? exit(http_response_code(200)) : die("$userInfo Whitelist Authorized");
  1130. }
  1131. }
  1132. if ($blacklist) {
  1133. if (in_array($currentIP, arrayIP($blacklist))) {
  1134. !$debug ? exit(http_response_code(401)) : die("$userInfo Blacklisted");
  1135. }
  1136. }
  1137. if ($group !== null) {
  1138. if (qualifyRequest($group) && $unlocked) {
  1139. !$debug ? exit(http_response_code(200)) : die("$userInfo Authorized");
  1140. } else {
  1141. !$debug ? exit(http_response_code(401)) : die("$userInfo Not Authorized");
  1142. }
  1143. } else {
  1144. !$debug ? exit(http_response_code(401)) : die("Not Authorized Due To No Parameters Set");
  1145. }
  1146. }
  1147. function logoOrText()
  1148. {
  1149. if ($GLOBALS['useLogo'] == false) {
  1150. return '<h1>' . $GLOBALS['title'] . '</h1>';
  1151. } else {
  1152. return '<img class="loginLogo" src="' . $GLOBALS['logo'] . '" alt="Home" />';
  1153. }
  1154. }
  1155. function showLogin()
  1156. {
  1157. if ($GLOBALS['hideRegistration'] == false) {
  1158. 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>';
  1159. }
  1160. }
  1161. function getImages()
  1162. {
  1163. $dirname = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1164. $path = 'plugins/images/tabs/';
  1165. $images = scandir($dirname);
  1166. $ignore = array(".", "..", "._.DS_Store", ".DS_Store", ".pydio_id");
  1167. $allIcons = array();
  1168. foreach ($images as $image) {
  1169. if (!in_array($image, $ignore)) {
  1170. $allIcons[] = $path . $image;
  1171. }
  1172. }
  1173. return $allIcons;
  1174. }
  1175. function imageSelect($form)
  1176. {
  1177. $i = 1;
  1178. $images = getImages();
  1179. $return = '<select class="form-control tabIconImageList" id="' . $form . '-chooseImage" name="chooseImage"><option lang="en">Select or type Icon</option>';
  1180. foreach ($images as $image) {
  1181. $i++;
  1182. $return .= '<option value="' . $image . '">' . basename($image) . '</option>';
  1183. }
  1184. return $return . '</select>';
  1185. }
  1186. function editImages()
  1187. {
  1188. $array = array();
  1189. $postCheck = array_filter($_POST);
  1190. $filesCheck = array_filter($_FILES);
  1191. if (!empty($postCheck)) {
  1192. if ($_POST['data']['action'] == 'deleteImage') {
  1193. if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) {
  1194. writeLog('success', 'Image Manager Function - Deleted Image [' . $_POST['data']['imageName'] . ']', $GLOBALS['organizrUser']['username']);
  1195. return (unlink(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . $_POST['data']['imagePath'])) ? true : false;
  1196. }
  1197. }
  1198. }
  1199. if (!empty($filesCheck)) {
  1200. ini_set('upload_max_filesize', '10M');
  1201. ini_set('post_max_size', '10M');
  1202. $tempFile = $_FILES['file']['tmp_name'];
  1203. $targetPath = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'tabs' . DIRECTORY_SEPARATOR;
  1204. $targetFile = $targetPath . $_FILES['file']['name'];
  1205. return (move_uploaded_file($tempFile, $targetFile)) ? true : false;
  1206. }
  1207. return false;
  1208. }
  1209. function getThemes()
  1210. {
  1211. $themes = array();
  1212. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . "*.css") as $filename) {
  1213. $themes[] = array(
  1214. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1215. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename))
  1216. );
  1217. }
  1218. return $themes;
  1219. }
  1220. function getSounds()
  1221. {
  1222. $sounds = array();
  1223. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1224. $sounds[] = array(
  1225. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1226. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/default/' . basename($filename) . '.mp3')
  1227. );
  1228. }
  1229. foreach (glob(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sounds' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.mp3") as $filename) {
  1230. $sounds[] = array(
  1231. 'name' => preg_replace('/\\.[^.\\s]{3,4}$/', '', basename($filename)),
  1232. 'value' => preg_replace('/\\.[^.\\s]{3,4}$/', '', 'plugins/sounds/custom/' . basename($filename) . '.mp3')
  1233. );
  1234. }
  1235. return $sounds;
  1236. }
  1237. function getBranches()
  1238. {
  1239. return array(
  1240. array(
  1241. 'name' => 'Develop',
  1242. 'value' => 'v2-develop'
  1243. ),
  1244. array(
  1245. 'name' => 'Master',
  1246. 'value' => 'v2-master'
  1247. )
  1248. );
  1249. }
  1250. function getAuthTypes()
  1251. {
  1252. return array(
  1253. array(
  1254. 'name' => 'Organizr DB',
  1255. 'value' => 'internal'
  1256. ),
  1257. array(
  1258. 'name' => 'Organizr DB + Backend',
  1259. 'value' => 'both'
  1260. ),
  1261. array(
  1262. 'name' => 'Backend Only',
  1263. 'value' => 'external'
  1264. )
  1265. );
  1266. }
  1267. function getAuthBackends()
  1268. {
  1269. $backendOptions = array();
  1270. $backendOptions[] = array(
  1271. 'name' => 'Choose Backend',
  1272. 'value' => false,
  1273. 'disabled' => true
  1274. );
  1275. foreach (array_filter(get_defined_functions()['user'], function ($v) {
  1276. return strpos($v, 'plugin_auth_') === 0;
  1277. }) as $value) {
  1278. $name = str_replace('plugin_auth_', '', $value);
  1279. if (strpos($name, 'disabled') === false) {
  1280. $backendOptions[] = array(
  1281. 'name' => ucwords(str_replace('_', ' ', $name)),
  1282. 'value' => $name
  1283. );
  1284. } else {
  1285. $backendOptions[] = array(
  1286. 'name' => $value(),
  1287. 'value' => 'none',
  1288. 'disabled' => true,
  1289. );
  1290. }
  1291. }
  1292. ksort($backendOptions);
  1293. return $backendOptions;
  1294. }
  1295. function wizardPath($array)
  1296. {
  1297. $path = $array['data']['path'];
  1298. if (file_exists($path)) {
  1299. if (is_writable($path)) {
  1300. return true;
  1301. }
  1302. } else {
  1303. if (is_writable(dirname($path, 1))) {
  1304. if (mkdir($path, 0760, true)) {
  1305. return true;
  1306. }
  1307. }
  1308. }
  1309. return 'permissions';
  1310. }
  1311. function groupSelect()
  1312. {
  1313. $groups = allGroups();
  1314. $select = array();
  1315. foreach ($groups as $key => $value) {
  1316. $select[] = array(
  1317. 'name' => $value['group'],
  1318. 'value' => $value['group_id']
  1319. );
  1320. }
  1321. return $select;
  1322. }
  1323. function getImage()
  1324. {
  1325. $refresh = false;
  1326. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1327. if (!file_exists($cacheDirectory)) {
  1328. mkdir($cacheDirectory, 0777, true);
  1329. }
  1330. @$image_url = $_GET['img'];
  1331. @$key = $_GET['key'];
  1332. @$image_height = $_GET['height'];
  1333. @$image_width = $_GET['width'];
  1334. @$source = $_GET['source'];
  1335. @$itemType = $_GET['type'];
  1336. if (strpos($key, '$') !== false) {
  1337. $key = explode('$', $key)[0];
  1338. $refresh = true;
  1339. }
  1340. switch ($source) {
  1341. case 'plex':
  1342. $plexAddress = qualifyURL($GLOBALS['plexURL']);
  1343. $image_src = $plexAddress . '/photo/:/transcode?height=' . $image_height . '&width=' . $image_width . '&upscale=1&url=' . $image_url . '&X-Plex-Token=' . $GLOBALS['plexToken'];
  1344. break;
  1345. case 'emby':
  1346. $embyAddress = qualifyURL($GLOBALS['embyURL']);
  1347. $imgParams = array();
  1348. if (isset($_GET['height'])) {
  1349. $imgParams['height'] = 'maxHeight=' . $_GET['height'];
  1350. }
  1351. if (isset($_GET['width'])) {
  1352. $imgParams['width'] = 'maxWidth=' . $_GET['width'];
  1353. }
  1354. $image_src = $embyAddress . '/Items/' . $image_url . '/Images/' . $itemType . '?' . implode('&', $imgParams);
  1355. break;
  1356. default:
  1357. # code...
  1358. break;
  1359. }
  1360. if (isset($image_url) && isset($image_height) && isset($image_width) && isset($image_src)) {
  1361. $cachefile = $cacheDirectory . $key . '.jpg';
  1362. $cachetime = 604800;
  1363. // Serve from the cache if it is younger than $cachetime
  1364. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && $refresh == false) {
  1365. header("Content-type: image/jpeg");
  1366. //@readfile($cachefile);
  1367. echo @curl('get', $cachefile)['content'];
  1368. exit;
  1369. }
  1370. ob_start(); // Start the output buffer
  1371. header('Content-type: image/jpeg');
  1372. //@readfile($image_src);
  1373. echo @curl('get', $image_src)['content'];
  1374. // Cache the output to a file
  1375. $fp = fopen($cachefile, 'wb');
  1376. fwrite($fp, ob_get_contents());
  1377. fclose($fp);
  1378. ob_end_flush(); // Send the output to the browser
  1379. die();
  1380. } else {
  1381. die("Invalid Request");
  1382. }
  1383. }
  1384. function cacheImage($url, $name)
  1385. {
  1386. $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  1387. if (!file_exists($cacheDirectory)) {
  1388. mkdir($cacheDirectory, 0777, true);
  1389. }
  1390. $cachefile = $cacheDirectory . $name . '.jpg';
  1391. copy($url, $cachefile);
  1392. }
  1393. function downloader($array)
  1394. {
  1395. switch ($array['data']['source']) {
  1396. case 'sabnzbd':
  1397. switch ($array['data']['action']) {
  1398. case 'resume':
  1399. case 'pause':
  1400. sabnzbdAction($array['data']['action'], $array['data']['target']);
  1401. break;
  1402. default:
  1403. # code...
  1404. break;
  1405. }
  1406. break;
  1407. case 'nzbget':
  1408. break;
  1409. default:
  1410. # code...
  1411. break;
  1412. }
  1413. }
  1414. function sabnzbdAction($action = null, $target = null)
  1415. {
  1416. if ($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])) {
  1417. $url = qualifyURL($GLOBALS['sabnzbdURL']);
  1418. switch ($action) {
  1419. case 'pause':
  1420. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=pause&value=' . $target . '&' : 'mode=pause';
  1421. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1422. break;
  1423. case 'resume':
  1424. $id = ($target !== '' && $target !== 'main' && isset($target)) ? 'mode=queue&name=resume&value=' . $target . '&' : 'mode=resume';
  1425. $url = $url . '/api?' . $id . '&output=json&apikey=' . $GLOBALS['sabnzbdToken'];
  1426. break;
  1427. default:
  1428. # code...
  1429. break;
  1430. }
  1431. try {
  1432. $options = (localURL($url)) ? array('verify' => false) : array();
  1433. $response = Requests::get($url, array(), $options);
  1434. if ($response->success) {
  1435. $api['content'] = json_decode($response->body, true);
  1436. }
  1437. } catch (Requests_Exception $e) {
  1438. writeLog('error', 'SabNZBd Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1439. };
  1440. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1441. return $api;
  1442. }
  1443. }
  1444. // Deluge API isn't working ATM - will get with dev.
  1445. function delugeAction($action = null, $target = null)
  1446. {
  1447. if ($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && !empty($GLOBALS['delugePassword']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])) {
  1448. $url = qualifyURL($GLOBALS['delugeURL']);
  1449. try {
  1450. $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
  1451. switch ($action) {
  1452. case 'pause':
  1453. $torrents = $deluge->pauseTorrent($target);
  1454. break;
  1455. case 'pauseAll':
  1456. $torrents = $deluge->pauseAllTorrents();
  1457. break;
  1458. case 'resume':
  1459. $torrents = $deluge->resumeTorrent($target);
  1460. break;
  1461. case 'resumeAll':
  1462. $torrents = $deluge->resumeAllTorrents();
  1463. break;
  1464. default:
  1465. # code...
  1466. break;
  1467. }
  1468. $api['content'] = $torrents;
  1469. } catch (Excecption $e) {
  1470. writeLog('error', 'Deluge Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1471. }
  1472. $api['content'] = isset($api['content']) ? $api['content'] : false;
  1473. return $api;
  1474. }
  1475. return false;
  1476. }
  1477. function getOrgUsers()
  1478. {
  1479. $result = allUsers();
  1480. if (is_array($result) || is_object($result)) {
  1481. foreach ($result['users'] as $k => $v) {
  1482. $return[$v['username']] = $v['email'];
  1483. }
  1484. return $return;
  1485. }
  1486. }
  1487. function convertPlexName($user, $type)
  1488. {
  1489. $array = userList('plex');
  1490. switch ($type) {
  1491. case "username":
  1492. case "u":
  1493. $plexUser = array_search($user, $array['users']);
  1494. break;
  1495. case "id":
  1496. if (array_key_exists(strtolower($user), $array['users'])) {
  1497. $plexUser = $array['users'][strtolower($user)];
  1498. }
  1499. break;
  1500. default:
  1501. $plexUser = false;
  1502. }
  1503. return (!empty($plexUser) ? $plexUser : null);
  1504. }
  1505. function userList($type = null)
  1506. {
  1507. switch ($type) {
  1508. case 'plex':
  1509. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1510. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'] . '/shared_servers';
  1511. try {
  1512. $headers = array(
  1513. "Accept" => "application/json",
  1514. "X-Plex-Token" => $GLOBALS['plexToken']
  1515. );
  1516. $response = Requests::get($url, $headers, array());
  1517. libxml_use_internal_errors(true);
  1518. if ($response->success) {
  1519. $libraryList = array();
  1520. $plex = simplexml_load_string($response->body);
  1521. foreach ($plex->SharedServer as $child) {
  1522. if (!empty($child['username'])) {
  1523. $username = (string)strtolower($child['username']);
  1524. $email = (string)strtolower($child['email']);
  1525. $libraryList['users'][$username] = (string)$child['id'];
  1526. $libraryList['emails'][$email] = (string)$child['id'];
  1527. $libraryList['both'][$username] = $email;
  1528. }
  1529. }
  1530. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1531. return $libraryList;
  1532. }
  1533. } catch (Requests_Exception $e) {
  1534. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1535. };
  1536. }
  1537. break;
  1538. default:
  1539. # code...
  1540. break;
  1541. }
  1542. return false;
  1543. }
  1544. function libraryList($type = null)
  1545. {
  1546. switch ($type) {
  1547. case 'plex':
  1548. if (!empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'])) {
  1549. $url = 'https://plex.tv/api/servers/' . $GLOBALS['plexID'];
  1550. try {
  1551. $headers = array(
  1552. "Accept" => "application/json",
  1553. "X-Plex-Token" => $GLOBALS['plexToken']
  1554. );
  1555. $response = Requests::get($url, $headers, array());
  1556. libxml_use_internal_errors(true);
  1557. if ($response->success) {
  1558. $libraryList = array();
  1559. $plex = simplexml_load_string($response->body);
  1560. foreach ($plex->Server->Section as $child) {
  1561. $libraryList['libraries'][(string)$child['title']] = (string)$child['id'];
  1562. }
  1563. $libraryList = array_change_key_case($libraryList, CASE_LOWER);
  1564. return $libraryList;
  1565. }
  1566. } catch (Requests_Exception $e) {
  1567. writeLog('error', 'Plex Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1568. };
  1569. }
  1570. break;
  1571. default:
  1572. # code...
  1573. break;
  1574. }
  1575. return false;
  1576. }
  1577. function plexJoinAPI($array)
  1578. {
  1579. return plexJoin($array['data']['username'], $array['data']['email'], $array['data']['password']);
  1580. }
  1581. function plexJoin($username, $email, $password)
  1582. {
  1583. try {
  1584. $url = 'https://plex.tv/users.json';
  1585. $headers = array(
  1586. 'Accept' => 'application/json',
  1587. 'Content-Type' => 'application/x-www-form-urlencoded',
  1588. 'X-Plex-Product' => 'Organizr',
  1589. 'X-Plex-Version' => '2.0',
  1590. 'X-Plex-Client-Identifier' => '01010101-10101010',
  1591. );
  1592. $data = array(
  1593. 'user[email]' => $email,
  1594. 'user[username]' => $username,
  1595. 'user[password]' => $password,
  1596. );
  1597. $response = Requests::post($url, $headers, $data, array());
  1598. $json = json_decode($response->body, true);
  1599. $errors = (!empty($json['errors']) ? true : false);
  1600. $success = (!empty($json['user']) ? true : false);
  1601. //Use This for later
  1602. $usernameError = (!empty($json['errors']['username']) ? $json['errors']['username'][0] : false);
  1603. $emailError = (!empty($json['errors']['email']) ? $json['errors']['email'][0] : false);
  1604. $passwordError = (!empty($json['errors']['password']) ? $json['errors']['password'][0] : false);
  1605. $errorMessage = "";
  1606. if ($errors) {
  1607. if ($usernameError) {
  1608. $errorMessage .= "[Username Error: " . $usernameError . "]";
  1609. }
  1610. if ($emailError) {
  1611. $errorMessage .= "[Email Error: " . $emailError . "]";
  1612. }
  1613. if ($passwordError) {
  1614. $errorMessage .= "[Password Error: " . $passwordError . "]";
  1615. }
  1616. }
  1617. return (!empty($success) && empty($errors) ? true : $errorMessage);
  1618. } catch (Requests_Exception $e) {
  1619. writeLog('error', 'Plex.TV Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
  1620. };
  1621. return false;
  1622. }
  1623. function checkFrame($array, $url)
  1624. {
  1625. if (array_key_exists("x-frame-options", $array)) {
  1626. if ($array['x-frame-options'] == "deny") {
  1627. return false;
  1628. } elseif ($array['x-frame-options'] == "sameorgin") {
  1629. $digest = parse_url($url);
  1630. $host = (isset($digest['host']) ? $digest['host'] : '');
  1631. if (getServer() == $host) {
  1632. return true;
  1633. } else {
  1634. return false;
  1635. }
  1636. }
  1637. } else {
  1638. if (!$array) {
  1639. return false;
  1640. }
  1641. return true;
  1642. }
  1643. }
  1644. function frameTest($url)
  1645. {
  1646. $array = array_change_key_case(get_headers(qualifyURL($url), 1));
  1647. $url = qualifyURL($url);
  1648. if (checkFrame($array, $url)) {
  1649. return true;
  1650. } else {
  1651. return false;
  1652. }
  1653. }
  1654. function ping($pings)
  1655. {
  1656. if (qualifyRequest($GLOBALS['pingAuth'])) {
  1657. $type = gettype($pings);
  1658. $ping = new Ping("");
  1659. $ping->setTtl(128);
  1660. $ping->setTimeout(2);
  1661. switch ($type) {
  1662. case "array":
  1663. $results = [];
  1664. foreach ($pings as $k => $v) {
  1665. if (strpos($v, ':') !== false) {
  1666. $domain = explode(':', $v)[0];
  1667. $port = explode(':', $v)[1];
  1668. $ping->setHost($domain);
  1669. $ping->setPort($port);
  1670. $latency = $ping->ping('fsockopen');
  1671. } else {
  1672. $ping->setHost($v);
  1673. $latency = $ping->ping();
  1674. }
  1675. if ($latency || $latency === 0) {
  1676. $results[$v] = $latency;
  1677. } else {
  1678. $results[$v] = false;
  1679. }
  1680. }
  1681. break;
  1682. case "string":
  1683. if (strpos($pings, ':') !== false) {
  1684. $domain = explode(':', $pings)[0];
  1685. $port = explode(':', $pings)[1];
  1686. $ping->setHost($domain);
  1687. $ping->setPort($port);
  1688. $latency = $ping->ping('fsockopen');
  1689. } else {
  1690. $ping->setHost($pings);
  1691. $latency = $ping->ping();
  1692. }
  1693. if ($latency || $latency === 0) {
  1694. $results = $latency;
  1695. } else {
  1696. $results = false;
  1697. }
  1698. break;
  1699. }
  1700. return $results;
  1701. }
  1702. return false;
  1703. }