예제 #1
0
 protected function actionRedirect()
 {
     $tmpFile = \GO\Base\Fs\File::tempFile();
     $tmpFile->putContents(\GO::user()->id);
     if (empty(\GO::config()->phpbb3_url)) {
         throw new \Exception('You must configure phpbb3_url in your config.php file');
     }
     $url = \GO::config()->phpbb3_url . '?goauth=' . base64_encode($tmpFile->path()) . '&sid=' . md5(uniqid(time()));
     header('Location: ' . $url);
     exit;
 }
예제 #2
0
 /**
  * Creates a new file in the directory
  *
  * data is a readable stream resource
  *
  * @param string $name Name of the file
  * @param resource $data Initial payload
  * @return void
  */
 public function createFile($name, $data = null)
 {
     \GO::debug("FSD::createFile({$name})");
     $folder = $this->_getFolder();
     if (!$folder->checkPermissionLevel(\GO\Base\Model\Acl::WRITE_PERMISSION)) {
         throw new Sabre\DAV\Exception\Forbidden();
     }
     $newFile = new \GO\Base\Fs\File($this->path . '/' . $name);
     if ($newFile->exists()) {
         throw new \Exception("File already exists!");
     }
     $tmpFile = \GO\Base\Fs\File::tempFile();
     $tmpFile->putContents($data);
     if (!\GO\Files\Model\File::checkQuota($tmpFile->size())) {
         $tmpFile->delete();
         throw new Sabre\DAV\Exception\InsufficientStorage();
     }
     //		$newFile->putContents($data);
     $tmpFile->move($folder->fsFolder, $name);
     $folder->addFile($name);
 }
예제 #3
0
 public function output()
 {
     $this->_sendHeaders();
     $this->_setupExcel();
     if ($this->header) {
         if ($this->humanHeaders) {
             $this->_write(array_values($this->getLabels()));
         } else {
             $this->_write(array_keys($this->getLabels()));
         }
     }
     while ($record = $this->store->nextRecord()) {
         $record = $this->prepareRecord($record);
         $this->_write($record);
     }
     // Hack to write contents of file to string
     $writer = PHPExcel_IOFactory::createWriter($this->phpExcel, 'Excel5');
     //$tmpFilename = tempnam('./temp', 'tmp');
     $file = \GO\Base\Fs\File::tempFile();
     $writer->save($file->path());
     $file->output();
     $file->delete();
 }
예제 #4
0
 /**
  * 
  * @param type $params
  * @return boolean
  * @throws Exception
  */
 protected function actionImport($params)
 {
     if ($this->client->getAccessToken()) {
         $file = $this->service->files->get(\GO::session()->values['googledrive']['editing'][$params[id]]['gd_id']);
         $goFile = \GO\Files\Model\File::model()->findByPk(\GO::session()->values['googledrive']['editing'][$params[id]]['go_file_id']);
         $mimeType = $goFile->fsFile->mimeType();
         //hack for strange gdocs mimetype
         if ($mimeType == 'application/vnd.oasis.opendocument.spreadsheet') {
             $mimeType = 'application/x-vnd.oasis.opendocument.spreadsheet';
         }
         $downloadUrl = isset($file->exportLinks[$mimeType]) ? $file->exportLinks[$mimeType] : false;
         if ($downloadUrl) {
             $tmpFile = \GO\Base\Fs\File::tempFile($goFile->name);
             $request = new Google_HttpRequest($downloadUrl, 'GET', null, null);
             $httpRequest = Google_Client::$io->authenticatedRequest($request);
             if ($httpRequest->getResponseHttpCode() == 200) {
                 $tmpFile->putContents($httpRequest->getResponseBody());
                 $goFile->replace($tmpFile);
                 $this->service->files->delete(\GO::session()->values['googledrive']['editing'][$params[id]]['gd_id']);
                 unset(\GO::session()->values['googledrive']['editing'][$params[id]]);
                 $response['success'] = true;
             } else {
                 throw new Exception("Got HTTP response code " . $httpRequest->getResponseHttpCode() . " from Google");
             }
         } else {
             var_dump($file->exportLinks);
             throw new Exception("Document type " . $mimeType . " is not supported");
         }
         $this->saveToken();
     } else {
         throw new Exception("No access to Google!");
     }
     if (!$response['success']) {
         throw new Exception("Failed to import file!");
     }
     return $response;
 }
예제 #5
0
 private function _duplicateFileColumns(ActiveRecord $duplicate)
 {
     foreach ($this->columns as $column => $attr) {
         if ($attr['gotype'] == 'file') {
             if (!empty($this->_attributes[$column])) {
                 $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $this->_attributes[$column]);
                 $tmpFile = \GO\Base\Fs\File::tempFile('', $file->extension());
                 $file->copy($tmpFile->parent(), $tmpFile->name());
                 $duplicate->{$column} = $tmpFile;
             }
         }
     }
 }
