示例#1
1
 /**
  * Establece la conceccion al servidor de FTP
  *
  * @param $servidor_ftp=host  $user=usuario $pass=password $modo=de conexxion por defecto en true
  * @return $id_con identificador de la conexion FTP
  */
 function conexion($servidor_ftp, $user, $pass, $modo = true, $puerto = 21, $tiempoEspera = 360)
 {
     // configurar una conexion o abortar
     // el arroba es para evitar los warning que salgan por pantalla
     if (empty($tiempoEspera)) {
         $tiempoEspera = 90;
     }
     @($id_con = ftp_connect($servidor_ftp, $puerto, $tiempoEspera));
     if (!$id_con || !isset($id_con)) {
         return false;
         //return false conexion no establecida
     } else {
         // Abrir la session con usuario y contraseña
         // el arroba es para evitar los warning que salgan por pantalla
         @($login_result = ftp_login($id_con, $user, $pass));
         if (!$login_result || !isset($login_result)) {
             return false;
             //return false el logueo no fue establecida
         }
     }
     // Habilita o deshabilita el modo pasivo. En modo pasivo, las conexiones de datos son
     // iniciadas por el cliente, en lugar del servidor. Puede requerirse si el cliente se
     // encuentra detrás de un firewall. ftp_pasv() únicamente puede llamarse después de
     // un inicio de sesión exitoso, de otra forma fallará.
     ftp_pasv($id_con, $modo);
     // Verifico que type UNIX (tambien lo toman como valor la mayoria de los servidores windows)
     $res = ftp_systype($id_con);
     //if($res != "UNIX") return false;
     // Se conect OK
     return $id_con;
 }
示例#2
0
 public function connect()
 {
     $this->printLog("Connect");
     if ($this->conn_id = ftp_connect($this->host, $this->port, $this->timeout)) {
         if (ftp_login($this->conn_id, $this->user, $this->pass)) {
             $this->updateState(PR_FTP_STATE_LOGGED_IN);
             if ($status = ftp_chdir($this->conn_id, $this->cur_path)) {
                 $this->updateState(PR_FTP_STATE_TARGETED);
                 $this->updateStatus(PR_FTP_STATUS_READY);
                 $this->systype = ftp_systype($this->conn_id);
                 // TODO: make specific OS dependednt things
                 $this->printLog("OS: " . $this->systype . " " . ftp_pwd($this->conn_id));
                 // TODO: pass the mode into the module
                 ftp_pasv($this->conn_id, true);
                 unset($this->listing_cache);
                 $this->listing_cache = array();
             } else {
                 $this->updateState(PR_FTP_STATE_ERROR);
             }
         } else {
             $this->updateState(PR_FTP_STATE_DISCONNECTED);
             $this->updateStatus(PR_FTP_STATUS_NOT_READY);
         }
     } else {
         $this->updateState(PR_FTP_STATE_DISCONNECTED);
         $this->updateStatus(PR_FTP_STATUS_NOT_READY);
     }
 }
示例#3
0
 function connect($ssl = false)
 {
     if (!is_bool($ssl)) {
         $ssl = false;
     }
     $this->ssl = $ssl;
     if (!$this->ssl) {
         if (!($this->_connectid = ftp_connect($this->_host, $this->_port, $this->_timeout))) {
             $this->error[] = "Błąd połączenia z serwerem FTP " . $this->_host;
             return false;
         }
     } elseif (function_exists("ftp_ssl_connect")) {
         if (!($this->_connectid = ftp_ssl_connect($this->_host, $this->_port, $this->_timeout))) {
             $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " (SSL)";
             return false;
         }
     } else {
         $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " (nieznany typ połączenia)";
         return false;
     }
     if (ftp_login($this->_connectid, $this->_user, $this->_pass)) {
         ftp_pasv($this->_connectid, (bool) $this->passive);
         $this->system_type = ftp_systype($this->_connectid);
         return true;
     } else {
         $this->error = "Błąd połączenia z serwerem FTP " . $this->_host . " - błędny login";
         return false;
     }
 }
示例#4
0
文件: FTP.php 项目: thaian2009/php
 /**
  * __construct
  * 
  * @param string $user
  * @param string $pass
  * @param string $host
  * @param int $port
  */
 public function __construct($user = '******', $pass = '', $host = 'localhost', $port = 21)
 {
     $this->_res = ftp_connect($host, $port, 10);
     ftp_login($this->_res, $user, $pass);
     ftp_pasv($this->_res, true);
     Registry::set('sysType', strtoupper(substr(ftp_systype($this->_res), 0, 3)) == 'WIN' ? 'WIN' : 'NIX');
     // URL
     //$this->_url = 'ftp://' . $user . ':' . $pass . '@' . $host . ':' . $port;
 }
示例#5
0
文件: FTP.php 项目: Halilli/gmanager
 /**
  * __construct
  * 
  * @param string $user
  * @param string $pass
  * @param string $host
  * @param int $port
  */
 public function __construct($user = '******', $pass = '', $host = 'localhost', $port = 21)
 {
     $host = NetworkWrapper::set($host);
     $this->_res = ftp_connect($host, $port, 10);
     ftp_login($this->_res, $user, $pass);
     ftp_pasv($this->_res, true);
     $this->_setSysType(ftp_systype($this->_res));
     // URL
     //$this->_url = 'ftp://' . $user . ':' . $pass . '@' . $host . ':' . $port;
 }
示例#6
0
 public function connect()
 {
     $this->conn_id = ftp_connect($this->host, $this->port, 30);
     if ($this->conn_id === false) {
         return false;
     }
     $result = ftp_login($this->conn_id, $this->username, $this->password);
     if ($result == true) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         if ($this->passive == true) {
             ftp_pasv($this->conn_id, true);
         } else {
             ftp_pasv($this->conn_id, false);
         }
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } else {
         return false;
     }
 }
示例#7
0
文件: FTP.php 项目: mahlstrom/remote
 /**
  * @param $hostName
  * @param $user
  * @param $password
  * @param int $port
  * @param int $timeout
  * @throws Exceptions\RemoteConnectException
  * @throws Exceptions\RemoteLoginException
  */
 public function __construct($hostName, $user, $password, $port = 21, $timeout = 10)
 {
     $this->hostname = $hostName;
     $this->user = $user;
     $this->password = $password;
     $this->conn_id = ftp_connect($hostName, $port, $timeout);
     if (!$this->conn_id) {
         unset($this);
         throw new Exceptions\RemoteConnectException($hostName . ' is dead');
     }
     $loginResult = @ftp_login($this->conn_id, $user, $password);
     if (!$loginResult) {
         throw new RemoteLoginException();
     }
     $this->system = ftp_systype($this->conn_id);
     $this->userRoot = $this->pwd();
     if (substr($this->userRoot, -1, 1) != '/') {
         $this->userRoot .= '/';
     }
     return true;
 }
