Example #1
0
 function testShell()
 {
     $Shell = new Shell();
     //
     // Delete tmp file
     //
     @unlink("/tmp/shelltest");
     $this->assertFalse(file_exists("/tmp/shelltest"), "Tmp file does not exists");
     //
     // Create tmp file
     //
     $Shell->Execute("touch", array("/tmp/shelltest"));
     $this->assertTrue(file_exists("/tmp/shelltest"), "Tmp file exists");
     //
     // ls -al
     //
     $result = $Shell->Query("ls", array("-al"));
     $this->assertTrue(!empty($result), "Result not empty");
     // Query raw
     $Shell->QueryRaw("ls -al");
     $this->assertTrue(!empty($result), "Result not empty");
 }
Example #2
0
        /**
         * Whois request
         *
         * @param string $host
         * @return string
         */
    	public function FetchRecord($host)
    	{
            // Cut off www
    		if(substr($host, 0, 4) == 'www.')
                $host = substr($host, 4);
    		
            // Extract TLD and find a suitable whois server
    	    $pi = pathinfo($host);
    	    $whoisinfo = $this->Servers[$pi["extension"]];
    	    
    	    
    	    if (!$whoisinfo[0])
    	    {
    	    	Core::RaiseWarning(sprintf(_("No custom whois server defined for %s. Using default one."), $host));
    	    	$hostparam = "";
    	    }
    	    else 
    	       $hostparam = " -h {$whoisinfo[0]}";
    	    	

    	    // Sanitize
    	    $host = escapeshellcmd($host);
    	   
    	       	     
    	    // Execute Shell command and Get result
    	    $retval = $this->Shell->QueryRaw("{$this->WhoisBinPath} {$hostparam} {$host}");
   	       	        
    	    
    	    // Check domain name existense and return false if domain NOT exists or Raw whois data about domain
    	    if (stristr($retval, $whoisinfo[1]) ||     
    	           stristr($retval, "hostname nor servname provided") || 
    	           preg_match("/((No entries found)|(No match)|(No Data Found)|(No match for)|(No data found))/si", $retval)
    	       )
    	        return false;
    	    else 
    	       return $retval;
    	}
Example #3
0
 public function SendTrap($trap)
 {
     return $this->Shell->QueryRaw(self::$SNMPTrapPath . ' -v 2c -c ' . $this->Community . ' ' . $this->Connection . ' "" ' . $trap);
 }
		/**
		* Find user by username
		* @access public
		* @param string $username username
		* @return SystemUser SystemUser object
		*/

		public function GetUserByUID($uid) 
		{
			if (!is_readable("/etc/passwd"))
				Core::RaiseError(_("/etc/passwd not readable"));
			
			$res = $this->Shell->QueryRaw("cat /etc/passwd | grep ':[\*x]:$uid:'");
			$rowarr = explode(":", $res);
			$retval = new SystemUser($rowarr[2]);
			return $retval;
		}
		/**
		* Validate license file
		* @access public
		* @return bool True in case if license is valid
		*/
		public final function ValidateLic()
		{
			$this->SelectWeakestLic();
			$licdata = $this->DecryptLic();
			
			$type = key($this->WeakestLic);
			
			// Remove this lic from Lics list
			array_shift($this->Lics);
			
			$contact = "Please contact " . LIC_EMAIL;
			
			$retval = ($type == $licdata[0]);
			
			// Check type matching
			if (!$retval && $this->ErrorOnFailure)
			{
				$this->RaiseError("License types don't match. {$contact}");
				die();
			}
			
			$retval &= ($licdata[2] >= time());
			
			// Check expiration
			if (!$retval && $this->ErrorOnFailure)
			{
				$this->RaiseError("License expired. {$contact}");
				die();
			}
			
			
			$retval &= ($licdata[4] == LIC_PRODUCTID || $licdata[4] == $this->ProductID);
			
			// Check Product ID
			if (!$retval && $this->ErrorOnFailure)
			{
				$this->RaiseError("This license was generated for another product. {$contact}");
				die();
			}
			
			if ($licdata[5])
				$md5_prepend = @md5_file(LIBWEBTA_BASE . "/../../prepend.inc.php");
			if ($licdata[6])
				$md5_lic = @md5_file(__FILE__);
			
			$retval &= ((!$licdata[5] || ($licdata[5] == $md5_prepend)) && (!$licdata[6] || ($licdata[6] == $md5_lic)));
			
			// Checksum
			if (!$retval && $this->ErrorOnFailure)
			{
				$this->RaiseError("Invalid checksum. {$contact}");
				die();
			}
			
		
			// Check value
			switch ($type)
			{
				default:
				case "ip":
					
					$message = "IP address of the server and IP address of license do not match.";
					if (!getenv("windir") && !preg_match("/windows/i", getenv("OS")))
					{
						$retval &= count($this->Shell->QueryRaw("/sbin/ifconfig | grep {$licdata[1]}", false));

						if (!$retval)
						{
						    $ip = @gethostbyname($_SERVER['HTTP_HOST']);
						    $retval &= ($ip == $licdata[1]);
						}
					}
					else 
					{
						$ip = @gethostbyname($_SERVER['HTTP_HOST']);
						$retval &= ($ip == $licdata[1]);
					}
					break;
					
				case "trial":
					
					// Nothing to do here. Expiration already being checked
					break;
					
			}
			
			
			
			if (!$retval)
			{
				// Try to validate next lic in Lics
				while(count($this->Lics) > 0)
					$retval = $this->ValidateLic();
			}
			
			if (!$retval && $this->ErrorOnFailure)
			{
				$this->RaiseError("Invalid license: $message $contact");
				die();
			}
			
			return $retval;
		}