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>";
83 foreach ($Options as $Option) {
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 $OutBuf .=
"Invalid configuration variable. Unknown type.";
110 $OutBuf .=
"</td></tr>";
111 $OutBuf .=
"<INPUT type='hidden' name='old[$row[variablename]]' value='$ConfVal'>";
113 $OutBuf .=
"</table>";
114 pg_free_result($result);
116 $btnlabel = _(
"Update");
117 $OutBuf .=
"<p><input type='submit' value='$btnlabel'>";
118 $OutBuf .=
"</form>";
128 if ($this->
State != PLUGIN_STATE_READY) {
135 if (!empty($newarray)) {
137 $boolFalseArray = array_diff_key($oldarray, $newarray);
138 foreach ($boolFalseArray as $varname => $value) {
140 $isBoolean = $this->
dbManager->getSingleRow(
"SELECT 1 FROM sysconfig " .
142 array($varname), __METHOD__ .
'.checkIfBool');
143 if (! empty($isBoolean)) {
144 $newarray[$varname] =
'false';
153 if (! empty($newarray)) {
155 if (! empty($newarray[
"OidcDiscoveryURL"]) &&
156 $newarray[
"OidcDiscoveryURL"] != $oldarray[
"OidcDiscoveryURL"]) {
159 foreach ($newarray as $VarName => $VarValue) {
160 if ($VarValue != $oldarray[$VarName]) {
162 $sys_array = $this->
dbManager->getSingleRow(
"select validation_function, ui_label from sysconfig where variablename=$1",array($VarName),__METHOD__.
'.getVarNameData');
163 $validation_function = $sys_array[
'validation_function'];
164 $ui_label = $sys_array[
'ui_label'];
165 $is_empty = empty($validation_function);
170 if ($is_empty || (! $is_empty && (1 == $validation_function($VarValue)))) {
172 "update sysconfig set conf_value=$1 where variablename=$2",
173 array($VarValue, $VarName), __METHOD__ .
'.setVarNameData');
174 if (! empty($UpdateMsg)) {
177 $UpdateMsg .= $VarName;
178 }
else if (! $is_empty && (0 == $validation_function($VarValue))) {
183 if (! strcmp($validation_function,
'check_boolean')) {
185 "Error: You set $ui_label to ".htmlspecialchars($VarValue).
". Valid values are 'true' and 'false'.");
186 echo
"<script>alert('$warning_msg');</script>";
187 }
else if (strpos($validation_function,
"url")) {
189 "Error: $ui_label ".htmlspecialchars($VarValue).
", is not a reachable URL.");
190 echo
"<script>alert('$warning_msg');</script>";
193 if (! empty($ErrorMsg)) {
196 $ErrorMsg .= $VarName;
201 if (! empty($UpdateMsg)) {
202 $UpdateMsg .= _(
" updated.");
204 if (! empty($ErrorMsg)) {
205 $ErrorMsg .= _(
" Error occurred.");
210 if ($this->OutputType ==
'HTML') {
213 $OutBuf .=
"<span style='background-color:#99FF99'>$UpdateMsg</style>";
216 $OutBuf .=
"<span style='background-color:#FF8181'>$ErrorMsg</style><hr>";
218 $OutBuf .=
"</div> <hr>";
221 $this->vars[
'content'] = $OutBuf;
237 $client =
new Client();
239 if (array_key_exists(
'http_proxy', $SysConf[
'FOSSOLOGY']) &&
240 ! empty($SysConf[
'FOSSOLOGY'][
'http_proxy'])) {
241 $proxy[
'http'] = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
243 if (array_key_exists(
'https_proxy', $SysConf[
'FOSSOLOGY']) &&
244 ! empty($SysConf[
'FOSSOLOGY'][
'https_proxy'])) {
245 $proxy[
'https'] = $SysConf[
'FOSSOLOGY'][
'https_proxy'];
247 if (array_key_exists(
'no_proxy', $SysConf[
'FOSSOLOGY']) &&
248 ! empty($SysConf[
'FOSSOLOGY'][
'no_proxy'])) {
249 $proxy[
'no'] = explode(
',', $SysConf[
'FOSSOLOGY'][
'no_proxy']);
252 $res = $client->request(
"GET", $newarray[
"OidcDiscoveryURL"], [
255 }
catch (RequestException $e) {
258 if ($res->getStatusCode() !== 200) {
261 $body = (string)$res->getBody();
262 $body = json_decode($body,
true);
264 $oldarray[
"OidcIssuer"] =
"";
265 $oldarray[
"OidcAuthorizeURL"] =
"";
266 $oldarray[
"OidcAccessTokenURL"] =
"";
267 $oldarray[
"OidcResourceURL"] =
"";
268 $oldarray[
"OidcJwksURL"] =
"";
269 $newarray[
"OidcIssuer"] = $body[
"issuer"];
270 $newarray[
"OidcAuthorizeURL"] = $body[
"authorization_endpoint"];
271 $newarray[
"OidcAccessTokenURL"] = $body[
"token_endpoint"];
272 $newarray[
"OidcResourceURL"] = $body[
"userinfo_endpoint"];
273 $newarray[
"OidcJwksURL"] = $body[
"jwks_uri"];
278 $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_PASSWORD
#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