コード例 #1
0
ファイル: ScpClient.php プロジェクト: dsi-agpt/minibus
 /**
  *
  * @param string $remoteFileName            
  * @param string $localFilename            
  * @throws \Exception
  */
 public function send($remoteFileName, $localFilename)
 {
     if (empty($this->session)) {
         throw new \Exception("Veuillez vous connecter au serveur avant de déposer un fichier");
     }
     ssh2_scp_send($this->session, $localFilename, $remoteFileName);
 }
コード例 #2
0
ファイル: SSH2.php プロジェクト: p13eater/backup-lib
 /**
  * @inheritdoc
  */
 public function store(File $file)
 {
     if ($this->session === null) {
         $this->connect();
     }
     return ssh2_scp_send($this->session, $file->getLocation(), $this->remoteLocation . DIRECTORY_SEPARATOR . $file->getName());
 }
コード例 #3
0
ファイル: SCP.php プロジェクト: CoatesDigital/nutshell
 public function put($local, $remote)
 {
     //make sure we are connected
     $this->connect();
     $this->plugin->Logger('nutshell.plugin.transfer.scp')->info(sprintf('Uploading to remote file %s...', $remote));
     if (is_resource($local)) {
         throw new TransferException(sprintf('SCP of file handle has not been implemented.', $remote));
     } else {
         if (is_string($local)) {
             //upload using file name.
             $this->plugin->Logger('nutshell.plugin.transfer.scp')->debug('Uploading using local file path.');
             //check for file existence
             if (!is_readable($local)) {
                 throw new TransferException(sprintf('File %s not be found or not accessible', $local));
             }
             //transfers the file
             if (!ssh2_scp_send($this->connection, $local, $remote, 0644)) {
                 throw new TransferException(sprintf('Transfer of file %s to %s failed', $local, $remote));
             }
         } else {
             throw new TransferException(sprintf('Invalid parameter %s: expected string or file handle', parse_r($local, true)));
         }
     }
     $this->plugin->Logger('nutshell.plugin.transfer.scp')->info(sprintf('File transfered to %s successfully.', $remote));
 }
コード例 #4
0
ファイル: SetBannerGroup.php プロジェクト: josmel/movistar
 function coneccionSshImg($ids, $mBanner, $config)
 {
     $porciones = explode(",", $ids);
     foreach ($porciones as $value) {
         $dataBanner = $mBanner->select($value);
         $avanzado = ROOT_IMG_DINAMIC . '/banner/avanzado/' . $dataBanner["ImgAvanzado"];
         $basico128 = ROOT_IMG_DINAMIC . '/banner/basico128/' . $dataBanner["ImgBasico128"];
         $basico240 = ROOT_IMG_DINAMIC . '/banner/basico240/' . $dataBanner["ImgBasico240"];
         $basico360 = ROOT_IMG_DINAMIC . '/banner/basico360/' . $dataBanner["ImgBasico360"];
         if (!function_exists("ssh2_connect")) {
             die("function ssh2_connect doesn't exist");
         }
         if (!($con = ssh2_connect($config['app']['server'], $config['app']['puerto']))) {
             echo "fail: unable to establish connection\n";
         } else {
             if (!ssh2_auth_password($con, $config['app']['user'], $config['app']['pass'])) {
                 echo "fail: unable to authenticate\n";
             } else {
                 ssh2_scp_send($con, $avanzado, $config['app']['rutaImg'] . 'banner/avanzado/' . $dataBanner["ImgAvanzado"], 0644);
                 ssh2_scp_send($con, $basico128, $config['app']['rutaImg'] . 'banner/basico128/' . $dataBanner["ImgBasico128"], 0644);
                 ssh2_scp_send($con, $basico240, $config['app']['rutaImg'] . 'banner/basico240/' . $dataBanner["ImgBasico240"], 0644);
                 ssh2_scp_send($con, $basico360, $config['app']['rutaImg'] . 'banner/basico360/' . $dataBanner["ImgBasico360"], 0644);
             }
             ssh2_exec($con, 'exit');
         }
     }
     return;
 }
コード例 #5
0
ファイル: Sftp.php プロジェクト: shebin512/Magento_Zoff
 /**
  * Saves the image to the remote server. If the folder structure doesn't exist, create it.
  *
  * @param string $relFilename	path (with filename) from the CDN root
  * @param string $tempfile		temp file name to upload
  * @return bool
  */
 protected function _save($relFilename, $tempfile)
 {
     $base = Mage::getStoreConfig('imagecdn/ftp/base');
     $remotePath = str_replace('\\', '/', str_replace('//', '/', '/' . $base . '/' . $relFilename));
     ssh2_sftp_mkdir(ssh2_sftp($this->auth()), substr($remotePath, 0, strrpos($remotePath, '/')), 0777, true);
     $result = ssh2_scp_send($this->auth(), $tempfile, $remotePath, 0644);
     return $result ? true : false;
 }
