27 define(
"CONFIG_TYPE_INT", 1);
29 define(
"CONFIG_TYPE_TEXT", 2);
31 define(
"CONFIG_TYPE_TEXTAREA", 3);
33 define(
"CONFIG_TYPE_PASSWORD", 4);
35 define(
"CONFIG_TYPE_DROP", 5);
80 $versionFile =
"{$sysconfdir}/VERSION";
81 $versionConf = parse_ini_file($versionFile,
true);
86 foreach ($versionConf as $groupName => $groupArray) {
87 foreach ($groupArray as $var => $assign) {
88 $toeval =
"\$$var = \"$assign\";";
90 $SysConf[$groupName][$var] = ${$var};
91 $GLOBALS[$var] = ${$var};
97 $dbPath =
"{$sysconfdir}/Db.conf";
98 $dbConf = parse_ini_file($dbPath,
true);
103 foreach ($dbConf as $var => $val) {
104 $SysConf[
'DBCONF'][$var] = $val;
115 $postgresDriver = new \Fossology\Lib\Db\Driver\Postgres($PG_CONN);
116 $container->get(
'db.manager')->setDriver($postgresDriver);
127 $sql =
"SELECT variablename, conf_value FROM sysconfig;";
128 $result = pg_query($PG_CONN, $sql);
131 while ($row = pg_fetch_assoc($result)) {
132 $SysConf[
'SYSCONFIG'][$row[
'variablename']] = $row[
'conf_value'];
134 pg_free_result($result);
151 $sql =
"SELECT typlen FROM pg_type WHERE typname='sysconfig' limit 1;";
152 $result = pg_query($PG_CONN, $sql);
154 $numrows = pg_num_rows($result);
155 pg_free_result($result);
162 CREATE TABLE sysconfig ( 163 sysconfig_pk serial NOT NULL PRIMARY KEY, 164 variablename character varying(30) NOT NULL UNIQUE, 166 ui_label character varying(60) NOT NULL, 167 vartype int NOT NULL, 168 group_name character varying(20) NOT NULL, 170 description text NOT NULL, 171 validation_function character varying(40) DEFAULT NULL, 172 option_value character varying(40) DEFAULT NULL 176 $result = pg_query($PG_CONN, $sql);
178 pg_free_result($result);
182 COMMENT ON TABLE sysconfig IS 'System configuration values'; 183 COMMENT ON COLUMN sysconfig.variablename IS 'Name of configuration variable'; 184 COMMENT ON COLUMN sysconfig.conf_value IS 'value of config variable'; 185 COMMENT ON COLUMN sysconfig.ui_label IS 'Label that appears on user interface to prompt for variable'; 186 COMMENT ON COLUMN sysconfig.group_name IS 'Name of this variables group in the user interface'; 187 COMMENT ON COLUMN sysconfig.group_order IS 'The order this variable appears in the user interface group'; 188 COMMENT ON COLUMN sysconfig.description IS 'Description of variable to document how/where the variable value is used.'; 189 COMMENT ON COLUMN sysconfig.validation_function IS 'Name of function to validate input. Not currently implemented.'; 190 COMMENT ON COLUMN sysconfig.vartype IS 'variable type. 1=int, 2=text, 3=textarea, 4=password, 5=dropdown'; 191 COMMENT ON COLUMN sysconfig.option_value IS 'If vartype is 5, provide options in format op1{val1}|op2{val2}|...'; 194 $result = pg_query($PG_CONN, $sql);
196 pg_free_result($result);
208 $columns = array(
"variablename",
"conf_value",
"ui_label",
"vartype",
"group_name",
209 "group_order",
"description",
"validation_function",
"option_value");
210 $valueArray = array();
213 $variable =
"SupportEmailLabel";
214 $supportEmailLabelPrompt = _(
'Support Email Label');
215 $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.');
216 $valueArray[$variable] = array(
"'$variable'",
"'Support'",
"'$supportEmailLabelPrompt'",
217 strval(
CONFIG_TYPE_TEXT),
"'Support'",
"1",
"'$supportEmailLabelDesc'",
"null",
"null");
219 $variable =
"SupportEmailAddr";
220 $supportEmailAddrPrompt = _(
'Support Email Address');
221 $supportEmailAddrValid =
"check_email_address";
222 $supportEmailAddrDesc = _(
'e.g. "support@mycompany.com"<br>Individual or group email address to those providing FOSSology support.');
223 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$supportEmailAddrPrompt'",
224 strval(
CONFIG_TYPE_TEXT),
"'Support'",
"2",
"'$supportEmailAddrDesc'",
"'$supportEmailAddrValid'",
"null");
226 $variable =
"SupportEmailSubject";
227 $supportEmailSubjectPrompt = _(
'Support Email Subject line');
228 $supportEmailSubjectDesc = _(
'e.g. "fossology support"<br>Subject line to use on support email.');
229 $valueArray[$variable] = array(
"'$variable'",
"'FOSSology Support'",
"'$supportEmailSubjectPrompt'",
230 strval(
CONFIG_TYPE_TEXT),
"'Support'",
"3",
"'$supportEmailSubjectDesc'",
"null",
"null");
233 $variable =
"BannerMsg";
234 $bannerMsgPrompt = _(
'Banner message');
235 $bannerMsgDesc = _(
'This is message will be displayed on every page with a banner. HTML is ok.');
236 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$bannerMsgPrompt'",
240 $variable =
"LogoImage";
241 $logoImagePrompt = _(
'Logo Image URL');
242 $logoImageValid =
"check_logo_image_url";
243 $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.');
244 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$logoImagePrompt'",
245 strval(
CONFIG_TYPE_TEXT),
"'Logo'",
"1",
"'$logoImageDesc'",
"'$logoImageValid'",
"null");
247 $variable =
"LogoLink";
248 $logoLinkPrompt = _(
'Logo URL');
249 $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.');
250 $logoLinkValid =
"check_logo_url";
251 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$logoLinkPrompt'",
252 strval(
CONFIG_TYPE_TEXT),
"'Logo'",
"2",
"'$logoLinkDesc'",
"'$logoLinkValid'",
"null");
254 $variable =
"FOSSologyURL";
255 $urlPrompt = _(
"FOSSology URL");
256 $hostname = exec(
"hostname -f");
257 if (empty($hostname)) {
258 $hostname =
"localhost";
260 $fossologyURL = $hostname.
"/repo/";
261 $urlDesc = _(
"URL of this FOSSology server, e.g. $fossologyURL");
262 $urlValid =
"check_fossology_url";
263 $valueArray[$variable] = array(
"'$variable'",
"'$fossologyURL'",
"'$urlPrompt'",
264 strval(
CONFIG_TYPE_TEXT),
"'URL'",
"1",
"'$urlDesc'",
"'$urlValid'",
"null");
266 $variable =
"NomostListNum";
267 $nomosNumPrompt = _(
"Maximum licenses to List");
268 $nomostListNum =
"2200";
269 $NomosNumDesc = _(
"For License List and License List Download, you can set the maximum number of lines to list/download. Default 2200.");
270 $valueArray[$variable] = array(
"'$variable'",
"'$nomostListNum'",
"'$nomosNumPrompt'",
271 strval(
CONFIG_TYPE_TEXT),
"'Number'",
"1",
"'$NomosNumDesc'",
"null",
"null");
273 $variable =
"BlockSizeHex";
274 $hexPrompt = _(
"Chars per page in hex view");
275 $hexDesc = _(
"Number of characters per page in hex view");
276 $valueArray[$variable] = array(
"'$variable'",
"'8192'",
"'$hexPrompt'",
279 $variable =
"BlockSizeText";
280 $textPrompt = _(
"Chars per page in text view");
281 $textDesc = _(
"Number of characters per page in text view");
282 $valueArray[$variable] = array(
"'$variable'",
"'81920'",
"'$textPrompt'",
285 $variable =
"ShowJobsAutoRefresh";
286 $contextNamePrompt = _(
"ShowJobs Auto Refresh Time");
287 $contextValue =
"10";
288 $contextDesc = _(
"No of seconds to refresh ShowJobs");
289 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
290 strval(
CONFIG_TYPE_TEXT),
"'Number'",
"4",
"'$contextDesc'",
"null",
"null");
293 $variable =
"ReportHeaderText";
294 $contextNamePrompt = _(
"Report Header Text");
295 $contextValue =
"FOSSology";
296 $contextDesc = _(
"Report Header Text at right side corner");
297 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
298 strval(
CONFIG_TYPE_TEXT),
"'ReportText'",
"1",
"'$contextDesc'",
"null",
"null");
300 $variable =
"CommonObligation";
301 $contextNamePrompt = _(
"Common Obligation");
303 $contextDesc = _(
"Common Obligation Text, add line break at the end of the line");
304 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
307 $variable =
"AdditionalObligation";
308 $contextNamePrompt = _(
"Additional Obligation");
310 $contextDesc = _(
"Additional Obligation Text, add line break at the end of the line");
311 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
314 $variable =
"ObligationAndRisk";
315 $contextNamePrompt = _(
"Obligation And Risk Assessment");
317 $contextDesc = _(
"Obligations and risk assessment, add line break at the end of the line");
318 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
322 $variable =
"UploadFromServerWhitelist";
323 $contextNamePrompt = _(
"Whitelist for serverupload");
324 $contextValue =
"/tmp";
325 $contextDesc = _(
"List of allowed prefixes for upload, separated by \":\" (colon)");
326 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
327 strval(
CONFIG_TYPE_TEXT),
"'UploadFromServer'",
"1",
"'$contextDesc'",
"null",
"null");
329 $variable =
"UploadFromServerAllowedHosts";
330 $contextNamePrompt = _(
"List of allowed hosts for serverupload");
331 $contextValue =
"localhost";
332 $contextDesc = _(
"List of allowed hosts for upload, separated by \":\" (colon)");
333 $valueArray[$variable] = array(
"'$variable'",
"'$contextValue'",
"'$contextNamePrompt'",
334 strval(
CONFIG_TYPE_TEXT),
"'UploadFromServer'",
"2",
"'$contextDesc'",
"null",
"null");
337 $variable =
"SMTPHostName";
338 $smtpHostPrompt = _(
'SMTP Host Name');
339 $smtpHostDesc = _(
'e.g.: "smtp.domain.com"<br>The domain to be used to send emails.');
340 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$smtpHostPrompt'",
341 strval(
CONFIG_TYPE_TEXT),
"'SMTP'",
"1",
"'$smtpHostDesc'",
"null",
"null");
343 $variable =
"SMTPPort";
344 $smtpPortPrompt = _(
'SMTP Port');
345 $smtpPortDesc = _(
'e.g.: "25"<br>SMTP port to be used.');
346 $valueArray[$variable] = array(
"'$variable'",
"25",
"'$smtpPortPrompt'",
347 strval(
CONFIG_TYPE_INT),
"'SMTP'",
"2",
"'$smtpPortDesc'",
"null",
"null");
349 $variable =
"SMTPAuth";
350 $smtpAuthPrompt = _(
'SMTP Auth Type');
351 $smtpAuthDesc = _(
'Algorithm to use for login.<br>Login => Encrypted<br>None => No authentication<br>Plain => Send as plain text');
352 $valueArray[$variable] = array(
"'$variable'",
"'L'",
"'$smtpAuthPrompt'",
353 strval(
CONFIG_TYPE_DROP),
"'SMTP'",
"3",
"'$smtpAuthDesc'",
"null",
"'Login{L}|None{N}|Plain{P}'");
355 $variable =
"SMTPFrom";
356 $smtpFrom = _(
'SMTP Email');
357 $smtpFromDesc = _(
'e.g.: "user@domain.com"<br>Sender email.');
358 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$smtpFrom'",
359 strval(
CONFIG_TYPE_TEXT),
"'SMTP'",
"4",
"'$smtpFromDesc'",
"'check_email_address'",
"null");
361 $variable =
"SMTPAuthUser";
362 $smtpAuthUserPrompt = _(
'SMTP User');
363 $smtpAuthUserDesc = _(
'e.g.: "user"<br>Login to be used for login on SMTP Server.');
364 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$smtpAuthUserPrompt'",
365 strval(
CONFIG_TYPE_TEXT),
"'SMTP'",
"5",
"'$smtpAuthUserDesc'",
"null",
"null");
367 $variable =
"SMTPAuthPasswd";
368 $smtpAuthPasswdPrompt = _(
'SMTP Login Password');
369 $smtpAuthPasswdDesc = _(
'Password used for SMTP login.');
370 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$smtpAuthPasswdPrompt'",
373 $variable =
"SMTPSslVerify";
374 $smtpSslPrompt = _(
'SMTP SSL Verify');
375 $smtpSslDesc = _(
'The SSL verification for connection is required?');
376 $valueArray[$variable] = array(
"'$variable'",
"'S'",
"'$smtpSslPrompt'",
377 strval(
CONFIG_TYPE_DROP),
"'SMTP'",
"6",
"'$smtpSslDesc'",
"null",
"'Ignore{I}|Strict{S}|Warn{W}'");
379 $variable =
"SMTPStartTls";
380 $smtpTlsPrompt = _(
'Start TLS');
381 $smtpTlsDesc = _(
'Use TLS connection for SMTP?');
382 $valueArray[$variable] = array(
"'$variable'",
"'1'",
"'$smtpTlsPrompt'",
383 strval(
CONFIG_TYPE_DROP),
"'SMTP'",
"7",
"'$smtpTlsDesc'",
"null",
"'Yes{1}|No{2}'");
385 $variable =
"PATMaxExipre";
386 $patTokenValidityPrompt = _(
'Max token validity');
387 $patTokenValidityDesc = _(
'Maximum validity of tokens (in days)');
388 $valueArray[$variable] = array(
"'$variable'",
"30",
"'$patTokenValidityPrompt'",
389 strval(
CONFIG_TYPE_INT),
"'PAT'",
"1",
"'$patTokenValidityDesc'",
"null",
"null");
391 $variable =
"SkipFiles";
392 $mimeTypeToSkip = _(
"Skip MimeTypes from scanning");
393 $mimeTypeDesc = _(
"add comma (,) separated mimetype to exclude files from scanning");
394 $valueArray[$variable] = array(
"'$variable'",
"null",
"'$mimeTypeToSkip'",
395 strval(
CONFIG_TYPE_TEXT),
"'Skip'",
"1",
"'$mimeTypeDesc'",
"null",
"null");
399 $variable =
"SourceCodeDownloadRights";
400 $SourceDownloadRightsPrompt = _(
'Acces rights required to download source code');
401 $SourceDownloadRightsDesc = _(
'Choose which acces level will be required for user to be able to download source code.');
402 $valueArray[$variable] = array(
"'$variable'",
"'$perm_write'",
"'$SourceDownloadRightsPrompt'",
403 strval(
CONFIG_TYPE_DROP),
"'DOWNLOAD'",
"1",
"'$SourceDownloadRightsDesc'",
"null",
"'Administrator{{$perm_admin}}|Read_Write{{$perm_write}}'");
408 foreach ($valueArray as $variable => $values) {
414 $VarRec =
GetSingleRec(
"sysconfig",
"WHERE variablename='$variable'");
415 if (empty($VarRec)) {
416 $sql =
"INSERT INTO sysconfig (" . implode(
",", $columns) .
") VALUES (" .
417 implode(
",", $values) .
");";
418 $result = pg_query($PG_CONN, $sql);
420 pg_free_result($result);
423 foreach ($columns as $index => $column) {
424 if ($index != 0 && $index != 1) {
425 $updateString[] = $column .
"=" . $values[$index];
428 $sql =
"UPDATE sysconfig SET " . implode(
",", $updateString) .
429 " WHERE variablename='$variable';";
430 $result = pg_query($PG_CONN, $sql);
432 pg_free_result($result);
449 $sql =
"SELECT column_name FROM information_schema.columns WHERE " 450 .
"table_name='sysconfig' and column_name='option_value' limit 1;";
451 $result = pg_query($PG_CONN, $sql);
453 $numrows = pg_num_rows($result);
454 pg_free_result($result);
460 $sql =
"ALTER TABLE sysconfig ADD COLUMN option_value character varying(40) DEFAULT NULL;";
462 $result = pg_query($PG_CONN, $sql);
464 pg_free_result($result);
467 $sql =
"COMMENT ON COLUMN sysconfig.option_value IS 'If vartype is 5, " 468 .
"provide options in format op1{val1}|op2{val2}|...';";
470 $result = pg_query($PG_CONN, $sql);
472 pg_free_result($result);
488 if (! strcmp($value,
'true') || ! strcmp($value,
'false')) {
506 $url_array = explode(
"/", $url, 2);
507 $name = $url_array[0];
508 if (! empty($name)) {
509 $hostname = exec(
"hostname -f");
510 if (empty($hostname)) {
511 $hostname =
"localhost";
514 $hostname1 = gethostbyaddr($name);
515 if (strcmp($hostname, $hostname1) == 0) {
519 $server_name = $_SERVER[
'SERVER_NAME'];
522 if (strcmp($name, $hostname) && strcmp($name, $server_name)) {
570 $logoLink = @$SysConf[
"LogoLink"];
571 $new_url = $logoLink . $url;
609 if (array_key_exists(
'http_proxy', $SysConf[
'FOSSOLOGY']) &&
610 $SysConf[
'FOSSOLOGY'][
'http_proxy']) {
611 $proxyStmts .=
"export http_proxy={$SysConf['FOSSOLOGY']['http_proxy']};";
613 if (array_key_exists(
'https_proxy', $SysConf[
'FOSSOLOGY']) &&
614 $SysConf[
'FOSSOLOGY'][
'https_proxy']) {
615 $proxyStmts .=
"export https_proxy={$SysConf['FOSSOLOGY']['https_proxy']};";
617 if (array_key_exists(
'ftp_proxy', $SysConf[
'FOSSOLOGY']) &&
618 $SysConf[
'FOSSOLOGY'][
'ftp_proxy']) {
619 $proxyStmts .=
"export ftp_proxy={$SysConf['FOSSOLOGY']['ftp_proxy']};";
622 $commands =
"$proxyStmts wget --spider '$url' --tries=$tries --timeout=$timeout";
623 system($commands, $return_var);
624 if (0 == $return_var) {
639 preg_match(
"@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $url) != 1 ||
640 preg_match(
"@[[:space:]]@", $url) != 0) {
654 $e =
"([0-9]|1[0-9]{2}|[1-9][0-9]|2[0-4][0-9]|25[0-5])";
655 return preg_match(
"/^$e\.$e\.$e\.$e$/", $ip);
const CONFIG_TYPE_TEXTAREA
DBconnect($sysconfdir, $options="", $exitOnFail=true)
Connect to database engine. This is a no-op if $PG_CONN already has a value.
check_url($url)
Check if the url is valid.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
Populate_sysconfig()
Populate the sysconfig table with core variables.
const CONFIG_TYPE_PASSWORD
check_fossology_url($url)
Validation function check_fossology_url().
check_email_address($email_address)
Validation function check_email_address().
Create_option_value()
Create the option_value column in sysconfig table.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
check_logo_image_url($url)
Validation function check_logo_image_url().
Create_sysconfig()
Create the sysconfig table.
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
check_logo_url($url)
Validation function check_logo_url().
check_boolean($value)
Validation function check_boolean().
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().
check_IP($ip)
Check if the ip address is valid.
is_available($url, $timeout=2, $tries=2)
Check if the URL is available.
#define PERM_ADMIN
Administrator.
#define PERM_WRITE
Read-Write permission.