Works on files encryption

This commit is contained in:
Regis Houssin 2009-12-16 15:49:47 +00:00
parent 7026f72827
commit 1b95553693

View File

@ -63,8 +63,8 @@
*/ */
// Define mandatory variables // Define mandatory variables
if (!defined("__SECURE_PATH__")) if (!defined("__CONFIG_SECURE_PATH__"))
define("__SECURE_PATH__", "{$_SERVER['DOCUMENT_ROOT']}/crypt/", TRUE); define("__CONFIG_SECURE_PATH__", DOL_DATA_ROOT."/admin/", TRUE);
// Include Extended Class // Include Extended Class
require_once('crypt_class.php'); require_once('crypt_class.php');
@ -83,42 +83,25 @@ require_once('crypt_class.php');
class easyfilecrypt extends CRYPT_CLASS { class easyfilecrypt extends CRYPT_CLASS {
// Set default variables for all new objects // Set default variables for all new objects
/**
* easyfilecrypt::$defaultcipher //!default cipher to use
*
* { default cipher to use }
*
*/
var $defaultcipher; var $defaultcipher;
/**
* easyfilecrypt::$defaultmode //!default encryption mode to use
*
* { default encryption mode to use }
*
*/
var $defaultmode; var $defaultmode;
// Our vars // Our vars
/**
* easyfilecrypt::$efc //!This is the array that will contain all needed variables
*
* { This is the array that will contain all needed variables }
*
*/
var $efc; var $efc;
/**
* easyfilecrypt::$_userfile //!This is the array that will contain all file upload variables
*
* { This is the array that will contain all file upload variables }
*
*/
var $_userfile; var $_userfile;
/**
* easyfilecrypt::$cfg_filename //!This is the array that will contain all file path
* var $_userfilepath;
* { Cipher config filename }
* //!Cipher config filename
*/
var $cfg_filename; var $cfg_filename;
/** /**
@ -140,7 +123,7 @@ class easyfilecrypt extends CRYPT_CLASS {
$this->defaultcipher = $this->cipher = 'twofish'; $this->defaultcipher = $this->cipher = 'twofish';
$this->defaultmode = $this->mode = 'cbc'; $this->defaultmode = $this->mode = 'cbc';
$this->cfg_filename = __SECURE_PATH__.".efc.config.php"; $this->cfg_filename = __CONFIG_SECURE_PATH__.".efc.config.php";
} }
@ -234,14 +217,14 @@ print_r($xfss[$this->cipher]);
// Set source and destination files name // Set source and destination files name
$src_filename = $this->_userfile['tmp_name']; $src_filename = $this->_userfile['tmp_name'];
$dst_filename = __SECURE_PATH__.$this->efc['name']; $dst_filename = $this->_userfilepath.$this->efc['name'];
// make sure file exists and is readable // make sure file exists and is readable
$msg = "encrypt_file: cannot read ".$this->_userfile['tmp_name']." "; $msg = "encrypt_file: cannot read ".$this->_userfile['tmp_name']." ";
if (!is_readable($src_filename)) if (!is_readable($src_filename))
trigger_error($msg, E_USER_ERROR); trigger_error($msg, E_USER_ERROR);
// touch destion file so it will exist when we check for it // touch destination file so it will exist when we check for it
@touch($dst_filename); @touch($dst_filename);
// can we write to it // can we write to it
@ -259,7 +242,7 @@ print_r($xfss[$this->cipher]);
$filecontents = fread($fp, filesize($src_filename)); $filecontents = fread($fp, filesize($src_filename));
fclose($fp); fclose($fp);
// open the destionation file for writing // open the destination file for writing
$dest_fp = fopen($dst_filename, w); $dest_fp = fopen($dst_filename, w);
// return false if unable to open file // return false if unable to open file
@ -292,7 +275,7 @@ print_r($xfss[$this->cipher]);
trigger_error('Decryption: cipher, mode, and key must be set before using this.', E_USER_ERROR); trigger_error('Decryption: cipher, mode, and key must be set before using this.', E_USER_ERROR);
// make sure file exists and is readable // make sure file exists and is readable
$src_filename = __SECURE_PATH__.$this->efc['name']; $src_filename = $this->_userfilepath.$this->efc['name'];
if (!is_readable($src_filename)) if (!is_readable($src_filename))
trigger_error('Encrypted data is corrupted: Not readable', E_USER_ERROR); trigger_error('Encrypted data is corrupted: Not readable', E_USER_ERROR);