예제 #6
0
파일: Message.php 프로젝트: ajaboa/crmpuan
 private function _embedPastedImages($body)
 {
     $regex = '/src="data:image\\/([^;]+);([^,]+),([^"]+)/';
     preg_match_all($regex, $body, $allMatches, PREG_SET_ORDER);
     foreach ($allMatches as $matches) {
         if ($matches[2] == 'base64') {
             $extension = $matches[1];
             $tmpFile = \GO\Base\Fs\File::tempFile('', $extension);
             $tmpFile->putContents(base64_decode($matches[3]));
             $img = \Swift_EmbeddedFile::fromPath($tmpFile->path());
             $img->setContentType($tmpFile->mimeType());
             $contentId = $this->embed($img);
             $body = str_replace($matches[0], 'src="' . $contentId, $body);
         }
     }
     return $body;
 }
예제 #7
0
파일: Contact.php 프로젝트: ajaboa/crmpuan
 /**
  * Import a contact (with or without company) from a VObject 
  * 
  * @param Sabre\VObject\Component $vobject
  * @param array $attributes Extra attributes to apply to the contact. Raw values should be past. No input formatting is applied.
  * @return Contact
  */
 public function importVObject(Sabre\VObject\Component $vobject, $attributes = array(), $saveToDb = true, $ignoreInvalidProperties = true)
 {
     //$event = new \GO\Calendar\Model\Event();
     $companyAttributes = array();
     //		if (!empty($attributes['addressbook_id'])) {
     //			$companyAttributes['addressbook_id'] = $attributes['addressbook_id'];
     //		}
     $uid = (string) $vobject->uid;
     if (!empty($uid) && empty($attributes['uuid'])) {
         $attributes['uuid'] = $uid;
     }
     $emails = array();
     foreach ($vobject->children as $vobjProp) {
         switch ($vobjProp->name) {
             case 'PHOTO':
                 if ($vobjProp->getValue()) {
                     $photoFile = \GO\Base\Fs\File::tempFile('', 'jpg');
                     $photoFile->putContents($vobjProp->getValue());
                 }
                 break;
             case 'N':
                 $nameArr = explode(';', $vobjProp->getValue());
                 if (isset($nameArr[0])) {
                     $attributes['last_name'] = $nameArr[0];
                 }
                 if (isset($nameArr[1])) {
                     $attributes['first_name'] = $nameArr[1];
                 }
                 $attributes['middle_name'] = !empty($nameArr[2]) ? $nameArr[2] : '';
                 $attributes['suffix'] = !empty($nameArr[4]) ? $nameArr[4] : '';
                 $attributes['title'] = !empty($nameArr[3]) ? $nameArr[3] : '';
                 break;
             case 'ORG':
                 $companyAttributes['name'] = null;
                 if ($vobjProp->getValue()) {
                     $compNameArr = explode(';', $vobjProp->getValue());
                     if (!empty($compNameArr[0])) {
                         $companyAttributes['name'] = $compNameArr[0];
                     }
                     if (!empty($compNameArr[1])) {
                         $attributes['department'] = $compNameArr[1];
                     }
                     if (!empty($compNameArr[2])) {
                         $companyAttributes['name2'] = $compNameArr[2];
                     }
                 }
                 break;
                 //				case 'TITLE':
                 //					$attributes['title'] = $vobjProp->getValue() ? $vobjProp->getValue() : null;
                 //					break;
             //				case 'TITLE':
             //					$attributes['title'] = $vobjProp->getValue() ? $vobjProp->getValue() : null;
             //					break;
             case 'TEL':
                 if ($vobjProp->getValue()) {
                     $types = array();
                     foreach ($vobjProp->parameters as $param) {
                         if ($param->name == 'TYPE') {
                             $types = explode(',', strtolower($param->getValue()));
                         }
                     }
                     if (in_array('work', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         $attributes['work_phone'] = $vobjProp->getValue();
                         $companyAttributes['phone'] = $vobjProp->getValue();
                     }
                     if (in_array('cell', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         if (empty($attributes['cellular'])) {
                             $attributes['cellular'] = $vobjProp->getValue();
                         } elseif (empty($attributes['cellular2'])) {
                             $attributes['cellular2'] = $vobjProp->getValue();
                         }
                     }
                     if (in_array('fax', $types) && in_array('home', $types)) {
                         $attributes['fax'] = $vobjProp->getValue();
                     }
                     if (in_array('fax', $types) && in_array('work', $types)) {
                         $companyAttributes['fax'] = $vobjProp->getValue();
                         $attributes['work_fax'] = $vobjProp->getValue();
                     }
                     if (in_array('home', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         $attributes['home_phone'] = $vobjProp->getValue();
                     }
                 }
                 //					foreach ($vobjProp->parameters as $param) {
                 //						if ($param['name']=='TYPE') {
                 //							switch (susbstr($param['value'],0,4)) {
                 //								case 'work':
                 //									$attributes['work_phone'] = $vobjProp->getValue();
                 //									break;
                 //								default:
                 //									$attributes['home_phone'] = $vobjProp->getValue();
                 //									break;
                 //							}
                 //						}
                 //					}
                 break;
                 //				case 'LABEL':
             //				case 'LABEL':
             case 'ADR':
                 $types = array();
                 foreach ($vobjProp->parameters as $param) {
                     if ($param->name == 'TYPE') {
                         $types = explode(',', strtolower($param->getValue()));
                     }
                 }
                 if (in_array('work', $types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $companyAttributes['address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $companyAttributes['city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $companyAttributes['state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $companyAttributes['zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $companyAttributes['country'] = $addrArr[6];
                     }
                 }
                 if (in_array('home', $types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $attributes['address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $attributes['city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $attributes['state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $attributes['zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $attributes['country'] = $addrArr[6];
                     }
                 }
                 if (empty($types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $companyAttributes['post_address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $companyAttributes['post_city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $companyAttributes['post_state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $companyAttributes['post_zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $companyAttributes['post_country'] = $addrArr[6];
                     }
                 }
                 break;
             case 'EMAIL':
                 //					foreach ($vobjProp->parameters as $param) {
                 //						if ($param->name=='TYPE')
                 //							$types = explode(',',strtolower($param->getValue()));
                 //						else
                 //							$types = array();
                 //					}
                 //					if(in_array('pref',$types)) {
                 //						$attributes['email'] = $vobjProp->getValue();
                 //					} elseif(in_array('home',$types)) {
                 //						$attributes['email2'] = $vobjProp->getValue();
                 //					} elseif(in_array('work',$types)) {
                 //						$attributes['email3'] = $vobjProp->getValue();
                 //					} else {
                 //						$attributes['email'] = $vobjProp->getValue();
                 //					}
                 if ($vobjProp->getValue()) {
                     $emails[] = $vobjProp->getValue();
                 }
                 break;
             case 'TITLE':
                 $attributes['function'] = $vobjProp->getValue();
                 break;
             case 'BDAY':
                 if ($vobjProp->getValue()) {
                     // is already formatted in GO\Base\VObject\Reader::convertVCard21ToVCard30
                     // $attributes['birthday'] = substr($vobjProp->getValue(),0,4).'-'.substr($vobjProp->getValue(),5,2).'-'.substr($vobjProp->getValue(),8,2);
                     $attributes['birthday'] = $vobjProp->getValue();
                 }
                 break;
             case 'NOTE':
                 $attributes['comment'] = $vobjProp->getValue();
                 break;
             case 'VERSION':
             case 'LAST-MODIFIED':
                 break;
             default:
                 $paramsArr = array();
                 foreach ($vobjProp->parameters as $param) {
                     $paramsArr[] = $param->serialize();
                 }
                 //					$remainingVcardProps[] = array('name' => $vobjProp->name, 'parameters'=>implode(';',$paramsArr), 'value'=>$vobjProp->getValue());
                 break;
         }
     }
     foreach ($emails as $email) {
         if (!isset($attributes['email'])) {
             $attributes['email'] = $email;
         } elseif (!isset($attributes['email2'])) {
             $attributes['email2'] = $email;
         } elseif (!isset($attributes['email3'])) {
             $attributes['email3'] = $email;
         }
     }
     //some attributes can be specified with multiple values like tel and email.
     //We don't know which value is going to map to which exact GO attribute because every client handles this differently.
     //Clear the values if they haven't been found at all.
     //
     // Not clearing them cause some client might not send it and this can cause data loss.
     //		$attributesMultiple=array('home_phone','work_phone','fax', 'work_fax','cellular','email','email2','email3');
     //		foreach($attributesMultiple as $attributeName){
     //			if(!isset($attributes[$attributeName]))
     //				$attributes[$attributeName]="";
     //		}
     $attributes = array_map('trim', $attributes);
     $attributes = $this->_splitAddress($attributes);
     if (empty($attributes['last_name']) && empty($attributes['first_name'])) {
         $attributes['first_name'] = 'unnamed';
     }
     $this->setAttributes($attributes, false);
     if (isset($companyAttributes['name'])) {
         $company = Company::model()->findSingleByAttributes(array('name' => $companyAttributes['name'], 'addressbook_id' => $this->addressbook_id));
         if (!$company) {
             $company = new Company();
             $company->setAttributes($companyAttributes, false);
             $company->addressbook_id = $this->addressbook_id;
         }
         if (!empty($saveToDb)) {
             $company->save();
         }
         $this->setAttribute('company_id', $company->id);
     }
     $this->cutAttributeLengths();
     if ($ignoreInvalidProperties) {
         $this->ignoreInvalidProperties();
     }
     if (!empty($saveToDb)) {
         $this->save();
     }
     if (!empty($photoFile) && $saveToDb) {
         $this->setPhoto($photoFile);
         $this->save();
     }
     //		foreach ($remainingVcardProps as $prop) {
     //			if (!empty($this->id) && substr($prop['name'],0,2)=='X-') {
     //				// Process encounters a custom property name in the VCard.
     //				$arr = explode('-',$prop['name']);
     //				$currentPropName = 'X-'.$arr[1];
     //				if (!in_array($currentPropName,$deletedPropertiesPrefixes_nonGO)) {
     //					// Process encounters a new custom property prefix in the VCard.
     //					// Now deleting all properties with this contact that have this prefix.
     //					// Because of $deletedPropertiesPrefixes_nonGO, this is only done once
     //					// per sync per VCard.
     //					$deletablePropertiesStmt = ContactVcardProperty::model()->find(
     //						\GO\Base\Db\FindParams::newInstance()->criteria(
     //							\GO\Base\Db\FindCriteria::newInstance()
     //								->addCondition('contact_id',$this->id)
     //								->addCondition('name',$currentPropName.'-%','LIKE')
     //						)
     //					);
     //
     //					while ($delPropModel = $deletablePropertiesStmt->fetch())
     //						$delPropModel->delete();
     //
     //					$deletedPropertiesPrefixes_nonGO[] = $currentPropName; // Keep track of prefixes for which we have deleted the properties.
     //				}
     //			}
     //
     //			$propModel = ContactVcardProperty::model()->find(
     //				\GO\Base\Db\FindParams::newInstance()
     //					->single()
     //					->criteria(
     //						\GO\Base\Db\FindCriteria::newInstance()
     //							->addCondition('contact_id',$this->id)
     //							->addCondition('name',$prop['name'])
     //							->addCondition('parameters',$prop['parameters'])
     //					)
     //				);
     //			if (empty($propModel))
     //				$propModel = new ContactVcardProperty();
     //			$propModel->contact_id = $this->id;
     //			$propModel->name = $prop['name'];
     //			$propModel->parameters = $prop['parameters'];
     //			$propModel->value = $prop['value'];
     //			$propModel->cutAttributeLengths();
     //			$propModel->save();
     //		}
     return $this;
 }
예제 #8
0
 private static function _savePhoto(&$response, &$model, &$params)
 {
     if (!empty($params['delete_photo'])) {
         $model->removePhoto();
         $model->save();
     }
     if (isset($_FILES['image']['tmp_name'][0]) && is_uploaded_file($_FILES['image']['tmp_name'][0])) {
         $destinationFile = new \GO\Base\Fs\File(\GO::config()->getTempFolder()->path() . '/' . $_FILES['image']['name'][0]);
         move_uploaded_file($_FILES['image']['tmp_name'][0], $destinationFile->path());
         $model->setPhoto($destinationFile);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     } elseif (!empty($params['download_photo_url'])) {
         $file = \GO\Base\Fs\File::tempFile();
         $c = new \GO\Base\Util\HttpClient();
         if (!$c->downloadFile($params['download_photo_url'], $file)) {
             throw new \Exception("Could not download photo from: '" . $params['download_photo_url'] . "'");
         }
         $model->setPhoto($file);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     }
 }
예제 #9
0
파일: Imap.php 프로젝트: ajaboa/crmpuan
 /**
  * Append a message to a mailbox
  *
  * @param string $mailbox
  * @param string|\Swift_Message $data
  * @param string $flags See set_message_flag
  * @return boolean
  */
 public function append_message($mailbox, $data, $flags = "")
 {
     if ($data instanceof \Swift_Message) {
         $tmpfile = \GO\Base\Fs\File::tempFile();
         $is = new \Swift_ByteStream_FileByteStream($tmpfile->path(), true);
         $data->toByteStream($is);
         unset($data);
         unset($is);
         if (!$this->append_start($mailbox, $tmpfile->size(), $flags)) {
             return false;
         }
         $fp = fopen($tmpfile->path(), 'r');
         while ($line = fgets($fp, 1024)) {
             if (!$this->append_feed($line)) {
                 return false;
             }
         }
         fclose($fp);
         $tmpfile->delete();
     } else {
         if (!$this->append_start($mailbox, strlen($data), $flags)) {
             return false;
         }
         if (!$this->append_feed($data)) {
             return false;
         }
     }
     $this->append_feed("\r\n");
     return $this->append_end();
 }
예제 #10
0
파일: Message.php 프로젝트: ajaboa/crmpuan
 protected function extractUuencodedAttachments(&$body)
 {
     //		$body = str_replace("\r", '', $body);
     if (($pos = strpos($body, "\nbegin ")) === false) {
         return;
     }
     //		$regex = "/(begin ([0-7]{3}) (.+))\n/";
     $regex = "/(begin ([0-7]{1,3}) (.+))\n/";
     //		$regex = "/(begin ([0-7]+) (.+))\n/";
     if (preg_match_all($regex, $body, $matches, PREG_OFFSET_CAPTURE)) {
         //		throw new E$attxception(var_export($matches, true));
         //			$body = substr($body, 0, $pos);
         for ($i = 0, $count = count($matches[3]); $i < $count; $i++) {
             //			$boundary	= $matches[1][$i];
             //			$fileperm	= $matches[2][$i];
             $filename = trim($matches[3][$i][0]);
             $offset = $matches[3][$i][1] + strlen($matches[3][$i][0]) + 1;
             $endpos = strpos($body, 'end', $offset) - $offset - 1;
             if ($endpos) {
                 if (!isset($startPosAtts)) {
                     $startPosAtts = $matches[0][$i][1];
                 }
                 $att = str_replace(array("\r"), "", substr($body, $offset, $endpos));
                 //$size = strlen($matches[4][$i]);
                 $file = \GO\Base\Fs\File::tempFile($filename);
                 $file->putContents(convert_uudecode($att));
                 //			$file->putContents($att);
                 $a = MessageAttachment::model()->createFromTempFile($file);
                 $a->number = "UU" . $i;
                 $this->addAttachment($a);
             }
         }
         $body = substr($body, 0, $startPosAtts);
     }
     \GO::debug($matches);
 }
예제 #11
0
 /**
  * Compress the selected files and return as download
  * 
  * @param array $params
  * @return boolean
  * @throws \Exception
  */
 protected function actionCompressAndDownload($params)
 {
     if (!isset($params['archive_name'])) {
         throw new \Exception('No name for the archive given');
     }
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '512M');
     $sources = json_decode($params['sources'], true);
     $workingFolder = false;
     // Read the sources and create objects from them
     $sourceObjects = array();
     // The total filesize in bytes
     $totalFileSize = 0;
     // The maximum filesize that is allowed to zip (Default is 256MB)
     $maxFilesize = GO::config()->zip_max_file_size;
     for ($i = 0; $i < count($sources); $i++) {
         $path = \GO::config()->file_storage_path . $sources[$i];
         $sourceFile = \GO\Base\Fs\Base::createFromPath($path);
         // Increase the total filesize
         $totalFileSize += $sourceFile->size();
         if ($totalFileSize >= $maxFilesize) {
             throw new \Exception(sprintf(\GO::t('zipFilesizeTooBig', 'base'), \GO\Base\Util\Number::formatSize($maxFilesize, 2)));
         }
         // Set the workingFolder
         if (!$workingFolder) {
             $workingFolder = $sourceFile->parent();
         }
         $sourceObjects[] = $sourceFile;
     }
     // Create the zipped temp file object
     $archiveFile = \GO\Base\Fs\File::tempFile($params['archive_name'], 'zip');
     if ($archiveFile->exists()) {
         throw new \Exception(sprintf(\GO::t('filenameExists', 'files'), $archiveFile->stripFileStoragePath()));
     }
     // Create the zipfile
     if (\GO\Base\Fs\Zip::create($archiveFile, $workingFolder, $sourceObjects)) {
         // Output download headers
         //			\GO\Base\Util\Http::outputDownloadHeaders($archiveFile,false,true);
         //			$archiveFile->output();
         $response['archive'] = $archiveFile->stripTempPath();
         $response['success'] = true;
     } else {
         throw new \Exception("ZIP creation failed");
     }
     return $response;
 }
예제 #12
0
 private function _doSign()
 {
     if (!$this->signed) {
         openssl_pkcs12_read($this->pkcs12_data, $certs, $this->passphrase);
         if (!is_array($certs)) {
             //unfortunately exceptions are catched by swift and it leads to an SMTP timeout somehow.
             trigger_error("Could not decrypt key. Invalid passphrase?", E_USER_ERROR);
         }
         if (!empty($certs['extracerts'])) {
             $extraCertsFile = \GO\Base\Fs\File::tempFile();
             foreach ($certs['extracerts'] as $certData) {
                 $extraCertsFile->putContents($certData, FILE_APPEND);
             }
         }
         //$this->extra_certs=array_merge($this->extra_certs,$certs['extracerts']);
         if (!file_exists($this->tempin)) {
             trigger_error('Failed to sign. Temp file disappeared', E_USER_ERROR);
         }
         if (!isset($extraCertsFile)) {
             openssl_pkcs7_sign($this->tempin, $this->tempout, $certs['cert'], array($certs['pkey'], $this->passphrase), $this->saved_headers, PKCS7_DETACHED);
         } else {
             openssl_pkcs7_sign($this->tempin, $this->tempout, $certs['cert'], array($certs['pkey'], $this->passphrase), $this->saved_headers, PKCS7_DETACHED, $extraCertsFile->path());
             $extraCertsFile->delete();
         }
         $this->signed = true;
     }
 }
예제 #13
0
 /**
  * Run from the browser's address bar. Collects all language files, and puts
  * them in a zip file in the file storage path, respecting the folder
  * structure. I.e., you can later unpack the file contents to the
  * Group-Office path.
  * @param type $params 
  */
 protected function actionZipLanguage($params)
 {
     if (!empty($params['lang'])) {
         $langCode = $params['lang'];
     } else {
         die('<font color="red"><i>The GET parameter lang is required for the zipLanguage action!</i></font>');
     }
     $fileNames = array();
     //gather file list in array
     $commonLangFolder = new \GO\Base\Fs\Folder(\GO::config()->root_path . 'language/');
     if ($commonLangFolder->exists()) {
         $commonLangFolderContentArr = $commonLangFolder->ls();
         $moduleModelArr = \GO::modules()->getAllModules();
         foreach ($commonLangFolderContentArr as $commonLangFolder) {
             if (get_class($commonLangFolder) == 'GO\\Base\\Fs\\Folder') {
                 $commonLangFileArr = $commonLangFolder->ls();
                 foreach ($commonLangFileArr as $commonLangFile) {
                     if (get_class($commonLangFile) == 'GO\\Base\\Fs\\File' && $commonLangFile->name() == $langCode . '.php') {
                         $fileNames[] = str_replace(\GO::config()->root_path, '', $commonLangFile->path());
                     }
                 }
             }
         }
     }
     foreach ($moduleModelArr as $moduleModel) {
         $modLangFolder = new \GO\Base\Fs\Folder($moduleModel->path . 'language/');
         if ($modLangFolder->exists()) {
             $modLangFiles = $modLangFolder->ls();
             foreach ($modLangFiles as $modLangFile) {
                 if ($modLangFile->name() == $langCode . '.php') {
                     $fileNames[] = str_replace(\GO::config()->root_path, '', $modLangFile->path());
                 }
             }
         }
     }
     $tmpFile = \GO\Base\Fs\File::tempFile($langCode . '-' . str_replace('.', '-', \GO::config()->version), 'zip');
     //exec zip
     $cmdString = \GO::config()->cmd_zip . ' ' . $tmpFile->path() . ' ' . implode(" ", $fileNames);
     exec($cmdString, $outputArr, $retVal);
     if ($retVal > 0) {
         trigger_error("Creating ZIP file failed! " . implode("<br />", $outputArr), E_USER_ERROR);
     }
     \GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
     $tmpFile->output();
     $tmpFile->delete();
 }
예제 #14
0
 protected function afterSubmit(&$response, &$model, &$params, $modifiedAttributes)
 {
     $stmt = \GO\Addressbook\Model\Addresslist::model()->find();
     while ($addresslist = $stmt->fetch()) {
         $linkModel = $addresslist->hasManyMany('companies', $model->id);
         $mustHaveLinkModel = isset($params['addresslist_' . $addresslist->id]);
         if ($linkModel && !$mustHaveLinkModel) {
             $linkModel->delete();
         }
         if (!$linkModel && $mustHaveLinkModel) {
             $addresslist->addManyMany('companies', $model->id);
         }
     }
     if (!empty($params['delete_photo'])) {
         $model->removePhoto();
         $model->save();
     }
     if (isset($_FILES['image']['tmp_name'][0]) && is_uploaded_file($_FILES['image']['tmp_name'][0])) {
         $destinationFile = new \GO\Base\Fs\File(\GO::config()->getTempFolder()->path() . '/' . $_FILES['image']['name'][0]);
         move_uploaded_file($_FILES['image']['tmp_name'][0], $destinationFile->path());
         $model->setPhoto($destinationFile);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     } elseif (!empty($params['download_photo_url'])) {
         $file = \GO\Base\Fs\File::tempFile();
         $c = new \GO\Base\Util\HttpClient();
         if (!$c->downloadFile($params['download_photo_url'], $file)) {
             throw new \Exception("Could not download photo from: '" . $params['download_photo_url'] . "'");
         }
         $model->setPhoto($file);
         $model->save();
         $response['photo_url'] = $model->photoThumbURL;
         $response['original_photo_url'] = $model->photoURL;
     }
     return parent::afterSubmit($response, $model, $params, $modifiedAttributes);
 }
예제 #15
0
 protected function actionHandleAttachedVCard($params)
 {
     $account = \GO\Email\Model\Account::model()->findByPk($params['account_id']);
     $imap = $account->openImapConnection($params['mailbox']);
     $tmpFile = \GO\Base\Fs\File::tempFile($params['filename']);
     $imap->save_to_file($params['uid'], $tmpFile->path(), $params['number'], $params['encoding']);
     if (!isset($params['importVCard'])) {
         \GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
         echo $tmpFile->getContents();
         return;
     }
     $options = \Sabre\VObject\Reader::OPTION_FORGIVING + \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES;
     $card = \Sabre\VObject\Reader::read($tmpFile->getContents(), $options);
     $contact = new \GO\Addressbook\Model\Contact();
     $contact->importVObject($card, array(), false);
     //format utf-8 attributes
     foreach ($contact->getAttributes('raw') as $key => $value) {
         try {
             $contact->{$key} = utf8_decode($value);
         } catch (\Exception $e) {
         }
     }
     //GO\Base\Util\Http::outputDownloadHeaders($tmpFile);
     return array('success' => true, 'contacts' => array($contact->getAttributes()));
     //echo $tmpFile->getContents();
 }
예제 #16
0
 public function actionMessageAttachment($params)
 {
     $account = Account::model()->findByPk($params['account_id']);
     $tmpFile = \GO\Base\Fs\File::tempFile('message.eml');
     $imap = $account->openImapConnection($params['mailbox']);
     /* @var $imap \GO\Base\Mail\Imap  */
     $imap->save_to_file($params['uid'], $tmpFile->path(), $params['number'], $params['encoding']);
     $message = \GO\Email\Model\SavedMessage::model()->createFromMimeData($tmpFile->getContents());
     $response = $message->toOutputArray();
     $response = $this->_checkXSS($params, $response);
     $response['path'] = $tmpFile->stripTempPath();
     $response['is_tmp_file'] = true;
     $response['success'] = true;
     return $response;
 }
예제 #17
-1
 private function _decryptFile(\GO\Base\Fs\File $srcFile, \GO\Email\Model\Account $account)
 {
     $data = $srcFile->getContents();
     if (strpos($data, "enveloped-data") || strpos($data, 'Encrypted Message')) {
         $cert = \GO\Smime\Model\Certificate::model()->findByPk($account->id);
         $password = \GO::session()->values['smime']['passwords'][$_REQUEST['account_id']];
         openssl_pkcs12_read($cert->cert, $certs, $password);
         $decryptedFile = \GO\Base\Fs\File::tempFile();
         $ret = openssl_pkcs7_decrypt($srcFile->path(), $decryptedFile->path(), $certs['cert'], array($certs['pkey'], $password));
         if (!$decryptedFile->exists()) {
             throw new \Exception("Could not decrypt message: " . openssl_error_string());
         }
         $decryptedFile->move($srcFile->parent(), $srcFile->name());
     }
 }
예제 #18
-1
 public static function toOutputArray(array &$response, \GO\Email\Model\ImapMessage $imapMessage)
 {
     if ($imapMessage->content_type == 'application/x-pkcs7-mime') {
         $imapMessage->content_type = 'application/pkcs7-mime';
     }
     if ($imapMessage->content_type == 'application/pkcs7-mime' && isset($imapMessage->content_type_attributes['smime-type']) && $imapMessage->content_type_attributes['smime-type'] == 'signed-data') {
         //signed data but not in clear text. Outlook has this option.
         $outfile = \GO\Base\Fs\File::tempFile();
         $imapMessage->getImapConnection()->save_to_file($imapMessage->uid, $outfile->path());
         $verifyOutfile = \GO\Base\Fs\File::tempFile();
         //			$cmd = '/usr/bin/openssl smime -verify -in ' . $outfile->path() . ' -out ' . $verifyOutfile->path();
         //			exec($cmd);
         //
         //PHP can't output the verified data without the signature without
         //suppling the extracerts option. We generated a dummy certificate for
         //this.
         openssl_pkcs7_verify($outfile->path(), null, "/dev/null", array(), GO::config()->root_path . "modules/smime/dummycert.pem", $verifyOutfile->path());
         $message = \GO\Email\Model\SavedMessage::model()->createFromMimeData($verifyOutfile->getContents());
         //remove temp files
         $outfile->delete();
         $verifyOutfile->delete();
         $newResponse = $message->toOutputArray(true);
         unset($newResponse['to']);
         unset($newResponse['cc']);
         foreach ($newResponse as $key => $value) {
             if (!empty($value) || $key == 'attachments') {
                 $response[$key] = $value;
             }
         }
         //			$response['path'] = $outfile->stripTempPath();
         return;
     }
     if ($imapMessage->content_type == 'application/pkcs7-mime') {
         $encrypted = !isset($imapMessage->content_type_attributes['smime-type']) || $imapMessage->content_type_attributes['smime-type'] != 'signed-data';
         if ($encrypted) {
             GO::debug("Message is encrypted");
             $cert = Model\Certificate::model()->findByPk($imapMessage->account->id);
             if (!$cert || empty($cert->cert)) {
                 GO::debug('SMIME: No private key at all found for this account');
                 $response['htmlbody'] = GO::t('noPrivateKeyForDecrypt', 'smime');
                 return false;
             }
             if (isset($_REQUEST['password'])) {
                 GO::session()->values['smime']['passwords'][$imapMessage->account->id] = $_REQUEST['password'];
             }
             if (!isset(GO::session()->values['smime']['passwords'][$imapMessage->account->id])) {
                 $response['askPassword'] = true;
                 GO::debug("Need to ask for password");
                 return false;
             }
         }
         $attachments = $imapMessage->getAttachments();
         $att = array_shift($attachments);
         //			array (
         //      'type' => 'application',
         //      'subtype' => 'pkcs7-mime',
         //      'smime-type' => 'enveloped-data',
         //      'name' => 'smime.p7m',
         //      'id' => false,
         //      'encoding' => 'base64',
         //      'size' => '2302',
         //      'md5' => false,
         //      'disposition' => false,
         //      'language' => false,
         //      'location' => false,
         //      'charset' => false,
         //      'lines' => false,
         //      'number' => 1,
         //      'extension' => 'p7m',
         //      'human_size' => '2,2 KB',
         //      'tmp_file' => false,
         //    )
         $infile = \GO\Base\Fs\File::tempFile();
         $outfile = \GO\Base\Fs\File::tempFile();
         //$outfilerel = $reldir . 'unencrypted.txt';
         if ($encrypted) {
             GO::debug('Message is encrypted');
             //				$imapMessage->getImapConnection()->save_to_file($imapMessage->uid, $infile->path(), 'TEXT', 'base64');
             //				throw new \Exception($infile->path());
             if (!$imapMessage->saveToFile($infile->path())) {
                 throw new \Exception("Could not save IMAP message to file for decryption");
             }
             $password = GO::session()->values['smime']['passwords'][$imapMessage->account->id];
             openssl_pkcs12_read($cert->cert, $certs, $password);
             if (empty($certs)) {
                 //password invalid
                 $response['askPassword'] = true;
                 GO::debug("Invalid password");
                 return false;
             }
             $return = openssl_pkcs7_decrypt($infile->path(), $outfile->path(), $certs['cert'], array($certs['pkey'], $password));
             $infile->delete();
             if (!$return || !$outfile->exists() || !$outfile->size()) {
                 $response['htmlbody'] = GO::t('decryptionFailed', 'smime') . '<br />';
                 while ($str = openssl_error_string()) {
                     $response['htmlbody'] .= '<br />' . $str;
                 }
                 GO::debug("Decryption failed");
                 return false;
             } else {
                 //check if also signed
                 $data = $outfile->getContents();
                 if (strpos($data, 'signed-data')) {
                     $verifyOutfile = \GO\Base\Fs\File::tempFile();
                     openssl_pkcs7_verify($outfile->path(), null, "/dev/null", array(), GO::config()->root_path . "modules/smime/dummycert.pem", $verifyOutfile->path());
                     $outfile = $verifyOutfile;
                 }
                 $message = \GO\Email\Model\SavedMessage::model()->createFromMimeData($outfile->getContents());
                 $newResponse = $message->toOutputArray(true);
                 unset($newResponse['to']);
                 unset($newResponse['to_string']);
                 unset($newResponse['cc']);
                 foreach ($newResponse as $key => $value) {
                     if (!empty($value) || $key == 'attachments') {
                         $response[$key] = $value;
                     }
                 }
                 $response['smime_encrypted'] = true;
                 //$response['path']=$outfile->stripTempPath();
                 $outfile->delete();
             }
         } else {
             GO::debug('Message is NOT encrypted');
         }
     }
 }