~ubuntu-branches/ubuntu/utopic/lasso/utopic-proposed

« back to all changes in this revision

Viewing changes to php/examples/sample-sp/setup.php

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2004-09-13 09:26:34 UTC
  • Revision ID: james.westby@ubuntu.com-20040913092634-01vdfl8j9cp94exa
Tags: upstream-0.4.1
ImportĀ upstreamĀ versionĀ 0.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*  
 
3
 *
 
4
 * Service Provider Example -- Installation Script
 
5
 *
 
6
 * Copyright (C) 2004 Entr'ouvert
 
7
 * http://lasso.entrouvert.org
 
8
 * 
 
9
 * Authors: Christophe Nowicki <cnowicki@easter-eggs.com>
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify
 
12
 * it under the terms of the GNU General Public License as published by
 
13
 * the Free Software Foundation; either version 2 of the License, or
 
14
 * (at your option) any later version.
 
15
 * 
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 * 
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
?>
 
26
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
27
<?php
 
28
 if(!extension_loaded('lasso')) {
 
29
        $ret = @dl('lasso.' . PHP_SHLIB_SUFFIX);
 
30
        if ($ret == FALSE)
 
31
        {
 
32
                print "<p align='center'><b>The Lasso Extension is not available</b><br>";
 
33
                print "Please check your PHP extensions<br>";
 
34
                print "You can get more informations about <b>Lasso</b> at <br>";
 
35
                print "<a href='http://lasso.entrouvert.org/'>http://lasso.entrouvert.org/</a></p>";
 
36
                exit();
 
37
        }
 
38
 }
 
39
 
 
40
        require_once 'DB.php';
 
41
 
 
42
        # default config
 
43
        if (!file_exists('config.inc'))
 
44
        {
 
45
          $cwd = getcwd();
 
46
          $config = array(
 
47
          'dsn' => "pgsql://sp:sp@localhost/sp",
 
48
          'server_dump_filename' => "lasso_server_dump.xml",
 
49
          'sp-metadata' => "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/metadata.xml",
 
50
          'sp-public_key' => "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/public-key.pem",
 
51
          'sp-private_key' => "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/private-key-raw.pem",
 
52
          'sp-ca' => "/home/cnowicki/mcvs/lasso/tests/data/sp1-la/certificate.pem",
 
53
          'idp-metadata' => "/home/cnowicki/mcvs/lasso/tests/data/idp1-la/metadata.xml",
 
54
          'idp-public_key' => "/home/cnowicki/mcvs/lasso/tests/data/idp1-la/public-key.pem",
 
55
          'idp-ca' => "/home/cnowicki/mcvs/lasso/tests/data/ca1-la/certificate.pem",
 
56
          );
 
57
 
 
58
          $config_ser = serialize($config);
 
59
 
 
60
          if (($fd = fopen("config.inc", "w")))
 
61
                {
 
62
                  fwrite($fd, $config_ser);
 
63
                  fclose($fd);
 
64
                }
 
65
          else
 
66
                die("Could not write default config file");
 
67
        }
 
68
        else 
 
69
        {
 
70
          $config = unserialize(file_get_contents('config.inc'));
 
71
        }
 
72
 
 
73
        if ($_POST['action'] == 'setup') 
 
74
        {
 
75
                ob_start();
 
76
                
 
77
                $setup = FALSE;
 
78
                
 
79
                print "<b>Lasso Service Provider Setup</b><br>";
 
80
 
 
81
                unset($_POST['action']);
 
82
 
 
83
                $diff = array_diff($_POST, $config);
 
84
 
 
85
                foreach($diff as $key => $value) {
 
86
                  $config[$key] = $value;
 
87
                }
 
88
                
 
89
                print "Check Data base : ";
 
90
 
 
91
                $db = &DB::connect($config['dsn']);
 
92
                
 
93
                if (DB::isError($db)) {
 
94
                  die("Failed (" . $db->getMessage() . ")");
 
95
                }
 
96
                else 
 
97
                  print "OK";
 
98
                 
 
99
                print "<br>Create sequence 'user_id_seq' : ";
 
100
                
 
101
                $query = "DROP SEQUENCE user_id_seq";
 
102
                $res =& $db->query($query);
 
103
                
 
104
                $query = "CREATE SEQUENCE user_id_seq";
 
105
                $res =& $db->query($query);
 
106
                if (DB::isError($res)) 
 
107
                  die($res->getMessage());
 
108
                
 
109
                print "OK";
 
110
 
 
111
                print "<br>Create table 'users' : ";
 
112
                $query = "DROP TABLE users CASCADE";
 
113
                $res =& $db->query($query);
 
114
 
 
115
                $query = "CREATE TABLE users (
 
116
                  user_id         varchar(100) primary key,
 
117
                  identity_dump   text,
 
118
                  first_name      varchar(50),
 
119
                  last_name       varchar(50),
 
120
                  last_login      timestamp,
 
121
                  created                 timestamp)";
 
