Exemplo n.º 1
0
  function __construct($server_url,
		       $root = null, $rw = false, $debug = false)
  {
    parent::__construct($server_url);
    $this->_root = $root;
    $this->_rw = $rw;
    $this->_debug = $debug;
  }
Exemplo n.º 2
0
 function __construct($server_url, $url_template, $logger = NULL)
 {
   parent::__construct($server_url, $logger);
   $this->_url_template = $url_template;
 }
Exemplo n.º 3
0
  private function request($peer, $packet)
  {
    if(strlen($packet) < 4) {
      $this->log_debug($peer, "request: short packet");
      return false;
    }

    $reply = false;
    $transfer = false;
    if(isset($this->_transfers[$peer])) {
      $this->log_debug($peer, "request: existing transfer");
      $transfer = $this->_transfers[$peer];
    }

    $fields = unpack("n", $packet);
    $op = $fields[1];
    $this->log_debug($peer, "request: opcode " .
		     TFTPOpcode::name($op) . " ($op)");
    switch($op) {
      case TFTPOpcode::WRQ:
      case TFTPOpcode::RRQ:
	$a = explode("\0", substr($packet, 2));
	if(count($a) < 3 || $a[count($a) - 1] != "") {
	  $this->log_warning($peer, "request: malformed " .
			     TFTPOpcode::name($op));
	  return false;
	}

	$rawexts = array_slice($a, 2, -1);

	// Cisco IP Phone 7941 (and possibly others) return an extra null
	// at the end; a breach of RFC rfc2347. This is a workaround.
	// If odd count strip last and continue if empty, else warn and ignore
	if(count($rawexts) % 2 != 0) {
	  if(array_pop($rawexts)!="") {
	    $this->log_warning($peer, "request: malformed extension " .
			       "key/value pairs " . TFTPOpcode::name($op));
	    return false;
	  }
	}

	$extensions = array();
	foreach(array_chunk($rawexts, 2) as $pair)
	  $extensions[strtolower($pair[0])] = $pair[1];

	if($transfer === false) {
	  if($op == TFTPOpcode::RRQ)
	    $transfer = new TFTPReadTransfer($this, $peer, $extensions);
	  else
	    $transfer = new TFTPWriteTransfer($this, $peer, $extensions);

	  $this->_transfers[$peer] = $transfer;
	}
	
	if($op == TFTPOpcode::RRQ)
	  $reply = $transfer->rrq($a[0], $a[1]);
	else
	  $reply = $transfer->wrq($a[0], $a[1]);

	break;
      case TFTPOpcode::ACK:
	if(strlen($packet) != 4) {
	  $this->log_warning($peer, "request: malformed ACK");
	  return false;
	}

	$a = unpack("n", substr($packet, 2));
	if($transfer === false) {
	  // do not warn, some clients like BSD tftp sends ack on read error
	  $this->log_debug($peer, "request: ack from unknwon peer");
	} else
	  $reply = $transfer->ack($a[1]);
	break;
      case TFTPOpcode::DATA:
	if(strlen($packet) < 4) {
	  $this->log_warning($peer, "request: malformed DATA");
	  return false;
	}
	
	$a = unpack("n", substr($packet, 2));
	$data = substr($packet, 4, strlen($packet) - 4);
	if($transfer === false) {
	  $this->log_warning($peer, "request: data from unknwon peer");
	  $reply = TFTPServer::packet_error(TFTPError::UNKNOWN_TID,
					    "Unknown TID for DATA");
	} else
	  $reply = $transfer->data($a[1], $data);
	break;
      case TFTPOpcode::ERROR:
	$a = unpack("n", substr($packet, 2, 2));
	$message = substr($packet, 4, strlen($packet) - 5);

	if($transfer === false)
	  $this->log_warning($peer, "request: error from unknwon peer, " .
			     "{$a[1]}:$message");
	else
	  $transfer->error($a[1], $message);
	break;
      default:
	break;
    }

    if($transfer !== false &&
       $transfer->state == TFTPTransferState::TERMINATING) {
      $this->log_debug($peer, "request: terminating");
      unset($this->_transfers[$transfer->peer]);
    }

    return $reply;
  }
Exemplo n.º 4
0
 function __construct($server_url, $debug = false)
 {
   parent::__construct($server_url);
   $this->_debug = $debug;
   $this->max_put_size = 60000000;
 }
Exemplo n.º 5
0
 function __construct($server_url, $config)
 {
   parent::__construct($server_url);
   $this->_config = $config;
 }