organizr-functions.php 51 KB

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