11 define(
"TITLE_FOSSDASH_CONFIG", _(
"Fossdash Configuration"));
19 var $CreateAttempts = 0;
25 $this->Name =
"FossdashConfig";
26 $this->Title = TITLE_FOSSDASH_CONFIG;
27 $this->MenuList =
"Admin::Fossdash";
29 $this->PluginLevel = 50;
30 parent::__construct();
31 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
43 $sql =
"select * from fossdashconfig order by group_name, group_order";
48 $InputStyle =
"style='background-color:#dbf0f7'";
49 $OutBuf .=
'<style> table.myTable > tbody > tr:first-child > td:first-child{width:20%} </style>';
50 $OutBuf .=
"<form method='POST' enctype='multipart/form-data'>";
51 while ($row = pg_fetch_assoc($result)) {
52 if ($Group != $row[
'group_name']) {
54 $OutBuf .=
'</table><br>';
56 $Group = $row[
'group_name'];
57 $OutBuf .=
'<table border=1 class="myTable table table-striped" style="border-collapse: unset;" >';
59 if ($row[
'variablename']==
"InfluxDBUser" || $row[
'variablename']==
"InfluxDBUserPassword") {
60 $OutBuf .=
"<tr id='rowId$row[variablename]' style='display: none;'><td>$row[ui_label]</td><td>";
62 $OutBuf .=
"<tr id='rowId$row[variablename]'><td>$row[ui_label]</td><td>";
65 switch ($row[
'vartype']) {
68 $ConfVal = htmlentities($row[
'conf_value']);
69 $OutBuf .=
"<INPUT type='text' name='new[$row[variablename]]' size='70' value='$ConfVal' title='$row[description]' $InputStyle>";
70 $OutBuf .=
"<br>$row[description]";
73 $ConfVal = htmlentities($row[
'conf_value']);
74 $OutBuf .=
"<br><textarea name='new[$row[variablename]]' rows=3 cols=100 title='$row[description]' $InputStyle>$ConfVal</textarea>";
75 $OutBuf .=
"<br>$row[description]";
78 $ConfVal = htmlentities($row[
'conf_value']);
79 $OutBuf .=
"<INPUT type='password' name='new[$row[variablename]]' size='70' value='$ConfVal' title='$row[description]' $InputStyle>";
80 $OutBuf .=
"<br>$row[description]";
83 $ConfVal = htmlentities($row[
'conf_value']);
84 $Options = explode(
"|",$row[
'option_value']);
85 $OutBuf .=
"<select name='new[$row[variablename]]' title='$row[description]' $InputStyle>";
86 foreach ($Options as $Option) {
88 preg_match(
'/(\\w+)[{](.*)[}]/', $Option, $matches);
89 $Option_display = $matches[1];
90 $Option_value = $matches[2];
91 $OutBuf .=
"<option $InputStyle value='$Option_value' ";
92 if ($ConfVal == $Option_value) {
93 $OutBuf .=
"selected";
95 $OutBuf .=
">$Option_display</option>";
97 $OutBuf .=
"</select>";
98 $OutBuf .=
"<br>$row[description]";
101 $OutBuf .=
"Invalid configuration variable. Unknown type.";
103 $OutBuf .=
"</td></tr>";
104 $OutBuf .=
"<INPUT type='hidden' name='old[$row[variablename]]' value='$ConfVal'>";
106 $OutBuf .=
"</table>";
107 pg_free_result($result);
109 $btnlabel = _(
"Update");
110 $OutBuf .=
"<p><input type='submit' class='btn btn-secondary btn-sm' style='display: block; margin: 0 auto;' value='$btnlabel'>";
111 $OutBuf .=
"</form>";
113 $scriptToHideShow =
'
115 function showHide() {
116 if($(\'[name="new[AuthType]"]\').val() == "0") {
117 $("#rowIdInfluxDBToken").show();
118 $("#rowIdInfluxDBUser").hide();
119 $("#rowIdInfluxDBUserPassword").hide();
122 $("#rowIdInfluxDBToken").hide();
123 $("#rowIdInfluxDBUser").show();
124 $("#rowIdInfluxDBUserPassword").show();
128 $(\'[name="new[AuthType]"]\').change(showHide);
131 window.onload = function() {
146 if ($this->
State != PLUGIN_STATE_READY) {
152 $LIBEXECDIR = $GLOBALS[
'SysConf'][
'DIRECTORIES'][
'LIBEXECDIR'];
158 if (! empty($newarray)) {
159 foreach ($newarray as $VarName => $VarValue) {
160 if ($VarValue != $oldarray[$VarName]) {
162 $sys_array = $this->
dbManager->getSingleRow(
"select validation_function, ui_label from fossdashconfig where variablename=$1",array($VarName),__METHOD__.
'.getVarNameData');
163 $validation_function = $sys_array[
'validation_function'];
164 $ui_label = $sys_array[
'ui_label'];
165 $is_empty = empty($validation_function);
170 if ($is_empty || (! $is_empty && (1 == $validation_function($VarValue)))) {
172 "update fossdashconfig set conf_value=$1 where variablename=$2",
173 array($VarValue, $VarName), __METHOD__ .
'.setVarNameData');
174 if ($VarName ==
"FossdashEnableDisable") {
175 $exec_fossdash_configuration_cmd =
"python3 ".$LIBEXECDIR.
"/fossdash-publish.py fossdash_configure " . escapeshellarg($VarValue);
176 $output = shell_exec($exec_fossdash_configuration_cmd);
177 file_put_contents(
'php://stderr',
"output of the cmd for fossology_configuration(enable/Disable) changed ={$output} \n");
178 } elseif ($VarName ==
"FossologyInstanceName") {
179 $parameterName =
"uuid";
180 $exec_script_uuid_cmd =
"python3 ".$LIBEXECDIR.
"/fossdash-publish.py " . $parameterName;
181 $output = shell_exec($exec_script_uuid_cmd);
182 file_put_contents(
'php://stderr',
"output of cmd for fossology_instance_name changed ={$output} \n");
183 } elseif ($VarName ==
"FossDashScriptCronSchedule") {
184 $parameterName =
"cron";
185 $exec_script_cron_cmd =
"python3 ".$LIBEXECDIR.
"/fossdash-publish.py " . $parameterName;
186 $output = shell_exec($exec_script_cron_cmd);
187 file_put_contents(
'php://stderr',
"output of cmd for cron job changed ={$output} \n");
190 if (! empty($UpdateMsg)) {
193 $UpdateMsg .= $VarName;
194 }
else if (! $is_empty && (0 == $validation_function($VarValue))) {
199 if (! empty($ErrorMsg)) {
202 $ErrorMsg .= $VarName;
207 if (! empty($UpdateMsg)) {
208 $UpdateMsg .= _(
" updated.");
210 if (! empty($ErrorMsg)) {
211 $ErrorMsg .= _(
" Error occurred.");
216 if ($this->OutputType ==
'HTML') {
219 $OutBuf .=
"<span style='background-color:#99FF99'>$UpdateMsg</style>";
222 $OutBuf .=
"<span style='background-color:#FF8181'>$ErrorMsg</style><hr>";
224 $OutBuf .=
"</div> <hr>";
227 $this->vars[
'content'] = $OutBuf;
232 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
renderScripts($scripts)
Render JavaScript in the template's footer.
display and set FOSSology configuration
HTMLout()
Generate HTML output.
__construct()
base constructor. Most plugins will just use this
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
const CONFIG_TYPE_TEXTAREA
const CONFIG_TYPE_PASSWORD
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
fo_dbManager * dbManager
fo_dbManager object