sso-functions.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. function ssoCheck($username, $password, $token = null)
  3. {
  4. $test = '';
  5. if ($GLOBALS['ssoPlex'] && $token) {
  6. coookie('set', 'mpt', $token, 7);
  7. }
  8. if ($GLOBALS['ssoOmbi']) {
  9. $ombiToken = getOmbiToken($username, $password);
  10. if ($ombiToken) {
  11. coookie('set', 'Auth', $ombiToken, 7, false);
  12. }
  13. }
  14. if ($GLOBALS['ssoTautulli']) {
  15. $tautulliToken = getTautulliToken($username, $password);
  16. if ($tautulliToken) {
  17. foreach ($tautulliToken as $key => $value) {
  18. coookie('set', 'tautulli_token_' . $value['uuid'], $value['token'], 7, false);
  19. }
  20. }
  21. }
  22. return true;
  23. }
  24. function getOmbiToken($username, $password)
  25. {
  26. try {
  27. $url = $GLOBALS['ombiURL'] . '/api/v1/Token';
  28. $token = null;
  29. $headers = array(
  30. "Accept" => "application/json",
  31. "Content-Type" => "application/json"
  32. );
  33. $data = array(
  34. "username" => $username,
  35. "password" => $password,
  36. "rememberMe" => "true",
  37. );
  38. $options = (localURL($url)) ? array('verify' => false) : array();
  39. $response = Requests::post($url, $headers, json_encode($data), $options);
  40. if ($response->success) {
  41. $token = json_decode($response->body, true)['access_token'];
  42. writeLog('success', 'Ombi Token Function - Grabbed token.', $username);
  43. }
  44. return ($token) ? $token : false;
  45. } catch (Requests_Exception $e) {
  46. writeLog('success', 'Ombi Token Function - Error: ' . $e->getMessage(), $username);
  47. };
  48. }
  49. function getTautulliToken($username, $password)
  50. {
  51. $tautulli = array();
  52. $token = null;
  53. $tautulliURLList = explode(',', $GLOBALS['tautulliURL']);
  54. if (count($tautulliURLList) !== 0) {
  55. foreach ($tautulliURLList as $key => $value) {
  56. try {
  57. $url = $value . '/auth/signin';
  58. $headers = array(
  59. "Accept" => "application/json",
  60. "Content-Type" => "application/x-www-form-urlencoded",
  61. "User-Agent" => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null
  62. );
  63. $data = array(
  64. "username" => $username,
  65. "password" => $password,
  66. "remember_me" => 1,
  67. );
  68. $options = (localURL($url)) ? array('verify' => false) : array();
  69. $response = Requests::post($url, $headers, $data, $options);
  70. if ($response->success) {
  71. $token[$key]['token'] = json_decode($response->body, true)['token'];
  72. $token[$key]['uuid'] = json_decode($response->body, true)['uuid'];
  73. writeLog('success', 'Tautulli Token Function - Grabbed token from: ' . $url, $username);
  74. } else {
  75. writeLog('error', 'Tautulli Token Function - Error on URL: ' . $url, $username);
  76. }
  77. } catch (Requests_Exception $e) {
  78. writeLog('error', 'Tautulli Token Function - Error: [' . $url . ']' . $e->getMessage(), $username);
  79. };
  80. }
  81. }
  82. return ($token) ? $token : false;
  83. }