FOSSology  4.4.0
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 
65 function ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
66 {
67  global $PG_CONN;
68 
69  $PG_CONN = get_pg_conn($sysconfdir, $SysConf, $exitOnDbFail);
70 
72  return $PG_CONN;
73 } // ConfigInit()
74 
85 function get_pg_conn($sysconfdir, &$SysConf, $exitOnDbFail=true)
86 {
87  /************* Parse VERSION *******************/
88  $versionFile = "{$sysconfdir}/VERSION";
89  $versionConf = parse_ini_file($versionFile, true);
90 
91  /* Add this file contents to $SysConf, then destroy $VersionConf
92  * This file can define its own groups and is eval'd.
93  */
94  foreach ($versionConf as $groupName => $groupArray) {
95  foreach ($groupArray as $var => $assign) {
96  $toeval = "\$$var = \"$assign\";";
97  eval($toeval);
98  $SysConf[$groupName][$var] = ${$var};
99  $GLOBALS[$var] = ${$var};
100  }
101  }
102  unset($versionConf);
103 
104  /************* Parse Db.conf *******************/
105  $dbPath = "{$sysconfdir}/Db.conf";
106  $dbConf = parse_ini_file($dbPath, true);
107 
108  /* Add this file contents to $SysConf, then destroy $dbConf
109  * This file can define its own groups and is eval'd.
110  */
111  foreach ($dbConf as $var => $val) {
112  $SysConf['DBCONF'][$var] = $val;
113  }
114  unset($dbConf);
115 
116  /*
117  * Connect to the database. If the connection fails,
118  * DBconnect() will print a failure message and exit.
119  */
120  $pg_conn = DBconnect($sysconfdir, "", $exitOnDbFail);
121 
122  if (! $exitOnDbFail && ($pg_conn === null || $pg_conn === false)) {
123  return -1;
124  }
125 
126  global $container;
127  $postgresDriver = new \Fossology\Lib\Db\Driver\Postgres($pg_conn);
128  $container->get('db.manager')->setDriver($postgresDriver);
129 
130  return $pg_conn;
131 }
132 
139 function populate_from_sysconfig($conn, &$SysConf)
140 {
141  /* populate the global $SysConf array with variable/value pairs */
142  $sql = "SELECT variablename, conf_value FROM sysconfig;";
143  $result = pg_query($conn, $sql);
144  DBCheckResult($result, $sql, __FILE__, __LINE__);
145 
146  while ($row = pg_fetch_assoc($result)) {
147  $SysConf['SYSCONFIG'][$row['variablename']] = $row['conf_value'];
148  }
149  pg_free_result($result);
150 }
151 
156 {
157  global $PG_CONN;
158 
159  $columns = array("variablename", "conf_value", "ui_label", "vartype", "group_name",
160  "group_order", "description", "validation_function", "option_value");
161  $valueArray = array();
162 
163  /* CorsOrigin */
164  $variable = "CorsOrigins";
165  $prompt = _('Allowed origins for REST API');
166  $desc = _('[scheme]://[hostname]:[port], "*" for anywhere');
167  $valueArray[$variable] = array("'$variable'", "'*'", "'$prompt'",
168  strval(CONFIG_TYPE_TEXT), "'PAT'", "3", "'$desc'", "null", "null");
169 
170  /* Email */
171  $variable = "SupportEmailLabel";
172  $supportEmailLabelPrompt = _('Support Email Label');
173  $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.');
174  $valueArray[$variable] = array("'$variable'", "'Support'", "'$supportEmailLabelPrompt'",
175  strval(CONFIG_TYPE_TEXT), "'Support'", "1", "'$supportEmailLabelDesc'", "null", "null");
176 
177  $variable = "SupportEmailAddr";
178  $supportEmailAddrPrompt = _('Support Email Address');
179  $supportEmailAddrValid = "check_email_address";
180  $supportEmailAddrDesc = _('e.g. "support@mycompany.com"<br>Individual or group email address to those providing FOSSology support.');
181  $valueArray[$variable] = array("'$variable'", "null", "'$supportEmailAddrPrompt'",
182  strval(CONFIG_TYPE_TEXT), "'Support'", "2", "'$supportEmailAddrDesc'", "'$supportEmailAddrValid'", "null");
183 
184  $variable = "SupportEmailSubject";
185  $supportEmailSubjectPrompt = _('Support Email Subject line');
186  $supportEmailSubjectDesc = _('e.g. "fossology support"<br>Subject line to use on support email.');
187  $valueArray[$variable] = array("'$variable'", "'FOSSology Support'", "'$supportEmailSubjectPrompt'",
188  strval(CONFIG_TYPE_TEXT), "'Support'", "3", "'$supportEmailSubjectDesc'", "null", "null");
189 
190  /* oAuth2 Service */
191  $variable = "OidcAppName";
192  $oidcPrompt = _('OIDC App Name');
193  $oidcDesc = _('e.g. "my oAuth"<br>App name to display on login page.');
194  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
195  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "1", "'$oidcDesc'", "null", "null");
196 
197  $variable = "OidcClientIdClaim";
198  $oidcPrompt = _('OIDC Client Id Claim');
199  $oidcDesc = _('e.g. "azp"<br>Client ID claim in the decoded payload.');
200  $valueArray[$variable] = array("'$variable'", "'client-id'", "'$oidcPrompt'",
201  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "2", "'$oidcDesc'", "null", "null");
202 
203  $variable = "OidcResourceOwnerId";
204  $oidcPrompt = _('Resource owner id field');
205  $oidcDesc = _('e.g. "email", "upn"<br>Field in token which provides user id. The field <b>should not be empty</b>.');
206  $valueArray[$variable] = array("'$variable'", "'email'", "'$oidcPrompt'",
207  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "3", "'$oidcDesc'", "null", "null");
208 
209  $variable = "OidcTokenType";
210  $oidcPrompt = _('Token to use from provider');
211  $oidcDesc = _('OpenID Connect providers 2 types of tokens, access and id. Which to use for authentication?<br>AzureAD prefers ID token.');
212  $valueArray[$variable] = array("'$variable'", "'A'", "'$oidcPrompt'",
213  strval(CONFIG_TYPE_DROP), "'OauthSupport'", "4", "'$oidcDesc'", "null", "'Access Token{A}|ID Token{I}'");
214 
215  $variable = "OidcAppId";
216  $oidcPrompt = _('OIDC Client Id');
217  $oidcDesc = _('e.g. "e0ec21b9f4b21adc76f185962b52bdfc13af134a"<br>Client ID generated while registering your application.');
218  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
219  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "5", "'$oidcDesc'", "null", "null");
220 
221  $variable = "OidcSecret";
222  $oidcPrompt = _('OIDC Secret');
223  $oidcDesc = _('e.g. "cf13476f185b9f4b2e0ec962b52211adbdfc13aa"<br>Secret generated while registering your application.');
224  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
225  strval(CONFIG_TYPE_PASSWORD), "'OauthSupport'", "6", "'$oidcDesc'", "null", "null");
226 
227  $variable = "OidcRedirectURL";
228  $oidcPrompt = _('Redirect URL');
229  $oidcDesc = _('e.g. "http://fossology.application.url.com/repo"<br>URL of your fossology application.');
230  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
231  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "7", "'$oidcDesc'", "null", "null");
232 
233  $variable = "OidcDiscoveryURL";
234  $oidcPrompt = _('OIDC Discovery URL');
235  $oidcDesc = _('e.g. "http://oauth.com/.well-known/openid-configuration"<br>URL for OIDC Discovery document JSON to fill following fields upon save.');
236  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
237  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "8", "'$oidcDesc'", "null", "null");
238 
239  $variable = "OidcIssuer";
240  $oidcPrompt = _('OIDC Token Issuer');
241  $oidcDesc = _('e.g. "http://oauth.com"<br>Issuer for OIDC tokens.');
242  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
243  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "9", "'$oidcDesc'", "null", "null");
244 
245  $variable = "OidcAuthorizeURL";
246  $oidcPrompt = _('OIDC Authorize URL');
247  $oidcDesc = _('e.g. "http://oauth.com/authorization.oauth2"<br>URL for OAuth2 authorization endpoint.');
248  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
249  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "10", "'$oidcDesc'", "null", "null");
250 
251  $variable = "OidcAccessTokenURL";
252  $oidcPrompt = _('OIDC Access Token URL');
253  $oidcDesc = _('e.g. "http://oauth.com/token.oauth2"<br>URL for OAuth2 access token endpoint.');
254  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
255  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "11", "'$oidcDesc'", "null", "null");
256 
257  $variable = "OidcResourceURL";
258  $oidcPrompt = _('OIDC User Info URL');
259  $oidcDesc = _('e.g. "http://oauth.com/userinfo.oauth2"<br>URL for OAuth2 user info endpoint.');
260  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
261  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "12", "'$oidcDesc'", "null", "null");
262 
263  $variable = "OidcJwksURL";
264  $oidcPrompt = _('OIDC JWKS URL');
265  $oidcDesc = _('e.g. "http://oauth.com/jwks.oauth2"<br>URL for OIDC JWKS keys.');
266  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
267  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "13", "'$oidcDesc'", "null", "null");
268 
269  $variable = "OidcJwkAlgInject";
270  $oidcPrompt = _('OIDC JWKS Algorithm inject');
271  $oidcDesc = _('Algorithm value to inject for JWKS. Leave empty to not modifiy.' .
272  '<br><a href="https://datatracker.ietf.org/doc/html/rfc7517#section-4.4">Check info</a>.');
273  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
274  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "14", "'$oidcDesc'", "null", "null");
275 
276  $variable = "OidcLogoutURL";
277  $oidcPrompt = _('Logout URL');
278  $oidcDesc = _('e.g. "http://oauth.com/logout.oauth2"<br>URL to redirect user to for logout.');
279  $valueArray[$variable] = array("'$variable'", "null", "'$oidcPrompt'",
280  strval(CONFIG_TYPE_TEXT), "'OauthSupport'", "15", "'$oidcDesc'", "null", "null");
281 
282  /* Banner Message */
283  $variable = "BannerMsg";
284  $bannerMsgPrompt = _('Banner message');
285  $bannerMsgDesc = _('This is message will be displayed on every page with a banner. HTML is ok.');
286  $valueArray[$variable] = array("'$variable'", "null", "'$bannerMsgPrompt'",
287  strval(CONFIG_TYPE_TEXTAREA), "'Banner'", "1", "'$bannerMsgDesc'", "null", "null");
288 
289  /* Logo */
290  $variable = "LogoImage";
291  $logoImagePrompt = _('Logo Image URL');
292  $logoImageValid = "check_logo_image_url";
293  $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.');
294  $valueArray[$variable] = array("'$variable'", "null", "'$logoImagePrompt'",
295  strval(CONFIG_TYPE_TEXT), "'Logo'", "1", "'$logoImageDesc'", "'$logoImageValid'", "null");
296 
297  $variable = "LogoLink";
298  $logoLinkPrompt = _('Logo URL');
299  $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.');
300  $logoLinkValid = "check_logo_url";
301  $valueArray[$variable] = array("'$variable'", "null", "'$logoLinkPrompt'",
302  strval(CONFIG_TYPE_TEXT), "'Logo'", "2", "'$logoLinkDesc'", "'$logoLinkValid'", "null");
303 
304  $variable = "FOSSologyURL";
305  $urlPrompt = _("FOSSology URL");
306  $hostname = exec("hostname -f");
307  if (empty($hostname)) {
308  $hostname = "localhost";
309  }
310  $fossologyURL = $hostname."/repo/";
311  $urlDesc = _("URL of this FOSSology server, e.g. $fossologyURL");
312  $urlValid = "check_fossology_url";
313  $valueArray[$variable] = array("'$variable'", "'$fossologyURL'", "'$urlPrompt'",
314  strval(CONFIG_TYPE_TEXT), "'URL'", "1", "'$urlDesc'", "'$urlValid'", "null");
315 
316  $variable = "ClearlyDefinedURL";
317  $urlPrompt = _("ClearlyDefined URL");
318  $cdURL = "https://api.clearlydefined.io/";
319  $urlDesc = _("URL of ClearlyDefined server, e.g. $cdURL");
320  $urlValid = "check_url";
321  $valueArray[$variable] = array("'$variable'", "'$cdURL'", "'$urlPrompt'",
322  strval(CONFIG_TYPE_TEXT), "'URL'", "2", "'$urlDesc'", "'$urlValid'", "null");
323 
324  $variable = "NomostListNum";
325  $nomosNumPrompt = _("Maximum licenses to List");
326  $nomostListNum = "2200";
327  $NomosNumDesc = _("For License List and License List Download, you can set the maximum number of lines to list/download. Default 2200.");
328  $valueArray[$variable] = array("'$variable'", "'$nomostListNum'", "'$nomosNumPrompt'",
329  strval(CONFIG_TYPE_TEXT), "'Number'", "1", "'$NomosNumDesc'", "null", "null");
330 
331  $variable = "BlockSizeHex";
332  $hexPrompt = _("Chars per page in hex view");
333  $hexDesc = _("Number of characters per page in hex view");
334  $valueArray[$variable] = array("'$variable'", "'8192'", "'$hexPrompt'",
335  strval(CONFIG_TYPE_TEXT), "'Number'", "2", "'$hexDesc'", "null", "null");
336 
337  $variable = "BlockSizeText";
338  $textPrompt = _("Chars per page in text view");
339  $textDesc = _("Number of characters per page in text view");
340  $valueArray[$variable] = array("'$variable'", "'81920'", "'$textPrompt'",
341  strval(CONFIG_TYPE_TEXT), "'Number'", "3", "'$textDesc'", "null", "null");
342 
343  $variable = "ShowJobsAutoRefresh";
344  $contextNamePrompt = _("ShowJobs Auto Refresh Time");
345  $contextValue = "10";
346  $contextDesc = _("No of seconds to refresh ShowJobs");
347  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
348  strval(CONFIG_TYPE_TEXT), "'Number'", "4", "'$contextDesc'", "null", "null");
349 
350  /* Report Header Text */
351  $variable = "ReportHeaderText";
352  $contextNamePrompt = _("Report Header Text");
353  $contextValue = "FOSSology";
354  $contextDesc = _("Report Header Text at right side corner");
355  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
356  strval(CONFIG_TYPE_TEXT), "'ReportText'", "1", "'$contextDesc'", "null", "null");
357 
358  $variable = "CommonObligation";
359  $contextNamePrompt = _("Common Obligation");
360  $contextValue = "";
361  $commonExObligations = _('you can add HTML line break, Also use json format for table rows');
362  $contextDesc = _("Common Obligation Text,". "$commonExObligations");
363  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
364  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "2", "'$contextDesc'", "null", "null");
365 
366  $variable = "AdditionalObligation";
367  $contextNamePrompt = _("Additional Obligation");
368  $contextValue = "";
369  $contextDesc = _("Additional Obligation Text,". "$commonExObligations");
370  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
371  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "3", "'$contextDesc'", "null", "null");
372 
373  $variable = "ObligationAndRisk";
374  $contextNamePrompt = _("Obligation And Risk Assessment");
375  $contextValue = "";
376  $contextDesc = _("Obligations and risk assessment,". "$commonExObligations");
377  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
378  strval(CONFIG_TYPE_TEXTAREA), "'ReportText'", "4", "'$contextDesc'", "null", "null");
379 
380  /* "Upload from server"-configuration */
381  $variable = "UploadFromServerWhitelist";
382  $contextNamePrompt = _("Whitelist for serverupload");
383  $contextValue = "/tmp";
384  $contextDesc = _("List of allowed prefixes for upload, separated by \":\" (colon)");
385  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
386  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "1", "'$contextDesc'", "null", "null");
387 
388  $variable = "UploadFromServerAllowedHosts";
389  $contextNamePrompt = _("List of allowed hosts for serverupload");
390  $contextValue = "localhost";
391  $contextDesc = _("List of allowed hosts for upload, separated by \":\" (colon)");
392  $valueArray[$variable] = array("'$variable'", "'$contextValue'", "'$contextNamePrompt'",
393  strval(CONFIG_TYPE_TEXT), "'UploadFromServer'", "2", "'$contextDesc'", "null", "null");
394 
395  /* SMTP config */
396  $variable = "SMTPHostName";
397  $smtpHostPrompt = _('SMTP Host Name');
398  $smtpHostDesc = _('e.g.: "smtp.domain.com"<br>The domain to be used to send emails.');
399  $valueArray[$variable] = array("'$variable'", "null", "'$smtpHostPrompt'",
400  strval(CONFIG_TYPE_TEXT), "'SMTP'", "1", "'$smtpHostDesc'", "null", "null");
401 
402  $variable = "SMTPPort";
403  $smtpPortPrompt = _('SMTP Port');
404  $smtpPortDesc = _('e.g.: "25"<br>SMTP port to be used.');
405  $valueArray[$variable] = array("'$variable'", "25", "'$smtpPortPrompt'",
406  strval(CONFIG_TYPE_INT), "'SMTP'", "2", "'$smtpPortDesc'", "null", "null");
407 
408  $variable = "SMTPAuth";
409  $smtpAuthPrompt = _('SMTP Auth Type');
410  $smtpAuthDesc = _('Algorithm to use for login.<br>Login => Encrypted<br>None => No authentication<br>Plain => Send as plain text');
411  $valueArray[$variable] = array("'$variable'", "'L'", "'$smtpAuthPrompt'",
412  strval(CONFIG_TYPE_DROP), "'SMTP'", "3", "'$smtpAuthDesc'", "null", "'Login{L}|None{N}|Plain{P}'");
413 
414  $variable = "SMTPFrom";
415  $smtpFrom = _('SMTP Email');
416  $smtpFromDesc = _('e.g.: "user@domain.com"<br>Sender email.');
417  $valueArray[$variable] = array("'$variable'", "null", "'$smtpFrom'",
418  strval(CONFIG_TYPE_TEXT), "'SMTP'", "4", "'$smtpFromDesc'", "'check_email_address'", "null");
419 
420  $variable = "SMTPAuthUser";
421  $smtpAuthUserPrompt = _('SMTP User');
422  $smtpAuthUserDesc = _('e.g.: "user"<br>Login to be used for login on SMTP Server.');
423  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthUserPrompt'",
424  strval(CONFIG_TYPE_TEXT), "'SMTP'", "5", "'$smtpAuthUserDesc'", "null", "null");
425 
426  $variable = "SMTPAuthPasswd";
427  $smtpAuthPasswdPrompt = _('SMTP Login Password');
428  $smtpAuthPasswdDesc = _('Password used for SMTP login.');
429  $valueArray[$variable] = array("'$variable'", "null", "'$smtpAuthPasswdPrompt'",
430  strval(CONFIG_TYPE_PASSWORD), "'SMTP'", "6", "'$smtpAuthPasswdDesc'", "null", "null");
431 
432  $variable = "SMTPSslVerify";
433  $smtpSslPrompt = _('SMTP SSL Verify');
434  $smtpSslDesc = _('The SSL verification for connection is required?');
435  $valueArray[$variable] = array("'$variable'", "'S'", "'$smtpSslPrompt'",
436  strval(CONFIG_TYPE_DROP), "'SMTP'", "7", "'$smtpSslDesc'", "null", "'Ignore{I}|Strict{S}|Warn{W}'");
437 
438  $variable = "SMTPStartTls";
439  $smtpTlsPrompt = _('Start TLS');
440  $smtpTlsDesc = _('Use TLS connection for SMTP?');
441  $valueArray[$variable] = array("'$variable'", "'1'", "'$smtpTlsPrompt'",
442  strval(CONFIG_TYPE_DROP), "'SMTP'", "8", "'$smtpTlsDesc'", "null", "'Yes{1}|No{2}'");
443 
444  $variable = "UploadVisibility";
445  $prompt = _('Default Upload Visibility');
446  $desc = _('Default Visibility for uploads by the user');
447  $valueArray[$variable] = array("'$variable'", "'protected'", "'$prompt'",
448  strval(CONFIG_TYPE_DROP), "'UploadFlag'", "1", "'$desc'", "null", "'Visible only for active group{private}|Visible for all groups{protected}|Make Public{public}'");
449 
450  /* Password policy config */
451  $variable = "PasswdPolicy";
452  $prompt = _('Enable password policy');
453  $desc = _('Enable password policy check');
454  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
455  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "1", "'$desc'",
456  "'check_boolean'", "null");
457 
458  $variable = "PasswdPolicyMinChar";
459  $prompt = _('Minimum characters');
460  $desc = _('Blank for no limit');
461  $valueArray[$variable] = array("'$variable'", "8", "'$prompt'",
462  strval(CONFIG_TYPE_INT), "'PASSWD'", "2", "'$desc'", "null", "null");
463 
464  $variable = "PasswdPolicyMaxChar";
465  $prompt = _('Maximum characters');
466  $desc = _('Blank for no limit');
467  $valueArray[$variable] = array("'$variable'", "16", "'$prompt'",
468  strval(CONFIG_TYPE_INT), "'PASSWD'", "3", "'$desc'", "null", "null");
469 
470  $variable = "PasswdPolicyLower";
471  $prompt = _('Lowercase');
472  $desc = _('Minimum one lowercase character.');
473  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
474  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "4", "'$desc'",
475  "'check_boolean'", "null");
476 
477  $variable = "PasswdPolicyUpper";
478  $prompt = _('Uppercase');
479  $desc = _('Minimum one uppercase character.');
480  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
481  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "5", "'$desc'",
482  "'check_boolean'", "null");
483 
484  $variable = "PasswdPolicyDigit";
485  $prompt = _('Digit');
486  $desc = _('Minimum one digit.');
487  $valueArray[$variable] = array("'$variable'", "true", "'$prompt'",
488  strval(CONFIG_TYPE_BOOL), "'PASSWD'", "6", "'$desc'",
489  "'check_boolean'", "null");
490 
491  $variable = "PasswdPolicySpecial";
492  $prompt = _('Allowed special characters');
493  $desc = _('Empty for do not care');
494  $valueArray[$variable] = array("'$variable'", "'@$!%*?&'", "'$prompt'",
495  strval(CONFIG_TYPE_TEXT), "'PASSWD'", "7", "'$desc'", "null", "null");
496 
497  $variable = "PATMaxExipre";
498  $patTokenValidityPrompt = _('Max token validity');
499  $patTokenValidityDesc = _('Maximum validity of tokens (in days)');
500  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenValidityPrompt'",
501  strval(CONFIG_TYPE_INT), "'PAT'", "1", "'$patTokenValidityDesc'", "null", "null");
502 
503  $variable = "PATMaxPostExpiryRetention";
504  $patTokenRetentionPrompt = _('Max expired token retention period');
505  $patTokenRetentionDesc = _('Maximum retention period of expired tokens (in days) for Maintagent');
506  $valueArray[$variable] = array("'$variable'", "30", "'$patTokenRetentionPrompt'",
507  strval(CONFIG_TYPE_INT), "'PAT'", "2", "'$patTokenRetentionDesc'", "null", "null");
508 
509  $variable = "SkipFiles";
510  $mimeTypeToSkip = _("Skip MimeTypes from scanning");
511  $mimeTypeDesc = _("add comma (,) separated mimetype to exclude files from scanning");
512  $valueArray[$variable] = array("'$variable'", "null", "'$mimeTypeToSkip'",
513  strval(CONFIG_TYPE_TEXT), "'Skip'", "1", "'$mimeTypeDesc'", "null", "null");
514 
515  $perm_admin=Auth::PERM_ADMIN;
516  $perm_write=Auth::PERM_WRITE;
517  $variable = "SourceCodeDownloadRights";
518  $SourceDownloadRightsPrompt = _('Access rights required to download source code');
519  $SourceDownloadRightsDesc = _('Choose which access level will be required for user to be able to download source code.');
520  $valueArray[$variable] = array("'$variable'", "'$perm_write'", "'$SourceDownloadRightsPrompt'",
521  strval(CONFIG_TYPE_DROP), "'DOWNLOAD'", "1", "'$SourceDownloadRightsDesc'", "null", "'Administrator{{$perm_admin}}|Read_Write{{$perm_write}}'");
522 
523  $variable = "UserDescReadOnly";
524  $prompt = _('Make account details read-only');
525  $desc = _('Make account details (username, email, description) read-only');
526  $valueArray[$variable] = array("'$variable'", "false", "'$prompt'",
527  strval(CONFIG_TYPE_BOOL), "'USER_READ_ONLY'", "1", "'$desc'",
528  "'check_boolean'", "null");
529 
530  /* SoftwareHeritage agent config */
531  $variable = "SwhURL";
532  $prompt = _('SoftwareHeritage URL');
533  $desc = _('URL to Software Heritage servers');
534  $valueArray[$variable] = array("'$variable'",
535  "'https://archive.softwareheritage.org'", "'$prompt'",
536  strval(CONFIG_TYPE_TEXT), "'SWH'", "1", "'$desc'", "'check_url'", "null");
537 
538  $variable = "SwhBaseURL";
539  $prompt = _('SoftwareHeritage API base URI');
540  $desc = _('Base URI for API calls');
541  $valueArray[$variable] = array("'$variable'", "'/api/1/content/sha256:'",
542  "'$prompt'", strval(CONFIG_TYPE_TEXT), "'SWH'", "2", "'$desc'", "null",
543  "null");
544 
545  $variable = "SwhContent";
546  $prompt = _('Content endpoint');
547  $desc = _('Endpoint to get content about file');
548  $valueArray[$variable] = array("'$variable'", "'/license'", "'$prompt'",
549  strval(CONFIG_TYPE_TEXT), "'SWH'", "3", "'$desc'", "null", "null");
550 
551  $variable = "SwhSleep";
552  $prompt = _('Max sleep time');
553  $desc = _('Max time to sleep for rate-limit. Note: This concerns with scheduler heartbeat.');
554  $valueArray[$variable] = array("'$variable'", "100", "'$prompt'",
555  strval(CONFIG_TYPE_INT), "'SWH'", "4", "'$desc'", "null", "null");
556 
557  $variable = "SwhToken";
558  $prompt = _('Auth token');
559  $desc = _('');
560  $valueArray[$variable] = array("'$variable'", "''", "'$prompt'",
561  strval(CONFIG_TYPE_PASSWORD), "'SWH'", "5", "'$desc'", "null", "null");
562 
563  $variable = "ScAPIURL";
564  $prompt = _('Scanoss API url');
565  $desc = _('Set URL to SCANOSS API (blank for default osskb.org)');
566  $valueArray[$variable] = array("'$variable'",
567  "''", "'$prompt'",
568  strval(CONFIG_TYPE_TEXT), "'SSS'", "1", "'$desc'", "null", "null");
569 
570  $variable = "ScToken";
571  $prompt = _('Access token');
572  $desc = _('Set token to access full service (blank for basic scan)');
573  $valueArray[$variable] = array("'$variable'",
574  "''", "'$prompt'",
575  strval(CONFIG_TYPE_TEXT), "'SSS'", "2", "'$desc'", "null", "null");
576 
577  /* Doing all the rows as a single insert will fail if any row is a dupe.
578  So insert each one individually so that new variables get added.
579  */
580  foreach ($valueArray as $variable => $values) {
581  /*
582  * Check if the variable already exists. Insert it if it does not.
583  * This is better than an insert ignoring duplicates, because that
584  * generates a postresql log message.
585  */
586  $VarRec = GetSingleRec("sysconfig", "WHERE variablename='$variable'");
587  if (empty($VarRec)) {
588  $sql = "INSERT INTO sysconfig (" . implode(",", $columns) . ") VALUES (" .
589  implode(",", $values) . ");";
590  } else { // Values exist, update them
591  $updateString = [];
592  foreach ($columns as $index => $column) {
593  if ($index != 0 && $index != 1) { // Skip variablename and conf_value
594  $updateString[] = $column . "=" . $values[$index];
595  }
596  }
597  $sql = "UPDATE sysconfig SET " . implode(",", $updateString) .
598  " WHERE variablename='$variable';";
599  }
600  $result = pg_query($PG_CONN, $sql);
601  DBCheckResult($result, $sql, __FILE__, __LINE__);
602  pg_free_result($result);
603  unset($VarRec);
604  }
605 }
606 
617 function check_boolean($value)
618 {
619  if (! strcmp($value, 'true') || ! strcmp($value, 'false')) {
620  return 1;
621  } else {
622  return 0;
623  }
624 }
625 
635 function check_fossology_url($url)
636 {
637  $url_array = explode("/", $url, 2);
638  $name = $url_array[0];
639  if (! empty($name)) {
640  $hostname = exec("hostname -f");
641  if (empty($hostname)) {
642  $hostname = "localhost";
643  }
644  if (check_IP($name)) {
645  $hostname1 = gethostbyaddr($name);
646  if (strcmp($hostname, $hostname1) == 0) {
647  return 0; // host is not reachable
648  }
649  }
650  $server_name = $_SERVER['SERVER_NAME'];
651 
652  /* intput $name must match either the hostname or the server name */
653  if (strcmp($name, $hostname) && strcmp($name, $server_name)) {
654  return 0;
655  }
656  } else {
657  return 0;
658  }
659  return 1;
660 }
661 
671 function check_logo_url($url)
672 {
673  if (empty($url)) {
674  return 1; /* logo url can be null, with the default */
675  }
676  // $res = check_url($url);
677  $res = is_available($url);
678  if (1 == $res) {
679  return 1;
680  } else {
681  return 0;
682  }
683 }
684 
694 function check_logo_image_url($url)
695 {
696  global $SysConf;
697 
698  if (empty($url)) {
699  return 1; /* logo url can be null, with the default */
700  }
701  $logoLink = @$SysConf["LogoLink"];
702  $new_url = $logoLink . $url;
703  if (is_available($url) || is_available($new_url)) {
704  return 1;
705  } else {
706  return 0;
707  }
708 
709 }
710 
721 function check_email_address($email_address)
722 {
723  return 1;
724 }
725 
735 function is_available($url, $timeout = 2, $tries = 2)
736 {
737  global $SysConf;
738 
739  $proxyStmts = "";
740  if (array_key_exists('http_proxy', $SysConf['FOSSOLOGY']) &&
741  $SysConf['FOSSOLOGY']['http_proxy']) {
742  $proxyStmts .= "export http_proxy={$SysConf['FOSSOLOGY']['http_proxy']};";
743  }
744  if (array_key_exists('https_proxy', $SysConf['FOSSOLOGY']) &&
745  $SysConf['FOSSOLOGY']['https_proxy']) {
746  $proxyStmts .= "export https_proxy={$SysConf['FOSSOLOGY']['https_proxy']};";
747  }
748  if (array_key_exists('ftp_proxy', $SysConf['FOSSOLOGY']) &&
749  $SysConf['FOSSOLOGY']['ftp_proxy']) {
750  $proxyStmts .= "export ftp_proxy={$SysConf['FOSSOLOGY']['ftp_proxy']};";
751  }
752 
753  $commands = "$proxyStmts wget --spider '$url' --tries=$tries --timeout=$timeout";
754  system($commands, $return_var);
755  if (0 == $return_var) {
756  return 1;
757  } else {
758  return 0;
759  }
760 }
761 
767 function check_url($url)
768 {
769  if (empty($url) ||
770  preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $url) != 1 ||
771  preg_match("@[[:space:]]@", $url) != 0) {
772  return 0;
773  } else {
774  return 1;
775  }
776 }
777 
783 function check_IP($ip)
784 {
785  $e = "([0-9]|1[0-9]{2}|[1-9][0-9]|2[0-4][0-9]|25[0-5])";
786  return preg_match("/^$e\.$e\.$e\.$e$/", $ip);
787 }
788 
793 function set_python_path(): array
794 {
795  global $SysConf;
796  $path = "/home/" . $SysConf['DIRECTORIES']['PROJECTUSER'] . "/pythondeps";
797  putenv("PYTHONPATH=$path");
798  return ["PYTHONPATH" => $path];
799 }
809 {
810  // Get No.of cores
811  $cores = trim(shell_exec("nproc"));
812 
813  // Get CPU load
814  $load = sys_getloadavg()[1];
815 
816  $percentageOfLoad = ($load / $cores);
817 
818  if ($percentageOfLoad < 0.30) {
819  $class = 'btn-success';
820  } else if ($percentageOfLoad < 0.60) {
821  $class = 'btn-warning';
822  } else {
823  $class = 'btn-danger';
824  }
825 
826  return '<button type="button" aria-disabled="true" disabled class="btn '.$class.'">System Load</button>';
827 }
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:187
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().
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.
ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().
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