122
                $res =& $db->query($query);
 
123
                if (DB::isError($res)) 
 
124
                  die($res->getMessage());
 
125
 
 
126
                print "OK";
 
127
 
 
128
                print "<br>Create table 'nameidentifiers' : ";
 
129
 
 
130
                $query = "DROP TABLE nameidentifiers CASCADE";
 
131
                $res =& $db->query($query);
 
132
 
 
133
                $query = "CREATE TABLE nameidentifiers (
 
134
                  name_identifier varchar(100) primary key,
 
135
                  user_id         varchar(100),
 
136
                  FOREIGN KEY (user_id) REFERENCES users (user_id))";
 
137
                $res =& $db->query($query);
 
138
                if (DB::isError($res)) 
 
139
                  die($res->getMessage()); 
 
140
 
 
141
                print "OK";
 
142
                
 
143
                $db->disconnect();
 
144
                
 
145
                $keys = array_keys($config);
 
146
                $files = preg_grep("/(sp|idp)/", $keys);
 
147
 
 
148
                foreach($files as $file)
 
149
                {
 
150
                  print "<br>Check file " . $config[$file] . " : ";
 
151
                  if (!file_exists($config[$file]))
 
152
                  {
 
153
                        die("Failed (file does not exist)");
 
154
                  }
 
155
                  else
 
156
                        print "OK";
 
157
                }
 
158
 
 
159
                lasso_init();
 
160
 
 
161
                print "<br>Create Server : ";
 
162
 
 
163
                $server = new LassoServer($config['sp-metadata'], 
 
164
                  $config['sp-public_key'], $config['sp-private_key'], 
 
165
                  $config['sp-ca'], lassoSignatureMethodRsaSha1);
 
166
 
 
167
                if (empty($server))
 
168
                {
 
169
                  die("Failed");
 
170
                } 
 
171
                else
 
172
                  print "OK";
 
173
 
 
174
                print "<br>Add provider : ";
 
175
 
 
176
                $ret = $server->addProvider($config['idp-metadata'], 
 
177
                  $config['idp-public_key'], $config['idp-ca']);
 
178
 
 
179
                /*if ($ret != TRUE)
 
180
                {
 
181
                  print "Failed";
 
182
                  break;
 
183
                } 
 
184
                else */
 
185
                  print "OK";
 
186
 
 
187
                print "<br>Write XML Server Dump : ";
 
188
 
 
189
                $dump = $server->dump();
 
190
                
 
191
                if (($fd = fopen($config['server_dump_filename'], "w")))
 
192
                {
 
193
                  fwrite($fd, $dump);
 
194
                  fclose($fd);
 
195
                  print "OK";
 
196
                }
 
197
                else
 
198
                  die("Failed");
 
199
 
 
200
                lasso_shutdown();
 
201
 
 
202
                print "<br>Save configuration file : ";
 
203
 
 
204
                # Save configuration file
 
205
                $config_ser = serialize($config);
 
206
                if (($fd = fopen("config.inc", "w")))
 
207
                {
 
208
                  fwrite($fd, $config_ser);
 
209
                  fclose($fd);
 
210
                  print "OK";
 
211
                } 
 
212
                else
 
213
                {
 
214
                  print("Failed");
 
215
                  break;
 
216
                }
 
217
                $setup = TRUE;
 
218
        }
 
219
                ob_start();
 
220
?>
 
221
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 
222
<head>
 
223
<title>Setup script for Lasso (Liberty Alliance Single Sign On)</title>
 
224
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
 
225
<?php
 
226
  if ($setup == TRUE) {
 
227
?>
 
228
<meta http-equiv="Refresh" CONTENT="3; URL=index.php">
 
229
<?php } ?>
 
230
</head>
 
231
<body>
 
232
<?php
 
233
  ob_end_flush();
 
234
  ob_end_flush();
 
235
  ?>
 
236
</body>
 
237
</html>
 
238
<?php
 
239
        if (empty($setup))
 
240
        {
 
241
?>
 
242
 
 
243
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
 
244
<head>
 
245
<title>Setup script for Lasso (Liberty Alliance Single Sign On)</title>
 
246
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
 
247
</head>
 
248
<body>
 
249
<form name='frm' action='<?php echo $PHP_SELF ?>' method='POST'>
 
250
<table>
 
251
<caption>Lasso Service Provider Setup</caption>
 
252
<tr>
 
253
  <td colspan='3' align='center'>Database Configuration</td>
 
254
</tr>
 
255
<tr>
 
256
  <td>DSN (Data Source Name) :</td><td><input type='text' name='dsn' size='50' value='<?php echo $config['dsn']; ?>' maxlength='100'></td><td><a href='http://pear.php.net/manual/en/package.database.db.intro-dsn.php' target='_new'>Help</a></td>
 
257
</tr>
 
258
<tr>
 
259
  <td>Server XML Dump:</td><td><input type='text' name='server_dump_filename' size='50' value='<?php echo $config['server_dump_filename']; ?>' maxlength='100'></td><td>&nbsp;</td>
 
260
 
 
261
</tr>
 
262
<tr>
 
263
  <td colspan='3' align='center'>Service Provider</td>
 
264
</tr>
 
265
 
 
266
<tr>
 
267
  <td>Metadata</td><td><input type='text' name='sp-metadata' size='50' value='<?php echo $config['sp-metadata']; ?>'></td><td>&nbsp;</td>
 
268
 
 
269
</tr>
 
270
 
 
271
<tr>
 
272
  <td>Public Key</td><td><input type='text' name='sp-public_key' size='50' value='<?php echo $config['sp-public_key']; ?>'></td><td>&nbsp;</td>
 
273
 
 
274
</tr>
 
275
 
 
276
<tr>
 
277
  <td>Private Key</td><td><input type='text' name='sp-private_key' size='50' value='<?php echo $config['sp-private_key']; ?>'></td><td>&nbsp;</td>
 
278
 
 
279
</tr>
 
280
 
 
281
<tr>
 
282
  <td>Certificate</td><td><input type='text' name='sp-ca' size='50' value='<?php echo $config['sp-ca']; ?>'></td><td>&nbsp;</td>
 
283
 
 
284
</tr>
 
285
 
 
286
<tr>
 
287
  <td colspan='3' align='center'>Identity Provider</td>
 
288
</tr>
 
289
 
 
290
<tr>
 
291
  <td>Metadata</td><td><input type='text' name='idp-metadata' size='50' value='<?php echo $config['idp-metadata']; ?>'></td><td>&nbsp;</td>
 
292
 
 
293
</tr>
 
294
<tr>
 
295
  <td>Public Key</td><td><input type='text' name='idp-public_key' size='50' value='<?php echo $config['idp-public_key']; ?>'></td><td>&nbsp;</td>
 
296
 
 
297
</tr>
 
298
<tr>
 
299
  <td>Certificate</td><td><input type='text' name='idp-ca' size='50' value='<?php echo $config['idp-ca']; ?>'></td><td>&nbsp;</td>
 
300
</tr>
 
301
 
 
302
<tr>
 
303
  <td colspan='3'>&nbsp;</td>
 
304
</tr>
 
305
 
 
306
<tr>
 
307
  <td align='center' colspan='3'><input type='submit' value='setup'></td>
 
308
</tr>
 
309
</table>
 
310
<input type='hidden' name='action' value='setup'>
 
311
</form>
 
312
</body>
 
313
</html>
 
314
<?php
 
315
  }
 
316
?>