コード例 #1
0
ファイル: Form.php プロジェクト: sinfocol/gwf3
 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);
 }