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