27 define(
"TITLE_AGENT_NOMOS_ONCE", _(
"One-Shot License Analysis"));
39 function __construct()
41 $this->Name =
"agent_nomos_once";
42 $this->Title = TITLE_AGENT_NOMOS_ONCE;
43 $this->Dependency = array();
51 parent::__construct();
63 exec(
"$SYSCONFDIR/mods-enabled/nomos/agent/nomos -S $FilePath", $out, $rtn);
64 $licensesFromAgent = explode(
'contains license(s)', $out[0]);
65 $licenses_and_Highlight = end($licensesFromAgent);
66 $licenses = explode(
'Highlighting Info at', $licenses_and_Highlight);
68 preg_match_all(
'/Keyword at (?P<position>\d+), length (?P<length>\d+),/',
69 $licenses[1], $this->HighlightInfoKeywords);
71 '/License #(?P<name>[^#]*)# at (?P<position>\d+), length (?P<length>\d+),/',
72 $licenses[1], $this->HighlightInfoLicenses);
74 return ($licenses[0]);
85 if (empty($PG_CONN)) {
101 if ($this->
State != PLUGIN_STATE_READY) {
105 if (empty($ShowHeader)) {
114 if ($ThisMod && empty($_POST[
'showheader']) &&
115 ($_SERVER[
'REQUEST_METHOD'] ==
"POST")) {
116 $Fin = fopen(
"php://input",
"r");
117 $Ftmp = tempnam(NULL,
"fosslic-alo-");
118 $Fout = fopen($Ftmp,
"w");
119 while (! feof($Fin)) {
121 fwrite($Fout, $Line);
131 if (filesize($Ftmp) > 0) {
132 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
133 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
134 $_FILES[
'licfile'][
'unlink_flag'] = 1;
145 "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.");
151 if (! empty($_SESSION[
'User'])) {
153 menu_insert(
"Main::Upload::One-Shot Analysis", $this->MenuOrder,
154 $this->Name, $this->MenuTarget);
162 $menuText =
"One-Shot License";
164 $tooltipText = _(
"One-shot License, real-time license analysis");
166 menu_insert(
"View::{$menuText}", $menuPosition + 1, $URI, $tooltipText);
168 menu_insert(
"View-Meta::{$menuText}", $menuPosition + 1, $URI,
182 if ($this->
State != PLUGIN_STATE_READY) {
187 if (array_key_exists(self::FILE_INPUT, $_FILES) &&
188 array_key_exists(
'tmp_name', $_FILES[self::FILE_INPUT])) {
189 $tmp_name = $_FILES[self::FILE_INPUT][
'tmp_name'];
196 if ($this->OutputType !=
'HTML' && file_exists($tmp_name)) {
201 if (file_exists($tmp_name)) {
202 $this->vars[
'content'] = $this->htmlAnalyzedContent($tmp_name,
203 $_FILES[self::FILE_INPUT][
'name']);
204 }
else if ($this->OutputType ==
'HTML') {
205 return $this->
render(
'oneshot-upload.html.twig', $this->vars);
207 if (array_key_exists(
'licfile', $_FILES) &&
208 array_key_exists(
'unlink_flag', $_FILES[
'licfile'])) {
211 unset($_FILES[self::FILE_INPUT]);
212 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
213 return $this->
render($this->getTemplateName(), $this->vars);
222 private function htmlAnalyzedContent($tmp_name, $filename)
225 "A one shot license analysis shows the following license(s) in file");
226 $keep =
"$text <em>$filename:</em> ";
227 $keep .=
"<strong>" . $this->
AnalyzeFile($tmp_name) .
"</strong><br>";
228 $this->vars[
'message'] = $keep;
232 $view = & $Plugins[plugin_find_id(
"view")];
235 $highlights = array();
237 for ($index = 0; $index < count($this->HighlightInfoKeywords[
'position']); $index ++) {
238 $position = $this->HighlightInfoKeywords[
'position'][$index];
239 $length = $this->HighlightInfoKeywords[
'length'][$index];
241 $highlights[] =
new Highlight($position, $position + $length,
245 for ($index = 0; $index < count($this->HighlightInfoLicenses[
'position']); $index ++) {
246 $position = $this->HighlightInfoLicenses[
'position'][$index];
247 $length = $this->HighlightInfoLicenses[
'length'][$index];
248 $name = $this->HighlightInfoLicenses[
'name'][$index];
250 $highlights[] =
new Highlight($position, $position + $length,
251 Highlight::SIGNATURE, $name);
254 $inputFile = fopen($tmp_name,
"r");
256 $rtn = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
264 $NewPlugin->Install();
$HighlightInfoLicenses
Highlight info for licenses.
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Output()
Generate the text for this plugin.
AnalyzeFile($FilePath)
Analyze one uploaded file.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
const FILE_INPUT
Resource key for input file.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
RegisterMenus()
Change the type of output based on user-supplied parameters.
This is the Plugin class. All plugins should:
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
$HighlightInfoKeywords
Highlight info for keywords.
Class to run one-shot nomos.
Install()
This function (when defined) is only called when the plugin is first installed. It should make sure a...
render($templateName, $vars=null)