Exemple #1
0
 public function validate_gpg_paste(Module_Admin $module, $arg)
 {
     if (false === ($this->gpg_fingerprint = GWF_PublicKey::grabFingerprint($arg))) {
         return $this->module->lang('err_gpg_key');
     }
     return false;
 }
Exemple #2
0
 public function execute()
 {
     if (false === ($user = GWF_User::getByID(Common::getGet('userid')))) {
         return GWF_HTML::err('ERR_UNKNOWN_USER');
     }
     $tmpfile = GWF_PATH . 'extra/temp/gpg/' . $user->getVar('user_id');
     if (!is_file($tmpfile) || !is_readable($tmpfile)) {
         return GWF_HTML::err('ERR_FILE_NOT_FOUND', array($tmpfile));
     }
     if (false === ($file_content = file_get_contents($tmpfile))) {
         return GWF_HTML::err('ERR_FILE_NOT_FOUND', array($tmpfile));
     }
     if (false === unlink($tmpfile)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($tmpfile));
     }
     if (false === ($fingerprint = GWF_PublicKey::grabFingerprint($file_content))) {
         return $this->module->error('err_gpg_key');
     }
     if (Common::getGet('token') !== $fingerprint) {
         return $this->module->error('err_gpg_token');
     }
     if (false === GWF_PublicKey::updateKey($user->getID(), $file_content)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     if (false === $user->saveOption(GWF_User::EMAIL_GPG, true)) {
         return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__));
     }
     return $this->module->message('msg_setup_gpg');
 }
Exemple #3
0
 private function onSetupGPG()
 {
     $form = $this->getFormGPG();
     if (false !== ($error = $form->validate($this->module))) {
         return $error;
     }
     $user = GWF_Session::getUser();
     $outfile = GWF_PATH . 'extra/temp/gpg/' . $user->getVar('user_id');
     //		if (!is_writable($outfile)) {
     //			return GWF_HTML::err('ERR_WRITE_FILE', array($outfile));
     //		}
     if (false !== ($row = GWF_PublicKey::getKeyForUser($user))) {
         return $this->module->error('err_gpg_fine');
     }
     $file_content = '';
     if (false !== ($file = $form->getVar('gpg_file'))) {
         if (false === ($file_content = file_get_contents($file['tmp_name']))) {
             $file_content = '';
         }
     } else {
         $file_content = $form->getVar('gpg_paste');
     }
     $file_content = trim($file_content);
     //		if ($file_content === '') {
     //			return $this->module->error('err_gpg_setup');
     //		}
     if (strpos($file_content, '-----BEGIN ') !== 0) {
         return $this->module->error('err_gpg_raw');
     }
     if (false === file_put_contents($outfile, $file_content, GWF_CHMOD)) {
         return GWF_HTML::err('ERR_WRITE_FILE', array($outfile)) . '(PUTTING)';
     }
     if (false === ($fingerprint = GWF_PublicKey::grabFingerprint($file_content))) {
         return $this->module->error('err_gpg_key');
     }
     return $this->sendGPGMail($user, $fingerprint);
 }