Example #1
0
 public function indexAction()
 {
     // Display the send_us_a_file.html page if the "Send us a file" feature is on and the user is not logged in.
     if (fz_config_get('app', 'send_us_a_file_feature') && false == $this->getUser()) {
         set('start_from', Zend_Date::now()->get(Zend_Date::DATE_SHORT));
         $maxUploadSize = min(Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('upload_max_filesize')), Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('post_max_size')));
         set('max_upload_size', $maxUploadSize);
         return html('send_us_a_file.html');
     }
     $this->secure();
     $user = $this->getUser();
     $freeSpaceLeft = max(0, Fz_Db::getTable('File')->getRemainingSpaceForUser($user));
     $maxUploadSize = min(Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('upload_max_filesize')), Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('post_max_size')), $freeSpaceLeft);
     $progressMonitor = fz_config_get('app', 'progress_monitor');
     $progressMonitor = new $progressMonitor();
     set('upload_id', md5(uniqid(mt_rand(), true)));
     set('start_from', Zend_Date::now()->get(Zend_Date::DATE_SHORT));
     set('refresh_rate', 1200);
     set('files', Fz_Db::getTable('File')->findByOwnerOrderByUploadDateDesc($user));
     set('use_progress_bar', $progressMonitor->isInstalled());
     set('upload_id_name', $progressMonitor->getUploadIdName());
     set('free_space_left', $freeSpaceLeft);
     set('max_upload_size', $maxUploadSize);
     set('sharing_destinations', fz_config_get('app', 'sharing_destinations', array()));
     set('disk_usage', array('space' => '<b id="disk-usage-value">' . bytesToShorthand(Fz_Db::getTable('File')->getTotalDiskSpaceByUser($user)) . '</b>', 'quota' => fz_config_get('app', 'user_quota')));
     return html('main/index.php');
 }
Example #2
0
 /**
  * Return the current database version
  *
  * @return string or false if database doesn't exist
  */
 public function getCurrentVersion()
 {
     $sql = 'SELECT table_name ' . 'FROM information_schema.tables ' . 'WHERE table_name=\'fz_file\'' . '  or  table_name=\'fz_info\'' . '  or  table_name=\'Fichiers\'';
     $res = Fz_Db::findAssocBySQL($sql);
     if (count($res) == 0) {
         return false;
     } else {
         $version = false;
         foreach ($res as $table) {
             if ($table['table_name'] == 'Fichiers') {
                 return '1.2';
                 // TODO add more check
             } else {
                 if ($table['table_name'] == 'fz_file') {
                     $version = '2.0.0';
                 } else {
                     if ($table['table_name'] == 'fz_info') {
                         return Fz_Db::getTable('Info')->getDatabaseVersion();
                     }
                 }
             }
         }
         return $version;
     }
 }
Example #3
0
 /**
  * Action called to clean expired files and send mail to those who will be
  * in the next 2 days. This action is meant to be called from a cron script.
  * It should not respond any output except PHP execution errors. Everything
  * else is logged in 'filez-cron.log' and 'filez-cron-errors.log' files in
  * the configured log directory.
  */
 public function checkFilesAction()
 {
     // Delete files whose lifetime expired
     Fz_Db::getTable('File')->deleteExpiredFiles();
     // Send mail for files which will be deleted in less than 2 days
     $days = fz_config_get('cron', 'days_before_expiration_mail');
     foreach (Fz_Db::getTable('File')->findFilesToBeDeleted($days) as $file) {
         if ($file->notify_uploader) {
             $file->del_notif_sent = true;
             $file->save();
             $this->notifyDeletionByEmail($file);
         }
     }
 }
Example #4
0
 /**
  * Action called to clean expired files and send mail to those who will be
  * in the next 2 days. This action is meant to be called from a cron script.
  * It should not respond any output except PHP execution errors. Everything
  * else is logged in 'filez-cron.log' and 'filez-cron-errors.log' files in
  * the configured log directory.
  */
 public function checkFilesAction()
 {
     // Delete files whose lifetime expired
     Fz_Db::getTable('File')->deleteExpiredFiles();
     // Send mail for files which will be deleted in less than 2 days
     $days = fz_config_get('cron', 'days_before_expiration_mail');
     foreach (Fz_Db::getTable('File')->findFilesToBeDeleted($days) as $file) {
         // TODO improve the SQL command to retrieve uploader email at the same time
         //      to reduce the # of request made by notifyDeletionByEmail
         if ($file->notify_uploader) {
             $file->del_notif_sent = true;
             $file->save();
             $this->notifyDeletionByEmail($file);
         }
     }
 }
