FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fossinit-common.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2019 Siemens AG
4  Author: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ***********************************************************/
19 
26 function guessSysconfdir()
27 {
28  $rcfile = "fossology.rc";
29  $varfile = dirname(__DIR__).'/variable.list';
30  $sysconfdir = getenv('SYSCONFDIR');
31  if ((false===$sysconfdir) && file_exists($rcfile))
32  {
33  $sysconfdir = file_get_contents($rcfile);
34  }
35  if ((false===$sysconfdir) && file_exists($varfile))
36  {
37  $ini_array = parse_ini_file($varfile);
38  if($ini_array!==false && array_key_exists('SYSCONFDIR', $ini_array))
39  {
40  $sysconfdir = $ini_array['SYSCONFDIR'];
41  }
42  }
43  if (false===$sysconfdir)
44  {
45  $text = _("FATAL! System Configuration Error, no SYSCONFDIR.");
46  echo "$text\n";
47  exit(1);
48  }
49  return $sysconfdir;
50 }
51 
52 
69 function bootstrap($sysconfdir="")
70 {
71  if (empty($sysconfdir))
72  {
73  $sysconfdir = guessSysconfdir();
74  echo "assuming SYSCONFDIR=$sysconfdir\n";
75  }
76 
77  $sysconfdir = trim($sysconfdir);
78  $GLOBALS['SYSCONFDIR'] = $sysconfdir;
79 
80  /************* Parse fossology.conf *******************/
81  $ConfFile = "{$sysconfdir}/fossology.conf";
82  if (!file_exists($ConfFile))
83  {
84  $text = _("FATAL! Missing configuration file: $ConfFile");
85  echo "$text\n";
86  exit(1);
87  }
88  $SysConf = parse_ini_file($ConfFile, true);
89  if ($SysConf === false)
90  {
91  $text = _("FATAL! Invalid configuration file: $ConfFile");
92  echo "$text\n";
93  exit(1);
94  }
95 
96  /* evaluate all the DIRECTORIES group for variable substitutions.
97  * For example, if PREFIX=/usr/local and BINDIR=$PREFIX/bin, we
98  * want BINDIR=/usr/local/bin
99  */
100  foreach($SysConf['DIRECTORIES'] as $var=>$assign)
101  {
102  $toeval = "\$$var = \"$assign\";";
103  eval($toeval);
104 
105  /* now reassign the array value with the evaluated result */
106  $SysConf['DIRECTORIES'][$var] = ${$var};
107  $GLOBALS[$var] = ${$var};
108  }
109 
110  if (empty($MODDIR))
111  {
112  $text = _("FATAL! System initialization failure: MODDIR not defined in $SysConf");
113  echo "$text\n";
114  exit(1);
115  }
116 
117  //require("i18n.php"); DISABLED until i18n infrastructure is set-up.
118  require_once("$MODDIR/lib/php/common.php");
119  require_once("$MODDIR/lib/php/Plugin/FO_Plugin.php");
120  return $SysConf;
121 }
122 
132 function readlineTimeout($seconds, $default)
133 {
134  return trim(shell_exec('bash -c ' .
135  escapeshellarg('fossstdin=' . escapeshellarg($default) .
136  ';read -t ' . ((int)$seconds) . ' fossstdin;echo "$fossstdin"')));
137 }
bootstrap($sysconfdir="")
Determine SYSCONFDIR, parse fossology.conf.
readlineTimeout($seconds, $default)
Using bash&#39;s read command, read input from STDIN.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695