10 use GuzzleHttp\Exception\RequestException;
12 define(
"TITLE_FOCONFIG", _(
"Configuration Variables"));
20 var $CreateAttempts = 0;
26 $this->Name =
"foconfig";
27 $this->Title = TITLE_FOCONFIG;
28 $this->MenuList =
"Admin::Customize";
30 $this->PluginLevel = 50;
31 parent::__construct();
32 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
44 $sql =
"select * from sysconfig order by group_name, group_order";
49 $InputStyle =
"style='background-color:#dbf0f7'";
50 $OutBuf .=
'<style> table.myTable > tbody > tr:first-child > td:first-child{width:20%} </style>';
51 $OutBuf .=
"<form method='POST'>";
52 while ($row = pg_fetch_assoc($result)) {
53 if ($Group != $row[
'group_name']) {
55 $OutBuf .=
"</table><br>";
57 $Group = $row[
'group_name'];
58 $OutBuf .=
'<table border=1 class="myTable table table-striped" style="border-collapse: unset;">';
61 $OutBuf .=
"<tr><td>$row[ui_label]</td><td>";
62 switch ($row[
'vartype']) {
65 $ConfVal = htmlentities($row[
'conf_value']);
66 $OutBuf .=
"<INPUT type='text' name='new[$row[variablename]]' size='70' value='$ConfVal' title='$row[description]' $InputStyle>";
67 $OutBuf .=
"<br>$row[description]";
70 $ConfVal = htmlentities($row[
'conf_value']);
71 $OutBuf .=
"<br><textarea name='new[$row[variablename]]' rows=3 cols=80 title='$row[description]' $InputStyle>$ConfVal</textarea>";
72 $OutBuf .=
"<br>$row[description]";
75 $ConfVal = htmlentities($row[
'conf_value']);
76 $OutBuf .=
"<INPUT type='password' name='new[$row[variablename]]' size='70' value='$ConfVal' title='$row[description]' $InputStyle>";
77 $OutBuf .=
"<br>$row[description]";
80 $ConfVal = htmlentities($row[
'conf_value']);
81 $Options = explode(
"|",$row[
'option_value']);
82 $OutBuf .=
"<select name='new[$row[variablename]]' title='$row[description]' $InputStyle>";
85 preg_match(
'/([ \\w]+)\\{(.*)\\}/', $Option, $matches);
86 $Option_display = $matches[1];
87 $Option_value = $matches[2];
88 $OutBuf .=
"<option $InputStyle value='$Option_value' ";
89 if ($ConfVal == $Option_value) {
90 $OutBuf .=
"selected";
92 $OutBuf .=
">$Option_display</option>";
94 $OutBuf .=
"</select>";
95 $OutBuf .=
"<br>$row[description]";
98 $ConfVal = filter_var($row[
'conf_value'], FILTER_VALIDATE_BOOLEAN);
99 $checked = $ConfVal ?
"checked" :
"";
100 $ConfVal = $ConfVal ?
"true" :
"false";
101 $OutBuf .=
"<input type='checkbox' name='new[" . $row[
'variablename'] .
102 "]' id='" . $row[
'variablename'] .
"' value='true' title='" .
103 $row[
'description'] .
"' $InputStyle $checked />";
104 $OutBuf .=
"<label for='" . $row[
'variablename'] .
105 "'>" . $row[
'description'] .
"</label>";
108 $ConfVal = $row[
'conf_value'];
109 $selectedIds = array_map(
'trim', explode(
',', $ConfVal));
110 $Options = explode(
"|", $row[
'option_value']);
111 $OutBuf .=
"<div id='" . $row[
'variablename'] .
"Div' style='display:inline-block; padding:5px;'>";
114 preg_match(
'/([ \\w]+)\\{(.*)\\}/', $Option, $matches);
115 $Option_display = $matches[1];
116 $Option_value = $matches[2];
117 $isChecked = in_array($Option_value, $selectedIds) ?
"checked" :
"";
118 $OutBuf .=
"<label style='margin-right:15px;'>";
119 $OutBuf .=
"<input type='checkbox' name='new[" . $row[
'variablename'] .
"][]' " .
120 "value='$Option_value' $isChecked /> $Option_display";
121 $OutBuf .=
"</label>";
124 $OutBuf .=
"<br>$row[description]";
127 $OutBuf .=
"Invalid configuration variable. Unknown type.";
129 $OutBuf .=
"</td></tr>";
130 $OutBuf .=
"<INPUT type='hidden' name='old[$row[variablename]]' value='$ConfVal'>";
132 $OutBuf .=
"</table>";
133 pg_free_result($result);
135 $btnlabel = _(
"Update");
136 $OutBuf .=
"<p><input type='submit' value='$btnlabel'>";
137 $OutBuf .=
"</form>";
141 var autoDetect = document.getElementById('ReuserAutoDetect');
142 var statusDiv = document.getElementById('ReuserSearchStatusDiv');
143 if (!autoDetect || !statusDiv) {
146 var toggle = function () {
147 var greyed = !autoDetect.checked;
148 statusDiv.style.opacity = greyed ? '0.4' : '1';
149 statusDiv.style.pointerEvents = greyed ? 'none' : 'auto';
151 autoDetect.addEventListener('change', toggle);
164 if ($this->
State != PLUGIN_STATE_READY) {
171 if (!empty($newarray)) {
173 $boolFalseArray = array_diff_key($oldarray, $newarray);
174 foreach ($boolFalseArray as $varname => $value) {
176 $isBoolean = $this->
dbManager->getSingleRow(
"SELECT 1 FROM sysconfig " .
178 array($varname), __METHOD__ .
'.checkIfBool');
179 if (! empty($isBoolean)) {
180 $newarray[$varname] =
'false';
183 $isChecklist = $this->
dbManager->getSingleRow(
"SELECT 1 FROM sysconfig " .
185 array($varname), __METHOD__ .
'.checkIfChecklist');
186 if (! empty($isChecklist)) {
187 $newarray[$varname] =
'';
191 foreach ($newarray as $varname => $value) {
192 if (is_array($value)) {
193 $newarray[$varname] = implode(
',', $value);
202 if (! empty($newarray)) {
204 if (! empty($newarray[
"OidcDiscoveryURL"]) &&
205 $newarray[
"OidcDiscoveryURL"] != $oldarray[
"OidcDiscoveryURL"]) {
208 foreach ($newarray as $VarName => $VarValue) {
209 if ($VarValue != $oldarray[$VarName]) {
211 $sys_array = $this->
dbManager->getSingleRow(
"select validation_function, ui_label from sysconfig where variablename=$1",array($VarName),__METHOD__.
'.getVarNameData');
212 $validation_function = $sys_array[
'validation_function'];
213 $ui_label = $sys_array[
'ui_label'];
214 $is_empty = empty($validation_function);
219 if ($is_empty || (! $is_empty && (1 == $validation_function($VarValue)))) {
221 "update sysconfig set conf_value=$1 where variablename=$2",
222 array($VarValue, $VarName), __METHOD__ .
'.setVarNameData');
223 if (! empty($UpdateMsg)) {
226 $UpdateMsg .= $VarName;
227 }
else if (! $is_empty && (0 == $validation_function($VarValue))) {
232 if (! strcmp($validation_function,
'check_boolean')) {
234 "Error: You set $ui_label to ".htmlspecialchars($VarValue).
". Valid values are 'true' and 'false'.");
235 echo
"<script>alert('$warning_msg');</script>";
236 }
else if (strpos($validation_function,
"url")) {
238 "Error: $ui_label ".htmlspecialchars($VarValue).
", is not a reachable URL.");
239 echo
"<script>alert('$warning_msg');</script>";
242 if (! empty($ErrorMsg)) {
245 $ErrorMsg .= $VarName;
250 if (! empty($UpdateMsg)) {
251 $UpdateMsg .= _(
" updated.");
253 if (! empty($ErrorMsg)) {
254 $ErrorMsg .= _(
" Error occurred.");
259 if ($this->OutputType ==
'HTML') {
262 $OutBuf .=
"<span style='background-color:#99FF99'>$UpdateMsg</style>";
265 $OutBuf .=
"<span style='background-color:#FF8181'>$ErrorMsg</style><hr>";
267 $OutBuf .=
"</div> <hr>";
270 $this->vars[
'content'] = $OutBuf;
286 $client =
new Client();
288 if (array_key_exists(
'http_proxy', $SysConf[
'FOSSOLOGY']) &&
289 ! empty($SysConf[
'FOSSOLOGY'][
'http_proxy'])) {
290 $proxy[
'http'] = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
292 if (array_key_exists(
'https_proxy', $SysConf[
'FOSSOLOGY']) &&
293 ! empty($SysConf[
'FOSSOLOGY'][
'https_proxy'])) {
294 $proxy[
'https'] = $SysConf[
'FOSSOLOGY'][
'https_proxy'];
296 if (array_key_exists(
'no_proxy', $SysConf[
'FOSSOLOGY']) &&
297 ! empty($SysConf[
'FOSSOLOGY'][
'no_proxy'])) {
298 $proxy[
'no'] = explode(
',', $SysConf[
'FOSSOLOGY'][
'no_proxy']);
301 $res = $client->request(
"GET", $newarray[
"OidcDiscoveryURL"], [
304 }
catch (RequestException $e) {
307 if ($res->getStatusCode() !== 200) {
310 $body = (string)$res->getBody();
311 $body = json_decode($body,
true);
313 $oldarray[
"OidcIssuer"] =
"";
314 $oldarray[
"OidcAuthorizeURL"] =
"";
315 $oldarray[
"OidcAccessTokenURL"] =
"";
316 $oldarray[
"OidcResourceURL"] =
"";
317 $oldarray[
"OidcJwksURL"] =
"";
318 $newarray[
"OidcIssuer"] = $body[
"issuer"];
319 $newarray[
"OidcAuthorizeURL"] = $body[
"authorization_endpoint"];
320 $newarray[
"OidcAccessTokenURL"] = $body[
"token_endpoint"];
321 $newarray[
"OidcResourceURL"] = $body[
"userinfo_endpoint"];
322 $newarray[
"OidcJwksURL"] = $body[
"jwks_uri"];
327 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
display and set FOSSology configuration
updateOidcEndpoints(&$newarray, &$oldarray)
Update OIDC endpoints from OIDC discovery document.
HTMLout()
Generate HTML output.
__construct()
base constructor. Most plugins will just use this
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
const CONFIG_TYPE_TEXTAREA
const CONFIG_TYPE_CHECKLIST
const CONFIG_TYPE_PASSWORD
if(!function_exists('resolve_config_value')) $Options
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
fo_dbManager * dbManager
fo_dbManager object