コード例 #6
0
ファイル: SSHHost.php プロジェクト: jamesduan/etbackuptool
 function send($srcFilePath, $destFilePath)
 {
     if (ssh2_scp_send($this->ssh_connection, $srcFilePath, $destFilePath, 0644)) {
         echo "uploading {$srcFilePath} ok!\n";
     } else {
         echo "uploading {$srcFilePath} error!\n please check!\n";
     }
 }
コード例 #7
0
ファイル: ssh.php プロジェクト: enormego/EightPHP
 public function copy($source_pathname, $destination_pathname, $mime = NULL, $filename = NULL, $extras = array())
 {
     if (count($source_pathname) == 0 || count($destination_pathname) == 0) {
         return;
     }
     if ($destination_pathname[0] != '/') {
         $destination_pathname = $this->cwd . $destination_pathname;
     }
     ssh2_scp_send($this->session, $source_pathname, $destination_pathname);
 }
コード例 #8
0
ファイル: Ssh2.php プロジェクト: nouphet/xoops-tpSocialMedia
 public function scpSend($localFile, $remoteFile, $createMode = 0644)
 {
     $this->logs[] = '$ scp ' . $localFile . ' remote:' . $remoteFile;
     $result = ssh2_scp_send($this->connection, $localFile, $remoteFile, $createMode);
     if (!$result) {
         $this->logs[] = 'Send a file via SCP failed.';
         return false;
     }
     return true;
 }
コード例 #9
0
ファイル: admin.admin.model.php プロジェクト: conory/rhymix
 /**
  * Find XE installed path on sftp
  */
 function getSFTPPath()
 {
     $ftp_info = Context::getRequestVars();
     if (!$ftp_info->ftp_host) {
         $ftp_info->ftp_host = "127.0.0.1";
     }
     if (!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port)) {
         $ftp_info->ftp_port = '22';
     }
     $connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
     if (!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password)) {
         return new Object(-1, 'msg_ftp_invalid_auth_info');
     }
     $sftp = ssh2_sftp($connection);
     // create temp file
     $pin = $_SERVER['REQUEST_TIME'];
     FileHandler::writeFile('./files/cache/ftp_check', $pin);
     // create path candidate
     $xe_path = _XE_PATH_;
     $path_info = array_reverse(explode('/', _XE_PATH_));
     array_pop($path_info);
     // remove last '/'
     $path_candidate = array();
     $temp = '';
     foreach ($path_info as $path) {
         $temp = '/' . $path . $temp;
         $path_candidate[] = $temp;
     }
     // try
     foreach ($path_candidate as $path) {
         // upload check file
         if (!@ssh2_scp_send($connection, FileHandler::getRealPath('./files/cache/ftp_check'), $path . 'ftp_check.html')) {
             continue;
         }
         // get check file
         $result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
         // delete temp check file
         @ssh2_sftp_unlink($sftp, $path . 'ftp_check.html');
         // found
         if ($result == $pin) {
             $found_path = $path;
             break;
         }
     }
     FileHandler::removeFile('./files/cache/ftp_check', $pin);
     if ($found_path) {
         $this->add('found_path', $found_path);
     }
 }
コード例 #10
0
 public function upload($localFilename, $remoteFilename)
 {
     if (!file_exists($localFilename)) {
         throw new ConnectionException('File does not exist');
     }
     if (!is_resource($this->sftpResource)) {
         throw new ConnectionException('Connection is not open');
     }
     $scpResult = @ssh2_scp_send($this->sshResource, $localFilename, $this->getRemotePath($remoteFilename));
     if ($scpResult) {
         return $this;
     } else {
         throw new ConnectionException('Unable to upload file');
     }
 }
コード例 #11
0
ファイル: ScpTask.php プロジェクト: umesecke/phing
 public function main()
 {
     $this->determineEndpoints();
     $connection = ssh2_connect($this->host, $this->port);
     if (is_null($connection)) {
         throw new BuildException("Could not establish connection to " . $this->host . ":" . $this->port . "!");
     }
     $could_auth = ssh2_auth_password($connection, $this->username, $this->password);
     if (!$could_auth) {
         throw new BuildException("Could not authenticate connection!");
     }
     if (!is_null($this->mode)) {
         ssh2_scp_send($connection, $this->localEndpoint, $this->remoteEndpoint, $this->mode);
     } else {
         ssh2_scp_send($connection, $this->localEndpoint, $this->remoteEndpoint);
     }
 }