示例#8
0
 public function connect()
 {
     $time_start = time();
     $this->conn_id = ftp_connect($this->host, $this->port, 20);
     if ($this->conn_id) {
         $result = ftp_login($this->conn_id, $this->username, $this->password);
     }
     if (!empty($result)) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         ftp_pasv($this->conn_id, $this->passive);
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } elseif (time() - $time_start > 19) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             $updraftplus_admin->logged[] = sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP');
         } else {
             global $updraftplus;
             $updraftplus->log(sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP'), 'error');
         }
     }
     return false;
 }
示例#9
0
文件: Ftp.php 项目: nguyen113/Rai5
 /**
  *
  * @access	public
  * @return	@api
  */
 public function isWindows()
 {
     return 'Windows_NT' === ftp_systype($this->_conn);
 }
示例#10
0
 /**
  * get OS type
  *
  * @return string
  */
 function getSystemType()
 {
     if ($this->sysType) {
         return $this->sysType;
     }
     if ($this->checkFtp()) {
         $this->sysType = @ftp_systype($this->ftp);
     } else {
         if (!$this->FileManager->ftpHost) {
             $this->sysType = function_exists('php_uname') ? php_uname() : PHP_OS;
         }
     }
     if ($this->sysType) {
         if (!$this->FileManager->hideSystemType) {
             $this->addMsg("System type is {$this->sysType}");
         }
         return $this->sysType;
     }
     $this->addMsg('Could not get system type', 'error');
     return false;
 }
示例#11
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function upload(&$out)
 {
     set_time_limit(0);
     global $restore;
     global $file;
     global $file_name;
     global $folder;
     if (!$folder) {
         if (substr(php_uname(), 0, 7) == "Windows") {
             $folder = '/.';
         } else {
             $folder = '/';
         }
     } else {
         $folder = '/' . $folder;
     }
     if ($restore != '') {
         //$file=ROOT.'saverestore/'.$restore;
         $file = $restore;
     } elseif ($file != '') {
         copy($file, ROOT . 'saverestore/' . $file_name);
         //$file=ROOT.'saverestore/'.$file_name;
         $file = $file_name;
     }
     umask(0);
     @mkdir(ROOT . 'saverestore/temp', 0777);
     if ($file != '') {
         // && mkdir(ROOT.'saverestore/temp', 0777)
         chdir(ROOT . 'saverestore/temp');
         if (substr(php_uname(), 0, 7) == "Windows") {
             // for windows only
             exec(DOC_ROOT . '/gunzip ../' . $file, $output, $res);
             exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res);
             //@unlink('../'.str_replace('.tgz', '.tar', $file));
         } else {
             exec('tar xzvf ../' . $file, $output, $res);
         }
         @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php');
         //print_r($output);exit;
         if (1) {
             chdir('../../');
             if ($this->method == 'direct') {
                 // UPDATING FILES DIRECTLY
                 $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1);
                 // restore all files
             } elseif ($this->method == 'ftp') {
                 // UPDATING FILES BY FTP
                 $conn_id = @ftp_connect($this->config['FTP_HOST']);
                 if ($conn_id) {
                     $login_result = @ftp_login($conn_id, $this->config['FTP_USERNAME'], $this->config['FTP_PASSWORD']);
                     if ($login_result) {
                         $systyp = ftp_systype($conn_id);
                         if (@ftp_chdir($conn_id, $this->config['FTP_FOLDER'] . 'saverestore')) {
                             @ftp_chdir($conn_id, $this->config['FTP_FOLDER']);
                             // ok, we're in. updating!
                             $log = '';
                             $files = $this->getLocalFilesTree(ROOT . 'saverestore/temp' . $folder, '.+', 'installed', $log, 0);
                             $total = count($files);
                             $modules_processed = array();
                             for ($i = 0; $i < $total; $i++) {
                                 $file = $files[$i];
                                 $file['REMOTE_FILENAME'] = preg_replace('/^' . preg_quote(ROOT . 'saverestore/temp/' . $folder, '/') . '/is', $this->config['FTP_FOLDER'], $file['FILENAME']);
                                 $file['REMOTE_FILENAME'] = str_replace('//', '/', $file['REMOTE_FILENAME']);
                                 $res_f = $this->ftpput($conn_id, $file['REMOTE_FILENAME'], $file['FILENAME'], FTP_BINARY);
                                 if (preg_match('/\\.class\\.php$/', basename($file['FILENAME'])) && !$modules_processed[dirname($file['REMOTE_FILENAME'])]) {
                                     // if this a module then we should update attributes for folder and remove 'installed' file
                                     $modules_processed[dirname($file['REMOTE_FILENAME'])] = 1;
                                     @ftp_site($conn_id, "CHMOD 0777 " . dirname($file['REMOTE_FILENAME']));
                                     @ftp_delete($conn_id, dirname($file['REMOTE_FILENAME']) . '/installed');
                                 }
                             }
                         } else {
                             $out['FTP_ERR'] = 'Incorrect folder (' . $ftp_folder . ')';
                         }
                     } else {
                         $out['FTP_ERR'] = 'Incorrect username/password';
                     }
                     ftp_close($conn_id);
                 } else {
                     $out['FTP_ERR'] = 'Cannot connect to host (' . $ftp_host . ')';
                     $this->redirect("?err_msg=" . urlencode($out['FTP_ERR']));
                 }
             }
             //if (is_dir(ROOT.'saverestore/temp/'.$folder.'modules')) {
             // code restore
             $source = ROOT . 'modules';
             if ($dir = @opendir($source)) {
                 while (($file = readdir($dir)) !== false) {
                     if (Is_Dir($source . "/" . $file) && $file != '.' && $file != '..') {
                         // && !file_exists($source."/".$file."/installed")
                         @unlink(ROOT . "modules/" . $file . "/installed");
                     }
                 }
             }
             @unlink(ROOT . "modules/control_modules/installed");
             @SaveFile(ROOT . 'reboot', 'updated');
             //}
             if (file_exists(ROOT . 'saverestore/temp' . $folder . '/dump.sql')) {
                 // data restore
                 $this->restoredatabase(ROOT . 'saverestore/temp' . $folder . '/dump.sql');
             }
             $this->config['LATEST_UPDATED_ID'] = $out['LATEST_ID'];
             $this->saveConfig();
             $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!"));
         }
     }
     /*
          require 'Tar.php';
          $tar_object = new Archive_Tar($file);
          if ($tar_object->extract(ROOT.'skins/'.$basename)) {
           $out['OK_EXT']=1;
          } else {
           $out['ERR_FORMAT']=1;
          }
     */
 }
示例#12
0
 /**
  * Facade for ftp_systype().
  *
  * @param resource $ftp_stream The ftp resource.
  *
  * @return boolean True on ftp systype.
  */
 public function systype($ftp_stream)
 {
     return ftp_systype($ftp_stream);
 }
示例#13
0
文件: ftp.php 项目: luozhanhong/share
 /**
  *
  * 返回远程 FTP 服务器的操作系统类型
  *
  * @return string
  */
 public static function systype()
 {
     return ftp_systype(self::$resource);
 }
