17 define(
"TITLE_AGENT_NOMOS_ONCE", _(
"One-Shot License Analysis"));
31 $this->Name =
"agent_nomos_once";
32 $this->Title = TITLE_AGENT_NOMOS_ONCE;
33 $this->Dependency = array();
41 parent::__construct();
53 exec(
"$SYSCONFDIR/mods-enabled/nomos/agent/nomos -S $FilePath", $out, $rtn);
54 $licensesFromAgent = explode(
'contains license(s)', $out[0]);
55 $licenses_and_Highlight = end($licensesFromAgent);
56 $licenses = explode(
'Highlighting Info at', $licenses_and_Highlight);
58 preg_match_all(
'/Keyword at (?P<position>\d+), length (?P<length>\d+),/',
59 $licenses[1], $this->HighlightInfoKeywords);
61 '/License #(?P<name>[^#]*)# at (?P<position>\d+), length (?P<length>\d+),/',
62 $licenses[1], $this->HighlightInfoLicenses);
64 return ($licenses[0]);
91 if ($this->
State != PLUGIN_STATE_READY) {
95 if (empty($ShowHeader)) {
104 if ($ThisMod && empty($_POST[
'showheader']) &&
105 ($_SERVER[
'REQUEST_METHOD'] ==
"POST")) {
106 $Fin = fopen(
"php://input",
"r");
107 $Ftmp = tempnam(NULL,
"fosslic-alo-");
108 $Fout = fopen($Ftmp,
"w");
109 while (! feof($Fin)) {
111 fwrite($Fout, $Line);
121 if (filesize($Ftmp) > 0) {
122 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
123 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
124 $_FILES[
'licfile'][
'unlink_flag'] = 1;
135 "FATAL: your file did not get passed throught. Make sure this page wasn't a result of a web server redirect, or that it didn't exceed your php POST limit.");
141 if (! empty($_SESSION[Auth::USER_NAME])) {
142 if (array_key_exists(Auth::USER_LEVEL, $_SESSION) &&
144 menu_insert(
"Main::Upload::One-Shot Nomos Analysis", $this->MenuOrder,
145 $this->Name, $this->MenuTarget);
158 if ($this->
State != PLUGIN_STATE_READY) {
163 if (array_key_exists(self::FILE_INPUT, $_FILES) &&
164 array_key_exists(
'tmp_name', $_FILES[self::FILE_INPUT])) {
172 if ($this->OutputType !=
'HTML' && file_exists($tmp_name)) {
177 if (file_exists($tmp_name)) {
178 $this->vars[
'content'] = $this->htmlAnalyzedContent($tmp_name,
179 $_FILES[self::FILE_INPUT][
'name']);
180 }
else if ($this->OutputType ==
'HTML') {
181 return $this->
render(
'oneshot-upload.html.twig', $this->vars);
183 if (array_key_exists(
'licfile', $_FILES) &&
184 array_key_exists(
'unlink_flag', $_FILES[
'licfile'])) {
187 unset($_FILES[self::FILE_INPUT]);
188 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
189 return $this->
render($this->getTemplateName(), $this->vars);
198 private function htmlAnalyzedContent($tmp_name, $filename)
201 "A one shot license analysis shows the following license(s) in file");
202 $keep =
"$text <em>$filename:</em> ";
203 $keep .=
"<strong>" . $this->
AnalyzeFile($tmp_name) .
"</strong><br>";
204 $this->vars[
'message'] = $keep;
208 $view = & $Plugins[plugin_find_id(
"view")];
211 $highlights = array();
213 for ($index = 0; $index < count($this->HighlightInfoKeywords[
'position']); $index ++) {
214 $position = $this->HighlightInfoKeywords[
'position'][$index];
215 $length = $this->HighlightInfoKeywords[
'length'][$index];
217 $highlights[] =
new Highlight($position, $position + $length,
221 for ($index = 0; $index < count($this->HighlightInfoLicenses[
'position']); $index ++) {
222 $position = $this->HighlightInfoLicenses[
'position'][$index];
223 $length = $this->HighlightInfoLicenses[
'length'][$index];
224 $name = $this->HighlightInfoLicenses[
'name'][$index];
226 $highlights[] =
new Highlight($position, $position + $length,
227 Highlight::SIGNATURE, $name);
230 $inputFile = fopen($tmp_name,
"r");
232 $rtn = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
240 $NewPlugin->Install();
This is the Plugin class. All plugins should:
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
Class to run one-shot nomos.
const FILE_INPUT
Resource key for input file.
Output()
Generate the text for this plugin.
$HighlightInfoLicenses
Highlight info for licenses.
$HighlightInfoKeywords
Highlight info for keywords.
Install()
This function (when defined) is only called when the plugin is first installed. It should make sure a...
__construct()
base constructor. Most plugins will just use this
AnalyzeFile($FilePath)
Analyze one uploaded file.
RegisterMenus()
Change the type of output based on user-supplied parameters.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN