summaryrefslogblamecommitdiffstats
path: root/library/Poolctrl/Acl.php
blob: 6cd7a8728a3f410945143fd32a682521ed068161 (plain) (tree)
























                                                                           
                                                                                          
                                 



                                                                


























                                                                                    
                                         
                                
                                         

                         
                                 
































                                            
<?php
/*
 * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
 * This program is free software distributed under the GPL version 2.
 * See http://gpl.openslx.org/
 *
 * If you have any feedback please consult http://feedback.openslx.org/ and
 * send your suggestions, praise, or complaints to feedback@openslx.org
 *
 * General information about OpenSLX can be found at http://openslx.org/
 */

class Poolctrl_Acl
{
	protected $host;
	protected $path;
	protected $referer;

	public function __construct($host, $path, $referer) {
		$this->host = $host;
		$this->path = $path;
		$this->referer = $referer;
	}

	public function checkRight($rightShortcut) {
		if(!isset($this->host) || !isset($this->path) || !isset($this->referer)) {
			return 0;
		}

		$dataToSend = "rightshortcut=" . $rightShortcut;
		$fp = @ fsockopen($this->host, 80);
		@ fputs($fp, "POST $this->path HTTP/1.1\r\n");
		@ fputs($fp, "Host: $this->host\r\n");
		@ fputs($fp, "User-Agent: poolctrl\r\n");
		@ fputs($fp, "Referer: $this->referer\r\n");
		@ fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
		@ fputs($fp, "Content-length: ". strlen($dataToSend) ."\r\n");
		@ fputs($fp, "Connection: close\r\n\r\n");
		@ fputs($fp, $dataToSend);

		$res = "";

		while(!@ feof($fp)) {
			$res .= @ fgets($fp, 128);
		}

		@ fclose($fp);

		$res = @ explode("\r\n\r\n",$res);
		$result['http-header'] = $res[0];
		$result['http-body'] = $res[1];
		$checkRightXMLString = $result['http-body'];

		if(strlen($checkRightXMLString) > 0) {
			$checkRightXML = new SimpleXMLElement($checkRightXMLString);
			$success = $checkRightXML->checkright->success;

			if($success == "true") {
				return 1;
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	}

	public function getHost()
	{
		return $this->host;
	}

	public function setHost($host)
	{
		$this->host = $host;
	}

	public function getPath()
	{
		return $this->path;
	}

	public function setPath($path)
	{
		$this->path = $path;
	}

	public function getReferer()
	{
		return $this->referer;
	}

	public function setReferer($referer)
	{
		$this->referer = $referer;
	}
}