示例#14
0
 /**
  * @param $job_object
  * @return bool
  */
 public function job_run_archive(BackWPup_Job $job_object)
 {
     $job_object->substeps_todo = 2 + $job_object->backup_filesize;
     if ($job_object->steps_data[$job_object->step_working]['SAVE_STEP_TRY'] != $job_object->steps_data[$job_object->step_working]['STEP_TRY']) {
         $job_object->log(sprintf(__('%d. Try to send backup file to an FTP server&#160;&hellip;', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
     }
     if (!empty($job_object->job['ftpssl'])) {
         //make SSL FTP connection
         if (function_exists('ftp_ssl_connect')) {
             $ftp_conn_id = ftp_ssl_connect($job_object->job['ftphost'], $job_object->job['ftphostport'], $job_object->job['ftptimeout']);
             if ($ftp_conn_id) {
                 $job_object->log(sprintf(__('Connected via explicit SSL-FTP to server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_NOTICE);
             } else {
                 $job_object->log(sprintf(__('Cannot connect via explicit SSL-FTP to server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_ERROR);
                 return FALSE;
             }
         } else {
             $job_object->log(__('PHP function to connect with explicit SSL-FTP to server does not exist!', 'backwpup'), E_USER_ERROR);
             return TRUE;
         }
     } else {
         //make normal FTP connection if SSL not work
         $ftp_conn_id = ftp_connect($job_object->job['ftphost'], $job_object->job['ftphostport'], $job_object->job['ftptimeout']);
         if ($ftp_conn_id) {
             $job_object->log(sprintf(__('Connected to FTP server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('Cannot connect to FTP server: %s', 'backwpup'), $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport']), E_USER_ERROR);
             return FALSE;
         }
     }
     //FTP Login
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'USER ' . $job_object->job['ftpuser']), E_USER_NOTICE);
     if ($loginok = @ftp_login($ftp_conn_id, $job_object->job['ftpuser'], BackWPup_Encryption::decrypt($job_object->job['ftppass']))) {
         $job_object->log(sprintf(__('FTP server response: %s', 'backwpup'), 'User ' . $job_object->job['ftpuser'] . ' logged in.'), E_USER_NOTICE);
     } else {
         //if PHP ftp login don't work use raw login
         $return = ftp_raw($ftp_conn_id, 'USER ' . $job_object->job['ftpuser']);
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_NOTICE);
         if (substr(trim($return[0]), 0, 3) <= 400) {
             $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'PASS *******'), E_USER_NOTICE);
             $return = ftp_raw($ftp_conn_id, 'PASS ' . BackWPup_Encryption::decrypt($job_object->job['ftppass']));
             if (substr(trim($return[0]), 0, 3) <= 400) {
                 $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_NOTICE);
                 $loginok = TRUE;
             } else {
                 $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $return[0]), E_USER_ERROR);
             }
         }
     }
     if (!$loginok) {
         return FALSE;
     }
     //SYSTYPE
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'SYST'), E_USER_NOTICE);
     $systype = ftp_systype($ftp_conn_id);
     if ($systype) {
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), $systype), E_USER_NOTICE);
     } else {
         $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Error getting SYSTYPE', 'backwpup')), E_USER_ERROR);
     }
     //set actual ftp dir to ftp dir
     if (empty($job_object->job['ftpdir'])) {
         $job_object->job['ftpdir'] = trailingslashit(ftp_pwd($ftp_conn_id));
     }
     // prepend actual ftp dir if relative dir
     if (substr($job_object->job['ftpdir'], 0, 1) != '/') {
         $job_object->job['ftpdir'] = trailingslashit(ftp_pwd($ftp_conn_id)) . $job_object->job['ftpdir'];
     }
     //test ftp dir and create it if not exists
     if ($job_object->job['ftpdir'] != '/') {
         @ftp_chdir($ftp_conn_id, '/');
         //go to root
         $ftpdirs = explode('/', trim($job_object->job['ftpdir'], '/'));
         foreach ($ftpdirs as $ftpdir) {
             if (empty($ftpdir)) {
                 continue;
             }
             if (!@ftp_chdir($ftp_conn_id, $ftpdir)) {
                 if (@ftp_mkdir($ftp_conn_id, $ftpdir)) {
                     $job_object->log(sprintf(__('FTP Folder "%s" created!', 'backwpup'), $ftpdir), E_USER_NOTICE);
                     ftp_chdir($ftp_conn_id, $ftpdir);
                 } else {
                     $job_object->log(sprintf(__('FTP Folder "%s" cannot be created!', 'backwpup'), $ftpdir), E_USER_ERROR);
                     return FALSE;
                 }
             }
         }
     }
     // Get the current working directory
     $current_ftp_dir = trailingslashit(ftp_pwd($ftp_conn_id));
     if ($job_object->substeps_done == 0) {
         $job_object->log(sprintf(__('FTP current folder is: %s', 'backwpup'), $current_ftp_dir), E_USER_NOTICE);
     }
     //get file size to resume upload
     @clearstatcache();
     $job_object->substeps_done = @ftp_size($ftp_conn_id, $job_object->job['ftpdir'] . $job_object->backup_file);
     if ($job_object->substeps_done == -1) {
         $job_object->substeps_done = 0;
     }
     //PASV
     $job_object->log(sprintf(__('FTP client command: %s', 'backwpup'), 'PASV'), E_USER_NOTICE);
     if ($job_object->job['ftppasv']) {
         if (ftp_pasv($ftp_conn_id, TRUE)) {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Entering passive mode', 'backwpup')), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Cannot enter passive mode', 'backwpup')), E_USER_WARNING);
         }
     } else {
         if (ftp_pasv($ftp_conn_id, FALSE)) {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Entering normal mode', 'backwpup')), E_USER_NOTICE);
         } else {
             $job_object->log(sprintf(__('FTP server reply: %s', 'backwpup'), __('Cannot enter normal mode', 'backwpup')), E_USER_WARNING);
         }
     }
     if ($job_object->substeps_done < $job_object->backup_filesize) {
         $job_object->log(__('Starting upload to FTP &#160;&hellip;', 'backwpup'), E_USER_NOTICE);
         if ($fp = fopen($job_object->backup_folder . $job_object->backup_file, 'rb')) {
             //go to actual file pos
             fseek($fp, $job_object->substeps_done);
             $ret = ftp_nb_fput($ftp_conn_id, $current_ftp_dir . $job_object->backup_file, $fp, FTP_BINARY, $job_object->substeps_done);
             while ($ret == FTP_MOREDATA) {
                 $job_object->substeps_done = ftell($fp);
                 $job_object->update_working_data();
                 $job_object->do_restart_time();
                 $ret = ftp_nb_continue($ftp_conn_id);
             }
             if ($ret != FTP_FINISHED) {
                 $job_object->log(__('Cannot transfer backup to FTP server!', 'backwpup'), E_USER_ERROR);
                 return FALSE;
             } else {
                 $job_object->substeps_done = $job_object->backup_filesize + 1;
                 $job_object->log(sprintf(__('Backup transferred to FTP server: %s', 'backwpup'), $current_ftp_dir . $job_object->backup_file), E_USER_NOTICE);
                 if (!empty($job_object->job['jobid'])) {
                     BackWPup_Option::update($job_object->job['jobid'], 'lastbackupdownloadurl', "ftp://" . $job_object->job['ftpuser'] . ":" . BackWPup_Encryption::decrypt($job_object->job['ftppass']) . "@" . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $current_ftp_dir . $job_object->backup_file);
                 }
             }
             fclose($fp);
         } else {
             $job_object->log(__('Can not open source file for transfer.', 'backwpup'), E_USER_ERROR);
             return FALSE;
         }
     }
     $backupfilelist = array();
     $filecounter = 0;
     $files = array();
     if ($filelist = ftp_nlist($ftp_conn_id, '.')) {
         foreach ($filelist as $file) {
             if (basename($file) != '.' && basename($file) != '..') {
                 if ($job_object->is_backup_archive($file)) {
                     $time = ftp_mdtm($ftp_conn_id, $file);
                     if ($time != -1) {
                         $backupfilelist[$time] = basename($file);
                     } else {
                         $backupfilelist[] = basename($file);
                     }
                 }
                 $files[$filecounter]['folder'] = 'ftp://' . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $job_object->job['ftpdir'];
                 $files[$filecounter]['file'] = $job_object->job['ftpdir'] . basename($file);
                 $files[$filecounter]['filename'] = basename($file);
                 $files[$filecounter]['downloadurl'] = 'ftp://' . rawurlencode($job_object->job['ftpuser']) . ':' . rawurlencode(BackWPup_Encryption::decrypt($job_object->job['ftppass'])) . '@' . $job_object->job['ftphost'] . ':' . $job_object->job['ftphostport'] . $job_object->job['ftpdir'] . basename($file);
                 $files[$filecounter]['filesize'] = ftp_size($ftp_conn_id, $file);
                 $files[$filecounter]['time'] = ftp_mdtm($ftp_conn_id, $file);
                 $filecounter++;
             }
         }
     }
     if (!empty($job_object->job['ftpmaxbackups']) && $job_object->job['ftpmaxbackups'] > 0) {
         //Delete old backups
         if (count($backupfilelist) > $job_object->job['ftpmaxbackups']) {
             ksort($backupfilelist);
             $numdeltefiles = 0;
             while ($file = array_shift($backupfilelist)) {
                 if (count($backupfilelist) < $job_object->job['ftpmaxbackups']) {
                     break;
                 }
                 if (ftp_delete($ftp_conn_id, $file)) {
                     //delete files on ftp
                     foreach ($files as $key => $filedata) {
                         if ($filedata['file'] == $job_object->job['ftpdir'] . $file) {
                             unset($files[$key]);
                         }
                     }
                     $numdeltefiles++;
                 } else {
                     $job_object->log(sprintf(__('Cannot delete "%s" on FTP server!', 'backwpup'), $job_object->job['ftpdir'] . $file), E_USER_ERROR);
                 }
             }
             if ($numdeltefiles > 0) {
                 $job_object->log(sprintf(_n('One file deleted on FTP server', '%d files deleted on FTP server', $numdeltefiles, 'backwpup'), $numdeltefiles), E_USER_NOTICE);
             }
         }
     }
     set_site_transient('backwpup_' . $job_object->job['jobid'] . '_ftp', $files, YEAR_IN_SECONDS);
     $job_object->substeps_done++;
     ftp_close($ftp_conn_id);
     return TRUE;
 }
