Esempio n. 1
0
    public function actionData($params)
    {
        $response = array('success' => true, 'data' => array());
        try {
            $customCssFolder = new Folder(GO::config()->file_storage_path . 'customcss');
            if (!$customCssFolder->exists()) {
                $customCssFolder->create(0755);
            }
            $cssFile = new File(GO::config()->file_storage_path . 'customcss/style.css');
            $jsFile = new File(GO::config()->file_storage_path . 'customcss/javascript.js');
            if (Http::isPostRequest()) {
                if (isset($_POST['css'])) {
                    $cssFile->putContents($_POST['css']);
                }
                if (isset($_POST['javascript'])) {
                    $jsFile->putContents($_POST['javascript']);
                }
            }
            if ($cssFile->exists()) {
                $response['data']['css'] = $cssFile->getContents();
            } else {
                $response['data']['css'] = '/*
* Put custom styles here that will be applied to Group-Office. You can use the select file button to upload your logo and insert the URL in to this stylesheet.
*/

/* this will override the logo at the top right */
#headerLeft{
background-image:url(/insert/url/here) !important;
}

/* this will override the logo at the login screen */
.go-app-logo {
background-image:url(/insert/url/here) !important;
}';
            }
            if ($jsFile->exists()) {
                $response['data']['javascript'] = $jsFile->getContents();
            }
        } catch (Exception $e) {
            $response['feedback'] = $e->getMessage();
            $response['success'] = false;
        }
        echo $this->renderJson($response);
    }
Esempio n. 2
0
 /**
  * The code that needs to be called when the cron is running
  * 
  * If $this->enableUserAndGroupSupport() returns TRUE then the run function 
  * will be called for each $user. (The $user parameter will be given)
  * 
  * If $this->enableUserAndGroupSupport() returns FALSE then the 
  * $user parameter is null and the run function will be called only once.
  * 
  * @param CronJob $cronJob
  * @param User $user [OPTIONAL]
  */
 public function run(CronJob $cronJob, User $user = null)
 {
     GO::session()->runAsRoot();
     $licenseFile = \GO::getLicenseFile();
     $temporaryLicenseFile = new \GO\Base\Fs\File(GO::config()->file_storage_path . 'license/' . $licenseFile->name());
     if ($temporaryLicenseFile->exists()) {
         if (!$temporaryLicenseFile->move($licenseFile)) {
             throw new \Exception("Could not move license file to Group-Office root!");
         } else {
             if (!GO::scriptCanBeDecoded()) {
                 GO\Base\Mail\AdminNotifier::sendMail("Group-Office license invalid", "You attempted to install a license but the license file you provided didn't work. Please contant Intermesh about this error.");
             } else {
                 //add all users to the modules they have access too
                 \GO\Professional\License::autoConfigureModulePermissions();
                 GO\Base\Mail\AdminNotifier::sendMail("Group-Office license installed successfully!", "Your license was installed and the new users were automatically added to the App permissions if necessary.\n\nThank you for using Group-Office!");
             }
         }
     }
 }
Esempio n. 3
0
 protected function actionSaveToFile($params)
 {
     $message = new \GO\Base\Mail\Message();
     $alias = \GO\Email\Model\Alias::model()->findByPk($params['alias_id']);
     $message->handleEmailFormInput($params);
     $message->setFrom($alias->email, $alias->name);
     $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $params['save_to_path']);
     $fbs = new \Swift_ByteStream_FileByteStream($file->path(), true);
     $message->toByteStream($fbs);
     $response['success'] = $file->exists();
     return $response;
 }
Esempio n. 4
0
 /**
  * Public files are files stored in GO::config()->file_storage_path.'public'
  * They are publicly accessible.
  * Public files are cached
  * 
  * @param String $path 
  */
 protected function actionDownloadPublicFile($params)
 {
     $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . 'public/' . $params['path']);
     if ($file->exists()) {
         \GO\Base\Util\Http::outputDownloadHeaders($file, false, !empty($params['cache']));
         $file->output();
     } else {
         echo "File not found!";
     }
 }