コード例 #12
0
ファイル: Sftp.php プロジェクト: nicevoice/yhtx
 public function put($local, $remote, $file_mode = 0644, $auto_mkdir = true, $dir_mode = 0644)
 {
     $dir = dirname($remote);
     $sftp = ssh2_sftp($this->conn_);
     $remote_dir = "ssh2.sftp://{$sftp}/{$dir}";
     if (!file_exists($remote_dir)) {
         if ($auto_mkdir) {
             $rc = mkdir($remote_dir, $dir_mode, true);
             if (false === $rc) {
                 $this->setErr_(-1, 'failed to mkdir ' . $dir);
                 return false;
             }
         } else {
             return false;
         }
     }
     return ssh2_scp_send($this->conn_, $local, $remote, $file_mode);
 }
コード例 #13
0
ファイル: remote.php プロジェクト: 0151n/vichan
 public function write($data, $remote_path)
 {
     global $config;
     switch ($this->type) {
         case 'sftp':
             $sftp = ssh2_sftp($this->connection);
             file_write('ssh2.sftp://' . $sftp . $remote_path, $data, true);
             break;
         case 'scp':
             $file = tempnam($config['tmp'], 'tinyboard-scp');
             // Write to temp file
             file_write($file, $data);
             ssh2_scp_send($this->connection, $file, $remote_path, 0755);
             break;
         default:
             error('Unknown send method.');
     }
 }
コード例 #14
0
ファイル: check.php プロジェクト: cleberps/linux-learn-map
function run_script_on_server($script, $server, $user, $public_key_file, $private_key_file)
{
    $con = ssh2_connect($server);
    if ($con === false) {
        return array(false, false);
    }
    $result = ssh2_auth_pubkey_file($con, $user, $public_key_file, $private_key_file);
    if (!$result) {
        return array(false, false);
    }
    $remote_script = basename($script);
    $result = ssh2_scp_send($con, $script, $remote_script, 0700);
    if (!$result) {
        return array(false, false);
    }
    $io_stream = ssh2_exec($con, "( ./{$remote_script} ) 2>&1; echo \$?");
    if ($io_stream) {
        stream_set_blocking($io_stream, true);
        $output = '';
        while (true) {
            $line = fgets($io_stream);
            if ($line === false) {
                break;
            }
            $output .= $line;
        }
        fclose($io_stream);
        $output = rtrim($output);
        $last_newline_index = strrpos($output, "\n");
        $status_code = intval(substr($output, $last_newline_index + 1));
        $output = substr($output, 0, $last_newline_index);
    } else {
        $output = false;
        $status_code = false;
    }
    $sftp_con = ssh2_sftp($con);
    if ($sftp_con) {
        ssh2_sftp_unlink($sftp_con, $remote_script);
    }
    return array($output, $status_code);
}
コード例 #15
0
function sftp_walk($con, $sftp, $local_dir, $remote_dir)
{
    $dir = opendir($local_dir);
    ssh2_sftp_mkdir($sftp, $remote_dir, 0755, true);
    while (($file = readdir($dir)) !== false) {
        $local_file = $local_dir . '/' . $file;
        $remote_file = $remote_dir . '/' . $file;
        if (!is_dir($local_file)) {
            echo "Transferring {$local_file} to {$remote_file}\n";
            $scp_ret = ssh2_scp_send($con, $local_file, $remote_file, 0755);
            if (!$scp_ret) {
                fwrite(STDERR, "Failed to transfer {$local_file}.\n");
                exit(8);
            }
        } else {
            if ($file != "." && $file != "..") {
                sftp_walk($con, $sftp, $local_file, $remote_file);
            }
        }
    }
}
コード例 #16
0
ファイル: SetTopGroup.php プロジェクト: josmel/movistar
 function coneccionSshImg($ids, $mLink, $config)
 {
     $porciones = explode(",", $ids);
     foreach ($porciones as $value) {
         $dataLink = $mLink->select($value);
         if ($dataLink) {
             $avanzado = ROOT_IMG_DINAMIC . '/link/' . $dataLink["imagen"];
             if (!function_exists("ssh2_connect")) {
                 die("function ssh2_connect doesn't exist");
             }
             if (!($con = ssh2_connect($config['app']['server'], $config['app']['puerto']))) {
                 echo "fail: unable to establish connection\n";
             } else {
                 if (!ssh2_auth_password($con, $config['app']['user'], $config['app']['pass'])) {
                     echo "fail: unable to authenticate\n";
                 } else {
                     ssh2_scp_send($con, $avanzado, $config['app']['rutaImg'] . 'link/' . $dataLink["imagen"], 0644);
                 }
                 ssh2_exec($con, 'exit');
             }
         }
     }
     return;
 }