Example #5
0
 public function indexAction()
 {
     $this->secure();
     $user = $this->getUser();
     $freeSpaceLeft = max(0, Fz_Db::getTable('File')->getRemainingSpaceForUser($user));
     $maxUploadSize = min(Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('upload_max_filesize')), Fz_Db::getTable('File')->shorthandSizeToBytes(ini_get('post_max_size')), $freeSpaceLeft);
     $progressMonitor = fz_config_get('app', 'progress_monitor');
     $progressMonitor = new $progressMonitor();
     set('upload_id', md5(uniqid(mt_rand(), true)));
     set('start_from', Zend_Date::now()->get(Zend_Date::DATE_SHORT));
     set('refresh_rate', 1200);
     set('files', Fz_Db::getTable('File')->findByOwnerOrderByUploadDateDesc($user));
     set('use_progress_bar', $progressMonitor->isInstalled());
     set('upload_id_name', $progressMonitor->getUploadIdName());
     set('free_space_left', $freeSpaceLeft);
     set('max_upload_size', $maxUploadSize);
     return html('main/index.php');
 }
Example #6
0
 /**
  * Return the current user profile
  */
 protected function getUser()
 {
     $auth = $this->getAuthHandler();
     $factory = $this->getUserFactory();
     if (self::$_user === null && $auth->isSecured()) {
         self::$_user = Fz_Db::getTable('User')->findByUsername($auth->getUserId());
         if (!$factory->isInternal()) {
             if (self::$_user === null) {
                 self::$_user = new App_Model_User();
             }
             // Update fields
             $userData = $factory->findById($auth->getUserId());
             self::$_user->username = $userData['id'];
             self::$_user->email = $userData['email'];
             self::$_user->firstname = $userData['firstname'];
             self::$_user->lastname = $userData['lastname'];
             self::$_user->save();
             // will issue an update or insert only if a property changed
         }
     }
     return self::$_user;
 }
Example #7
0
 /**
  * Return file uploader info 
  *
  * @return App_Model_User $user
  */
 public function getUploader()
 {
     return Fz_Db::getTable('User')->findById($this->created_by);
 }
Example #8
0
 /**
  * Notify the file's owner by email that its file has been downloaded
  *
  * @param App_Model_File $file
  */
 private function sendFileDownloadedMail(App_Model_File $file)
 {
     if (!$file->notify_uploader) {
         return;
     }
     // find user IP
     // TODO: extract this function to generic place
     $ipaddress = '';
     if ($_SERVER['HTTP_CLIENT_IP']) {
         $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
     } else {
         if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
             $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } else {
             if ($_SERVER['HTTP_X_FORWARDED']) {
                 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
             } else {
                 if ($_SERVER['HTTP_FORWARDED_FOR']) {
                     $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
                 } else {
                     if ($_SERVER['HTTP_FORWARDED']) {
                         $ipaddress = $_SERVER['HTTP_FORWARDED'];
                     } else {
                         if ($_SERVER['REMOTE_ADDR']) {
                             $ipaddress = $_SERVER['REMOTE_ADDR'];
                         } else {
                             $ipaddress = 'UNKNOWN';
                         }
                     }
                 }
             }
         }
     }
     // Send confirmation mail
     $user = Fz_Db::getTable('User')->findById($file->created_by);
     // I don't get why $user = $this->getUser (); doesn't work ???
     $mail = $this->createMail();
     $mail->addTo($user->email);
     $mail->addTo($user->email, $user->firstname . ' ' . $user->lastname);
     $subject = __r('[FileZ] "%file_name%" downloaded', array('file_name' => $file->file_name));
     $msg = __r('email_file_downloaded (%file_name%, %file_url%, %sender%, %ip%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'sender' => $user, 'ip' => $ipaddress));
     $mail->setBodyText($msg);
     $mail->setSubject($subject);
     $mail->setReplyTo($user->email, $user);
     $mail->clearFrom();
     $mail->setFrom(fz_config_get('email', 'from_email'), fz_config_get('email', 'from_name'));
     try {
         $mail->send();
     } catch (Exception $e) {
         fz_log('Can\'t send email "File Downloaded" : ' . $e, FZ_LOG_ERROR);
     }
 }
