sso-functions.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. coookie('set', 'tautulli_token_'.$tautulliToken['uuid'], $tautulliToken['token'], 7, false);
  18. }
  19. }
  20. return true;
  21. }
  22. function getOmbiToken($username, $password)
  23. {
  24. try {
  25. $url = $GLOBALS['ombiURL'].'/api/v1/Token';
  26. $token = null;
  27. $headers = array(
  28. "Accept" => "application/json",
  29. "Content-Type" => "application/json"
  30. );
  31. $data = array(
  32. "username" => $username,
  33. "password" => $password,
  34. "rememberMe" => "true",
  35. );
  36. $options = (localURL($url)) ? array('verify' => false ) : array();
  37. $response = Requests::post($url, $headers, json_encode($data), $options);
  38. if ($response->success) {
  39. $token = json_decode($response->body, true)['access_token'];
  40. }
  41. return ($token) ? $token : false;
  42. } catch (Requests_Exception $e) {
  43. writeLog('success', 'Ombi Token Function - Error: '.$e->getMessage(), $username);
  44. };
  45. }
  46. function getTautulliToken($username, $password)
  47. {
  48. try {
  49. $url = $GLOBALS['tautulliURL'].'/auth/signin';
  50. $token = null;
  51. $headers = array(
  52. "Accept" => "application/json",
  53. "Content-Type" => "application/x-www-form-urlencoded"
  54. );
  55. $data = array(
  56. "username" => $username,
  57. "password" => $password,
  58. "remember_me" => 1,
  59. );
  60. $options = (localURL($url)) ? array('verify' => false ) : array();
  61. $response = Requests::post($url, $headers, $data, $options);
  62. if ($response->success) {
  63. $token['token'] = json_decode($response->body, true)['token'];
  64. $token['uuid'] = json_decode($response->body, true)['uuid'];
  65. }
  66. return ($token) ? $token : false;
  67. } catch (Requests_Exception $e) {
  68. writeLog('success', 'Tautulli Token Function - Error: '.$e->getMessage(), $username);
  69. };
  70. }