コード例 #17
0
ファイル: SshService.php プロジェクト: Namiastek/SGD
 public function sendFile($localFile, $remoteFile, $permision = 0644)
 {
     if (!is_file($localFile)) {
         throw new Exception("Local file {$localFile} does not exist");
     }
     $this->logAction("Sending file {$localFile} as {$remoteFile}");
     $sftp = ssh2_sftp($this->conn);
     $sftpStream = @fopen('ssh2.sftp://' . $sftp . $remoteFile, 'w');
     if (!$sftpStream) {
         //  if 1 method failes try the other one
         if (!@ssh2_scp_send($this->conn, $localFile, $remoteFile, $permision)) {
             throw new Exception("Could not open remote file: {$remoteFile}");
         } else {
             return true;
         }
     }
     $data_to_send = @file_get_contents($localFile);
     if (@fwrite($sftpStream, $data_to_send) === false) {
         throw new Exception("Could not send data from file: {$localFile}.");
     }
     fclose($sftpStream);
     $this->logAction("Sending file {$localFile} as {$remoteFile} succeeded");
     return true;
 }
コード例 #18
0
ファイル: ScpSendTask.php プロジェクト: nhemsley/phing
 /**
  * The main entry point method.
  */
 public function main()
 {
     if (function_exists('ssh2_scp_send') && !is_null($this->_connection)) {
         if (!is_null($this->mode)) {
             ssh2_scp_send($this->_connection, $this->localFile, $this->remoteFile, $this->mode);
         } else {
             ssh2_scp_send($this->_connection, $this->localFile, $this->remoteFile);
         }
     } else {
         print "ERROR: No SSH Connection Available";
     }
 }
コード例 #19
0
ファイル: autoinstall.lib.php プロジェクト: Gunmania/xe-core
 /**
  * Copy directory
  *
  * @param array $file_list File list to copy
  * @return Object
  */
 function _copyDir(&$file_list)
 {
     if (!$this->ftp_password) {
         return new Object(-1, 'msg_ftp_password_input');
     }
     $output = $this->_connect();
     if (!$output->toBool()) {
         return $output;
     }
     $target_dir = $this->ftp_info->ftp_root_path . $this->target_path;
     if (is_array($file_list)) {
         foreach ($file_list as $k => $file) {
             $org_file = $file;
             if ($this->package->path == ".") {
                 $file = substr($file, 3);
             }
             $path = FileHandler::getRealPath("./" . $this->target_path . "/" . $file);
             $pathname = dirname($target_dir . "/" . $file);
             if (!file_exists(FileHandler::getRealPath($real_path))) {
                 ssh2_sftp_mkdir($this->sftp, $pathname, 0755, TRUE);
             }
             ssh2_scp_send($this->connection, FileHandler::getRealPath($this->download_path . "/" . $org_file), $target_dir . "/" . $file);
         }
     }
     return new Object();
 }