Example #9
0
 /**
  * Retrieve the requested file from database.
  * If the file isn't found, the action is stopped and a 404 error is returned.
  *
  * @return App_Model_File
  */
 protected function getFile()
 {
     $file = Fz_Db::getTable('File')->findByHash(params('file_hash'));
     if ($file === null) {
         halt(NOT_FOUND, __('There is no file for this code'));
     }
     return $file;
 }
Example #10
0
 /**
  * Tells if users are retrieved from the build-in user table or from an external source
  * 
  * @return boolean
  */
 public function isInternal()
 {
     return $this->getOption('db_table') === Fz_Db::getTable('User')->getTableName();
 }
Example #11
0
 /**
  * Return the table object of the current row
  *
  * @return Fz_Table_Abstract
  */
 public function getTable()
 {
     return Fz_Db::getTable($this->_tableClass);
 }
Example #12
0
        echo $msg;
        ?>
</pre>
        <?php 
    }
    ?>
        </div>
      <?php 
}
?>

      <?php 
if (isset($user)) {
    ?>
        <p id="disk-usage"><?php 
    echo __r('Using %space% of %quota%', array('space' => '<b id="disk-usage-value">' . bytesToShorthand(Fz_Db::getTable('File')->getTotalDiskSpaceByUser($user)) . '</b>', 'quota' => fz_config_get('app', 'user_quota')));
    ?>
.
        </p>
      <?php 
}
?>

      <div id="support">
        <?php 
if (fz_config_get('looknfeel', 'help_url')) {
    ?>
          <a href="<?php 
    echo url_for(fz_config_get('looknfeel', 'help_url'));
    ?>
" class="help" target="#_blank"><?php 
Example #13
0
 /**
  * Function called on file upload success, a default message is returned
  * to the user.
  *
  * @param App_Model_File $file
  */
 private function onFileUploadSuccess(App_Model_File $file)
 {
     $user = $this->getUser();
     $response['status'] = 'success';
     $response['statusText'] = __('The file was successfully uploaded');
     $response['html'] = partial('main/_file_row.php', array('file' => $file));
     $response['disk_usage'] = bytesToShorthand(max(0, Fz_Db::getTable('File')->getTotalDiskSpaceByUser($user)));
     return $this->returnData($response);
 }
Example #14
0
function check_cron()
{
    if (!option('installing')) {
        $lastCron = Fz_Db::getTable('Info')->getLastCronTimestamp();
        $freq = fz_config_get('cron', 'frequency');
        if (strtotime($freq . " " . $lastCron) <= time()) {
            Fz_Db::getTable('Info')->setLastCronTimestamp(date('Y-m-d H:i:s'));
            return "<script src='" . url_for('admin/checkFiles') . "'></script>";
        }
    }
}
Example #15
0
 /**
  * List all users in filez DB.
  * Called on /admin/users
  * @param 
  * @return list of users
  *
  */
 public function listUsers()
 {
     return Fz_Db::getTable('User');
 }
Example #16
0
 /**
  * Action called to delete a user
  */
 public function deleteAction()
 {
     // TODO prevent CSRF
     $this->secure('admin');
     $user = Fz_Db::getTable('User')->findById(params('id'));
     if ($user) {
         $user->delete();
     }
     return redirect_to('/admin/users');
 }
Example #17
0
 /**
  * Function used to get the user disk usage
  *
  * @return disk space used by the user
  */
 public function getDiskUsage()
 {
     return bytesToShorthand(Fz_Db::getTable('File')->getTotalDiskSpaceByUser($this));
 }