summaryrefslogtreecommitdiffstats
path: root/modules/casserver/www/tickets.php
blob: 79498b1082d85769d1db6fe8cd945e7aa6190467 (plain)
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
<?php

function storeTicket($ticket, $path, $value ) {

	if (!is_dir($path)) 
		throw new Exception('Directory for CAS Server ticket storage [' . $path . '] does not exists. ');
		
	if (!is_writable($path)) 
		throw new Exception('Directory for CAS Server ticket storage [' . $path . '] is not writable. ');

	$filename = $path . '/' . $ticket;
	file_put_contents($filename, serialize($value));
}

function retrieveTicket($ticket, $path, $unlink = true) {

	if (!preg_match('/^(ST|PT|PGT)-?[a-zA-Z0-9]+$/D', $ticket)) throw new Exception('Invalid characters in ticket');

	if (!is_dir($path)) 
		throw new Exception('Directory for CAS Server ticket storage [' . $path . '] does not exists. ');

	$filename = $path . '/' . $ticket;

	if (!file_exists($filename))
		throw new Exception('Could not find ticket');
	
	$content = file_get_contents($filename);
	
	if ($unlink) {
		unlink($filename);
	}
	
	return unserialize($content);
}

function checkServiceURL($service, array $legal_service_urls) {
	foreach ($legal_service_urls AS $legalurl) {
		if (strpos($service, $legalurl) === 0) return TRUE;
	}
	return FALSE;
}