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 >= 2) && ($argc <= 4)) { |
23
|
|
|
$idpfile = $argv[1]; |
24
|
|
|
$filetype = 'json'; |
25
|
|
|
if ($argc >= 3) { |
26
|
|
|
$filetype = strtolower($argv[2]); |
27
|
|
|
} |
28
|
|
|
$checkfornew = 0; |
29
|
|
|
if ($argc >= 4) { |
30
|
|
|
$checkfornew = 1; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$oldEntityIdList = array(); |
34
|
|
|
|
35
|
|
|
// If checkfornew, attempt to read in the already existing |
36
|
|
|
// /var/www/html/include/idplist.{json,xml} file so we can use |
37
|
|
|
// that as the list of current IdPs. This will allow us to find |
38
|
|
|
// out if any new IdPs have been added to the InCommon metadata. |
39
|
|
|
if ($checkfornew) { |
40
|
|
|
// First, try reading /var/www/html/include/idplist.json |
41
|
|
|
$oldidplist = new IdpList(DEFAULT_IDP_JSON, '', false, 'json'); |
42
|
|
|
$oldEntityIDList = $oldidplist->getEntityIDs(); |
43
|
|
|
if (empty($oldEntityIDList)) { |
44
|
|
|
// Next, try /var/www/html/include/idplist.xml |
45
|
|
|
$filename = preg_replace( |
46
|
|
|
'/\.json$/', |
47
|
|
|
'.xml', |
48
|
|
|
DEFAULT_IDP_JSON |
49
|
|
|
); |
50
|
|
|
$oldidplist = new IdpList($filename, '', false, 'xml'); |
51
|
|
|
$oldEntityIDList = $oldidplist->getEntityIDs(); |
52
|
|
|
} |
53
|
|
|
// If we couldn't read in an exiting idplist, print warning message. |
54
|
|
|
if (empty($oldEntityIDList)) { |
55
|
|
|
fwrite( |
56
|
|
|
STDERR, |
57
|
|
|
"Warning: Unable to read an existing idplist file,\n", |
58
|
|
|
" so unable to check for new InCommon IdPs.\n" |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Now, create a new idplist from the InCommon Metadata |
64
|
|
|
$idplist = new IdpList( |
65
|
|
|
$idpfile, |
66
|
|
|
DEFAULT_INCOMMON_XML, |
67
|
|
|
false, |
68
|
|
|
$filetype |
69
|
|
|
); |
70
|
|
|
$idplist->create(); |
71
|
|
|
if (!$idplist->write($filetype)) { |
|
|
|
|
72
|
|
|
fwrite( |
73
|
|
|
STDERR, |
74
|
|
|
"Error! There was a problem writing to the file '" . |
75
|
|
|
$idpfile . "'\n" |
76
|
|
|
); |
77
|
|
|
exit(1); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// If we successfully read in a 'good' idplist.{json.xml} file from |
81
|
|
|
// /var/www/html/include, use that as the list of currently |
82
|
|
|
// 'greenlit' IdPs and check to see if any new IdP were added to |
83
|
|
|
// the InCommon metadata. |
84
|
|
|
$newIdPList = array(); |
85
|
|
|
if (!empty($oldEntityIDList)) { |
86
|
|
|
$entityIDList = $idplist->getEntityIDs(); |
87
|
|
|
foreach ($entityIDList as $value) { |
88
|
|
|
if (!in_array($value, $oldEntityIDList)) { |
89
|
|
|
$newIdPList[$value] = 1; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// Found some new InCommon metadata entries. Print them to STDOUT. |
95
|
|
|
if (!empty($newIdPList)) { |
96
|
|
|
$plural = (count($newIdPList) > 1); |
97
|
|
|
echo($plural ? 'New' : 'A new') , ' Identity Provider', |
98
|
|
|
($plural ? 's were' : ' was') , ' found in metadata ', |
99
|
|
|
"and added to the \nlist of available IdPs.\n", |
100
|
|
|
'--------------------------------------------------------------', |
101
|
|
|
"\n\n"; |
102
|
|
|
foreach ($newIdPList as $entityID => $value) { |
103
|
|
|
echo "EntityId = $entityID\n"; |
104
|
|
|
echo "Organization Name = " . |
105
|
|
|
$idplist->getOrganizationName($entityID) . "\n"; |
106
|
|
|
echo "Display Name = " . |
107
|
|
|
$idplist->getDisplayName($entityID) . "\n"; |
108
|
|
|
if ($idplist->isRegisteredByInCommon($entityID)) { |
109
|
|
|
echo "Registered by InCommon = Yes\n"; |
110
|
|
|
} |
111
|
|
|
if ($idplist->isInCommonRandS($entityID)) { |
112
|
|
|
echo "InCommon R & S = Yes\n"; |
113
|
|
|
} |
114
|
|
|
if ($idplist->isREFEDSRandS($entityID)) { |
115
|
|
|
echo "REFEDS R & S = Yes\n"; |
116
|
|
|
} |
117
|
|
|
if ($idplist->isSIRTFI($entityID)) { |
118
|
|
|
echo "SIRTFI = Yes\n"; |
119
|
|
|
} |
120
|
|
|
echo "\n"; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} else { |
124
|
|
|
printUsage(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
function printUsage() |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
echo "Usage: idplist.php IDPFILE {FILETYPE} <CHECK>\n"; |
130
|
|
|
echo " IDPFILE is the full path name of the idplist file.\n"; |
131
|
|
|
echo " FILETYPE is either 'xml' or 'json'. Defaults to 'json.'\n"; |
132
|
|
|
echo " CHECK means see if new IdPs added to InCommon metadata.\n"; |
133
|
|
|
echo "This function reads the InCommon metadata and writes out the\n"; |
134
|
|
|
echo "IDPFILE, which contains the list of all IdPs along with\n"; |
135
|
|
|
echo "their attributes needed by the CILogon Service.\n"; |
136
|
|
|
echo "If CHECK (optional) is specified, it attempts to read in an\n"; |
137
|
|
|
echo "existing /var/www/html/include,{json,xml} file as the 'current'\n"; |
138
|
|
|
echo "list of IdPs so it can check if any new IdPs have beenn added\n"; |
139
|
|
|
echo "to InCommon metadata. If so, the new IdPs are printed to STDOUT.\n"; |
140
|
|
|
} |
141
|
|
|
|
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.