Ejemplo n.º 1
0
 public function Test_of_encrypt_decrypt()
 {
     $original = "Este es el texto que quiero encriptar";
     $this->assertEqual(Ak::decrypt(Ak::encrypt($original)), $original);
     $key = Ak::randomString(20);
     $file = file_get_contents(__FILE__);
     $ecripted = Ak::encrypt($file, $key);
     $this->assertEqual(Ak::decrypt($ecripted, $key), $file);
 }
Ejemplo n.º 2
0
 function connect($base_dir = null)
 {
     static $ftp_conn, $_base_dir, $disconnected = false;
     if (!isset($ftp_conn) || $disconnected) {
         if (!defined('AK_FTP_PATH')) {
             trigger_error(Ak::t('You must set a valid FTP connection on AK_FTP_PATH in your config/config.php file'), E_USER_ERROR);
         } else {
             if (AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION && substr(AK_FTP_PATH, 0, 10) == 'PROTECTED:') {
                 // You should change the key bellow and encode this file if you are going to distribute applications
                 // The ideal protection would be to encode user configuration file.
                 $AK_FTP_PATH = Ak::decrypt(base64_decode(substr(AK_FTP_PATH, 10)), 'HR23JHR93JZ0ALi1UvTZ0ALi1UvTk7MD70');
                 $_pass_encoded = true;
             } else {
                 $AK_FTP_PATH = AK_FTP_PATH;
             }
             $f = parse_url($AK_FTP_PATH);
             if (@$f['scheme'] != 'ftps') {
                 $ftp_conn = isset($f['port']) ? ftp_connect($f['host'], $f['port']) : ftp_connect($f['host']);
             } else {
                 $ftp_conn = isset($f['port']) ? ftp_ssl_connect($f['host'], $f['port']) : ftp_ssl_connect($f['host']);
             }
             $f['user'] = str_replace('+', '@', @$f['user']);
             $login_result = ftp_login($ftp_conn, $f['user'], @$f['pass']);
             if (!$ftp_conn || !$login_result) {
                 AK_FTP_SHOW_ERRORS ? trigger_error(Ak::t('Could not connect to the FTP server'), E_USER_NOTICE) : null;
                 return false;
             }
             $_base_dir = isset($f['path']) ? '/' . trim($f['path'], '/') : '/';
             if (defined('AK_FTP_AUTO_DISCONNECT') && AK_FTP_AUTO_DISCONNECT) {
                 register_shutdown_function(array('AkFtp', 'disconnect'));
             }
             if (AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION && empty($_pass_encoded)) {
                 @register_shutdown_function(create_function('', "@Ak::file_put_contents(AK_CONFIG_DIR.DS.'config.php',\n                str_replace(AK_FTP_PATH,'PROTECTED:'.base64_encode(Ak::encrypt(AK_FTP_PATH,'HR23JHR93JZ0ALi1UvTZ0ALi1UvTk7MD70')),\n                Ak::file_get_contents(AK_CONFIG_DIR.DS.'config.php')));"));
             }
         }
     }
     if (isset($base_dir) && $base_dir === 'AK_DISCONNECT_FTP') {
         $disconnected = true;
         $base_dir = null;
     } else {
         $disconnected = false;
     }
     if (!isset($base_dir) && isset($_base_dir) && '/' . trim(ftp_pwd($ftp_conn), '/') != $_base_dir) {
         if (!@ftp_chdir($ftp_conn, $_base_dir) && AK_FTP_SHOW_ERRORS) {
             trigger_error(Ak::t('Could not change to the FTP base directory %directory', array('%directory' => $_base_dir)), E_USER_NOTICE);
         }
     } elseif (isset($base_dir)) {
         if (!ftp_chdir($ftp_conn, $base_dir) && AK_FTP_SHOW_ERRORS) {
             trigger_error(Ak::t('Could not change to the FTP directory %directory', array('%directory' => $base_dir)), E_USER_NOTICE);
         }
     }
     return $ftp_conn;
 }