Esempio n. 5
0
    /**
     * handleEmailFormInput
     * 
     * This method can be used in Models and Controllers. It puts the email body
     * and inline (image) attachments from the client in the message, which can
     * then be used for storage in the database or sending emails.
     * 
     * @param Array $params Must contain elements: body (string) and
     * 
     * inlineAttachments (string).
     */
    public function handleEmailFormInput($params)
    {
        if (!empty($params['subject'])) {
            $this->setSubject($params['subject']);
        }
        if (!empty($params['to'])) {
            $to = new EmailRecipients($params['to']);
            foreach ($to->getAddresses() as $email => $personal) {
                $this->addTo($email, $personal);
            }
        }
        if (!empty($params['cc'])) {
            $cc = new EmailRecipients($params['cc']);
            foreach ($cc->getAddresses() as $email => $personal) {
                $this->addCc($email, $personal);
            }
        }
        if (!empty($params['bcc'])) {
            $bcc = new EmailRecipients($params['bcc']);
            foreach ($bcc->getAddresses() as $email => $personal) {
                $this->addBcc($email, $personal);
            }
        }
        if (isset($params['alias_id'])) {
            $alias = \GO\Email\Model\Alias::model()->findByPk($params['alias_id']);
            $this->setFrom($alias->email, $alias->name);
            if (!empty($params['notification'])) {
                $this->setReadReceiptTo(array($alias->email => $alias->name));
            }
        }
        if (isset($params['priority'])) {
            $this->setPriority($params['priority']);
        }
        if (isset($params['in_reply_to'])) {
            $headers = $this->getHeaders();
            $headers->addTextHeader('In-Reply-To', $params['in_reply_to']);
            $headers->addTextHeader('References', $params['in_reply_to']);
        }
        if ($params['content_type'] == 'html') {
            $params['htmlbody'] = $this->_embedPastedImages($params['htmlbody']);
            //inlineAttachments is an array(array('url'=>'',tmp_file=>'relative/path/');
            if (!empty($params['inlineAttachments'])) {
                $inlineAttachments = json_decode($params['inlineAttachments']);
                /* inline attachments must of course exist as a file, and also be used in
                 * the message body
                 */
                if (count($inlineAttachments)) {
                    foreach ($inlineAttachments as $ia) {
                        //$tmpFile = new \GO\Base\Fs\File(\GO::config()->tmpdir.$ia['tmp_file']);
                        if (empty($ia->tmp_file)) {
                            continue;
                            // Continue to the next inline attachment for processing.
                            //throw new Exception("No temp file for inline attachment ".$ia->name);
                        }
                        $path = empty($ia->from_file_storage) ? \GO::config()->tmpdir . $ia->tmp_file : \GO::config()->file_storage_path . $ia->tmp_file;
                        $tmpFile = new \GO\Base\Fs\File($path);
                        if ($tmpFile->exists()) {
                            //Different browsers reformat URL's to absolute or relative. So a pattern match on the filename.
                            //$filename = rawurlencode($tmpFile->name());
                            $result = preg_match('/="([^"]*' . preg_quote($ia->token) . '[^"]*)"/', $params['htmlbody'], $matches);
                            if ($result) {
                                $img = \Swift_EmbeddedFile::fromPath($tmpFile->path());
                                $img->setContentType($tmpFile->mimeType());
                                $contentId = $this->embed($img);
                                //$tmpFile->delete();
                                $params['htmlbody'] = \GO\Base\Util\String::replaceOnce($matches[1], $contentId, $params['htmlbody']);
                            } else {
                                //this may happen when an inline image was attached but deleted in the editor afterwards.
                                //
                                //throw new \Exception("Error: inline attachment could not be found in text: ".$ia->token);
                            }
                        } else {
                            throw new \Exception("Error: inline attachment missing on server: " . $tmpFile->stripTempPath() . ".<br /><br />The temporary files folder is cleared on each login. Did you relogin?");
                        }
                    }
                }
            }
            $params['htmlbody'] = $this->_fixRelativeUrls($params['htmlbody']);
            $htmlTop = '<html>
<head>
<style type="text/css">
body,p,td,div,span{
	' . \GO::config()->html_editor_font . '
};
body p{
	margin:0px;
}
</style>
</head>
<body>';
            $htmlBottom = '</body></html>';
            $this->setHtmlAlternateBody($htmlTop . $params['htmlbody'] . $htmlBottom);
        } else {
            $this->setBody($params['plainbody'], 'text/plain');
        }
        if (!empty($params['attachments'])) {
            $attachments = json_decode($params['attachments']);
            foreach ($attachments as $att) {
                $path = empty($att->from_file_storage) ? \GO::config()->tmpdir . $att->tmp_file : \GO::config()->file_storage_path . $att->tmp_file;
                $tmpFile = new \GO\Base\Fs\File($path);
                if ($tmpFile->exists()) {
                    $file = \Swift_Attachment::fromPath($tmpFile->path());
                    $file->setContentType($tmpFile->mimeType());
                    $file->setFilename($att->fileName);
                    $this->attach($file);
                    //$tmpFile->delete();
                } else {
                    throw new \Exception("Error: attachment missing on server: " . $tmpFile->stripTempPath() . ".<br /><br />The temporary files folder is cleared on each login. Did you relogin?");
                }
            }
        }
    }
