Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->useSSL = AKFactory::get('kickstart.ftp.ssl', false);
     $this->passive = AKFactory::get('kickstart.ftp.passive', true);
     $this->host = AKFactory::get('kickstart.ftp.host', '');
     $this->port = AKFactory::get('kickstart.ftp.port', 21);
     if (trim($this->port) == '') {
         $this->port = 21;
     }
     $this->user = AKFactory::get('kickstart.ftp.user', '');
     $this->pass = AKFactory::get('kickstart.ftp.pass', '');
     $this->dir = AKFactory::get('kickstart.ftp.dir', '');
     $this->tempDir = AKFactory::get('kickstart.ftp.tempdir', '');
     $connected = $this->connect();
     if ($connected) {
         if (!empty($this->tempDir)) {
             $tempDir = rtrim($this->tempDir, '/\\') . '/';
             $writable = $this->isDirWritable($tempDir);
         } else {
             $tempDir = '';
             $writable = false;
         }
         if (!$writable) {
             // Default temporary directory is the current root
             $tempDir = function_exists('getcwd') ? getcwd() : dirname(__FILE__);
             if (empty($tempDir)) {
                 // Oh, we have no directory reported!
                 $tempDir = '.';
             }
             $absoluteDirToHere = $tempDir;
             $tempDir = rtrim(str_replace('\\', '/', $tempDir), '/');
             if (!empty($tempDir)) {
                 $tempDir .= '/';
             }
             $this->tempDir = $tempDir;
             // Is this directory writable?
             $writable = $this->isDirWritable($tempDir);
         }
         if (!$writable) {
             // Nope. Let's try creating a temporary directory in the site's root.
             $tempDir = $absoluteDirToHere . '/kicktemp';
             $this->createDirRecursive($tempDir, 0777);
             // Try making it writable...
             $this->fixPermissions($tempDir);
             $writable = $this->isDirWritable($tempDir);
         }
         // Was the new directory writable?
         if (!$writable) {
             // Let's see if the user has specified one
             $userdir = AKFactory::get('kickstart.ftp.tempdir', '');
             if (!empty($userdir)) {
                 // Is it an absolute or a relative directory?
                 $absolute = false;
                 $absolute = $absolute || substr($userdir, 0, 1) == '/';
                 $absolute = $absolute || substr($userdir, 1, 1) == ':';
                 $absolute = $absolute || substr($userdir, 2, 1) == ':';
                 if (!$absolute) {
                     // Make absolute
                     $tempDir = $absoluteDirToHere . $userdir;
                 } else {
                     // it's already absolute
                     $tempDir = $userdir;
                 }
                 // Does the directory exist?
                 if (is_dir($tempDir)) {
                     // Yeah. Is it writable?
                     $writable = $this->isDirWritable($tempDir);
                 }
             }
         }
         $this->tempDir = $tempDir;
         if (!$writable) {
             // No writable directory found!!!
             $this->setError(AKText::_('FTP_TEMPDIR_NOT_WRITABLE'));
         } else {
             AKFactory::set('kickstart.ftp.tempdir', $tempDir);
             $this->tempDir = $tempDir;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Public constructor. Tries to connect to the FTP server.
  */
 public function __construct()
 {
     parent::__construct();
     $this->useFTP = true;
     $this->useSSL = AKFactory::get('kickstart.ftp.ssl', false);
     $this->passive = AKFactory::get('kickstart.ftp.passive', true);
     $this->host = AKFactory::get('kickstart.ftp.host', '');
     $this->port = AKFactory::get('kickstart.ftp.port', 21);
     $this->user = AKFactory::get('kickstart.ftp.user', '');
     $this->pass = AKFactory::get('kickstart.ftp.pass', '');
     $this->dir = AKFactory::get('kickstart.ftp.dir', '');
     $this->tempDir = AKFactory::get('kickstart.ftp.tempdir', '');
     if (trim($this->port) == '') {
         $this->port = 21;
     }
     // If FTP is not configured, skip it altogether
     if (empty($this->host) || empty($this->user) || empty($this->pass)) {
         $this->useFTP = false;
     }
     // Try to connect to the FTP server
     $connected = $this->connect();
     // If the connection fails, skip FTP altogether
     if (!$connected) {
         $this->useFTP = false;
     }
     if ($connected) {
         if (!empty($this->tempDir)) {
             $tempDir = rtrim($this->tempDir, '/\\') . '/';
             $writable = $this->isDirWritable($tempDir);
         } else {
             $tempDir = '';
             $writable = false;
         }
         if (!$writable) {
             // Default temporary directory is the current root
             $tempDir = KSROOTDIR;
             if (empty($tempDir)) {
                 // Oh, we have no directory reported!
                 $tempDir = '.';
             }
             $absoluteDirToHere = $tempDir;
             $tempDir = rtrim(str_replace('\\', '/', $tempDir), '/');
             if (!empty($tempDir)) {
                 $tempDir .= '/';
             }
             $this->tempDir = $tempDir;
             // Is this directory writable?
             $writable = $this->isDirWritable($tempDir);
         }
         if (!$writable) {
             // Nope. Let's try creating a temporary directory in the site's root.
             $tempDir = $absoluteDirToHere . '/kicktemp';
             $trustMeIKnowWhatImDoing = 500 + 10 + 1;
             // working around overzealous scanners written by bozos
             $this->createDirRecursive($tempDir, $trustMeIKnowWhatImDoing);
             // Try making it writable...
             $this->fixPermissions($tempDir);
             $writable = $this->isDirWritable($tempDir);
         }
         // Was the new directory writable?
         if (!$writable) {
             // Let's see if the user has specified one
             $userdir = AKFactory::get('kickstart.ftp.tempdir', '');
             if (!empty($userdir)) {
                 // Is it an absolute or a relative directory?
                 $absolute = false;
                 $absolute = $absolute || substr($userdir, 0, 1) == '/';
                 $absolute = $absolute || substr($userdir, 1, 1) == ':';
                 $absolute = $absolute || substr($userdir, 2, 1) == ':';
                 if (!$absolute) {
                     // Make absolute
                     $tempDir = $absoluteDirToHere . $userdir;
                 } else {
                     // it's already absolute
                     $tempDir = $userdir;
                 }
                 // Does the directory exist?
                 if (is_dir($tempDir)) {
                     // Yeah. Is it writable?
                     $writable = $this->isDirWritable($tempDir);
                 }
             }
         }
         $this->tempDir = $tempDir;
         if (!$writable) {
             // No writable directory found!!!
             $this->setError(AKText::_('FTP_TEMPDIR_NOT_WRITABLE'));
         } else {
             AKFactory::set('kickstart.ftp.tempdir', $tempDir);
             $this->tempDir = $tempDir;
         }
     }
 }