示例#15
0
 public function system_type()
 {
     if ($this->debug) {
         echo "Recuperation du type de systeme distant\n<br>";
     }
     if (($systype = @ftp_systype($this->connexion)) === false) {
         throw new Exception('Impossible de recuperer le type de systeme');
     }
     return $systype;
 }
示例#16
0
文件: Ftp.php 项目: robeendey/ce
 public function getSystemType()
 {
     if (null === $this->_systemType) {
         $systype = @ftp_systype($this->getResource());
         $this->_systemType = self::processSystemType($systype);
     }
     return $this->_systemType;
 }
 protected function createFTPLink()
 {
     // If connexion exist and is still connected
     if (is_array($_SESSION["FTP_CONNEXIONS"]) && array_key_exists($this->repositoryId, $_SESSION["FTP_CONNEXIONS"]) && @ftp_systype($_SESSION["FTP_CONNEXIONS"][$this->repositoryId])) {
         AJXP_Logger::debug("Using stored FTP Session");
         return $_SESSION["FTP_CONNEXIONS"][$this->repositoryId];
     }
     AJXP_Logger::debug("Creating new FTP Session");
     $link = FALSE;
     //Connects to the FTP.
     if ($this->secure) {
         $link = @ftp_ssl_connect($this->host, $this->port);
     } else {
         $link = @ftp_connect($this->host, $this->port);
     }
     if (!$link) {
         throw new AJXP_Exception("Cannot connect to FTP server!");
     }
     //register_shutdown_function('ftp_close', $link);
     @ftp_set_option($link, FTP_TIMEOUT_SEC, 10);
     if (!@ftp_login($link, $this->user, $this->password)) {
         throw new AJXP_Exception("Cannot login to FTP server with user {$this->user}");
     }
     if (!$this->ftpActive) {
         @ftp_pasv($link, true);
         global $_SESSION;
         $_SESSION["ftpPasv"] = "true";
     }
     if (!is_array($_SESSION["FTP_CONNEXIONS"])) {
         $_SESSION["FTP_CONNEXIONS"] = array();
     }
     $_SESSION["FTP_CONNEXIONS"][$this->repositoryId] = $link;
     return $link;
 }
示例#18
0
 /**
  * Returns the remote system type.
  * 
  * @return string The remote system type
  */
 public function systype()
 {
     $this->connectIfNeeded();
     $res = @ftp_systype($this->handle);
     return $res == null || $res == false ? 'UNIX' : $res;
 }
示例#19
0
 /**
  * Connect to FTP server
  *
  * @return bool
  */
 public function connect()
 {
     $func = $this->ssl ? 'ftp_ssl_connect' : 'ftp_connect';
     $this->_stream = $func($this->_host, $this->_port, $this->_timeout);
     if (!$this->_stream) {
         $this->error = 'Failed to connect ' . $this->_host . '.';
         return false;
     }
     if (\ftp_login($this->_stream, $this->_user, $this->_pwd)) {
         \ftp_pasv($this->_stream, (bool) $this->passive);
         $this->system_type = \ftp_systype($this->_stream);
         return true;
     }
     $this->error = 'Failed to connect to ' . $this->_host . ' (login failed)';
     return false;
 }