Esempio n. 6
0
 /**
  * Output the right headers for outputting file data to a browser.
  * 
  * @param \GO\Base\Fs\File $file Use \GO\Base\Fs\MemoryFile for outputting variables
  * @param boolean $inline
  * @param boolean $cache Cache the file for one day in the browser.
  * @param array $extraHeaders  Key value array for extra headers
  */
 public static function outputDownloadHeaders(\GO\Base\Fs\File $file, $inline = true, $cache = false, $extraHeaders = array())
 {
     header('Content-Transfer-Encoding: binary');
     $disposition = $inline ? 'inline' : 'attachment';
     if ($cache) {
         header("Expires: " . date("D, j M Y G:i:s ", time() + 86400) . 'GMT');
         //expires in 1 day
         header('Cache-Control: cache');
         header('Pragma: cache');
     }
     if (Http::isInternetExplorer()) {
         header('Content-Type: application/download');
         header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($file->name()) . '"');
         if (!$cache) {
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
         }
     } else {
         header('Content-Type: ' . $file->mimeType());
         header('Content-Disposition: ' . $disposition . '; filename="' . $file->name() . '"');
         if (!$cache) {
             header('Pragma: no-cache');
         }
     }
     if ($file->exists()) {
         if ($file->extension() != 'zip') {
             //Don't set content lenght for zip files because gzip of apache will corrupt the download. http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php
             header('Content-Length: ' . $file->size());
         }
         header("Last-Modified: " . gmdate("D, d M Y H:i:s", $file->mtime()) . " GMT");
         header("ETag: " . $file->md5Hash());
     }
     foreach ($extraHeaders as $header => $value) {
         header($header . ': ' . $value);
     }
 }
Esempio n. 7
0
 protected function actionCompress($params)
 {
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '512M');
     $sources = json_decode($params['compress_sources'], true);
     $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']);
     $destinationFolder = \GO\Files\Model\Folder::model()->findByPk($params['destination_folder_id']);
     $archiveFile = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $destinationFolder->path . '/' . $params['archive_name'] . '.zip');
     if ($archiveFile->exists()) {
         throw new \Exception(sprintf(\GO::t('filenameExists', 'files'), $archiveFile->stripFileStoragePath()));
     }
     $sourceObjects = array();
     for ($i = 0; $i < count($sources); $i++) {
         $path = \GO::config()->file_storage_path . $sources[$i];
         $sourceObjects[] = \GO\Base\Fs\Base::createFromPath($path);
     }
     if (\GO\Base\Fs\Zip::create($archiveFile, $workingFolder->fsFolder, $sourceObjects)) {
         \GO\Files\Model\File::importFromFilesystem($archiveFile);
         $response['success'] = true;
     } else {
         throw new \Exception("ZIP creation failed");
     }
     return $response;
 }