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();
49 public function AnalyzeFile($FilePath, $getHighlightInfo =
false)
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 if ($getHighlightInfo) {
65 return array($licenses[0], $this->HighlightInfoKeywords, $this->HighlightInfoLicenses);
67 return ($licenses[0]);
94 if ($this->
State != PLUGIN_STATE_READY) {
98 if (empty($ShowHeader)) {
107 if ($ThisMod && empty($_POST[
'showheader']) &&
108 ($_SERVER[
'REQUEST_METHOD'] ==
"POST")) {
109 $Fin = fopen(
"php://input",
"r");
110 $Ftmp = tempnam(NULL,
"fosslic-alo-");
111 $Fout = fopen($Ftmp,
"w");
112 while (! feof($Fin)) {
114 fwrite($Fout, $Line);
124 if (filesize($Ftmp) > 0) {
125 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
126 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
127 $_FILES[
'licfile'][
'unlink_flag'] = 1;
138 "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.");
144 if (! empty($_SESSION[Auth::USER_NAME])) {
145 if (array_key_exists(Auth::USER_LEVEL, $_SESSION) &&
147 menu_insert(
"Main::Upload::One-Shot Nomos Analysis", $this->MenuOrder,
148 $this->Name, $this->MenuTarget);
161 if ($this->
State != PLUGIN_STATE_READY) {
166 if (array_key_exists(self::FILE_INPUT, $_FILES) &&
167 array_key_exists(
'tmp_name', $_FILES[self::FILE_INPUT])) {
175 if ($this->OutputType !=
'HTML' && file_exists($tmp_name)) {
180 if (file_exists($tmp_name)) {
181 $this->vars[
'content'] = $this->htmlAnalyzedContent($tmp_name,
182 $_FILES[self::FILE_INPUT][
'name']);
183 }
else if ($this->OutputType ==
'HTML') {
184 return $this->
render(
'oneshot-upload.html.twig', $this->vars);
186 if (array_key_exists(
'licfile', $_FILES) &&
187 array_key_exists(
'unlink_flag', $_FILES[
'licfile'])) {
190 unset($_FILES[self::FILE_INPUT]);
191 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
192 return $this->
render($this->getTemplateName(), $this->vars);
201 private function htmlAnalyzedContent($tmp_name, $filename)
204 "A one shot license analysis shows the following license(s) in file");
205 $keep =
"$text <em>$filename:</em> ";
206 $keep .=
"<strong>" . $this->
AnalyzeFile($tmp_name) .
"</strong><br>";
207 $this->vars[
'message'] = $keep;
211 $view = & $Plugins[plugin_find_id(
"view")];
214 $highlights = array();
216 for ($index = 0; $index < count($this->HighlightInfoKeywords[
'position']); $index ++) {
217 $position = $this->HighlightInfoKeywords[
'position'][$index];
218 $length = $this->HighlightInfoKeywords[
'length'][$index];
220 $highlights[] =
new Highlight($position, $position + $length,
224 for ($index = 0; $index < count($this->HighlightInfoLicenses[
'position']); $index ++) {
225 $position = $this->HighlightInfoLicenses[
'position'][$index];
226 $length = $this->HighlightInfoLicenses[
'length'][$index];
227 $name = $this->HighlightInfoLicenses[
'name'][$index];
229 $highlights[] =
new Highlight($position, $position + $length,
230 Highlight::SIGNATURE, $name);
233 $inputFile = fopen($tmp_name,
"r");
235 $rtn = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
243 $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.
AnalyzeFile($FilePath, $getHighlightInfo=false)
Analyze one uploaded file.
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
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