FOSSology  4.7.1
Open Source License Compliance by Open Source Software
common-sysconfig.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011-2015 Hewlett-Packard Development Company, L.P.
4  SPDX-FileCopyrightText: © 2021 Siemens AG
5 
6  SPDX-License-Identifier: LGPL-2.1-only
7 */
8 
10 
17 define("CONFIG_TYPE_INT", 1);
19 define("CONFIG_TYPE_TEXT", 2);
21 define("CONFIG_TYPE_TEXTAREA", 3);
23 define("CONFIG_TYPE_PASSWORD", 4);
25 define("CONFIG_TYPE_DROP", 5);
27 define("CONFIG_TYPE_BOOL", 6);
28 
29 
37 if (!function_exists('resolve_sysconfig_value')) {
38  function resolve_sysconfig_value($value, array $scope)
39  {
40  return preg_replace_callback('/\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})/', static function ($matches) use ($scope) {
41  $name = !empty($matches[1]) ? $matches[1] : $matches[2];
42  return array_key_exists($name, $scope) ? $scope[$name] : $matches[0];
43  }, $value);
44  }
45 }
46 
47 
83 function ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
84 {
85  global $PG_CONN;
86 
87  $PG_CONN = get_pg_conn($sysconfdir, $SysConf, $exitOnDbFail);
88 
90  return $PG_CONN;
91 } // ConfigInit()
92 
103 function get_pg_conn($sysconfdir, &$SysConf, $exitOnDbFail=true)
104 {
105  /************* Parse VERSION *******************/
106  $versionFile = "{$sysconfdir}/VERSION";
107  $versionConf = parse_ini_file($versionFile, true);
108  $resolvedValues = array();
109 
110  /* Add this file contents to $SysConf, then destroy $VersionConf.
111  * This file can define its own groups and uses simple placeholder expansion.
112  */
113  foreach ($versionConf as $groupName => $groupArray) {
114  foreach ($groupArray as $var => $assign) {
115  $resolvedValue = resolve_sysconfig_value($assign, $resolvedValues);
116  $resolvedValues[$var] = $resolvedValue;
117  $SysConf[$groupName][$var] = $resolvedValue;
118  ${$var} = $resolvedValue;
119  $GLOBALS[$var] = $resolvedValue;
120  }
121  }
122  unset($versionConf);
123 
124  /************* Parse Db.conf *******************/
125  $dbPath = "{$sysconfdir}/Db.conf";
126  $dbConf = parse_ini_file($dbPath, true);
127 
128  /* Add this file contents to $SysConf, then destroy $dbConf
129  * This file can define its own groups and is eval'd.
130  */
131  foreach ($dbConf as $var => $val) {
132  $SysConf['DBCONF'][$var] = $val;
133  }
134  unset($dbConf);
135 
136  /*
137  * Connect to the database. If the connection fails,
138  * DBconnect() will print a failure message and exit.
139  */
140  $pg_conn = DBconnect($sysconfdir, "", $exitOnDbFail);
141 
142  if (! $exitOnDbFail && ($pg_conn === null || $pg_conn === false)) {
143  return -1;
144  }
145 
146  global $container;
147  $postgresDriver = new \Fossology\Lib\Db\Driver\Postgres($pg_conn);
148  $container->get('db.manager')->setDriver($postgresDriver);
149 
150  return $pg_conn;
151 }
152 
159 function populate_from_sysconfig($conn, &$SysConf)
160 {
161  /* populate the global $SysConf array with variable/value pairs */
162  $sql = "SELECT variablename, conf_value FROM sysconfig;";
163  $result = pg_query($conn, $sql);
164  DBCheckResult($result, $sql, __FILE__, __LINE__);
165 
166  while ($row = pg_fetch_assoc($result)) {
167  $SysConf['SYSCONFIG'][$row['variablename']] = $row['conf_value'];
168  }
169  pg_free_result($result);
170 }
171 
176 {
177  global $PG_CONN;
178 
179  $columns = array("variablename", "conf_value", "ui_label", "vartype", "group_name",
180  "group_order", "description", "validation_function", "option_value");
181  $valueArray = array();
182 
183  /* CorsOrigin */
184  $variable = "CorsOrigins";
185  $prompt = _('Allowed origins for REST API');
186  $desc = _('[scheme]://[hostname]:[port], "*" for anywhere');
187  $valueArray[$variable] = array("'$variable'", "'*'", "'$prompt'",
188  strval(CONFIG_TYPE_TEXT), "'PAT'", "3", "'$desc'", "null", "null");
189 
190  /* Email */
191  $variable = "SupportEmailLabel";
192  $supportEmailLabelPrompt = _('Support Email Label');
193  $supportEmailLabelDesc = _('e.g. "Support"<br>Text that the user clicks on to create a new support email. This new email will be preaddressed to this support email address and subject. HTML is ok.');
194  $valueArray[$variable] = array("'$variable'", "'Support'", "'$supportEmailLabelPrompt'",
195  strval(CONFIG_TYPE_TEXT), "'Support'", "1", "'$supportEmailLabelDesc'", "null", "null");
196 
197  $variable = "SupportEmailAddr";
198  $supportEmailAddrPrompt = _('Support Email Address');
199  $supportEmailAddrValid = "check_email_address";
200  $supportEmailAddrDesc = _('e.g. "support@mycompany.com"<br>Individual or group email address to those providing FOSSology support.');
201  $valueArray[$variable] = array("'$variable'", "null", "'$supportEmailAddrPrompt'",
202  strval(CONFIG_TYPE_TEXT), "'Support'", "2", "'$supportEmailAddrDesc'", "'$supportEmailAddrValid'", "null");
203 
204  $variable = "SupportEmailSubject";
205  $supportEmailSubjectPrompt = _('Support Email Subject line');
206  $supportEmailSubjectDesc = _('e.g. "fossology support"<br>Subject line to use on support email.');
207  $valueArray[$variable] = array("'$variable'", "'FOSSology Support'", "'$supportEmailSubjectPrompt'",
208  strval(CONFIG_TYPE_TEXT), "'Support'", "3", "'$supportEmailSubjectDesc'", "null", "null");
209 
210  /* oAuth2 Service */
211  $variable = "OidcAppName";
212  $oidcPrompt = _('OIDC App Name');
213  $oidcDesc = _('e.g. "my oAuth"<br>App name to display on login page.');
214  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
215  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "1", "'$oidcDesc'", "null", "null");
216 
217  $variable = "OidcClientIdClaim";
218  $oidcPrompt = _('OIDC Client Id Claim');
219  $oidcDesc = _('e.g. "azp"<br>Client ID claim in the decoded payload.');
220  $valueArray[$variable] = array("'$variable'", "'client-id'", "'$oidcPrompt'",
221  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "2", "'$oidcDesc'", "null", "null");
222 
223  $variable = "OidcResourceOwnerId";
224  $oidcPrompt = _('Resource owner id field');
225  $oidcDesc = _('e.g. "email", "upn"<br>Field in token which provides user id. The field <b>should not be empty</b>.');
226  $valueArray[$variable] = array("'$variable'", "'email'", "'$oidcPrompt'",
227  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "3", "'$oidcDesc'", "null", "null");
228 
229  $variable = "OidcTokenType";
230  $oidcPrompt = _('Token to use from provider');
231  $oidcDesc = _('OpenID Connect providers 2 types of tokens, access and id. Which to use for authentication?<br>AzureAD prefers ID token.');
232  $valueArray[$variable] = array("'$variable'", "'A'", "'$oidcPrompt'",
233  strval(CONFIG_TYPE_DROP), "'OauthSupport'", "4", "'$oidcDesc'", "null", "'Access Token{A}|ID Token{I}'");
234 
235  $variable = "OidcAppId";
236  $oidcPrompt = _('OIDC Client Id');
237  $oidcDesc = _('e.g. "e0ec21b9f4b21adc76f185962b52bdfc13af134a"<br>Client ID generated while registering your application.');
238  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
239  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "5", "'$oidcDesc'", "null", "null");
240 
241  $variable = "OidcSecret";
242  $oidcPrompt = _('OIDC Secret');
243  $oidcDesc = _('e.g. "cf13476f185b9f4b2e0ec962b52211adbdfc13aa"<br>Secret generated while registering your application.');
244  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
245  strval(CONFIG_TYPE_PASSWORD), "'OauthSupport'", "6", "'$oidcDesc'", "null", "null");
246 
247  $variable = "OidcRedirectURL";
248  $oidcPrompt = _('Redirect URL');
249  $oidcDesc = _('e.g. "http://fossology.application.url.com/repo"<br>URL of your fossology application.');
250  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
251  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "7", "'$oidcDesc'", "null", "null");
252 
253  $variable = "OidcDiscoveryURL";
254  $oidcPrompt = _('OIDC Discovery URL');
255  $oidcDesc = _('e.g. "http://oauth.com/.well-known/openid-configuration"<br>URL for OIDC Discovery document JSON to fill following fields upon save.');
256  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
257  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "8", "'$oidcDesc'", "null", "null");
258 
259  $variable = "OidcIssuer";
260  $oidcPrompt = _('OIDC Token Issuer');
261  $oidcDesc = _('e.g. "http://oauth.com"<br>Issuer for OIDC tokens.');
262  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
263  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "9", "'$oidcDesc'", "null", "null");
264 
265  $variable = "OidcAuthorizeURL";
266  $oidcPrompt = _('OIDC Authorize URL');
267  $oidcDesc = _('e.g. "http://oauth.com/authorization.oauth2"<br>URL for OAuth2 authorization endpoint.');
268  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
269  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "10", "'$oidcDesc'", "null", "null");
270 
271  $variable = "OidcAccessTokenURL";
272  $oidcPrompt = _('OIDC Access Token URL');
273  $oidcDesc = _('e.g. "http://oauth.com/token.oauth2"<br>URL for OAuth2 access token endpoint.');
274  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
275  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "11", "'$oidcDesc'", "null", "null");
276 
277  $variable = "OidcResourceURL";
278  $oidcPrompt = _('OIDC User Info URL');
279  $oidcDesc = _('e.g. "http://oauth.com/userinfo.oauth2"<br>URL for OAuth2 user info endpoint.');
280  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
281  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "12", "'$oidcDesc'", "null", "null");
282 
283  $variable = "OidcJwksURL";
284  $oidcPrompt = _('OIDC JWKS URL');
285  $oidcDesc = _('e.g. "http://oauth.com/jwks.oauth2"<br>URL for OIDC JWKS keys.');
286  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
287  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "13", "'$oidcDesc'", "null", "null");
288 
289  $variable = "OidcJwkAlgInject";
290  $oidcPrompt = _('OIDC JWKS Algorithm inject');
291  $oidcDesc = _('Algorithm value to inject for JWKS. Leave empty to not modify.' .
292  '<br><a href="https://datatracker.ietf.org/doc/html/rfc7517#section-4.4">Check info</a>.');
293  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
294  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "14", "'$oidcDesc'", "null", "null");
295 
296  $variable = "OidcLogoutURL";
297  $oidcPrompt = _('Logout URL');
298  $oidcDesc = _('e.g. "http://oauth.com/logout.oauth2"<br>URL to redirect user to for logout.');
299  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
300  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "15", "'$oidcDesc'", "null", "null");
301 
302  $variable = "OidcScope";
303  $prompt = _('OIDC Scope');
304  $desc = _('Scope of OIDC for client_credential grant. Used with LicenseDB.');
305  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
306  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "16", "'$oidcDesc'", "null", "null");
307 
308  $variable = "OidcM2MAppId";
309  $oidcPrompt = _('OIDC M2M Client Id');
310  $oidcDesc = _('e.g. "e0ec21b9f4b21adc76f185962b52bdfc13af134a"<br>Client ID generated while registering the M2M application.');
311  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
312  strval(CONFIG_TYPE_TEXT), "'OauthM2M'", "1", "'$oidcDesc'", "null", "null");
313 
314  $variable = "OidcM2MSecret";
315  $oidcPrompt = _('OIDC M2M Secret');
316  $oidcDesc = _('e.g. "cf13476f185b9f4b2e0ec962b52211adbdfc13aa"<br>Secret generated while registering the M2M application.');
317  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
318  strval(CONFIG_TYPE_PASSWORD), "'OauthM2M'", "2", "'$oidcDesc'", "null", "null");
319 
320  $variable = "OidcM2MScope";
321  $oidcPrompt = _('OIDC M2M Scope');
322  $oidcDesc = _('Scope used for the client_credentials grant with LicenseDB.');
323  $valueArray[$variable] = array("'$variable'", "''", "'$oidcPrompt'",
324  strval(CONFIG_TYPE_TEXT), "'OauthM2M'", "3", "'$oidcDesc'", "null", "null");
325 
326  $variable = "OidcM2MAuthorizeURL";
327  $oidcPrompt = _('OIDC M2M Authorize URL');
328  $oidcDesc = _('URL for the M2M OAuth2 authorization endpoint.');
329  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
330  strval(CONFIG_TYPE_TEXT), "'OauthM2M'", "4", "'$oidcDesc'", "null", "null");
331 
332  $variable = "OidcM2MAccessTokenURL";
333  $oidcPrompt = _('OIDC M2M Access Token URL');
334  $oidcDesc = _('URL for the M2M OAuth2 access token endpoint.');
335  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
336  strval(CONFIG_TYPE_TEXT), "'OauthM2M'", "5", "'$oidcDesc'", "null", "null");
337 
338  $variable = "OidcM2MResourceOwnerURL";
339  $oidcPrompt = _('OIDC M2M User Info URL(required for provider initialisation)');
340  $oidcDesc = _('e.g. "http://oauth.com/userinfo.oauth2"<br>URL for M2M OAuth2 user info endpoint.');
341  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
342  strval(CONFIG_TYPE_TEXT), "'OauthM2M'", "6", "'$oidcDesc'", "null", "null");
343 
344  /* Banner Message */
345  $variable = "BannerMsg";
346  $bannerMsgPrompt = _('Banner message');
347  $bannerMsgDesc = _('This is message will be displayed on every page with a banner. HTML is ok.');
348  $valueArray[$variable] = array("'$variable'", "null", "'$bannerMsgPrompt'",
349  strval(CONFIG_TYPE_TEXTAREA), "'Banner'", "1", "'$bannerMsgDesc'", "null", "null");
350 
351  /* Logo */
352  $variable = "LogoImage";
353  $logoImagePrompt = _('Logo Image URL');
354  $logoImageValid = "check_logo_image_url";
355  $logoImageDesc = _('e.g. "http://mycompany.com/images/companylogo.png" or "images/mylogo.png"<br>This image replaces the fossology project logo. Image is constrained to 150px wide. 80-100px high is a good target. If you change this URL, you MUST also enter a logo URL.');
356  $valueArray[$variable] = array("'$variable'", "null", "'$logoImagePrompt'",
357  strval(CONFIG_TYPE_TEXT), "'Logo'", "1", "'$logoImageDesc'", "'$logoImageValid'", "null");
358 
359  $variable = "LogoLink";
360  $logoLinkPrompt = _('Logo URL');
361  $logoLinkDesc = _('e.g. "http://mycompany.com/fossology"<br>URL a person goes to when they click on the logo. If you change the Logo URL, you MUST also enter a Logo Image.');
362  $logoLinkValid = "check_logo_url";
363  $valueArray[$variable] = array("'$variable'", "null", "'$logoLinkPrompt'",
364  strval(CONFIG_TYPE_TEXT), "'Logo'", "2", "'$logoLinkDesc'", "'$logoLinkValid'", "null");
365 
366  $variable = "FOSSologyURL";
367  $urlPrompt = _("FOSSology URL");
368  $hostname = exec("hostname -f");
369  if (empty($hostname)) {
370  $hostname = "localhost";
371  }
372  $fossologyURL = $hostname."/repo/";
373  $urlDesc = _("URL of this FOSSology server, e.g. $fossologyURL");
374  $urlValid = "check_fossology_url";
375  $valueArray[$variable] = array("'$variable'", "'$fossologyURL'", "'$urlPrompt'",
376  strval(CONFIG_TYPE_TEXT), "'URL'", "1", "'$urlDesc'", "'$urlValid'", "null");
377 
378  $variable = "ClearlyDefinedURL";
379  $urlPrompt = _("ClearlyDefined URL");
380  $cdURL = "https://api.clearlydefined.io/";
381  $urlDesc = _("URL of ClearlyDefined server, e.g. $cdURL");
382  $urlValid = "check_url";
383  $valueArray[$variable] = array("'$variable'", "'$cdURL'", "'$urlPrompt'",
384  strval(CONFIG_TYPE_TEXT), "'URL'", "2", "'$urlDesc'", "'$urlValid'", "null");
385 
386  $variable = "NomostListNum";
387  $nomosNumPrompt = _("Maximum licenses to List");
388  $nomostListNum = "2200";
389  $NomosNumDesc = _("For License List and License List Download, you can set the maximum number of lines to list/download. Default 2200.");
390  $valueArray[$variable] = array("'$variable'", "'$nomostListNum'", "'$nomosNumPrompt'",
391  strval(CONFIG_TYPE_TEXT), "'Number'", "1", "'$NomosNumDesc'", "null", "null");
392 
393  $variable = "BlockSizeHex";
394  $hexPrompt = _("Chars per page in hex view");
395  $hexDesc = _("Number of characters per page in hex view");
396  $valueArray[$variable] = array("'$variable'", "'8192'", "'$hexPrompt'",
397  strval(CONFIG_TYPE_TEXT), "'Number'", "2", "'$hexDesc'", "null", "null");
398 
399  $variable = "BlockSizeText";
400  $textPrompt = _("Chars per page in text view");
401  $textDesc = _("Number of characters per page in text view");
402  $valueArray[$variable] = array("'$variable'", "'81920'", "'$textPrompt'",
403  strval(CONFIG_TYPE_TEXT), "'Number'", "3", "'$textDesc'", "null", "null");
404 
405  $variable = "ShowJobsAutoRefresh";
406  $contextNamePrompt = _("ShowJobs Auto Refresh Time");
407  $contextValue = "10";
408  $contextDesc = _("No of seconds to refresh ShowJobs");
409  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
410  strval(CONFIG_TYPE_TEXT), "'Number'", "4", "'$contextDesc'", "null", "null");
411 
412  /* Report Header Text */
413  $variable = "ReportHeaderText";
414  $contextNamePrompt = _("Report Header Text");
415  $contextValue = "FOSSology";
416  $contextDesc = _("Report Header Text at right side corner");
417  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
418  strval(CONFIG_TYPE_TEXT), "'ReportText'", "1", "'$contextDesc'", "null", "null");
419 
420  $variable = "CommonObligation";
421  $contextNamePrompt = _("Common Obligation");
422  $contextValue = "";
423  $commonExObligations = _('you can add HTML line break, Also use json format for table rows');
424  $contextDesc = _("Common Obligation Text,". "$commonExObligations");
425  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
426  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "2", "'$contextDesc'", "null", "null");
427 
428  $variable = "AdditionalObligation";
429  $contextNamePrompt = _("Additional Obligation");
430  $contextValue = "";
431  $contextDesc = _("Additional Obligation Text,". "$commonExObligations");
432  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
433  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "3", "'$contextDesc'", "null", "null");
434 
435  $variable = "ObligationAndRisk";
436  $contextNamePrompt = _("Obligation And Risk Assessment");
437  $contextValue = "";
438  $contextDesc = _("Obligations and risk assessment,". "$commonExObligations");
439  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
440  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "4", "'$contextDesc'", "null", "null");
441 
442  $variable = "EnableOsselotReuse";
443  $prompt = ("Enable OSSelot Reuse");
444  $desc = ("When enabled, shows the OSSelot-based reuse option in the Reuser plugin");
445  $valueArray[$variable] = array("'$variable'","true","'$prompt'",
446  strval(CONFIG_TYPE_BOOL),"'ReportText'","5","'$desc'","'check_boolean'","null");
447 
448  $variable = "OsselotCuratedUrl";
449  $osselotCuratedPrompt = _('OSSelot Curated API URL');
450  $osselotCuratedValid = "check_url";
451  $osselotCuratedDesc = _('URL for OSSelot curated package information API.');
452  $valueArray[$variable] = array("'$variable'", "'https://www.osselot.org/curated.php'", "'$osselotCuratedPrompt'",
453  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "1", "'$osselotCuratedDesc'", "'$osselotCuratedValid'", "null");
454 
455  $variable = "OsselotPackageAnalysisUrl";
456  $osselotPackagePrompt = _('OSSelot Package Analysis Base URL');
457  $osselotPackageValid = "check_url";
458  $osselotPackageDesc = _('Base URL for OSSelot package analysis repository.');
459  $valueArray[$variable] = array("'$variable'", "'https://raw.githubusercontent.com/Open-Source-Compliance/package-analysis/main/analysed-packages'", "'$osselotPackagePrompt'",
460  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "2", "'$osselotPackageDesc'", "'$osselotPackageValid'", "null");
461 
462  $variable = "OsselotPrimaryDomain";
463  $osselotPrimaryPrompt = _('OSSelot Primary Domain');
464  $osselotPrimaryValid = "check_domain";
465  $osselotPrimaryDesc = _('Primary domain used in OSSelot package analysis URLs (e.g., raw.githubusercontent.com).');
466  $valueArray[$variable] = array("'$variable'", "'raw.githubusercontent.com'", "'$osselotPrimaryPrompt'",
467  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "3", "'$osselotPrimaryDesc'", "'$osselotPrimaryValid'", "null");
468 
469  $variable = "OsselotFallbackDomain";
470  $osselotFallbackPrompt = _('OSSelot Fallback Domain');
471  $osselotFallbackValid = "check_domain";
472  $osselotFallbackDesc = _('Fallback domain used when primary domain fails (e.g., osselot.org).');
473  $valueArray[$variable] = array("'$variable'", "'osselot.org'", "'$osselotFallbackPrompt'",
474  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "4", "'$osselotFallbackDesc'", "'$osselotFallbackValid'", "null");
475 
476  /* "Upload from server"-configuration */
477  $variable = "UploadFromServerWhitelist";
478  $contextNamePrompt = _("Whitelist for serverupload");
479  $contextValue = "/tmp";
480  $contextDesc = _("List of allowed prefixes for upload, separated by \":\" (colon)");
481  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
482  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "1", "'$contextDesc'", "null", "null");
483 
484  $variable = "UploadFromServerAllowedHosts";
485  $contextNamePrompt = _("List of allowed hosts for serverupload");
486  $contextValue = "localhost";
487  $contextDesc = _("List of allowed hosts for upload, separated by \":\" (colon)");
488  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
489  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "2", "'$contextDesc'", "null", "null");
490 
491  /* SMTP config */
492  $variable = "SMTPHostName";
493  $smtpHostPrompt = _('SMTP Host Name');
494  $smtpHostDesc = _('e.g.: "smtp.domain.com"<br>The domain to be used to send emails.');
495  $valueArray[$variable] = array("'$variable'", "null", "'$smtpHostPrompt'",
496  strval(CONFIG_TYPE_TEXT), "'SMTP'", "1", "'$smtpHostDesc'", "null", "null");
497 
498  $variable = "SMTPPort";
499  $smtpPortPrompt = _('SMTP Port');
500  $smtpPortDesc = _('e.g.: "25"<br>SMTP port to be used.');
501  $valueArray[$variable] = array("'$variable'", "25", "'$smtpPortPrompt'",
502  strval(CONFIG_TYPE_INT), "'SMTP'", "2", "'$smtpPortDesc'", "null", "null");
503 
504  $variable = "SMTPAuth";
505  $smtpAuthPrompt = _('SMTP Auth Type');
506  $smtpAuthDesc = _('Algorithm to use for login.<br>Login => Encrypted<br>None => No authentication<br>Plain => Send as plain text');
507  $valueArray[$variable] = array("'$variable'", "'L'", "'$smtpAuthPrompt'",
508  strval(CONFIG_TYPE_DROP), "'SMTP'", "3", "'$smtpAuthDesc'", "null", "'Login{L}|None{N}|Plain{P}'");
509 
510  $variable = "SMTPFrom";
511  $smtpFrom = _('SMTP Email');
512  $smtpFromDesc = _('e.g.: "user@domain.com"<br>Sender email.');
513  $valueArray[$variable] = array("'$variable'", "null", "'$smtpFrom'",
514  strval(CONFIG_TYPE_TEXT), "'SMTP'", "4", "'$smtpFromDesc'", "'check_email_address'", "null");
515 
516  $variable = "SMTPAuthUser";
517  $smtpAuthUserPrompt = _('SMTP User');
518  $smtpAuthUserDesc = _('e.g.: "user"<br>Login to be used for login on SMTP Server.');
519  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthUserPrompt'",
520  strval(CONFIG_TYPE_TEXT), "'SMTP'", "5", "'$smtpAuthUserDesc'", "null", "null");
521 
522  $variable = "SMTPAuthPasswd";
523  $smtpAuthPasswdPrompt = _('SMTP Login Password');
524  $smtpAuthPasswdDesc = _('Password used for SMTP login.');
525  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthPasswdPrompt'",
526  strval(CONFIG_TYPE_PASSWORD), "'SMTP'", "6", "'$smtpAuthPasswdDesc'", "null", "null");
527 
528  $variable = "SMTPSslVerify";
529  $smtpSslPrompt = _('SMTP SSL Verify');
530  $smtpSslDesc = _('The SSL verification for connection is required?');
531  $valueArray[$variable] = array("'$variable'", "'S'", "'$smtpSslPrompt'",
532  strval(CONFIG_TYPE_DROP), "'SMTP'", "7", "'$smtpSslDesc'", "null", "'Ignore{I}|Strict{S}|Warn{W}'");
533 
534  $variable = "SMTPStartTls";
535  $smtpTlsPrompt = _('Start TLS');
536  $smtpTlsDesc = _('Use TLS connection for SMTP?');
537  $valueArray[$variable] = array("'$variable'", "'1'", "'$smtpTlsPrompt'",
538  strval(CONFIG_TYPE_DROP), "'SMTP'", "8", "'$smtpTlsDesc'", "null", "'Yes{1}|No{2}'");
539 
540  $variable = "UploadVisibility";
541  $prompt = _('Default Upload Visibility');
542  $desc = _('Default Visibility for uploads by the user');
543  $valueArray[$variable] = array("'$variable'", "'protected'", "'$prompt'",
544  strval(CONFIG_TYPE_DROP), "'UploadFlag'", "1", "'$desc'", "null", "'Visible only for active group{private}|Visible for all groups{protected}|Make Public{public}'");
545 
546  /* Password policy config */
547  $variable = "PasswdPolicy";
548  $prompt = _('Enable password policy');
549  $desc = _('Enable password policy check');
550  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
551  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "1", "'$desc'",
552  "'check_boolean'", "null");
553 
554  $variable = "PasswdPolicyMinChar";
555  $prompt = _('Minimum characters');
556  $desc = _('Blank for no limit');
557  $valueArray[$variable] = array("'$variable'", "8", "'$prompt'",
558  strval(CONFIG_TYPE_INT), "'PASSWD'", "2", "'$desc'", "null", "null");
559 
560  $variable = "PasswdPolicyMaxChar";
561  $prompt = _('Maximum characters');
562  $desc = _('Blank for no limit');
563  $valueArray[$variable] = array("'$variable'", "16", "'$prompt'",
564  strval(CONFIG_TYPE_INT), "'PASSWD'", "3", "'$desc'", "null", "null");
565 
566  $variable = "PasswdPolicyLower";
567  $prompt = _('Lowercase');
568  $desc = _('Minimum one lowercase character.');
569  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
570  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "4", "'$desc'",
571  "'check_boolean'", "null");
572 
573  $variable = "PasswdPolicyUpper";
574  $prompt = _('Uppercase');
575  $desc = _('Minimum one uppercase character.');
576  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
577  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "5", "'$desc'",
578  "'check_boolean'", "null");
579 
580  $variable = "PasswdPolicyDigit";
581  $prompt = _('Digit');
582  $desc = _('Minimum one digit.');
583  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
584  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "6", "'$desc'",
585  "'check_boolean'", "null");
586 
587  $variable = "PasswdPolicySpecial";
588  $prompt = _('Allowed special characters');
589  $desc = _('Empty for do not care');
590  $valueArray[$variable] = array("'$variable'", "'@$!%*?&'", "'$prompt'",
591  strval(CONFIG_TYPE_TEXT), "'PASSWD'", "7", "'$desc'", "null", "null");
592 
593  $variable = "PATMaxExipre";
594  $patTokenValidityPrompt = _('Max token validity');
595  $patTokenValidityDesc = _('Maximum validity of tokens (in days)');
596  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenValidityPrompt'",
597  strval(CONFIG_TYPE_INT), "'PAT'", "1", "'$patTokenValidityDesc'", "null", "null");
598 
599  $variable = "PATMaxPostExpiryRetention";
600  $patTokenRetentionPrompt = _('Max expired token retention period');
601  $patTokenRetentionDesc = _('Maximum retention period of expired tokens (in days) for Maintagent');
602  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenRetentionPrompt'",
603  strval(CONFIG_TYPE_INT), "'PAT'", "2", "'$patTokenRetentionDesc'", "null", "null");
604 
605  $variable = "SkipFiles";
606  $mimeTypeToSkip = _("Skip MimeTypes from scanning");
607  $mimeTypeDesc = _("add comma (,) separated mimetype to exclude files from scanning");
608  $valueArray[$variable] = array("'$variable'", "null", "'$mimeTypeToSkip'",
609  strval(CONFIG_TYPE_TEXT), "'Skip'", "1", "'$mimeTypeDesc'", "null", "null");
610 
611  $perm_admin=Auth::PERM_ADMIN;
612  $perm_write=Auth::PERM_WRITE;
613  $variable = "SourceCodeDownloadRights";
614  $SourceDownloadRightsPrompt = _('Access rights required to download source code');
615  $SourceDownloadRightsDesc = _('Choose which access level will be required for user to be able to download source code.');
616  $valueArray[$variable] = array("'$variable'", "'$perm_write'", "'$SourceDownloadRightsPrompt'",
617  strval(CONFIG_TYPE_DROP), "'DOWNLOAD'", "1", "'$SourceDownloadRightsDesc'", "null", "'Administrator{{$perm_admin}}|Read_Write{{$perm_write}}'");
618 
619  $variable = "UserDescReadOnly";
620  $prompt = _('Make account details read-only');
621  $desc = _('Make account details (username, email, description) read-only');
622  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
623  strval(CONFIG_TYPE_BOOL), "'USER_READ_ONLY'", "1", "'$desc'",
624  "'check_boolean'", "null");
625 
626  $variable = "LicenseTypes";
627  $licenseTypeTitle = _("License Types");
628  $licenseTypeDesc = _("add comma (,) separated different license types");
629  $valueArray[$variable] = array("'$variable'",
630  "'Permissive, Strong Copyleft, Weak Copyleft, Network Copyleft, Public Domain, Non-commercial, Source Available, Font, Data, Exception, Unknown'",
631  "'$licenseTypeTitle'",
632  strval(CONFIG_TYPE_TEXT), "'LICENSE'", "1", "'$licenseTypeDesc'", "null", "null");
633 
634  /* SoftwareHeritage agent config */
635  $variable = "SwhURL";
636  $prompt = _('SoftwareHeritage URL');
637  $desc = _('URL to Software Heritage servers');
638  $valueArray[$variable] = array("'$variable'",
639  "'https://archive.softwareheritage.org'", "'$prompt'",
640  strval(CONFIG_TYPE_TEXT), "'SWH'", "1", "'$desc'", "'check_url'", "null");
641 
642  $variable = "SwhBaseURL";
643  $prompt = _('SoftwareHeritage API base URI');
644  $desc = _('Base URI for API calls');
645  $valueArray[$variable] = array("'$variable'", "'/api/1/content/sha256:'",
646  "'$prompt'", strval(CONFIG_TYPE_TEXT), "'SWH'", "2", "'$desc'", "null",
647  "null");
648 
649  $variable = "SwhContent";
650  $prompt = _('Content endpoint');
651  $desc = _('Endpoint to get content about file');
652  $valueArray[$variable] = array("'$variable'", "'/license'", "'$prompt'",
653  strval(CONFIG_TYPE_TEXT), "'SWH'", "3", "'$desc'", "null", "null");
654 
655  $variable = "SwhSleep";
656  $prompt = _('Max sleep time');
657  $desc = _('Max time to sleep for rate-limit. Note: This concerns with scheduler heartbeat.');
658  $valueArray[$variable] = array("'$variable'", "100", "'$prompt'",
659  strval(CONFIG_TYPE_INT), "'SWH'", "4", "'$desc'", "null", "null");
660 
661  $variable = "SwhToken";
662  $prompt = _('Auth token');
663  $desc = _('');
664  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
665  strval(CONFIG_TYPE_PASSWORD), "'SWH'", "5", "'$desc'", "null", "null");
666 
667  $variable = "ScAPIURL";
668  $prompt = _('Scanoss API url');
669  $desc = _('Set URL to SCANOSS API (blank for default osskb.org)');
670  $valueArray[$variable] = array("'$variable'",
671  "''", "'$prompt'",
672  strval(CONFIG_TYPE_TEXT), "'SSS'", "1", "'$desc'", "null", "null");
673 
674  $variable = "ScToken";
675  $prompt = _('Access token');
676  $desc = _('Set token to access full service (blank for basic scan)');
677  $valueArray[$variable] = array("'$variable'",
678  "''", "'$prompt'",
679  strval(CONFIG_TYPE_TEXT), "'SSS'", "2", "'$desc'", "null", "null");
680 
681  /* LicenseDB config */
682  $variable = "LicenseDBBaseURL";
683  $prompt = _('LicenseDB API base URI');
684  $desc = _('Base URI for API calls e.g. /api/v1');
685  $valueArray[$variable] = array("'$variable'", "'http://localhost:8080/api/v1'",
686  "'$prompt'", strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "1", "'$desc'", "null",
687  "null");
688 
689  $variable = "LicenseDBHealth";
690  $prompt = _('Health check');
691  $desc = _('Endpoint to check health of LicenseDB service');
692  $valueArray[$variable] = array("'$variable'", "'/health'", "'$prompt'",
693  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "2", "'$desc'", "null", "null");
694 
695  $variable = "LicenseDBContent";
696  $prompt = _('Export endpoint Licenses');
697  $desc = _('Endpoint to Export licenses in JSON e.g. /licenses/export');
698  $valueArray[$variable] = array("'$variable'", "'/licenses/export'", "'$prompt'",
699  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "3", "'$desc'", "null", "null");
700 
701  $variable = "LicenseDBContentObligations";
702  $prompt = _('Export endpoint Obligations');
703  $desc = _('Endpoint to Export Obligations in JSON e.g. /obligations/export');
704  $valueArray[$variable] = array("'$variable'", "'/obligations/export'", "'$prompt'",
705  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "4", "'$desc'", "null", "null");
706 
707  $variable = "LicenseDBToken";
708  $prompt = _('Auth token For LicenseDB');
709  $desc = _("Token from LicenseDB. Do not set if using OIDC for LicenseDB and FOSSology communication.");
710  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
711  strval(CONFIG_TYPE_PASSWORD), "'LicenseDB'", "5", "'$desc'", "null", "null");
712 
713  $variable = "ExcludeFolders";
714  $mimeTypeToSkip = _("Exclude Folders from scanning");
715  $mimeTypeDesc = _("Add comma (,) separated folder patterns to exclude from unpacking");
716  $valueArray[$variable] = array("'$variable'", "null", "'$mimeTypeToSkip'",
717  strval(CONFIG_TYPE_TEXT), "'Skip'", "1", "'$mimeTypeDesc'", "null", "null");
718 
719  /* kotoba Agent */
720  $variable = "KotobaDelimiters";
721  $prompt = _('Kotoba Agent Delimiters');
722  $desc = _('Comma-separated list of additional delimiter characters for kotoba agent. Space, comma, tab, newline, carriage return, and form feed are always included as delimiters. Leave empty to use only the default delimiters. Example: "#,^,%,*" to add special characters');
723  $valueArray[$variable] = array("'$variable'", "null", "'$prompt'",
724  strval(CONFIG_TYPE_TEXT), "'Kotoba'", "1", "'$desc'", "null", "null");
725 
726  /* Doing all the rows as a single insert will fail if any row is a dupe.
727  So insert each one individually so that new variables get added.
728  */
729  foreach ($valueArray as $variable => $values) {
730  /*
731  * Check if the variable already exists. Insert it if it does not.
732  * This is better than an insert ignoring duplicates, because that
733  * generates a postresql log message.
734  */
735  $VarRec = GetSingleRec("sysconfig", "WHERE variablename='$variable'");
736  if (empty($VarRec)) {
737  $sql = "INSERT INTO sysconfig (" . implode(",", $columns) . ") VALUES (" .
738  implode(",", $values) . ");";
739  } else { // Values exist, update them
740  $updateString = [];
741  foreach ($columns as $index => $column) {
742  if ($index != 0 && $index != 1) { // Skip variablename and conf_value
743  $updateString[] = $column . "=" . $values[$index];
744  }
745  }
746  $sql = "UPDATE sysconfig SET " . implode(",", $updateString) .
747  " WHERE variablename='$variable';";
748  }
749  $result = pg_query($PG_CONN, $sql);
750  DBCheckResult($result, $sql, __FILE__, __LINE__);
751  pg_free_result($result);
752  unset($VarRec);
753  }
754 }
755 
766 function check_boolean($value)
767 {
768  if (! strcmp($value, 'true') || ! strcmp($value, 'false')) {
769  return 1;
770  } else {
771  return 0;
772  }
773 }
774 
784 function check_fossology_url($url)
785 {
786  $url_array = explode("/", $url, 2);
787  $name = $url_array[0];
788  if (! empty($name)) {
789  $hostname = exec("hostname -f");
790  if (empty($hostname)) {
791  $hostname = "localhost";
792  }
793  if (check_IP($name)) {
794  $hostname1 = gethostbyaddr($name);
795  if (strcmp($hostname, $hostname1) == 0) {
796  return 0; // host is not reachable
797  }
798  }
799  $server_name = $_SERVER['SERVER_NAME'];
800 
801  /* intput $name must match either the hostname or the server name */
802  if (strcmp($name, $hostname) && strcmp($name, $server_name)) {
803  return 0;
804  }
805  } else {
806  return 0;
807  }
808  return 1;
809 }
810 
820 function check_logo_url($url)
821 {
822  if (empty($url)) {
823  return 1; /* logo url can be null, with the default */
824  }
825  // $res = check_url($url);
826  $res = is_available($url);
827  if (1 == $res) {
828  return 1;
829  } else {
830  return 0;
831  }
832 }
833 
843 function check_logo_image_url($url)
844 {
845  global $SysConf;
846 
847  if (empty($url)) {
848  return 1; /* logo url can be null, with the default */
849  }
850  $logoLink = @$SysConf["LogoLink"];
851  $new_url = $logoLink . $url;
852  if (is_available($url) || is_available($new_url)) {
853  return 1;
854  } else {
855  return 0;
856  }
857 
858 }
859 
870 function check_email_address($email_address)
871 {
872  return 1;
873 }
874 
884 function is_available($url, $timeout = 2, $tries = 2)
885 {
886  global $SysConf;
887 
888  $proxyStmts = "";
889  if (array_key_exists('http_proxy', $SysConf['FOSSOLOGY']) &&
890  $SysConf['FOSSOLOGY']['http_proxy']) {
891  $proxyStmts .= "export http_proxy=" . escapeshellarg($SysConf['FOSSOLOGY']['http_proxy']) . ";";
892  }
893  if (array_key_exists('https_proxy', $SysConf['FOSSOLOGY']) &&
894  $SysConf['FOSSOLOGY']['https_proxy']) {
895  $proxyStmts .= "export https_proxy=" . escapeshellarg($SysConf['FOSSOLOGY']['https_proxy']) . ";";
896  }
897  if (array_key_exists('ftp_proxy', $SysConf['FOSSOLOGY']) &&
898  $SysConf['FOSSOLOGY']['ftp_proxy']) {
899  $proxyStmts .= "export ftp_proxy=" . escapeshellarg($SysConf['FOSSOLOGY']['ftp_proxy']) . ";";
900  }
901 
902  $commands = $proxyStmts . "wget --spider " . escapeshellarg($url) .
903  " --tries=" . (int) $tries . " --timeout=" . (int) $timeout;
904  system($commands, $return_var);
905  if (0 == $return_var) {
906  return 1;
907  } else {
908  return 0;
909  }
910 }
911 
917 function check_url($url)
918 {
919  if (empty($url) ||
920  preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $url) != 1 ||
921  preg_match("@[[:space:]]@", $url) != 0) {
922  return 0;
923  } else {
924  return 1;
925  }
926 }
927 
933 function check_IP($ip)
934 {
935  $e = "([0-9]|1[0-9]{2}|[1-9][0-9]|2[0-4][0-9]|25[0-5])";
936  return preg_match("/^$e\.$e\.$e\.$e$/", $ip);
937 }
938 
943 function set_python_path(): array
944 {
945  global $SysConf;
946  $path = "/home/" . $SysConf['DIRECTORIES']['PROJECTUSER'] . "/pythondeps";
947  putenv("PYTHONPATH=$path");
948  return ["PYTHONPATH" => $path];
949 }
959 {
960  // Get No.of cores
961  $cores = trim(shell_exec("nproc"));
962 
963  // Get CPU load
964  $load = sys_getloadavg()[1];
965 
966  $percentageOfLoad = ($load / $cores);
967 
968  if ($percentageOfLoad < 0.30) {
969  $class = 'btn-success';
970  } else if ($percentageOfLoad < 0.60) {
971  $class = 'btn-warning';
972  } else {
973  $class = 'btn-danger';
974  }
975 
976  return '<button type="button" aria-disabled="true" disabled class="btn '.$class.'">System Load</button>';
977 }
978 
Contains the constants and helpers for authentication of user.
Definition: Auth.php:24
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
Definition: common-db.php:33
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
Definition: common-db.php:189
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Definition: common-db.php:91
Populate_sysconfig()
Populate the sysconfig table with core variables.
check_fossology_url($url)
Validation function check_fossology_url().
if(!function_exists('resolve_sysconfig_value')) ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().
is_available($url, $timeout=2, $tries=2)
Check if the URL is available.
check_IP($ip)
Check if the ip address is valid.
const CONFIG_TYPE_TEXTAREA
check_logo_image_url($url)
Validation function check_logo_image_url().
const CONFIG_TYPE_TEXT
check_logo_url($url)
Validation function check_logo_url().
get_pg_conn($sysconfdir, &$SysConf, $exitOnDbFail=true)
get_system_load_average()
Get system load average.
check_email_address($email_address)
Validation function check_email_address().
const CONFIG_TYPE_DROP
check_boolean($value)
Validation function check_boolean().
populate_from_sysconfig($conn, &$SysConf)
const CONFIG_TYPE_INT
set_python_path()
check_url($url)
Check if the url is valid.
const CONFIG_TYPE_BOOL
const CONFIG_TYPE_PASSWORD
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690
#define PERM_WRITE
Read-Write permission.
Definition: libfossology.h:33
#define PERM_ADMIN
Administrator.
Definition: libfossology.h:34
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN