summaryrefslogtreecommitdiffstats
path: root/library/Poolctrl/Acl.php
blob: 6cd7a8728a3f410945143fd32a682521ed068161 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?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;
	}
}