Example #1
0
 /**
  * Returns a specified number of bytes of a file. 
  * Defaults to FILE_DEFAULT_READSIZE.  If $size is 0, all file will be read.
  * 
  * @access  public 
  * @param   string  $filename Name of file to read from
  * @param   integer $size Bytes to read
  * @param   mixed   $lock Type of lock to use
  * @return  mixed   PEAR_Error on error or a string which contains the data read
  *                  Will also return false upon EOF
  */
 function read($filename, $size = FILE_DEFAULT_READSIZE, $lock = false)
 {
     static $filePointers;
     if (0 == $size) {
         return File::readAll($filename, $lock);
     }
     if (!isset($filePointers[$filename]) || !is_resource($filePointers[$filename])) {
         if (PEAR::isError($fp =& File::_getFilePointer($filename, FILE_MODE_READ, $lock))) {
             return $fp;
         }
         $filePointers[$filename] =& $fp;
     } else {
         $fp =& $filePointers[$filename];
     }
     return !feof($fp) ? fread($fp, $size) : false;
 }
Example #2
0
 /**
  * Install your public key in a remote machine’s authorized_keys
  *
  * @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
  *
  * @throws Net_SSH2_Exception If the public key is not found.
  * 
  * @return mixed The exit code of the executed command or false on error
  */
 public function sshCopyId(&$std_output, &$std_error, $options = array())
 {
     //Check for valid options
     foreach ($options as $key => $value) {
         $this->{$key} = $value;
     }
     if (!is_readable($this->public_identity_file)) {
         throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_PUBLIC_KEY_UNAVAILABLE));
     }
     $exit_code = 255;
     $pub_key = trim(File::readAll($this->public_identity_file), "\n");
     $pub_key_array = explode(' ', $pub_key);
     try {
         $connection = $this->_authenticate($std_output);
         $pkey = ssh2_publickey_init($connection);
         ssh2_publickey_add($pkey, $pub_key_array[0], base64_decode($pub_key_array[1]), false, array('comment' => $pub_key_array[2]));
         $exit_code = 0;
     } catch (Exception $e) {
         $std_output = $e->getMessage();
     }
     return $exit_code;
 }
Example #3
0
 function testreadAll()
 {
     $this->assertEquals($this->getTestString(), File::readAll('test.txt'));
     $this->assertEquals($this->getTestString(), File::readAll('test.txt'));
     $this->assertEquals($this->getTestString(), File::readAll('test.txt'));
 }
Example #4
0
 /**
  * Install your public key in a remote machine’s authorized_keys
  *
  * @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
  *
  * @throws Net_SSH2_Exception If trying if the public key option is not specified.
  * 
  * @return mixed The exit code of the executed command or false on error
  */
 public function sshCopyId(&$std_output, &$std_error, $options = array())
 {
     //Check for valid options
     foreach ($options as $key => $value) {
         $this->{$key} = $value;
     }
     if ($this->public_identity_file !== null) {
         $cmd = 'echo "' . trim(File::readAll($this->public_identity_file), "\n") . '"';
     } else {
         throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_OPTION_REQUIRED, 'public_identity_file'));
     }
     $cmd .= ' | ';
     if ($this->password !== null) {
         $this->sshAskPass($this->password);
         $cmd .= 'DISPLAY=none:0.0 SSH_ASKPASS='******' ';
     }
     //Check for setsid utility required on such linux systems
     $setsid_path = System::which('setsid');
     if (is_file($setsid_path)) {
         $cmd .= $setsid_path . ' ';
     }
     //Prepare the command line to execute for sshExec
     $cmd .= $this->_getBinaryPath('ssh');
     if ($this->login_name !== null) {
         $cmd .= ' -l ' . escapeshellarg($this->login_name);
     }
     if ($this->port !== null) {
         $cmd .= ' -p ' . $this->port;
     }
     if ($this->hostname !== null) {
         $cmd .= ' ' . escapeshellarg($this->hostname);
     }
     $cmd .= ' "umask 077; test -d .ssh || mkdir .ssh && touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys; cat >> .ssh/authorized_keys" || exit 1';
     return $this->exec($cmd, &$std_output, &$std_error);
 }
	/**
	 * Get all supported languages as an array of LanguageMetadata objects.
	 * @return array
	 */
	function getLanguages()
	{
	    global $g_localizerConfig;
	    $fileName = $g_localizerConfig['TRANSLATION_DIR']
	               .$g_localizerConfig['LANGUAGE_METADATA_FILENAME'];
    	if (file_exists($fileName)) {
    		$xml = File::readAll($path);
    		File::rewind($path, FILE_MODE_READ);
    		$handle = new XML_Unserializer($this->m_unserializeOptions);
        	$handle->unserialize($xml);
        	$arr = $handle->getUnserializedData();
            $languages = $arr['language'];
            foreach ($languages as $language) {
                $languageDef = new LanguageMetadata();
                $languageDef->m_languageId = $language['Code'];
                $languageDef->m_languageCode = '';
                $languageDef->m_countryCode = '';
                $languageDef->m_englishName = '';
                $languageDef->m_nativeName = '';
            }
        } else {
            return Localizer::GetLanguages();
        }
	} // fn getLanguages
Example #6
0
 public function importSQL($file)
 {
     require_once 'File.php';
     if (!is_file($file)) {
         return PHPWS_Error::get(BOOST_ERR_NO_INSTALLSQL, 'boost', 'importSQL', 'File: ' . $file);
     }
     $sql = File::readAll($file);
     $db = new PHPWS_DB();
     $result = $db->import($sql);
     return $result;
 }
Example #7
0
 /**
  *  Open an existing iCal file and parse it
  *
  *  @static
  *  @access public
  *  @param  string  $filename   file to open for parsing
  *  @param  bool    $return_all Some iCalendar files contain multiple iCalendar objects
  *                              If this parameter is true, all iCalendar objects will be returned.
  *                              This automatically sets the return type to array
  *                              If false, the return type will always be File_iCal_iCalendar
  *  @todo   Implement multiple iCalendars per file
  */
 public static function ReadFile($filename, $return_all = false)
 {
     require_once 'File.php';
     $data = File::readAll($filename);
     require_once 'File/iCal/iCalendar.php';
     $icalendar = new File_iCal_iCalendar($data);
     return $icalendar;
 }
Example #8
0
 /**
  * cleans the object, then loads the specified zonefile.
  *
  * @param string $domain   domainname of this zone
  * @param string $zonefile filename of zonefile to load.
  *                          Can be anything that PEAR::File can read.
  * @param int    $lock     type of lock to establish on the zonefile.
  *                          Set to LOCK_SH for a shared lock (reader)
  *                          Set to LOCK_EX for an exclusive lock (writer)
  *                          Add LOCK_NB if you don't want locking to block
  *
  * @return bool  true on success, PEAR Error on failure.
  * @access public
  */
 public function load($domain, $zonefile, $lock = false)
 {
     //First, clean off the object.
     $this->free();
     $zone = File::readAll($zonefile, $lock);
     if (PEAR::isError($zone)) {
         //File package doesn't have codes associated with errors,
         //so raise our own.
         throw new PEAR_Exception('Unable to read file ' . $zonefile, FILE_DNS_FILE_READALL_FAILED);
     }
     $ret = $this->setDomainName($domain);
     $this->_filename = $zonefile;
     $parse = $this->_parseZone($zone);
     $this->_isModified = false;
     return $parse;
 }