4
0

sso-functions.php 2.0 KB

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