示例#20
0
function phpftp_getList($ftp, $dir, $start)
{
    $GLOBALS['real_systyp'] = ftp_systype($ftp);
    ftp_chdir($ftp, $dir);
    $dirlist = ftp_rawlist($ftp, '');
    for ($i = $start; $i < $start + $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs']; $i++) {
        if ($i < count($dirlist)) {
            $dirinfo[] = analysedir($dirlist[$i]);
        }
    }
    return $dirinfo;
}
         }
     }
     if (!empty($_REQUEST['ftpscanner'])) {
         if (checkthisporT($ip, 21, $timeout)) {
             $usps = explode(',', $_REQUEST['userpass']);
             foreach ($usps as $v) {
                 $user = substr($v, 0, strpos($v, ':'));
                 $pass = substr($v, strpos($v, ':') + 1);
                 if ($pass == '[BLANK]') {
                     $pass = '';
                 }
                 $ftp = @ftp_connect($ip, 21, $timeout);
                 if ($ftp) {
                     if (@ftp_login($ftp, $user, $pass)) {
                         $output = 1;
                         echo "{$ip}) FTP FOUND: ({$user}:{$pass}) <a href=\"ftp://{$ip}\" target=\"_blank\">{$ip}</a> System type: " . ftp_systype($ftp) . "<br>";
                     }
                 }
                 flusheR();
             }
         }
     }
     if ($output) {
         echo "<hr size=1 noshade>";
     }
     flusheR();
 }
 $time = time() - $start;
 echo "Done! ({$time} seconds)</font>";
 if (!empty($buglist)) {
     unlink($buglist);
示例#22
0
 /**
  * Check if the connection is open.
  *
  * @return bool
  */
 public function isConnected()
 {
     return !is_null($this->connection) && ftp_systype($this->connection) !== false;
 }
示例#23
0
 public function systype()
 {
     return ftp_systype($this->connection);
 }
示例#24
0
 /**
  * Read the OS identification string
  *
  * @return mixed  On success the name of the OS as string, otherwise FALSE
  */
 public function getSystem()
 {
     if (is_resource($this->cid)) {
         return ftp_systype($this->cid);
     }
 }
示例#25
0
文件: ftp.php 项目: akksi/jcg
 /**
  * Method to system string from the FTP server
  *
  * @access public
  * @return string System identifier string
  */
 function syst()
 {
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         if (($ret = @ftp_systype($this->_conn)) === false) {
             JError::raiseWarning('35', JText::_('JLIB_CLIENT_ERROR_JFTP_SYS_BAD_RESPONSE_NATIVE'));
             return false;
         }
     } else {
         // Send print working directory command and verify success
         if (!$this->_putCmd('SYST', 215)) {
             JError::raiseWarning('35', JText::sprintf('JLIB_CLIENT_ERROR_JFTP_SYST_BAD_RESPONSE', $this->_response));
             return false;
         }
         $ret = $this->_response;
     }
     // Match the system string to an OS
     if (strpos(strtoupper($ret), 'MAC') !== false) {
         $ret = 'MAC';
     } elseif (strpos(strtoupper($ret), 'WIN') !== false) {
         $ret = 'WIN';
     } else {
         $ret = 'UNIX';
     }
     // Return the os type
     return $ret;
 }
示例#26
0
文件: sftp.php 项目: beyond-z/braven
 public function connect()
 {
     // Implicit SSL - not handled via PHP's native ftp_ functions, so we use curl instead
     if ($this->port == 990 || defined('UPDRAFTPLUS_FTP_USECURL') && UPDRAFTPLUS_FTP_USECURL) {
         if ($this->ssl == false) {
             $this->port = 21;
         } else {
             $this->curl_handle = curl_init();
             if (!$this->curl_handle) {
                 $this->port = 21;
             } else {
                 $options = array(CURLOPT_USERPWD => $this->username . ':' . $this->password, CURLOPT_PORT => $this->port, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_FTP_CREATE_MISSING_DIRS => true);
                 $options[CURLOPT_FTP_SSL] = CURLFTPSSL_TRY;
                 //CURLFTPSSL_ALL, // require SSL For both control and data connections
                 if (990 == $this->port) {
                     $options[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_SSL;
                     // CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
                 } else {
                     $options[CURLOPT_FTPSSLAUTH] = CURLFTPAUTH_DEFAULT;
                     // let cURL choose the FTP authentication method (either SSL or TLS)
                 }
                 // Prints to STDERR by default - noisy
                 if (defined('WP_DEBUG') && WP_DEBUG == true && UpdraftPlus_Options::get_updraft_option('updraft_debug_mode')) {
                     $options[CURLOPT_VERBOSE] = true;
                 }
                 if ($this->disable_verify) {
                     $options[CURLOPT_SSL_VERIFYPEER] = false;
                     $options[CURLOPT_SSL_VERIFYHOST] = 0;
                 } else {
                     $options[CURLOPT_SSL_VERIFYPEER] = true;
                 }
                 if (!$this->use_server_certs) {
                     $options[CURLOPT_CAINFO] = UPDRAFTPLUS_DIR . '/includes/cacert.pem';
                 }
                 if ($this->passive != true) {
                     $options[CURLOPT_FTPPORT] = '-';
                 }
                 foreach ($options as $option_name => $option_value) {
                     if (!curl_setopt($this->curl_handle, $option_name, $option_value)) {
                         // 							throw new Exception( sprintf( 'Could not set cURL option: %s', $option_name ) );
                         global $updraftplus;
                         if (is_a($updraftplus, 'UpdraftPlus')) {
                             $updraftplus->log("Curl exception: will revert to normal FTP");
                         }
                         $this->port = 21;
                         $this->curl_handle = false;
                     }
                 }
             }
             // All done - leave
             if ($this->curl_handle) {
                 $this->login_type = 'encrypted (implicit, port 990)';
                 return true;
             }
         }
     }
     $time_start = time();
     if (function_exists('ftp_ssl_connect') && $this->ssl !== false) {
         $this->conn_id = ftp_ssl_connect($this->host, $this->port, 15);
         $attempting_ssl = true;
     }
     if ($this->conn_id) {
         $this->login_type = 'encrypted';
         $this->ssl = true;
     } else {
         $this->conn_id = ftp_connect($this->host, $this->port, 15);
     }
     if ($this->conn_id) {
         $result = ftp_login($this->conn_id, $this->username, $this->password);
     }
     if (!empty($result)) {
         ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
         ftp_pasv($this->conn_id, $this->passive);
         $this->system_type = ftp_systype($this->conn_id);
         return true;
     } elseif (!empty($attempting_ssl)) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             # Clear the previous PHP messages, so that we only show the user messages from the method that worked (or from both if both fail)
             $save_array = $updraftplus_admin->logged;
             $updraftplus_admin->logged = array();
             #trigger_error(__('Encrypted login failed; trying non-encrypted', 'updraftplus'), E_USER_NOTICE);
         }
         $this->ssl = false;
         $this->login_type = 'non-encrypted';
         $time_start = time();
         $this->conn_id = ftp_connect($this->host, $this->port, 15);
         if ($this->conn_id) {
             $result = ftp_login($this->conn_id, $this->username, $this->password);
         }
         if (!empty($result)) {
             ftp_set_option($this->conn_id, FTP_TIMEOUT_SEC, $this->timeout);
             ftp_pasv($this->conn_id, $this->passive);
             $this->system_type = ftp_systype($this->conn_id);
             return true;
         } else {
             # Add back the previous PHP messages
             if (isset($save_array)) {
                 $updraftplus_admin->logged = array_merge($save_array, $updraftplus_admin->logged);
             }
         }
     }
     # If we got here, then we failed
     if (time() - $time_start > 14) {
         global $updraftplus_admin;
         if (isset($updraftplus_admin->logged) && is_array($updraftplus_admin->logged)) {
             $updraftplus_admin->logged[] = sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP');
         } else {
             global $updraftplus;
             $updraftplus->log(sprintf(__('The %s connection timed out; if you entered the server correctly, then this is usually caused by a firewall blocking the connection - you should check with your web hosting company.', 'updraftplus'), 'FTP'), 'error');
         }
     }
     return false;
 }
 /**
  * @staticvar bool $is_windows
  * @param string $line
  * @return string
  */
 public function parselisting($line)
 {
     static $is_windows;
     if (is_null($is_windows)) {
         $is_windows = stripos(ftp_systype($this->link), 'win') !== false;
     }
     if ($is_windows && preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer)) {
         $b = array();
         if ($lucifer[3] < 70) {
             $lucifer[3] += 2000;
         } else {
             $lucifer[3] += 1900;
         }
         // 4digit year fix
         $b['isdir'] = $lucifer[7] == '<DIR>';
         if ($b['isdir']) {
             $b['type'] = 'd';
         } else {
             $b['type'] = 'f';
         }
         $b['size'] = $lucifer[7];
         $b['month'] = $lucifer[1];
         $b['day'] = $lucifer[2];
         $b['year'] = $lucifer[3];
         $b['hour'] = $lucifer[4];
         $b['minute'] = $lucifer[5];
         $b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
         $b['am/pm'] = $lucifer[6];
         $b['name'] = $lucifer[8];
     } elseif (!$is_windows && ($lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY))) {
         //echo $line."\n";
         $lcount = count($lucifer);
         if ($lcount < 8) {
             return '';
         }
         $b = array();
         $b['isdir'] = $lucifer[0][0] === 'd';
         $b['islink'] = $lucifer[0][0] === 'l';
         if ($b['isdir']) {
             $b['type'] = 'd';
         } elseif ($b['islink']) {
             $b['type'] = 'l';
         } else {
             $b['type'] = 'f';
         }
         $b['perms'] = $lucifer[0];
         $b['number'] = $lucifer[1];
         $b['owner'] = $lucifer[2];
         $b['group'] = $lucifer[3];
         $b['size'] = $lucifer[4];
         if ($lcount == 8) {
             sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
             sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
             $b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
             $b['name'] = $lucifer[7];
         } else {
             $b['month'] = $lucifer[5];
             $b['day'] = $lucifer[6];
             if (preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2)) {
                 $b['year'] = date("Y");
                 $b['hour'] = $l2[1];
                 $b['minute'] = $l2[2];
             } else {
                 $b['year'] = $lucifer[7];
                 $b['hour'] = 0;
                 $b['minute'] = 0;
             }
             $b['time'] = strtotime(sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']));
             $b['name'] = $lucifer[8];
         }
     }
     // Replace symlinks formatted as "source -> target" with just the source name
     if ($b['islink']) {
         $b['name'] = preg_replace('/(\\s*->\\s*.*)$/', '', $b['name']);
     }
     return $b;
 }
示例#28
0
 public function systype()
 {
     return ftp_systype($this->link_id);
 }
示例#29
0
文件: ftp.php 项目: joebushi/joomla
 /**
  * Method to system string from the FTP server
  *
  * @access public
  * @return string System identifier string
  */
 function syst()
 {
     // If native FTP support is enabled lets use it...
     if (FTP_NATIVE) {
         if (($ret = @ftp_systype($this->_conn)) === false) {
             JError::raiseWarning('35', 'JFTP::syst: Bad response');
             return false;
         }
     } else {
         // Send print working directory command and verify success
         if (!$this->_putCmd('SYST', 215)) {
             JError::raiseWarning('35', 'JFTP::syst: Bad response', 'Server response: ' . $this->_response . ' [Expected: 215]');
             return false;
         }
         $ret = $this->_response;
     }
     // Match the system string to an OS
     if (strpos(strtoupper($ret), 'MAC') !== false) {
         $ret = 'MAC';
     } elseif (strpos(strtoupper($ret), 'WIN') !== false) {
         $ret = 'WIN';
     } else {
         $ret = 'UNIX';
     }
     // Return the os type
     return $ret;
 }
function scanneR()
{
    global $hcwd, $et;
    if (!empty($_SERVER['SERVER_ADDR'])) {
        $host = $_SERVER['SERVER_ADDR'];
    } else {
        $host = '127.0.0.1';
    }
    $udp = empty($_REQUEST['udp']) ? 0 : 1;
    $tcp = empty($_REQUEST['tcp']) ? 0 : 1;
    if (($udp || $tcp) && !empty($_REQUEST['target']) && !empty($_REQUEST['fromport']) && !empty($_REQUEST['toport']) && !empty($_REQUEST['timeout']) && !empty($_REQUEST['portscanner'])) {
        $target = $_REQUEST['target'];
        $from = (int) $_REQUEST['fromport'];
        $to = (int) $_REQUEST['toport'];
        $timeout = (int) $_REQUEST['timeout'];
        $nu = 0;
        echo '<font color=blue>Port scanning started against ' . htmlspecialchars($target) . ':<br>';
        $start = time();
        for ($i = $from; $i <= $to; $i++) {
            if ($tcp) {
                if (checkthisporT($target, $i, $timeout)) {
                    $nu++;
                    $ser = '';
                    if (getservbyport($i, 'tcp')) {
                        $ser = '(' . getservbyport($i, 'tcp') . ')';
                    }
                    echo "{$nu}) {$i} {$ser} (<a href='telnet://{$target}:{$i}'>Connect</a>) [TCP]<br>";
                }
            }
            if ($udp) {
                if (checkthisporT($target, $i, $timeout, 1)) {
                    $nu++;
                    $ser = '';
                    if (getservbyport($i, 'udp')) {
                        $ser = '(' . getservbyport($i, 'udp') . ')';
                    }
                    echo "{$nu}) {$i} {$ser} [UDP]<br>";
                }
            }
        }
        $time = time() - $start;
        echo "Done! ({$time} seconds)</font>";
    } elseif (!empty($_REQUEST['securityscanner'])) {
        echo '<font color=blue>';
        $start = time();
        $from = $_REQUEST['from'];
        $to = (int) $_REQUEST['to'];
        $timeout = (int) $_REQUEST['timeout'];
        $f = substr($from, strrpos($from, '.') + 1);
        $from = substr($from, 0, strrpos($from, '.'));
        if (!empty($_REQUEST['httpscanner'])) {
            echo 'Loading webserver bug list...';
            $buglist = whereistmP() . DIRECTORY_SEPARATOR . uniqid('BL');
            $dl = downloadiT('http://www.cirt.net/nikto/UPDATES/1.36/scan_database.db', $buglist);
            if ($dl) {
                $file = file($buglist);
                echo 'Done! scanning started.<br><br>';
            } else {
                echo 'Failed!!! scanning started without webserver security testing...<br><br>';
            }
        } else {
            $fr = htmlspecialchars($from);
            echo "Scanning {$fr}.{$f}-{$fr}.{$to}:<br><br>";
        }
        for ($i = $f; $i <= $to; $i++) {
            $output = 0;
            $ip = "{$from}.{$i}";
            if (!empty($_REQUEST['nslookup'])) {
                $hn = gethostbyaddr($ip);
                if ($hn != $ip) {
                    echo "{$ip} [{$hn}]<br>";
                }
                $output = 1;
            }
            if (!empty($_REQUEST['ipscanner'])) {
                $port = $_REQUEST['port'];
                if (strstr($port, ',')) {
                    $p = explode(',', $port);
                } else {
                    $p[0] = $port;
                }
                $open = $ser = '';
                foreach ($p as $po) {
                    $scan = checkthisporT($ip, $po, $timeout);
                    if ($scan) {
                        $ser = '';
                        if ($ser = getservbyport($po, 'tcp')) {
                            $ser = "({$ser})";
                        }
                        $open .= " {$po}{$ser} ";
                    }
                }
                if ($open) {
                    echo "{$ip}) Open ports:{$open}<br>";
                    $output = 1;
                }
            }
            if (!empty($_REQUEST['httpbanner'])) {
                $res = get_sw_namE($ip, $timeout);
                if ($res) {
                    echo "{$ip}) Webserver software: ";
                    if ($res == -1) {
                        echo 'Unknow';
                    } else {
                        echo $res;
                    }
                    echo '<br>';
                    $output = 1;
                }
            }
            if (!empty($_REQUEST['httpscanner'])) {
                if (checkthisporT($ip, 80, $timeout) && !empty($file)) {
                    $admin = array('/admin/', '/adm/');
                    $users = array('adm', 'bin', 'daemon', 'ftp', 'guest', 'listen', 'lp', 'mysql', 'noaccess', 'nobody', 'nobody4', 'nuucp', 'operator', 'root', 'smmsp', 'smtp', 'sshd', 'sys', 'test', 'unknown', 'uucp', 'web', 'www');
                    $nuke = array('/', '/postnuke/', '/postnuke/html/', '/modules/', '/phpBB/', '/forum/');
                    $cgi = array('/cgi.cgi/', '/webcgi/', '/cgi-914/', '/cgi-915/', '/bin/', '/cgi/', '/mpcgi/', '/cgi-bin/', '/ows-bin/', '/cgi-sys/', '/cgi-local/', '/htbin/', '/cgibin/', '/cgis/', '/scripts/', '/cgi-win/', '/fcgi-bin/', '/cgi-exe/', '/cgi-home/', '/cgi-perl/');
                    foreach ($file as $v) {
                        $vuln = array();
                        $v = trim($v);
                        if (!$v || $v[0] == '#') {
                            continue;
                        }
                        $v = str_replace('","', '^', $v);
                        $v = str_replace('"', '', $v);
                        $vuln = explode('^', $v);
                        $page = $cqich = $nukech = $adminch = $userch = $vuln[1];
                        if (strstr($page, '@CGIDIRS')) {
                            foreach ($cgi as $cg) {
                                $cqich = str_replace('@CGIDIRS', $cg, $page);
                                $url = "http://{$ip}{$cqich}";
                                $res = check_urL($url, $vuln[3], $vuln[2], $timeout);
                                if ($res) {
                                    $output = 1;
                                    echo "{$ip})" . $vuln[4] . " <a href='{$url}' target='_blank'>{$url}</a><br>";
                                }
                            }
                        } elseif (strstr($page, '@ADMINDIRS')) {
                            foreach ($admin as $cg) {
                                $adminch = str_replace('@ADMINDIRS', $cg, $page);
                                $url = "http://{$ip}{$adminch}";
                                $res = check_urL($url, $vuln[3], $vuln[2], $timeout);
                                if ($res) {
                                    $output = 1;
                                    echo "{$ip})" . $vuln[4] . " <a href='{$url}' target='_blank'>{$url}</a><br>";
                                }
                            }
                        } elseif (strstr($page, '@USERS')) {
                            foreach ($users as $cg) {
                                $userch = str_replace('@USERS', $cg, $page);
                                $url = "http://{$ip}{$userch}";
                                $res = check_urL($url, $vuln[3], $vuln[2], $timeout);
                                if ($res) {
                                    $output = 1;
                                    echo "{$ip})" . $vuln[4] . " <a href='{$url}' target='_blank'>{$url}</a><br>";
                                }
                            }
                        } elseif (strstr($page, '@NUKE')) {
                            foreach ($nuke as $cg) {
                                $nukech = str_replace('@NUKE', $cg, $page);
                                $url = "http://{$ip}{$nukech}";
                                $res = check_urL($url, $vuln[3], $vuln[2], $timeout);
                                if ($res) {
                                    $output = 1;
                                    echo "{$ip})" . $vuln[4] . " <a href='{$url}' target='_blank'>{$url}</a><br>";
                                }
                            }
                        } else {
                            $url = "http://{$ip}{$page}";
                            $res = check_urL($url, $vuln[3], $vuln[2], $timeout);
                            if ($res) {
                                $output = 1;
                                echo "{$ip})" . $vuln[4] . " <a href='{$url}' target='_blank'>{$url}</a><br>";
                            }
                        }
                    }
                }
            }
            if (!empty($_REQUEST['smtprelay'])) {
                if (checkthisporT($ip, 25, $timeout)) {
                    $res = '';
                    $res = checksmtP($ip, $timeout);
                    if ($res == 1) {
                        echo "{$ip}) SMTP relay found.<br>";
                        $output = 1;
                    }
                }
            }
            if (!empty($_REQUEST['snmpscanner'])) {
                if (checkthisporT($ip, 161, $timeout, 1)) {
                    $com = $_REQUEST['com'];
                    $coms = $res = '';
                    if (strstr($com, ',')) {
                        $c = explode(',', $com);
                    } else {
                        $c[0] = $com;
                    }
                    foreach ($c as $v) {
                        $ret = snmpchecK($ip, $v, $timeout);
                        if ($ret) {
                            $coms .= " {$v} ";
                        }
                    }
                    if ($coms != '') {
                        echo "{$ip}) SNMP FOUND: {$coms}<br>";
                        $output = 1;
                    }
                }
            }
            if (!empty($_REQUEST['ftpscanner']) && function_exists('ftp_connect')) {
                if (checkthisporT($ip, 21, $timeout)) {
                    $usps = explode(',', $_REQUEST['userpass']);
                    foreach ($usps as $v) {
                        $user = substr($v, 0, strpos($v, ':'));
                        $pass = substr($v, strpos($v, ':') + 1);
                        if ($pass == '[BLANK]') {
                            $pass = '';
                        }
                        $ftp = ftp_connect($ip, 21, $timeout);
                        if ($ftp) {
                            if (ftp_login($ftp, $user, $pass)) {
                                $output = 1;
                                echo "{$ip}) FTP FOUND: ({$user}:{$pass}) System type: " . ftp_systype($ftp) . " (<b><a href='";
                                echo hlinK("seC=ftpc&workingdiR=" . getcwd() . "&hosT={$ip}&useR={$user}&pasS={$pass}");
                                echo "' target='_blank'>Connect</a></b>)<br>";
                            }
                        }
                    }
                }
            }
            if ($output) {
                echo '<hr size=1 noshade>';
            }
        }
        $time = time() - $start;
        echo "Done! ({$time} seconds)</font>";
        if (!empty($buglist)) {
            unlink($buglist);
        }
    } elseif (!empty($_REQUEST['directoryscanner'])) {
        $dir = file($_REQUEST['dic']);
        $host = $_REQUEST['host'];
        $r = $_REQUEST['r1'];
        echo "<font color=blue><pre>Tahap Scanning Dimulai ...\n";
        for ($i = 0; $i < count($dir); $i++) {
            $d = trim($dir[$i]);
            if ($r) {
                $adr = "http://{$host}/{$d}/";
                if (check_urL($adr, 'GET', '302')) {
                    echo "Directory Found: <a href='{$adr}' target='_blank'>{$adr}</a>\n";
                }
            } else {
                $adr = "{$d}.{$host}";
                $ip = gethostbyname($adr);
                if ($ip != $adr) {
                    echo "Subdomain Found: <a href='http://{$adr}' target='_blank'>{$adr}({$ip})</a>\n";
                }
            }
        }
        echo 'Done!</pre></font>';
    } else {
        $t = "<br><table border=0 cellpadding=0 cellspacing=0 style='border-collapse: collapse' bgcolor='#333333' width='50%'><tr><form method='POST'";
        $chbox = extension_loaded('sockets') ? "<input type=checkbox style='border-width:1px;background-color:#808080;' name=tcp value=1 checked>TCP<input type=checkbox name=udp style='border-width:1px;background-color:#808080;' value=1 checked>UDP" : "<input type=hidden name=tcp value=1>";
        echo "<center>{$t}><td>Port scanner:</td></tr><td width='25%' bgcolor='#808080'>Target:</td><td bgcolor='#808080' width=80%><input name=target value={$host} size=40></td></tr><tr><td bgcolor='#666666' width=25%>From:</td><td bgcolor='#666666' width=25%><input name=fromport type=text value='1' size=5></td></tr><tr><td bgcolor='#808080' width=25%>To:</td><td bgcolor='#808080' width=25%><input name=toport type=text value='1024' size=5></td></tr><tr><td width='25%' bgcolor='#666666'>Timeout:</td><td bgcolor='#666666'><input name=timeout type=text value='2' size=5></td><tr><td width='25%' bgcolor='#808080'>{$chbox}</td><td bgcolor='#808080' align='right'>{$hcwd}<input type=submit class=buttons name=portscanner value=Scan></form>{$et}{$t}><td>Discoverer:</td></tr><tr><td width='25%' bgcolor='#808080'>Host:</td><td bgcolor='#808080' width=80%><input name=host value='" . $_SERVER["HTTP_HOST"] . "' size=40></td><td bgcolor='#808080'></td></tr><tr><td width='25%' bgcolor='#666666'>Dictionary:</td><td bgcolor='#666666' width=80%><input name=dic size=40></td><td bgcolor='#666666'></td></tr><tr><td width='25%' bgcolor='#808080'>Search for:</td><td bgcolor='#808080' width=40%><input type=radio value=1 checked name=r1>Directories<input type=radio name=r1 value=0>Subdomains</td><td bgcolor='#808080' align='right' width=40%><input type=submit class=buttons name=directoryscanner value=Scan></td></form></tr></table>";
        $host = substr($host, 0, strrpos($host, "."));
        echo "{$t} name=security><td>Security scanner:</td></tr><td width='25%' bgcolor='#808080'>From:</td><td bgcolor='#808080' width=80%><input name=from value={$host}.1 size=40> <input type=checkbox value=1 style='border-width:1px;background-color:#808080;' name=nslookup checked>NS lookup</td></tr><tr><td bgcolor='#666666' width=25%>To:</td><td bgcolor='#666666' width=25%>xxx.xxx.xxx.<input name=to type=text value=254 size=4>{$hcwd}</td></tr><tr><td width='25%' bgcolor='#808080'>Timeout:</td><td bgcolor='#808080'><input name=timeout type=text value='2' size=5></td></tr><tr><td width='25%' bgcolor='#666666'><input type=checkbox name=ipscanner value=1 checked onClick='document.security.port.disabled = !document.security.port.disabled;' style='border-width:1px;background-color:#666666;'>Port scanner:</td><td bgcolor='#666666'><input name=port type=text value='21,23,25,80,110,135,139,143,443,445,1433,3306,3389,8080,65301' size=60></td></tr><tr><td width='25%' bgcolor='#808080'><input type=checkbox name=httpbanner value=1 checked style='border-width:1px;background-color:#808080;'>Get web banner</td><td bgcolor='#808080'><input type=checkbox name=httpscanner value=1 checked style='border-width:1px;background-color:#808080;'>Webserver security scanning&nbsp;&nbsp;&nbsp;<input type=checkbox name=smtprelay value=1 checked style='border-width:1px;background-color:#808080;'>SMTP relay check</td></tr><tr><td width='25%' bgcolor='#666666'><input type=checkbox name=ftpscanner value=1 checked onClick='document.security.userpass.disabled = !document.security.userpass.disabled;' style='border-width:1px;background-color:#666666;'>FTP password:</td><td bgcolor='#666666'><input name=userpass type=text value='anonymous:admin@nasa.gov,ftp:ftp,Administrator:[BLANK],guest:[BLANK]' size=60></td></tr><tr><td width='25%' bgcolor='#808080'><input type=checkbox name=snmpscanner value=1 onClick='document.security.com.disabled = !document.security.com.disabled;' checked style='border-width:1px;background-color:#808080;'>SNMP:</td><td bgcolor='#808080'><input name=com type=text value='public,private,secret,cisco,write,test,guest,ilmi,ILMI,password,all private,admin,all,system,monitor,sun,agent,manager,ibm,hello,switch,solaris,OrigEquipMfr,default,world,tech,mngt,tivoli,openview,community,snmp,SNMP,none,snmpd,Secret C0de,netman,security,pass,passwd,root,access,rmon,rmon_admin,hp_admin,NoGaH\$@!,router,agent_steal,freekevin,read,read-only,read-write,0392a0,cable-docsis,fubar,ANYCOM,Cisco router,xyzzy,c,cc,cascade,yellow,blue,internal,comcomcom,IBM,apc,TENmanUFactOryPOWER,proxy,core,CISCO,regional,1234,2read,4changes' size=60></td></tr><tr><td width='25%' bgcolor='#666666'></td><td bgcolor='#666666' align='right'><input type=submit class=buttons name=securityscanner value=Scan></form>{$et}";
    }
}