Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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');
 }
Ejemplo n.º 3
0
 /**
  * Method used to get a value for a specified key.
  *
  * @param string $key
  * @return string or false if the key wasn't found
  */
 public function get($key)
 {
     $db = Fz_Db::getConnection();
     $sql = 'SELECT `value` FROM `' . $this->getTableName() . '` WHERE `fz_info`.`key` = ?';
     $stmt = $db->prepare($sql);
     $stmt->execute(array($key));
     $result = $stmt->fetch(PDO::FETCH_ASSOC);
     return $result ? $result['value'] : false;
 }
Ejemplo n.º 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) {
         if ($file->notify_uploader) {
             $file->del_notif_sent = true;
             $file->save();
             $this->notifyDeletionByEmail($file);
         }
     }
 }
Ejemplo n.º 5
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);
         }
     }
 }
Ejemplo n.º 6
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');
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
 /**
  * Return the table object of the current row
  *
  * @return Fz_Table_Abstract
  */
 public function getTable()
 {
     return Fz_Db::getTable($this->_tableClass);
 }
Ejemplo n.º 9
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 
Ejemplo n.º 10
0
 /**
  * Check if we can connect to the database user factory
  *
  */
 public function checkUserFactoryDatabaseConf(&$errors, &$config)
 {
     $oldDb = option('db_conn');
     // save filez db connection
     if (!array_key_exists('db_use_global_conf', $config['user_factory_options']) || $config['user_factory_options']['db_use_global_conf'] == false) {
         try {
             $db = new PDO($config['user_factory_options']['db_server_dsn'], $config['user_factory_options']['db_server_user'], $config['user_factory_options']['db_server_password']);
             $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             $db->exec('SET NAMES \'utf8\'');
             option('db_conn', $db);
         } catch (Exception $e) {
             $errors[] = array('title' => 'Can\'t connect to the user database', 'msg' => $e->getMessage());
         }
     }
     try {
         $sql = 'SELECT * FROM ' . $config['user_factory_options']['db_table'] . ' WHERE ' . $config['user_factory_options']['db_username_field'] . ' LIKE \'%\'' . ' AND   ' . $config['user_factory_options']['db_password_field'] . ' LIKE \'%\'';
         try {
             $result = Fz_Db::findAssocBySQL($sql);
         } catch (Exception $e) {
             $errors[] = array('title' => 'Can\'t fetch data from the user table', 'msg' => $e->getMessage());
         }
     } catch (Exception $e) {
         $errors[] = array('title' => 'Can\'t find the user table', 'msg' => $e->getMessage());
     }
     option('db_conn', $oldDb);
     // restore filez db connection
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
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>";
        }
    }
}
Ejemplo n.º 13
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);
     }
 }
Ejemplo n.º 14
0
 /**
  * Retrieve a table row from a sql query
  *
  * @param   string  $sql
  * @return  Fz_Table_Row_Abstrat or null
  */
 public function findOneBySql($sql, $data = array())
 {
     return Fz_Db::findObjectBySQL($sql, $this->getRowClass(), $data);
 }
Ejemplo n.º 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');
 }
Ejemplo n.º 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');
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 18
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();
 }
Ejemplo n.º 19
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;
 }
Ejemplo n.º 20
0
 /**
  * Tells if filez table 'fz_file' (or 'Fichiers' if Fz1) exists on the
  * configured connection
  *
  * @return boolean
  */
 public function databaseExists()
 {
     $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') {
                         $res = Fz_Db::findAssocBySQL('SELECT `value` FROM `fz_info` WHERE `key`=\'db_version\'');
                         if (!empty($res)) {
                             return $res[0]['value'];
                         }
                     }
                 }
             }
         }
         return $version;
     }
 }
Ejemplo n.º 21
0
 /**
  * Return file uploader info 
  *
  * @return App_Model_User $user
  */
 public function getUploader()
 {
     return Fz_Db::getTable('User')->findById($this->created_by);
 }
Ejemplo n.º 22
0
 /**
  * Count the number of users
  * 
  * @return integer number of users
  */
 public function getNumberOfUsers()
 {
     $sql = 'SELECT COUNT(*) AS count FROM ' . $this->getTableName();
     $res = Fz_Db::findAssocBySQL($sql);
     return $res[0]['count'];
 }