14 define(
"TITLE_AGENT_COPYRIGHT_ONCE", _(
"One-Shot Copyright/Email/URL Analysis"));
25 $this->Name =
"agent_copyright_once";
26 $this->Title = TITLE_AGENT_COPYRIGHT_ONCE;
27 $this->Version =
"1.0";
34 parent::__construct();
37 $this->uploadDao = $container->get(
'dao.upload');
38 $this->copyrightDao = $container->get(
'dao.copyright');
45 function AnalyzeOne($getHighlightInfo =
false, $tempFileName =
null)
50 $copyright_array = array();
54 $view = & $Plugins[plugin_find_id(
"view") ];
55 $tempFileName = $getHighlightInfo ? $tempFileName : $_FILES[
'licfile'][
'tmp_name'];
57 $copyright_dir =
"$SYSCONFDIR/mods-enabled/copyright/agent/";
58 if (!chdir($copyright_dir)) {
59 return _(
"unable to change working directory to $copyright_dir\n");
62 $escapedSysConfDir = escapeshellarg($SYSCONFDIR);
63 $escapedTempFile = escapeshellarg($tempFileName);
64 $Sys =
"./copyright -c $escapedSysConfDir $escapedTempFile";
66 $inputFile = popen($Sys,
"r");
68 $colors[
'statement'] = 0;
72 $stuff[
'statement'] = array();
73 $stuff[
'email'] = array();
74 $stuff[
'url'] = array();
77 $highlights = array();
79 $typeToHighlightTypeMap = array(
80 'statement' => Highlight::COPYRIGHT,
81 'email' => Highlight::EMAIL,
82 'url' => Highlight::URL);
83 while (!feof($inputFile)) {
84 $Line = fgets($inputFile);
85 if ($Line[0] ==
'/') {
88 $count = strlen($Line);
91 if ((($count > 1) && (
"'" != $Line[$count - 2])) || ((1 == $count) && (
"'" != $Line[$count - 1]))) {
92 $Line = str_replace(
"\n",
' ', $Line);
99 preg_match_all(
"/\t\[(?P<start>\d+)\:(?P<end>\d+)\:(?P<type>[A-Za-z]+)\] \'(?P<content>.+)\'/", $realline, $match);
101 if (!empty($match[
'start'])) {
102 $stuff[$match[
'type'][0]][] = $match[
'content'][0];
104 $copyright_array[] = $match[
'content'][0];
106 $highlights[] =
new Highlight($match[
'start'][0], $match[
'end'][0], $typeToHighlightTypeMap[$match[
'type'][0]], -1, -1, $match[
'content'][0]);
114 if ($getHighlightInfo) {
115 return array($copyright_array, $highlights);
118 return $copyright_array;
121 $inputFile = fopen($tempFileName,
"r");
123 $V = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
126 if (!chdir($ui_dir)) {
127 return _(
"unable to change back to working directory $ui_dir\n");
142 if ($this->
State != PLUGIN_STATE_READY) {
146 if (empty($Hightlight)) {
150 if (empty($ShowHeader)) {
159 if ($ThisMod && empty($_POST[
'licfile'])) {
160 $Fin = fopen(
"php://input",
"r");
161 $Ftmp = tempnam(NULL,
"fosslic-alo-");
162 $Fout = fopen($Ftmp,
"w");
163 while (!feof($Fin)) {
165 fwrite($Fout, $Line);
168 if (filesize($Ftmp) > 0) {
169 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
170 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
171 $_FILES[
'licfile'][
'unlink_flag'] = 1;
177 if ($ThisMod && file_exists(@$_FILES[
'licfile'][
'tmp_name']) && ($Highlight != 1) && ($ShowHeader != 1)) {
182 if (!empty($_SESSION[Auth::USER_NAME])) {
184 if (array_key_exists(Auth::USER_LEVEL, $_SESSION) &&
186 menu_insert(
"Main::Upload::One-Shot Copyright/ Email/ URL Analysis", $this->MenuOrder, $this->Name, $this->MenuTarget);
197 if ($this->
State != PLUGIN_STATE_READY) {
206 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'tmp_name', $_FILES[
'licfile'])) {
207 $tmp_name = $_FILES[
'licfile'][
'tmp_name'];
210 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
211 if ($this->OutputType!=
'HTML' && file_exists($tmp_name)) {
212 $copyright_res = $this->AnalyzeOne();
214 foreach ($copyright_res as $copyright) {
215 $cont =
"$copyright\n";
221 if ($this->OutputType==
'HTML') {
224 if ($_FILES[
'licfile'][
'size'] <= 1024 * 1024 * 10) {
225 $this->vars[
'content'] = $this->AnalyzeOne();
227 $this->vars[
'message'] = _(
'file is to large for one-shot copyright analyze');
233 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'unlink_flag',$_FILES[
'licfile'])) {
245 $V = _(
"This analyzer allows you to upload a single file for copyright/email/url analysis.\n");
247 $V.=
"<li>" . _(
"The analysis is done in real-time.");
248 $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");
249 $V.=
"<li>" . _(
"Results are <b>not</b> stored. As soon as you get your results, your uploaded file is removed from the system.\n");
252 $V.=
"<form enctype='multipart/form-data' method='post'>\n";
253 $V.= _(
"Select the file to upload:");
254 $V.=
"<br><input name='licfile' size='60' type='file' /><br />\n";
255 $V.=
"<input type='hidden' name='showheader' value='1'>";
257 $text = _(
"Upload and scan");
258 $V.=
"<p><input type='submit' value='$text'>\n";
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
One-Shot plugin for Copyright/Email/URL Analysis.
htmlContent()
Form and help content for plugin.
__construct()
base constructor. Most plugins will just use this
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....
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_NONE
Plugin requires no DB permission.