|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* ***************************************************************************** |
|
4
|
|
|
* Contributions to this work were made on behalf of the GÉANT project, a |
|
5
|
|
|
* project that has received funding from the European Union’s Framework |
|
6
|
|
|
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus), |
|
7
|
|
|
* Horizon 2020 research and innovation programme under Grant Agreements No. |
|
8
|
|
|
* 691567 (GN4-1) and No. 731122 (GN4-2). |
|
9
|
|
|
* On behalf of the aforementioned projects, GEANT Association is the sole owner |
|
10
|
|
|
* of the copyright in all material which was developed by a member of the GÉANT |
|
11
|
|
|
* project. GÉANT Vereniging (Association) is registered with the Chamber of |
|
12
|
|
|
* Commerce in Amsterdam with registration number 40535155 and operates in the |
|
13
|
|
|
* UK as a branch of GÉANT Vereniging. |
|
14
|
|
|
* |
|
15
|
|
|
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. |
|
16
|
|
|
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK |
|
17
|
|
|
* |
|
18
|
|
|
* License: see the web/copyright.inc.php file in the file structure or |
|
19
|
|
|
* <base_url>/copyright.php after deploying the software |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* This page is used create a duplicate of a RADIUS profile by its administrator. |
|
24
|
|
|
* The new profile will have the display names replaces with one velue set by |
|
25
|
|
|
* the admin during duplication. The production-ready flag will be removed. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Tomasz Wolniewicz <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
?> |
|
30
|
|
|
|
|
31
|
|
|
<?php |
|
32
|
|
|
require_once dirname(dirname(dirname(__FILE__))) . "/config/_config.php"; |
|
33
|
|
|
|
|
34
|
|
|
$deco = new \web\lib\admin\PageDecoration(); |
|
35
|
|
|
$validator = new \web\lib\common\InputValidation(); |
|
36
|
|
|
$auth = new \web\lib\admin\Authentication(); |
|
37
|
|
|
$auth->authenticate(); |
|
38
|
|
|
|
|
39
|
|
|
function copyRow($row, $feldsArray, $table, $dbHandle) { |
|
40
|
|
|
$fieldsList = implode(',', array_keys($row)); |
|
41
|
|
|
foreach ($row as $key => $value) { |
|
42
|
|
|
if ($feldsArray[$key] == 's') { |
|
43
|
|
|
if ($value === null) { |
|
44
|
|
|
$row[$key] = 'NULL'; |
|
45
|
|
|
} else { |
|
46
|
|
|
$row[$key] = '"'.$value.'"'; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$valuesList = implode(',', array_values($row)); |
|
51
|
|
|
$insert = 'INSERT INTO '.$table.' ('.$fieldsList.') VALUES ('.$valuesList.')'; |
|
52
|
|
|
$dbHandle->exec($insert); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function runSelect($profileId, $feldsArray, $table, $dbHandle) { |
|
56
|
|
|
$fieldsList = implode(',', array_keys($feldsArray)); |
|
57
|
|
|
$query = 'SELECT '.$fieldsList.' FROM '.$table.' WHERE profile_id=?'; |
|
58
|
|
|
return $dbHandle->exec($query, "i", $profileId); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$fields = [ |
|
62
|
|
|
'inst_id'=>'i', |
|
63
|
|
|
'realm'=>'s', |
|
64
|
|
|
'use_anon_outer'=>'i', |
|
65
|
|
|
'showtime'=>'i', |
|
66
|
|
|
'sufficient_config'=>'i', |
|
67
|
|
|
'checkuser_value'=>'s', |
|
68
|
|
|
'verify_userinput_suffix'=>'i', |
|
69
|
|
|
'hint_userinput_suffix'=>'i', |
|
70
|
|
|
'openroaming'=>'i', |
|
71
|
|
|
'preference'=>'i' |
|
72
|
|
|
]; |
|
73
|
|
|
|
|
74
|
|
|
$optionsFields = [ |
|
75
|
|
|
'profile_id'=>'i', |
|
76
|
|
|
'eap_method_id'=>'i', |
|
77
|
|
|
'device_id'=>'s', |
|
78
|
|
|
'option_name'=>'s', |
|
79
|
|
|
'option_value'=>'s', |
|
80
|
|
|
'option_lang'=>'s' |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
$eapFields = [ |
|
84
|
|
|
'profile_id'=>'i', |
|
85
|
|
|
'eap_method_id'=>'i', |
|
86
|
|
|
'preference'=>'i' |
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
[$my_inst, $editMode] = $validator->existingIdPInt($_POST['inst_id'], $_SESSION['user']); |
|
90
|
|
|
echo $deco->defaultPagePrelude(sprintf(_("%s: Profile duplication (Step 2)"), \config\Master::APPEARANCE['productname'])); |
|
91
|
|
|
echo "<body>"; |
|
92
|
|
|
echo $deco->productheader("ADMIN-IDP"); |
|
93
|
|
|
if ($editMode !== 'fullaccess') { |
|
94
|
|
|
echo "<h2>"._("No write access to this IdP"); |
|
95
|
|
|
exit; |
|
96
|
|
|
} |
|
97
|
|
|
if (isset($_POST['profile_id'])) { |
|
98
|
|
|
$my_profile = $validator->existingProfile($_POST['profile_id'], $my_inst->identifier); |
|
99
|
|
|
if (!$my_profile instanceof \core\ProfileRADIUS) { |
|
100
|
|
|
throw new Exception("This page is only for editing RADIUS profiles!"); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$newProfileName = $validator->string($_POST['new_profile'], true); |
|
105
|
|
|
$origProfileName = $validator->string($_POST['orig_profile_name'], true); |
|
106
|
|
|
$handle = \core\DBConnection::handle("INST"); |
|
107
|
|
|
|
|
108
|
|
|
$result = runSelect($my_profile->identifier, $fields, 'profile', $handle); |
|
109
|
|
|
$row = $result->fetch_assoc(); |
|
110
|
|
|
$row['showtime']= 0; |
|
111
|
|
|
$row['preference'] = 1000; |
|
112
|
|
|
copyRow($row, $fields, 'profile', $handle); |
|
113
|
|
|
$newProfileId = $handle->lastID(); |
|
114
|
|
|
|
|
115
|
|
|
$result = runSelect($my_profile->identifier, $optionsFields, 'profile_option', $handle); |
|
116
|
|
|
while ($row = $result->fetch_assoc()) { |
|
117
|
|
|
$row['profile_id'] = $newProfileId; |
|
118
|
|
|
if ($row['option_name'] == 'profile:name' || $row['option_name'] == 'profile:production') { |
|
119
|
|
|
continue; |
|
120
|
|
|
} |
|
121
|
|
|
copyRow($row, $optionsFields, 'profile_option', $handle); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$row = [ |
|
125
|
|
|
'profile_id'=>$newProfileId, |
|
126
|
|
|
'option_name'=>'profile:name', |
|
127
|
|
|
'option_value'=>$newProfileName, |
|
128
|
|
|
'option_lang'=>'C' |
|
129
|
|
|
]; |
|
130
|
|
|
copyRow($row, $optionsFields, 'profile_option', $handle); |
|
131
|
|
|
|
|
132
|
|
|
$result = runSelect($my_profile->identifier, $eapFields, 'supported_eap', $handle); |
|
133
|
|
|
while ($row = $result->fetch_assoc()) { |
|
134
|
|
|
$row['profile_id'] = $newProfileId; |
|
135
|
|
|
copyRow($row, $optionsFields, 'supported_eap', $handle); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
printf("<h1>"._("Copied %s to %s")."</h1>", $origProfileName, $newProfileName); ?> |
|
139
|
|
|
|
|
140
|
|
|
<button type="button" id="cancel" name="cancel" value="abort" onclick="javascript:window.location = 'overview_org.php?inst_id=<?php echo $my_inst->identifier?>'"><?php echo _("Continue to dashboard"); ?></button> |
|
141
|
|
|
<?php echo $deco->footer(); |