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  /* Banner Message */
309  $variable = "BannerMsg";
310  $bannerMsgPrompt = _('Banner message');
311  $bannerMsgDesc = _('This is message will be displayed on every page with a banner. HTML is ok.');
312  $valueArray[$variable] = array("'$variable'", "null", "'$bannerMsgPrompt'",
313  strval(CONFIG_TYPE_TEXTAREA), "'Banner'", "1", "'$bannerMsgDesc'", "null", "null");
314 
315  /* Logo */
316  $variable = "LogoImage";
317  $logoImagePrompt = _('Logo Image URL');
318  $logoImageValid = "check_logo_image_url";
319  $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.');
320  $valueArray[$variable] = array("'$variable'", "null", "'$logoImagePrompt'",
321  strval(CONFIG_TYPE_TEXT), "'Logo'", "1", "'$logoImageDesc'", "'$logoImageValid'", "null");
322 
323  $variable = "LogoLink";
324  $logoLinkPrompt = _('Logo URL');
325  $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.');
326  $logoLinkValid = "check_logo_url";
327  $valueArray[$variable] = array("'$variable'", "null", "'$logoLinkPrompt'",
328  strval(CONFIG_TYPE_TEXT), "'Logo'", "2", "'$logoLinkDesc'", "'$logoLinkValid'", "null");
329 
330  $variable = "FOSSologyURL";
331  $urlPrompt = _("FOSSology URL");
332  $hostname = exec("hostname -f");
333  if (empty($hostname)) {
334  $hostname = "localhost";
335  }
336  $fossologyURL = $hostname."/repo/";
337  $urlDesc = _("URL of this FOSSology server, e.g. $fossologyURL");
338  $urlValid = "check_fossology_url";
339  $valueArray[$variable] = array("'$variable'", "'$fossologyURL'", "'$urlPrompt'",
340  strval(CONFIG_TYPE_TEXT), "'URL'", "1", "'$urlDesc'", "'$urlValid'", "null");
341 
342  $variable = "ClearlyDefinedURL";
343  $urlPrompt = _("ClearlyDefined URL");
344  $cdURL = "https://api.clearlydefined.io/";
345  $urlDesc = _("URL of ClearlyDefined server, e.g. $cdURL");
346  $urlValid = "check_url";
347  $valueArray[$variable] = array("'$variable'", "'$cdURL'", "'$urlPrompt'",
348  strval(CONFIG_TYPE_TEXT), "'URL'", "2", "'$urlDesc'", "'$urlValid'", "null");
349 
350  $variable = "NomostListNum";
351  $nomosNumPrompt = _("Maximum licenses to List");
352  $nomostListNum = "2200";
353  $NomosNumDesc = _("For License List and License List Download, you can set the maximum number of lines to list/download. Default 2200.");
354  $valueArray[$variable] = array("'$variable'", "'$nomostListNum'", "'$nomosNumPrompt'",
355  strval(CONFIG_TYPE_TEXT), "'Number'", "1", "'$NomosNumDesc'", "null", "null");
356 
357  $variable = "BlockSizeHex";
358  $hexPrompt = _("Chars per page in hex view");
359  $hexDesc = _("Number of characters per page in hex view");
360  $valueArray[$variable] = array("'$variable'", "'8192'", "'$hexPrompt'",
361  strval(CONFIG_TYPE_TEXT), "'Number'", "2", "'$hexDesc'", "null", "null");
362 
363  $variable = "BlockSizeText";
364  $textPrompt = _("Chars per page in text view");
365  $textDesc = _("Number of characters per page in text view");
366  $valueArray[$variable] = array("'$variable'", "'81920'", "'$textPrompt'",
367  strval(CONFIG_TYPE_TEXT), "'Number'", "3", "'$textDesc'", "null", "null");
368 
369  $variable = "ShowJobsAutoRefresh";
370  $contextNamePrompt = _("ShowJobs Auto Refresh Time");
371  $contextValue = "10";
372  $contextDesc = _("No of seconds to refresh ShowJobs");
373  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
374  strval(CONFIG_TYPE_TEXT), "'Number'", "4", "'$contextDesc'", "null", "null");
375 
376  /* Report Header Text */
377  $variable = "ReportHeaderText";
378  $contextNamePrompt = _("Report Header Text");
379  $contextValue = "FOSSology";
380  $contextDesc = _("Report Header Text at right side corner");
381  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
382  strval(CONFIG_TYPE_TEXT), "'ReportText'", "1", "'$contextDesc'", "null", "null");
383 
384  $variable = "CommonObligation";
385  $contextNamePrompt = _("Common Obligation");
386  $contextValue = "";
387  $commonExObligations = _('you can add HTML line break, Also use json format for table rows');
388  $contextDesc = _("Common Obligation Text,". "$commonExObligations");
389  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
390  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "2", "'$contextDesc'", "null", "null");
391 
392  $variable = "AdditionalObligation";
393  $contextNamePrompt = _("Additional Obligation");
394  $contextValue = "";
395  $contextDesc = _("Additional Obligation Text,". "$commonExObligations");
396  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
397  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "3", "'$contextDesc'", "null", "null");
398 
399  $variable = "ObligationAndRisk";
400  $contextNamePrompt = _("Obligation And Risk Assessment");
401  $contextValue = "";
402  $contextDesc = _("Obligations and risk assessment,". "$commonExObligations");
403  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
404  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "4", "'$contextDesc'", "null", "null");
405 
406  $variable = "EnableOsselotReuse";
407  $prompt = ("Enable OSSelot Reuse");
408  $desc = ("When enabled, shows the OSSelot-based reuse option in the Reuser plugin");
409  $valueArray[$variable] = array("'$variable'","true","'$prompt'",
410  strval(CONFIG_TYPE_BOOL),"'ReportText'","5","'$desc'","'check_boolean'","null");
411 
412  $variable = "OsselotCuratedUrl";
413  $osselotCuratedPrompt = _('OSSelot Curated API URL');
414  $osselotCuratedValid = "check_url";
415  $osselotCuratedDesc = _('URL for OSSelot curated package information API.');
416  $valueArray[$variable] = array("'$variable'", "'https://www.osselot.org/curated.php'", "'$osselotCuratedPrompt'",
417  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "1", "'$osselotCuratedDesc'", "'$osselotCuratedValid'", "null");
418 
419  $variable = "OsselotPackageAnalysisUrl";
420  $osselotPackagePrompt = _('OSSelot Package Analysis Base URL');
421  $osselotPackageValid = "check_url";
422  $osselotPackageDesc = _('Base URL for OSSelot package analysis repository.');
423  $valueArray[$variable] = array("'$variable'", "'https://raw.githubusercontent.com/Open-Source-Compliance/package-analysis/main/analysed-packages'", "'$osselotPackagePrompt'",
424  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "2", "'$osselotPackageDesc'", "'$osselotPackageValid'", "null");
425 
426  $variable = "OsselotPrimaryDomain";
427  $osselotPrimaryPrompt = _('OSSelot Primary Domain');
428  $osselotPrimaryValid = "check_domain";
429  $osselotPrimaryDesc = _('Primary domain used in OSSelot package analysis URLs (e.g., raw.githubusercontent.com).');
430  $valueArray[$variable] = array("'$variable'", "'raw.githubusercontent.com'", "'$osselotPrimaryPrompt'",
431  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "3", "'$osselotPrimaryDesc'", "'$osselotPrimaryValid'", "null");
432 
433  $variable = "OsselotFallbackDomain";
434  $osselotFallbackPrompt = _('OSSelot Fallback Domain');
435  $osselotFallbackValid = "check_domain";
436  $osselotFallbackDesc = _('Fallback domain used when primary domain fails (e.g., osselot.org).');
437  $valueArray[$variable] = array("'$variable'", "'osselot.org'", "'$osselotFallbackPrompt'",
438  strval(CONFIG_TYPE_TEXT), "'OSSelot'", "4", "'$osselotFallbackDesc'", "'$osselotFallbackValid'", "null");
439 
440  /* "Upload from server"-configuration */
441  $variable = "UploadFromServerWhitelist";
442  $contextNamePrompt = _("Whitelist for serverupload");
443  $contextValue = "/tmp";
444  $contextDesc = _("List of allowed prefixes for upload, separated by \":\" (colon)");
445  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
446  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "1", "'$contextDesc'", "null", "null");
447 
448  $variable = "UploadFromServerAllowedHosts";
449  $contextNamePrompt = _("List of allowed hosts for serverupload");
450  $contextValue = "localhost";
451  $contextDesc = _("List of allowed hosts for upload, separated by \":\" (colon)");
452  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
453  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "2", "'$contextDesc'", "null", "null");
454 
455  /* SMTP config */
456  $variable = "SMTPHostName";
457  $smtpHostPrompt = _('SMTP Host Name');
458  $smtpHostDesc = _('e.g.: "smtp.domain.com"<br>The domain to be used to send emails.');
459  $valueArray[$variable] = array("'$variable'", "null", "'$smtpHostPrompt'",
460  strval(CONFIG_TYPE_TEXT), "'SMTP'", "1", "'$smtpHostDesc'", "null", "null");
461 
462  $variable = "SMTPPort";
463  $smtpPortPrompt = _('SMTP Port');
464  $smtpPortDesc = _('e.g.: "25"<br>SMTP port to be used.');
465  $valueArray[$variable] = array("'$variable'", "25", "'$smtpPortPrompt'",
466  strval(CONFIG_TYPE_INT), "'SMTP'", "2", "'$smtpPortDesc'", "null", "null");
467 
468  $variable = "SMTPAuth";
469  $smtpAuthPrompt = _('SMTP Auth Type');
470  $smtpAuthDesc = _('Algorithm to use for login.<br>Login => Encrypted<br>None => No authentication<br>Plain => Send as plain text');
471  $valueArray[$variable] = array("'$variable'", "'L'", "'$smtpAuthPrompt'",
472  strval(CONFIG_TYPE_DROP), "'SMTP'", "3", "'$smtpAuthDesc'", "null", "'Login{L}|None{N}|Plain{P}'");
473 
474  $variable = "SMTPFrom";
475  $smtpFrom = _('SMTP Email');
476  $smtpFromDesc = _('e.g.: "user@domain.com"<br>Sender email.');
477  $valueArray[$variable] = array("'$variable'", "null", "'$smtpFrom'",
478  strval(CONFIG_TYPE_TEXT), "'SMTP'", "4", "'$smtpFromDesc'", "'check_email_address'", "null");
479 
480  $variable = "SMTPAuthUser";
481  $smtpAuthUserPrompt = _('SMTP User');
482  $smtpAuthUserDesc = _('e.g.: "user"<br>Login to be used for login on SMTP Server.');
483  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthUserPrompt'",
484  strval(CONFIG_TYPE_TEXT), "'SMTP'", "5", "'$smtpAuthUserDesc'", "null", "null");
485 
486  $variable = "SMTPAuthPasswd";
487  $smtpAuthPasswdPrompt = _('SMTP Login Password');
488  $smtpAuthPasswdDesc = _('Password used for SMTP login.');
489  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthPasswdPrompt'",
490  strval(CONFIG_TYPE_PASSWORD), "'SMTP'", "6", "'$smtpAuthPasswdDesc'", "null", "null");
491 
492  $variable = "SMTPSslVerify";
493  $smtpSslPrompt = _('SMTP SSL Verify');
494  $smtpSslDesc = _('The SSL verification for connection is required?');
495  $valueArray[$variable] = array("'$variable'", "'S'", "'$smtpSslPrompt'",
496  strval(CONFIG_TYPE_DROP), "'SMTP'", "7", "'$smtpSslDesc'", "null", "'Ignore{I}|Strict{S}|Warn{W}'");
497 
498  $variable = "SMTPStartTls";
499  $smtpTlsPrompt = _('Start TLS');
500  $smtpTlsDesc = _('Use TLS connection for SMTP?');
501  $valueArray[$variable] = array("'$variable'", "'1'", "'$smtpTlsPrompt'",
502  strval(CONFIG_TYPE_DROP), "'SMTP'", "8", "'$smtpTlsDesc'", "null", "'Yes{1}|No{2}'");
503 
504  $variable = "UploadVisibility";
505  $prompt = _('Default Upload Visibility');
506  $desc = _('Default Visibility for uploads by the user');
507  $valueArray[$variable] = array("'$variable'", "'protected'", "'$prompt'",
508  strval(CONFIG_TYPE_DROP), "'UploadFlag'", "1", "'$desc'", "null", "'Visible only for active group{private}|Visible for all groups{protected}|Make Public{public}'");
509 
510  /* Password policy config */
511  $variable = "PasswdPolicy";
512  $prompt = _('Enable password policy');
513  $desc = _('Enable password policy check');
514  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
515  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "1", "'$desc'",
516  "'check_boolean'", "null");
517 
518  $variable = "PasswdPolicyMinChar";
519  $prompt = _('Minimum characters');
520  $desc = _('Blank for no limit');
521  $valueArray[$variable] = array("'$variable'", "8", "'$prompt'",
522  strval(CONFIG_TYPE_INT), "'PASSWD'", "2", "'$desc'", "null", "null");
523 
524  $variable = "PasswdPolicyMaxChar";
525  $prompt = _('Maximum characters');
526  $desc = _('Blank for no limit');
527  $valueArray[$variable] = array("'$variable'", "16", "'$prompt'",
528  strval(CONFIG_TYPE_INT), "'PASSWD'", "3", "'$desc'", "null", "null");
529 
530  $variable = "PasswdPolicyLower";
531  $prompt = _('Lowercase');
532  $desc = _('Minimum one lowercase character.');
533  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
534  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "4", "'$desc'",
535  "'check_boolean'", "null");
536 
537  $variable = "PasswdPolicyUpper";
538  $prompt = _('Uppercase');
539  $desc = _('Minimum one uppercase character.');
540  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
541  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "5", "'$desc'",
542  "'check_boolean'", "null");
543 
544  $variable = "PasswdPolicyDigit";
545  $prompt = _('Digit');
546  $desc = _('Minimum one digit.');
547  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
548  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "6", "'$desc'",
549  "'check_boolean'", "null");
550 
551  $variable = "PasswdPolicySpecial";
552  $prompt = _('Allowed special characters');
553  $desc = _('Empty for do not care');
554  $valueArray[$variable] = array("'$variable'", "'@$!%*?&'", "'$prompt'",
555  strval(CONFIG_TYPE_TEXT), "'PASSWD'", "7", "'$desc'", "null", "null");
556 
557  $variable = "PATMaxExipre";
558  $patTokenValidityPrompt = _('Max token validity');
559  $patTokenValidityDesc = _('Maximum validity of tokens (in days)');
560  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenValidityPrompt'",
561  strval(CONFIG_TYPE_INT), "'PAT'", "1", "'$patTokenValidityDesc'", "null", "null");
562 
563  $variable = "PATMaxPostExpiryRetention";
564  $patTokenRetentionPrompt = _('Max expired token retention period');
565  $patTokenRetentionDesc = _('Maximum retention period of expired tokens (in days) for Maintagent');
566  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenRetentionPrompt'",
567  strval(CONFIG_TYPE_INT), "'PAT'", "2", "'$patTokenRetentionDesc'", "null", "null");
568 
569  $variable = "SkipFiles";
570  $mimeTypeToSkip = _("Skip MimeTypes from scanning");
571  $mimeTypeDesc = _("add comma (,) separated mimetype to exclude files from scanning");
572  $valueArray[$variable] = array("'$variable'", "null", "'$mimeTypeToSkip'",
573  strval(CONFIG_TYPE_TEXT), "'Skip'", "1", "'$mimeTypeDesc'", "null", "null");
574 
575  $perm_admin=Auth::PERM_ADMIN;
576  $perm_write=Auth::PERM_WRITE;
577  $variable = "SourceCodeDownloadRights";
578  $SourceDownloadRightsPrompt = _('Access rights required to download source code');
579  $SourceDownloadRightsDesc = _('Choose which access level will be required for user to be able to download source code.');
580  $valueArray[$variable] = array("'$variable'", "'$perm_write'", "'$SourceDownloadRightsPrompt'",
581  strval(CONFIG_TYPE_DROP), "'DOWNLOAD'", "1", "'$SourceDownloadRightsDesc'", "null", "'Administrator{{$perm_admin}}|Read_Write{{$perm_write}}'");
582 
583  $variable = "UserDescReadOnly";
584  $prompt = _('Make account details read-only');
585  $desc = _('Make account details (username, email, description) read-only');
586  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
587  strval(CONFIG_TYPE_BOOL), "'USER_READ_ONLY'", "1", "'$desc'",
588  "'check_boolean'", "null");
589 
590  $variable = "LicenseTypes";
591  $licenseTypeTitle = _("License Types");
592  $licenseTypeDesc = _("add comma (,) separated different license types");
593  $valueArray[$variable] = array("'$variable'",
594  "'Permissive, Strong Copyleft, Weak Copyleft, Network Copyleft, Public Domain, Non-commercial, Source Available, Font, Data, Exception, Unknown'",
595  "'$licenseTypeTitle'",
596  strval(CONFIG_TYPE_TEXT), "'LICENSE'", "1", "'$licenseTypeDesc'", "null", "null");
597 
598  /* SoftwareHeritage agent config */
599  $variable = "SwhURL";
600  $prompt = _('SoftwareHeritage URL');
601  $desc = _('URL to Software Heritage servers');
602  $valueArray[$variable] = array("'$variable'",
603  "'https://archive.softwareheritage.org'", "'$prompt'",
604  strval(CONFIG_TYPE_TEXT), "'SWH'", "1", "'$desc'", "'check_url'", "null");
605 
606  $variable = "SwhBaseURL";
607  $prompt = _('SoftwareHeritage API base URI');
608  $desc = _('Base URI for API calls');
609  $valueArray[$variable] = array("'$variable'", "'/api/1/content/sha256:'",
610  "'$prompt'", strval(CONFIG_TYPE_TEXT), "'SWH'", "2", "'$desc'", "null",
611  "null");
612 
613  $variable = "SwhContent";
614  $prompt = _('Content endpoint');
615  $desc = _('Endpoint to get content about file');
616  $valueArray[$variable] = array("'$variable'", "'/license'", "'$prompt'",
617  strval(CONFIG_TYPE_TEXT), "'SWH'", "3", "'$desc'", "null", "null");
618 
619  $variable = "SwhSleep";
620  $prompt = _('Max sleep time');
621  $desc = _('Max time to sleep for rate-limit. Note: This concerns with scheduler heartbeat.');
622  $valueArray[$variable] = array("'$variable'", "100", "'$prompt'",
623  strval(CONFIG_TYPE_INT), "'SWH'", "4", "'$desc'", "null", "null");
624 
625  $variable = "SwhToken";
626  $prompt = _('Auth token');
627  $desc = _('');
628  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
629  strval(CONFIG_TYPE_PASSWORD), "'SWH'", "5", "'$desc'", "null", "null");
630 
631  $variable = "ScAPIURL";
632  $prompt = _('Scanoss API url');
633  $desc = _('Set URL to SCANOSS API (blank for default osskb.org)');
634  $valueArray[$variable] = array("'$variable'",
635  "''", "'$prompt'",
636  strval(CONFIG_TYPE_TEXT), "'SSS'", "1", "'$desc'", "null", "null");
637 
638  $variable = "ScToken";
639  $prompt = _('Access token');
640  $desc = _('Set token to access full service (blank for basic scan)');
641  $valueArray[$variable] = array("'$variable'",
642  "''", "'$prompt'",
643  strval(CONFIG_TYPE_TEXT), "'SSS'", "2", "'$desc'", "null", "null");
644 
645  /* LicenseDB config */
646  $variable = "LicenseDBBaseURL";
647  $prompt = _('LicenseDB API base URI');
648  $desc = _('Base URI for API calls e.g. /api/v1');
649  $valueArray[$variable] = array("'$variable'", "'http://localhost:8080/api/v1'",
650  "'$prompt'", strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "1", "'$desc'", "null",
651  "null");
652 
653  $variable = "LicenseDBHealth";
654  $prompt = _('Health check');
655  $desc = _('Endpoint to check health of LicenseDB service');
656  $valueArray[$variable] = array("'$variable'", "'/health'", "'$prompt'",
657  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "2", "'$desc'", "null", "null");
658 
659  $variable = "LicenseDBContent";
660  $prompt = _('Export endpoint Licenses');
661  $desc = _('Endpoint to Export licenses in JSON e.g. /licenses/export');
662  $valueArray[$variable] = array("'$variable'", "'/licenses/export'", "'$prompt'",
663  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "3", "'$desc'", "null", "null");
664 
665  $variable = "LicenseDBContentObligations";
666  $prompt = _('Export endpoint Obligations');
667  $desc = _('Endpoint to Export Obligations in JSON e.g. /obligations/export');
668  $valueArray[$variable] = array("'$variable'", "'/obligations/export'", "'$prompt'",
669  strval(CONFIG_TYPE_TEXT), "'LicenseDB'", "4", "'$desc'", "null", "null");
670 
671  $variable = "LicenseDBToken";
672  $prompt = _('Auth token For LicenseDB');
673  $desc = _("Token from LicenseDB. Do not set if using OIDC for LicenseDB and FOSSology communication.");
674  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
675  strval(CONFIG_TYPE_PASSWORD), "'LicenseDB'", "5", "'$desc'", "null", "null");
676 
677  $variable = "ExcludeFolders";
678  $mimeTypeToSkip = _("Exclude Folders from scanning");
679  $mimeTypeDesc = _("Add comma (,) separated folder patterns to exclude from unpacking");
680  $valueArray[$variable] = array("'$variable'", "null", "'$mimeTypeToSkip'",
681  strval(CONFIG_TYPE_TEXT), "'Skip'", "1", "'$mimeTypeDesc'", "null", "null");
682 
683  /* kotoba Agent */
684  $variable = "KotobaDelimiters";
685  $prompt = _('Kotoba Agent Delimiters');
686  $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');
687  $valueArray[$variable] = array("'$variable'", "null", "'$prompt'",
688  strval(CONFIG_TYPE_TEXT), "'Kotoba'", "1", "'$desc'", "null", "null");
689 
690  /* Doing all the rows as a single insert will fail if any row is a dupe.
691  So insert each one individually so that new variables get added.
692  */
693  foreach ($valueArray as $variable => $values) {
694  /*
695  * Check if the variable already exists. Insert it if it does not.
696  * This is better than an insert ignoring duplicates, because that
697  * generates a postresql log message.
698  */
699  $VarRec = GetSingleRec("sysconfig", "WHERE variablename='$variable'");
700  if (empty($VarRec)) {
701  $sql = "INSERT INTO sysconfig (" . implode(",", $columns) . ") VALUES (" .
702  implode(",", $values) . ");";
703  } else { // Values exist, update them
704  $updateString = [];
705  foreach ($columns as $index => $column) {
706  if ($index != 0 && $index != 1) { // Skip variablename and conf_value
707  $updateString[] = $column . "=" . $values[$index];
708  }
709  }
710  $sql = "UPDATE sysconfig SET " . implode(",", $updateString) .
711  " WHERE variablename='$variable';";
712  }
713  $result = pg_query($PG_CONN, $sql);
714  DBCheckResult($result, $sql, __FILE__, __LINE__);
715  pg_free_result($result);
716  unset($VarRec);
717  }
718 }
719 
730 function check_boolean($value)
731 {
732  if (! strcmp($value, 'true') || ! strcmp($value, 'false')) {
733  return 1;
734  } else {
735  return 0;
736  }
737 }
738 
748 function check_fossology_url($url)
749 {
750  $url_array = explode("/", $url, 2);
751  $name = $url_array[0];
752  if (! empty($name)) {
753  $hostname = exec("hostname -f");
754  if (empty($hostname)) {
755  $hostname = "localhost";
756  }
757  if (check_IP($name)) {
758  $hostname1 = gethostbyaddr($name);
759  if (strcmp($hostname, $hostname1) == 0) {
760  return 0; // host is not reachable
761  }
762  }
763  $server_name = $_SERVER['SERVER_NAME'];
764 
765  /* intput $name must match either the hostname or the server name */
766  if (strcmp($name, $hostname) && strcmp($name, $server_name)) {
767  return 0;
768  }
769  } else {
770  return 0;
771  }
772  return 1;
773 }
774 
784 function check_logo_url($url)
785 {
786  if (empty($url)) {
787  return 1; /* logo url can be null, with the default */
788  }
789  // $res = check_url($url);
790  $res = is_available($url);
791  if (1 == $res) {
792  return 1;
793  } else {
794  return 0;
795  }
796 }
797 
807 function check_logo_image_url($url)
808 {
809  global $SysConf;
810 
811  if (empty($url)) {
812  return 1; /* logo url can be null, with the default */
813  }
814  $logoLink = @$SysConf["LogoLink"];
815  $new_url = $logoLink . $url;
816  if (is_available($url) || is_available($new_url)) {
817  return 1;
818  } else {
819  return 0;
820  }
821 
822 }
823 
834 function check_email_address($email_address)
835 {
836  return 1;
837 }
838 
848 function is_available($url, $timeout = 2, $tries = 2)
849 {
850  global $SysConf;
851 
852  $proxyStmts = "";
853  if (array_key_exists('http_proxy', $SysConf['FOSSOLOGY']) &&
854  $SysConf['FOSSOLOGY']['http_proxy']) {
855  $proxyStmts .= "export http_proxy={$SysConf['FOSSOLOGY']['http_proxy']};";
856  }
857  if (array_key_exists('https_proxy', $SysConf['FOSSOLOGY']) &&
858  $SysConf['FOSSOLOGY']['https_proxy']) {
859  $proxyStmts .= "export https_proxy={$SysConf['FOSSOLOGY']['https_proxy']};";
860  }
861  if (array_key_exists('ftp_proxy', $SysConf['FOSSOLOGY']) &&
862  $SysConf['FOSSOLOGY']['ftp_proxy']) {
863  $proxyStmts .= "export ftp_proxy={$SysConf['FOSSOLOGY']['ftp_proxy']};";
864  }
865 
866  $commands = "$proxyStmts wget --spider '$url' --tries=$tries --timeout=$timeout";
867  system($commands, $return_var);
868  if (0 == $return_var) {
869  return 1;
870  } else {
871  return 0;
872  }
873 }
874 
880 function check_url($url)
881 {
882  if (empty($url) ||
883  preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $url) != 1 ||
884  preg_match("@[[:space:]]@", $url) != 0) {
885  return 0;
886  } else {
887  return 1;
888  }
889 }
890 
896 function check_IP($ip)
897 {
898  $e = "([0-9]|1[0-9]{2}|[1-9][0-9]|2[0-4][0-9]|25[0-5])";
899  return preg_match("/^$e\.$e\.$e\.$e$/", $ip);
900 }
901 
906 function set_python_path(): array
907 {
908  global $SysConf;
909  $path = "/home/" . $SysConf['DIRECTORIES']['PROJECTUSER'] . "/pythondeps";
910  putenv("PYTHONPATH=$path");
911  return ["PYTHONPATH" => $path];
912 }
922 {
923  // Get No.of cores
924  $cores = trim(shell_exec("nproc"));
925 
926  // Get CPU load
927  $load = sys_getloadavg()[1];
928 
929  $percentageOfLoad = ($load / $cores);
930 
931  if ($percentageOfLoad < 0.30) {
932  $class = 'btn-success';
933  } else if ($percentageOfLoad < 0.60) {
934  $class = 'btn-warning';
935  } else {
936  $class = 'btn-danger';
937  }
938 
939  return '<button type="button" aria-disabled="true" disabled class="btn '.$class.'">System Load</button>';
940 }
941 
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