1#!/apps/bin/php
2<?
3# zxid/zxidhlocgi.php  -  Hello World SAML SP role in PHP using zxid extension
4#
5# Copyright (c) 2007 Symlabs (symlabs@symlabs.com), All Rights Reserved.
6# Author: Sampo Kellomaki (sampo@iki.fi)
7# This is confidential unpublished proprietary source code of the author.
8# NO WARRANTY, not even implied warranties. Contains trade secrets.
9# Distribution prohibited unless authorized in writing.
10# Licensed under Apache License 2.0, see file COPYING.
11# $Id: zxidhlocgi.php,v 1.1 2007-08-11 12:34:13 sampo Exp $
12# 16.1.2007, created --Sampo
13
14dl("php_zxid.so");  # These three lines can go to initialization: they only need to run once
15# CONFIG: You must have created /var/zxid directory hierarchy. See `make dir'
16# CONFIG: You must edit the URL to match your domain name and port
17$conf = "PATH=/var/zxid/&URL=https://sp1.zxidsp.org:8443/zxidhlocgi.php";
18$cf = zxid_new_conf_to_cf($conf);
19?>
20<?
21# For every page that is accessed. Debug: QUERY_STRING=o=E REQUEST_METHOD=GET ./zxidhlo.php
22#print_r(phpinfo());
23#print_r($_SERVER);
24$qs = $_SERVER['REQUEST_METHOD'] == 'GET'
25      ? $_SERVER['QUERY_STRING']
26      : file_get_contents('php://input');
27#error_log("zxidphp: qs($qs)");
28$res = zxid_simple_cf($cf, -1, $qs, null, 0x0814);
29#error_log("zxidphp: res($res) conf($conf)");
30
31switch (substr($res, 0, 1)) {
32case 'L': header($res); exit;  # Redirect (Location header)
33case '<': header('Content-type: text/xml'); echo $res; exit;  # Metadata or SOAP
34case 'n': exit;   # Already handled
35case 'e':
36?>
37Content-type: text/html
38
39<title>Please Login Using IdP</title>
40<body bgcolor="#330033" text="#ffaaff" link="#ffddff"
41 vlink="#aa44aa" alink="#ffffff"><font face=sans>
42<h1>Please Login Using IdP</h1>
43<?=zxid_idp_select_cf($cf, null, 0x0800)?>
44<hr>zxidhlo.php, <a href="http://zxid.org/">zxid.org</a>
45<?
46exit;
47case 'd': break;  # Logged in case -- continue after switch
48default:  die("Unknown zxid_simple() res($res)");
49}
50
51# Parse the LDIF in $res into a hash of attributes $attr
52
53foreach (split("\n", $res) as $line) {
54    $a = split(": ", $line);
55    $attr[$a[0]] = $a[1];
56}
57?>
58Content-type: text/html
59
60<title>Protected content, logged in</title>
61<body bgcolor="#330033" text="#ffaaff" link="#ffddff"
62 vlink="#aa44aa" alink="#ffffff"><font face=sans>
63<h1>Protected content, logged in as <?=$attr['cn']?>, session(<?=$attr['sesid']?>)</h1>
64<?=zxid_fed_mgmt_cf($cf, null, -1, $attr['sesid'], 0x0800)?>
65<hr>zxidhlo.php, <a href="http://zxid.org/">zxid.org</a>
66