25 define(
"TITLE_AGENT_COPYRIGHT_ONCE", _(
"One-Shot Copyright/Email/URL Analysis"));
33 function __construct()
35 $this->Name =
"agent_copyright_once";
36 $this->Title = TITLE_AGENT_COPYRIGHT_ONCE;
37 $this->Version =
"1.0";
44 parent::__construct();
47 $this->uploadDao = $container->get(
'dao.upload');
48 $this->copyrightDao = $container->get(
'dao.copyright');
55 function AnalyzeOne() {
59 $copyright_array = array();
63 $view = & $Plugins[plugin_find_id(
"view") ];
64 $tempFileName = $_FILES[
'licfile'][
'tmp_name'];
66 $copyright_dir =
"$SYSCONFDIR/mods-enabled/copyright/agent/";
67 if(!chdir($copyright_dir)) {
68 $errmsg = _(
"unable to change working directory to $copyright_dir\n");
72 $Sys =
"./copyright -c $SYSCONFDIR $tempFileName";
74 $inputFile = popen($Sys,
"r");
76 $colors[
'statement'] = 0;
80 $stuff[
'statement'] = array();
81 $stuff[
'email'] = array();
82 $stuff[
'url'] = array();
85 $highlights = array();
87 $typeToHighlightTypeMap = array(
88 'statement' => Highlight::COPYRIGHT,
89 'email' => Highlight::EMAIL,
90 'url' => Highlight::URL);
91 while (!feof($inputFile)) {
92 $Line = fgets($inputFile);
93 if ($Line[0] ==
'/') {
continue;
95 $count = strlen($Line);
98 if ((($count > 1) && (
"'" != $Line[$count - 2])) || ((1 == $count) && (
"'" != $Line[$count - 1])))
100 $Line = str_replace(
"\n",
' ', $Line);
107 preg_match_all(
"/\t\[(?P<start>\d+)\:(?P<end>\d+)\:(?P<type>[A-Za-z]+)\] \'(?P<content>.+)\'/", $realline, $match);
109 if (!empty($match[
'start'])) {
110 $stuff[$match[
'type'][0]][] = $match[
'content'][0];
112 array_push($copyright_array, $match[
'content'][0]);
114 $highlights[] =
new Highlight($match[
'start'][0], $match[
'end'][0], $typeToHighlightTypeMap[$match[
'type'][0]], -1, -1, $match[
'content'][0]);
124 return $copyright_array;
127 $inputFile = fopen($tempFileName,
"r");
129 $V = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
132 if(!chdir($ui_dir)) {
133 $errmsg = _(
"unable to change back to working directory $ui_dir\n");
148 if ($this->
State != PLUGIN_STATE_READY) {
152 if (empty($Hightlight)) {
156 if (empty($ShowHeader)) {
166 if ($ThisMod && empty($_POST[
'licfile'])) {
167 $Fin = fopen(
"php://input",
"r");
168 $Ftmp = tempnam(NULL,
"fosslic-alo-");
169 $Fout = fopen($Ftmp,
"w");
170 while (!feof($Fin)) {
172 fwrite($Fout, $Line);
175 if (filesize($Ftmp) > 0) {
176 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
177 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
178 $_FILES[
'licfile'][
'unlink_flag'] = 1;
185 if ($ThisMod && file_exists(@$_FILES[
'licfile'][
'tmp_name']) && ($Highlight != 1) && ($ShowHeader != 1)) {
190 if (!empty($_SESSION[Auth::USER_NAME]))
195 menu_insert(
"Main::Upload::One-Shot Copyright/Email/URL", $this->MenuOrder, $this->Name, $this->MenuTarget);
197 $tooltipText = _(
"Copyright/Email/URL One-shot, real-time analysis");
198 $menuText =
"One-Shot Copyright/Email/URL";
201 menu_insert(
"View::{$menuText}", $menuPosition + 1, $this->Name, $tooltipText);
203 menu_insert(
"View-Meta::{$menuText}", $menuPosition + 1, $this->Name, $tooltipText);
213 if ($this->
State != PLUGIN_STATE_READY) {
222 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'tmp_name', $_FILES[
'licfile']))
224 $tmp_name = $_FILES[
'licfile'][
'tmp_name'];
227 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
228 if ($this->OutputType!=
'HTML' && file_exists($tmp_name))
230 $copyright_res = $this->AnalyzeOne();
232 foreach ($copyright_res as $copyright)
234 $cont =
"$copyright\n";
240 if ($this->OutputType==
'HTML') {
243 if ($_FILES[
'licfile'][
'size'] <= 1024 * 1024 * 10) {
244 $this->vars[
'content'] = $this->AnalyzeOne();
247 $this->vars[
'message'] = _(
'file is to large for one-shot copyright analyze');
253 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'unlink_flag',$_FILES[
'licfile'])) {
265 $V = _(
"This analyzer allows you to upload a single file for copyright/email/url analysis.\n");
267 $V.=
"<li>" . _(
"The analysis is done in real-time.");
268 $V.=
"<li>" . _(
"Files that contain files are <b>not</b> unpacked. If you upload a container like a gzip file, then only that binary file will be scanned.\n");
269 $V.=
"<li>" . _(
"Results are <b>not</b> stored. As soon as you get your results, your uploaded file is removed from the system.\n");
272 $V.=
"<form enctype='multipart/form-data' method='post'>\n";
273 $V.= _(
"Select the file to upload:");
274 $V.=
"<br><input name='licfile' size='60' type='file' /><br />\n";
275 $V.=
"<input type='hidden' name='showheader' value='1'>";
277 $text = _(
"Upload and scan");
278 $V.=
"<p><input type='submit' value='$text'>\n";
One-Shot plugin for Copyright/Email/URL Analysis.
RegisterMenus()
Change the type of output based on user-supplied parameters.
Output()
This function is called when user output is requested. This function is responsible for content...
htmlContent()
Form and help content for plugin.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
This is the Plugin class. All plugins should: