1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
set_include_path( |
4
|
|
|
'/var/www/html' . PATH_SEPARATOR . |
5
|
|
|
'/var/www/html/vendor/pear/pear-core-minimal/src' . PATH_SEPARATOR . |
6
|
|
|
'/var/www/html/vendor/pear/pear_exception' . PATH_SEPARATOR . |
7
|
|
|
'/var/www/html/vendor/pear/log' . PATH_SEPARATOR . |
8
|
|
|
'/var/www/html/vendor/pear/db' . PATH_SEPARATOR . |
9
|
|
|
'/var/www/html/vendor/pear/net_ldap2' . PATH_SEPARATOR . |
10
|
|
|
'/var/www/html/vendor/cilogon/service-lib/src/Service' . PATH_SEPARATOR . |
11
|
|
|
'.' |
12
|
|
|
); |
13
|
|
|
|
14
|
|
|
require_once 'config.php'; |
15
|
|
|
include_once 'config.secrets.php'; |
16
|
|
|
require_once 'DBService.php'; |
17
|
|
|
require_once 'Util.php'; |
18
|
|
|
require_once 'IdpList.php'; |
19
|
|
|
|
20
|
|
|
use CILogon\Service\IdpList; |
21
|
|
|
|
22
|
|
|
if ($argc == 4) { |
23
|
|
|
$command = $argv[1]; |
24
|
|
|
$file1 = $argv[2]; |
25
|
|
|
$file2 = $argv[3]; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
if ($command == 'xml2json') { |
29
|
|
|
$readtype = 'xml'; |
30
|
|
|
$writetype = 'json'; |
31
|
|
|
} elseif ($command = 'json2xml') { |
32
|
|
|
$readtype = 'json'; |
33
|
|
|
$writetype = 'xml'; |
34
|
|
|
} else { |
35
|
|
|
printUsage(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$idplist = new IdpList($file1, '', false, $readtype); |
39
|
|
|
if (!$idplist->read($readtype)) { |
|
|
|
|
40
|
|
|
fwrite(STDERR, "Unable to read from $file1\n"); |
41
|
|
|
exit(1); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$idplist->setFilename($file2); |
45
|
|
|
if (!$idplist->write($writetype)) { |
|
|
|
|
46
|
|
|
fwrite(STDERR, "Unable to write to $file2\n"); |
47
|
|
|
exit(1); |
48
|
|
|
} |
49
|
|
|
} else { |
50
|
|
|
printUsage(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
function printUsage() |
55
|
|
|
{ |
56
|
|
|
echo "Usage: convertidplist.php COMMAND {FILE1} {FILE2}\n"; |
57
|
|
|
echo " where COMMAND is one of the following:\n"; |
58
|
|
|
echo " xml2json - read FILE1 as XML and write FILE2 as JSON\n"; |
59
|
|
|
echo " json2xml - read FILE1 as JSON and write FILE2 as XML\n"; |
60
|
|
|
echo " FILE1 is the file to read from\n"; |
61
|
|
|
echo " FILE2 is the file to write to\n"; |
62
|
|
|
echo "Convert the idplist file betwewn XML and JSON.\n"; |
63
|
|
|
} |
64
|
|
|
|
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.