コード例 #20
0
ファイル: Catalog.php プロジェクト: hukumonline/quart80
 private function remotefile($type, $target_path, $remote_path, $catalogGuid = '', $ext = '')
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get(Pandamp_Keys::REGISTRY_APP_OBJECT);
     $ftp = $config->getOption('ftp');
     $strServer = $ftp['remote']['server'];
     $strServerPort = $ftp['remote']['port'];
     $strServerUsername = $ftp['remote']['username'];
     $strServerPassword = $ftp['remote']['passwd'];
     //connect to server
     $resConnection = ssh2_connect($strServer, $strServerPort);
     if (ssh2_auth_password($resConnection, $strServerUsername, $strServerPassword)) {
         $resSFTP = ssh2_sftp($resConnection);
         if ($type == 'image') {
             if (is_dir("ssh2.sftp://{$resSFTP}" . $remote_path)) {
                 ssh2_scp_send($resConnection, $target_path . "/" . $catalogGuid . "." . $ext, $remote_path . "/" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
                 if (file_exists($target_path . '/tn_' . $catalogGuid . "." . $ext)) {
                     ssh2_scp_send($resConnection, $target_path . '/tn_' . $catalogGuid . "." . $ext, $remote_path . "/tn_" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer thumbnail to {$strServer} - Operation aborted.");
                 }
             } else {
                 if (mkdir("ssh2.sftp://{$resSFTP}" . $remote_path)) {
                     ssh2_scp_send($resConnection, $target_path . "/" . $catalogGuid . "." . $ext, $remote_path . "/" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
                     if (file_exists($target_path . '/tn_' . $catalogGuid . "." . $ext)) {
                         ssh2_scp_send($resConnection, $target_path . '/tn_' . $catalogGuid . "." . $ext, $remote_path . "/tn_" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer thumbnail after mkdir to {$strServer} - Operation aborted.");
                     }
                 } else {
                     ssh2_scp_send($resConnection, $target_path . "/" . $catalogGuid . "." . $ext, $remote_path . "/" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
                     if (file_exists($target_path . '/tn_' . $catalogGuid . "." . $ext)) {
                         ssh2_scp_send($resConnection, $target_path . '/tn_' . $catalogGuid . "." . $ext, $remote_path . "/tn_" . $catalogGuid . "." . $ext, 0644) or die("Could not transfer thumbnail after mkdir to {$strServer} - Operation aborted.");
                     }
                 }
             }
         } elseif ($type == 'file') {
             if (is_dir("ssh2.sftp://{$resSFTP}" . $remote_path)) {
                 ssh2_scp_send($resConnection, $target_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), $remote_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
             } else {
                 if (mkdir("ssh2.sftp://{$resSFTP}" . $remote_path)) {
                     ssh2_scp_send($resConnection, $target_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), $remote_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
                 } else {
                     ssh2_scp_send($resConnection, $target_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), $remote_path . "/" . strtoupper(str_replace(' ', '_', $catalogGuid)), 0644) or die("Could not transfer to {$strServer} - Operation aborted.");
                 }
             }
         }
     }
 }
コード例 #21
0
ファイル: SSH.php プロジェクト: HakS/drupal8_training
 /**
  * Implements Drupal\Core\FileTransfer\FileTransfer::copyFileJailed().
  */
 protected function copyFileJailed($source, $destination)
 {
     if (!@ssh2_scp_send($this->connection, $source, $destination)) {
         throw new FileTransferException('Cannot copy @source_file to @destination_file.', NULL, array('@source' => $source, '@destination' => $destination));
     }
 }
コード例 #22
0
ファイル: LibSSH2.php プロジェクト: pear/net_ssh2
 /**
  * Send a file via SCP
  *
  * @param string $std_output The standard output of the executed command
  * @param string $std_error  The standard error of the executed command
  * @param array  $options    Additional options for the specified method
  *
  * @return mixed The exit code of the executed command or false on error
  */
 public function scpSend(&$std_output, &$std_error, $options = array())
 {
     //Check for valid options
     foreach ($options as $key => $value) {
         $this->{$key} = $value;
     }
     $exit_code = 255;
     try {
         $connection = $this->_authenticate($std_output);
         ssh2_scp_send($connection, $this->local_path, $this->remote_path, $this->create_mode);
         $exit_code = 0;
     } catch (Exception $e) {
         $std_output = $e->getMessage();
     }
     return $exit_code;
 }
コード例 #23
0
 /**
  * Copies a file to the remote system
  *
  * @param string $local
  * @param string $remote 
  */
 protected function copyFile($localEndpoint, $remoteEndpoint)
 {
     ssh2_sftp_mkdir($this->sftp, dirname($remoteEndpoint), 2775, true);
     $ret = ssh2_scp_send($this->connection, $localEndpoint, $remoteEndpoint);
     if ($ret === false) {
         throw new BuildException("Could not create remote file '" . $remoteEndpoint . "'");
     }
 }
コード例 #24
0
ファイル: gstep.php プロジェクト: BackupTheBerlios/ascore
function _scripting($connection)
{
    $fichero_destino = strftime("{$this->path}/{$this->ficheros}");
    /* Sustitucion de variables */
    $script = preg_replace("/__FECHA{([^\\{]{1,100}?)}/e", 'strftime("$1")', $this->script);
    //$script=$this->script;
    debug($script, "blue");
    /**/
    $localfile = "/tmp/" . md5(time() . serialize($_SESSION) . rand(0, 1000));
    $f_localfile = fopen($localfile, "wb");
    fwrite($f_localfile, $script);
    fclose($f_localfile);
    chmod($localfile, 0755);
    if (!ssh2_scp_send($connection, $localfile, $fichero_destino)) {
        $this->ERROR = "Error al copiar el script {$localfile},{$fichero_destino}";
        return false;
    }
    if ($this->comando) {
        return $this->_run_command($connection);
    }
    return true;
}
コード例 #25
0
 /**
  * Upload a file on the server
  *
  * @param      string     $remoteFilePath  The remote file path on the server
  * @param      string     $localFilePath   The local file path
  *
  * @throws     Exception  If the upload fails
  */
 public function upload(string $remoteFilePath, string $localFilePath)
 {
     ftp_pasv($this->resource, true);
     $fileName = basename($remoteFilePath);
     $pathFile = dirname($remoteFilePath);
     if ($pathFile !== '') {
         $this->changeDir($pathFile);
     }
     if (!ssh2_scp_send($this->sftp, $localFilePath, $fileName)) {
         throw new Exception('Fail to upload "' . $fileName . '" to "' . $pathFile . '"', Exception::$WARNING);
     }
     if ($this->verbose) {
         static::out('File "' . $localFilePath . '" successfully uploaded to "' . $remoteFilePath . '"' . PHP_EOL);
     }
 }
コード例 #26
0
    public static function render_page_process($PATH)
    {
        echo phoromatic_webui_header_logged_in();
        $main = null;
        if (!PHOROMATIC_USER_IS_VIEWER) {
            if (function_exists('ssh2_connect') && isset($_POST['ip']) && isset($_POST['port']) && isset($_POST['password']) && isset($_POST['username'])) {
                $connection = ssh2_connect($_POST['ip'], $_POST['port']);
                if (ssh2_auth_password($connection, $_POST['username'], $_POST['password'])) {
                    $tmp_local_file = tempnam('/tmp', 'pts-ssh');
                    $tmp_remote_file = 'pts-ssh-' . rand(9999, 99999);
                    file_put_contents($tmp_local_file, '#!/bin/sh
if [ -w /var/lib/phoronix-test-suite/ ]
then
	PHORO_FILE_PATH=/var/lib/phoronix-test-suite/
elif [ -w $HOME/.phoronix-test-suite/ ]
then
	PHORO_FILE_PATH=$HOME/.phoronix-test-suite/
fi

echo "' . phoromatic_web_socket_server_ip() . '" >> $PHORO_FILE_PATH/phoromatic-servers
mkdir -p $PHORO_FILE_PATH/modules-data/phoromatic
echo "' . phoromatic_web_socket_server_addr() . '" > $PHORO_FILE_PATH/modules-data/phoromatic/last-phoromatic-server
');
                    ssh2_scp_send($connection, $tmp_local_file, $tmp_remote_file);
                    unlink($tmp_local_file);
                    ssh2_exec($connection, 'chmod +x ' . $tmp_remote_file);
                    ssh2_exec($connection, './' . $tmp_remote_file);
                    ssh2_exec($connection, 'rm' . $tmp_remote_file);
                }
            }
            if (isset($_POST['ip_claim']) && !empty($_POST['ip_claim']) && isset($_POST['ping'])) {
                $ip_ping = ip2long($_POST['ip_claim']) !== false ? $_POST['ip_claim'] : null;
                if ($ip_ping) {
                    echo '<h3>Ping Test: ' . $ip_ping . '</h3>';
                    echo '<pre>';
                    echo shell_exec('ping -c 1 ' . $ip_ping);
                    echo '</pre>';
                }
            } else {
                if (isset($_POST['ip_claim']) && !empty($_POST['ip_claim']) || isset($_POST['mac_claim']) && !empty($_POST['mac_claim'])) {
                    $stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_system_association_claims (AccountID, IPAddress, NetworkMAC, CreationTime) VALUES (:account_id, :ip_address, :mac_address, :creation_time)');
                    $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                    $stmt->bindValue(':ip_address', $_POST['ip_claim']);
                    $stmt->bindValue(':mac_address', $_POST['mac_claim']);
                    $stmt->bindValue(':creation_time', phoromatic_server::current_time());
                    $result = $stmt->execute();
                }
            }
            if (isset($_POST['remove_claim']) && !empty($_POST['remove_claim'])) {
                list($ipc, $macc) = explode(',', $_POST['remove_claim']);
                $stmt = phoromatic_server::$db->prepare('DELETE FROM phoromatic_system_association_claims WHERE AccountID = :account_id AND NetworkMAC = :mac_address AND IPAddress = :ip_address');
                $stmt->bindValue(':account_id', $_SESSION['AccountID']);
                $stmt->bindValue(':ip_address', $ipc);
                $stmt->bindValue(':mac_address', $macc);
                $stmt->bindValue(':creation_time', phoromatic_server::current_time());
                $result = $stmt->execute();
            }
            $main .= '<h2>Add Phoromatic Server Info Via SSH</h2>
			<p>If your Phoromatic client systems are SSH-enabled, you can specify their SSH connection information below. In doing so, the Phoromatic Server will do a one-time connection to it immediately to pre-seed the system with the Phoromatic Server account information for this account. This should allow the client systems to then find the server automatically next time the phoronix-test-suite is run. This command assumes the Phoronix Test Suite is already pre-installed on the client system in your desired configuration.</p>';
            if (function_exists('ssh2_connect')) {
                $main .= '<h3>Phoromatic Client SSH Information:</h3>';
                $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="ssh_connect" method="post">
				<p><strong>IP Address:</strong> <input type="text" name="ip" /></p>
				<p><strong>SSH Port:</strong> <input type="text" name="port" value="22" /></p>
				<p><strong>Username:</strong> <input type="text" name="username" /></p>
				<p><strong>Password:</strong> <input type="password" name="password" /></p>
				<p><input name="submit" value="Seed Phoromatic Server Account Information" type="submit" /></p>
				</form>';
            } else {
                $main .= '<h3>PHP SSH2 Must Be Installed For This Feature</h3>';
            }
            $main .= '<hr />';
            $main .= '<h2>Add Phoromatic Server Info Via IP/MAC</h2>
			<p>If deploying a Phoromatic Server within an organization, you can attempt for automatic configuration of Phoromatic clients if you know the system\'s IP or MAC addresses. When specifying either of these fields, if a Phoromatic client attempts to connect to this Phoromatic system without being associated to an account, it will be claimed by this account as long as no other Phoromatic accounts are attempting to claim the IP/MAC. This method can be particularly useful if running the Phoromatic client as a systemd/Upstart service where it will continually poll every 90 seconds auto-detected Phoromatic Servers on the LAN via zero-conf networking. For this feature to work, the zero-conf networking (Avahi) support must be enabled and working.</p>';
            $main .= '<form action="' . $_SERVER['REQUEST_URI'] . '" name="auto_associate" method="post">
			<p><strong>IP Address Claim:</strong> <input type="text" name="ip_claim" /></p>
			<p><strong>MAC Address Claim:</strong> <input type="text" name="mac_claim" /></p>
			<p><input name="ping" value="Ping Test" type="submit" /> &nbsp; <input name="submit" value="Submit Claim" type="submit" /></p>
			</form>';
            $stmt = phoromatic_server::$db->prepare('SELECT * FROM phoromatic_system_association_claims WHERE AccountID = :account_id ORDER BY IPAddress ASC');
            $stmt->bindValue(':account_id', $_SESSION['AccountID']);
            $result = $stmt->execute();
            $claims = array();
            $main .= '<p style="max-height: 500px; overflow-y: auto; ">';
            while ($row = $result->fetchArray()) {
                $ip = $row['IPAddress'] != null ? $row['IPAddress'] : '<em>' . pts_network::mac_to_ip($row['NetworkMAC']) . '</em>';
                $main .= $ip . ' ' . $row['NetworkMAC'] . '<br />';
                array_push($claims, $row['IPAddress'] . ',' . $row['NetworkMAC']);
            }
            $main .= '</p>';
            if (!empty($claims)) {
                $main .= '<hr /><h2>Remove Claim</h2><p>Removing a claimed IP / MAC address.</p>';
                $main .= '<p><form action="' . $_SERVER['REQUEST_URI'] . '" name="remove_claim" method="post"><select name="remove_claim" id="remove_claim">';
                foreach ($claims as $claim) {
                    $main .= '<option value="' . $claim . '">' . str_replace(',', ' ', $claim) . '</option>';
                }
                $main .= '</select> <input name="submit" value="Remove Claim" type="submit" /></form></p>';
            }
            $main .= '<hr />';
        }
        $right = null;
        echo phoromatic_webui_main($main, phoromatic_webui_right_panel_logged_in($right));
        echo phoromatic_webui_footer();
    }
コード例 #27
0
     # Getting the dest server
     $query = "\tSELECT\n\t\t\t\t\t\t\t\t*\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t" . NQ_SERVER_DATABASE_BACKUP_TABLE . "\n\t\t\t\t\t\t\tLIMIT 1";
     $ssh_data = mysqli_single_result_query($G_CONTROLLER_DBLINK, $query);
     # Connecting to our remote server
     $ssh_connection = ssh2_connect($ssh_data['host'], 22);
     # Bad connection
     if (!$ssh_connection) {
         $status = 'CREATE Unable to connect to ' . $ssh_data['host'];
     }
     # Sending auth
     if ($ssh_connection && !ssh2_auth_password($ssh_connection, $ssh_data['ssh_username'], $ssh_data['ssh_password'])) {
         $status = 'CREATE Unable to log in to ' . $ssh_data['host'];
     }
     # Copying the file
     $destfile = 'W' . $partition_data['app_id'] . '-' . $partition_data['table_id'] . '-' . $partition_data['id'] . '-' . date('YmdHis') . '.sql.gz';
     if ($ssh_connection && !ssh2_scp_send($ssh_connection, $dumpfile, $ssh_data['ssh_path'] . $destfile, 0644)) {
         $status = 'CREATE Unable to transfer file to ' . $ssh_data['host'] . ' : ' . $ssh_data['ssh_path'];
     }
     # Adding to the number of tables backed up.
     $tables_backed_up++;
 } else {
     echo $command, '<br />';
     $status = 'CREATE Error dumping file. (' . print_r($options) . ')';
     # Adding to the number of tables not backed up.
     $tables_not_backed_up++;
 }
 # Adding our record
 $query = "\tINSERT INTO\n\t\t\t\t\t\t\t" . NQ_BACKUP_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $table_data['app_id'] . ",\n\t\t\t\t\t\t\t`table_id`\t\t=" . (int) $table_data['id'] . ",\n\t\t\t\t\t\t\t`partition_id`\t=" . (int) $partition_data['id'] . ",\n\t\t\t\t\t\t\t`host_id`\t\t=" . (int) $ssh_data['id'] . ",\n\t\t\t\t\t\t\t`filename`\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $destfile) . "',\n\t\t\t\t\t\t\t`filesize`\t\t=" . (int) filesize($dumpfile) . ",\n\t\t\t\t\t\t\t`created`\t\t=NOW(),\n\t\t\t\t\t\t\t`expires`\t\t='" . date('Y-m-01 00:00:00', strtotime('+1 year')) . "',\n\t\t\t\t\t\t\t`period`\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $period) . "',\n\t\t\t\t\t\t\t`status`\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $status) . "'";
 mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
 # Deleting the dumped file
 file_exists($dumpfile) && unlink($dumpfile);
コード例 #28
0
ファイル: SshClient.php プロジェクト: seferov/deployer-bundle
 /**
  * @param $file
  * @param $path
  */
 public function upload($file, $path)
 {
     ssh2_scp_send($this->stream, $file, $path);
 }
コード例 #29
0
 function put_contents($file, $contents, $type = '')
 {
     $this->debug("put_contents({$file});");
     $tempfile = wp_tempnam($file);
     $temp = fopen($tempfile, 'w');
     if (!$temp) {
         return false;
     }
     fwrite($temp, $contents);
     fclose($temp);
     $ret = ssh2_scp_send($this->link, $tempfile, $file, $this->permission);
     unlink($tempfile);
     return $ret;
 }
コード例 #30
0
ファイル: gsteplog.php プロジェクト: BackupTheBerlios/ascore
function _scripting($connection)
{
    $parent = newObject("gtasklog", $this->gtasklog_id);
    $fechadeevaluacion = $parent->inicio > 3600 ? $parent->inicio + $this->diasderetraso * 24 * 60 * 60 : $parent->inicio + $parent->diasderetraso * 24 * 60 * 60;
    $fichero_destino = strftime("{$this->path}/{$this->ficheros}", $fechadeevaluacion);
    /* Sustitucion de variables */
    $script = preg_replace("/__FECHA{([^\\{]{1,100}?)}/e", 'strftime("$1",' . $fechadeevaluacion . ')', $this->script);
    //$script=$this->script;
    debug($script, "blue");
    /**/
    $localfile = "/tmp/" . md5(time() . serialize($_SESSION) . rand(0, 1000));
    $f_localfile = fopen($localfile, "wb");
    fwrite($f_localfile, $script);
    fclose($f_localfile);
    chmod($localfile, 0755);
    if (!ssh2_scp_send($connection, $localfile, $fichero_destino)) {
        $this->ERROR = "Error al copiar el script {$localfile},{$fichero_destino}";
        return false;
    }
    $this->ultimoerror = "Script preparado. " . strftime("%d-%m-%Y %H:%M:%S");
    if ($this->comando) {
        return $this->_run_command($connection);
    }
    return true;
}