gal_keyfile_uploader

The Google Apps Login gal keyfile uploader class.

Defined (1)

The class is defined in the following location(s).

/core/keyfile_uploader.php  
  1. class gal_keyfile_uploader { 
  2.  
  3. protected $fileindex = ''; 
  4. protected $jsontext = ''; 
  5. // JSON could have been submitted by a file or by text 
  6. public function __construct($fileindex, $jsontext) { 
  7. $this->fileindex = $fileindex; 
  8. $this->jsontext = $jsontext; 
  9. $this->attempt_upload(); 
  10.  
  11. protected $contents = null; 
  12. protected function attempt_upload() { 
  13. // If there was an attempt to upload a file 
  14. if (isset($_FILES[$this->fileindex])  
  15. && (!isset($_FILES[$this->fileindex]['error']) || $_FILES[$this->fileindex]['error'] != 4)) { 
  16. // error 4 = no file chosen anyway 
  17.  
  18. if (isset($_FILES[$this->fileindex]['error']) && $_FILES[$this->fileindex]['error'] != 0) { 
  19. error_log('JSON Key file upload error number '.$_FILES[$this->fileindex]['error']); 
  20. // Some import errors have error explanations 
  21. $this->error = 'file_upload_error'.(in_array($_FILES[$this->fileindex]['error'], array(2, 6, 7)) ? $_FILES[$this->fileindex]['error'] : ''); 
  22. return; 
  23.  
  24. if (isset($_FILES[$this->fileindex]['size']) && $_FILES[$this->fileindex]['size'] <= 0) { 
  25. $this->error = 'no_content'; 
  26. return; 
  27.  
  28. $filepath = $_FILES[$this->fileindex]['tmp_name']; 
  29. $this->contents = @file_get_contents($filepath); 
  30. else if (strlen(trim($this->jsontext)) > 0) { 
  31. $this->contents = strpos($this->jsontext, '\\\\') !== false ? stripslashes($this->jsontext) : $this->jsontext; 
  32. if ($this->contents !== null) { 
  33. $this->read_json(); 
  34.  
  35. protected function read_json() { 
  36. $fullkey = json_decode($this->contents, TRUE); 
  37. if ($fullkey === null || !is_array($fullkey)) { 
  38. $this->error = 'decode_error'; 
  39. return; 
  40. if (!isset($fullkey['client_id']) || !isset($fullkey['client_email']) || !isset($fullkey['private_key']) || !isset($fullkey['type']) 
  41. || $fullkey['client_id'] == '' || $fullkey['client_email'] == '' || $fullkey['private_key'] == '') { 
  42. $this->error = 'missing_values'; 
  43. return; 
  44. if (isset($fullkey['type']) && $fullkey['type'] != 'service_account') { 
  45. $this->error = 'not_serviceacct'; 
  46. return; 
  47.  
  48. if (!$this->test_key($fullkey['private_key'])) { 
  49. $this->error = 'bad_pem'; 
  50. return; 
  51.  
  52. $this->key = $fullkey['private_key']; 
  53. $this->id = $fullkey['client_id']; 
  54. $this->email = $fullkey['client_email']; 
  55. $this->pkeyprint = isset($fullkey['private_key_id']) ? $fullkey['private_key_id'] : '<unspecified>'; 
  56.  
  57. protected function test_key($pemkey) { 
  58. $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; 
  59. $data = 'test data'; 
  60. $signature = ''; 
  61. if (!@openssl_sign($data, $signature, $pemkey, $hash)) { 
  62. return false; 
  63. return $signature != '' ? true : false; 
  64.  
  65. protected $email = ''; 
  66. public function getEmail() { 
  67. return $this->email; 
  68.  
  69. protected $id = ''; 
  70. public function getId() { 
  71. return $this->id; 
  72.  
  73. protected $key = ''; 
  74. public function getKey() { 
  75. return $this->key; 
  76.  
  77. protected $pkeyprint = ''; 
  78. public function getPrint() { 
  79. return $this->pkeyprint; 
  80.  
  81. protected $error = ''; 
  82. public function getError() { 
  83. return $this->error;