sso-functions.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. function ssoCheck($username, $password, $token=null){
  3. $test = '';
  4. if($GLOBALS['ssoPlex']){
  5. //coookie('set','mpt',$authSuccess['token'],7);
  6. }
  7. if($GLOBALS['ssoOmbi']){
  8. $ombiToken = getOmbiToken($username, $password);
  9. if($ombiToken){
  10. coookie('set','Auth',$ombiToken,7, false);
  11. }
  12. }
  13. if($GLOBALS['ssoTautulli']){
  14. $tautulliToken = getTautulliToken($username, $password);
  15. if($tautulliToken){
  16. coookie('set','tuatulli_token_'.$tautulliToken['uuid'],$tautulliToken['token'],7, false);
  17. }
  18. }
  19. return true;
  20. }
  21. function getOmbiToken($username, $password){
  22. $url = $GLOBALS['ombiURL'].'/api/v1/Token';
  23. $token = null;
  24. $headers = array(
  25. "Accept" => "application/json",
  26. "Content-Type" => "application/json"
  27. );
  28. $data = array(
  29. "username" => $username,
  30. "password" => $password,
  31. "rememberMe" => "true",
  32. );
  33. $options = (localURL($url)) ? array('verify' => false ) : array();
  34. $response = Requests::post($url, $headers, json_encode($data), $options);
  35. if($response->success){
  36. $token = json_decode($response->body, true)['access_token'];
  37. }
  38. return ($token) ? $token : false;
  39. }
  40. function getTautulliToken($username, $password){
  41. $url = $GLOBALS['tautulliURL'].'/auth/signin';
  42. $token = null;
  43. $headers = array(
  44. "Accept" => "application/json",
  45. "Content-Type" => "application/x-www-form-urlencoded"
  46. );
  47. $data = array(
  48. "username" => $username,
  49. "password" => $password,
  50. "remember_me" => 1,
  51. );
  52. $options = (localURL($url)) ? array('verify' => false ) : array();
  53. $response = Requests::post($url, $headers, $data, $options);
  54. if($response->success){
  55. $token['token'] = json_decode($response->body, true)['token'];
  56. $token['uuid'] = json_decode($response->body, true)['uuid'];
  57. }
  58. return ($token) ? $token : false;
  59. }