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 $Sys =
"./copyright -c $SYSCONFDIR $tempFileName";
64 $inputFile = popen($Sys,
"r");
66 $colors[
'statement'] = 0;
70 $stuff[
'statement'] = array();
71 $stuff[
'email'] = array();
72 $stuff[
'url'] = array();
75 $highlights = array();
77 $typeToHighlightTypeMap = array(
78 'statement' => Highlight::COPYRIGHT,
79 'email' => Highlight::EMAIL,
80 'url' => Highlight::URL);
81 while (!feof($inputFile)) {
82 $Line = fgets($inputFile);
83 if ($Line[0] ==
'/') {
86 $count = strlen($Line);
89 if ((($count > 1) && (
"'" != $Line[$count - 2])) || ((1 == $count) && (
"'" != $Line[$count - 1]))) {
90 $Line = str_replace(
"\n",
' ', $Line);
97 preg_match_all(
"/\t\[(?P<start>\d+)\:(?P<end>\d+)\:(?P<type>[A-Za-z]+)\] \'(?P<content>.+)\'/", $realline, $match);
99 if (!empty($match[
'start'])) {
100 $stuff[$match[
'type'][0]][] = $match[
'content'][0];
102 $copyright_array[] = $match[
'content'][0];
104 $highlights[] =
new Highlight($match[
'start'][0], $match[
'end'][0], $typeToHighlightTypeMap[$match[
'type'][0]], -1, -1, $match[
'content'][0]);
112 if ($getHighlightInfo) {
113 return array($copyright_array, $highlights);
116 return $copyright_array;
119 $inputFile = fopen($tempFileName,
"r");
121 $V = $view->getView($inputFile, $ModBack, 0, NULL, $highlights);
124 if (!chdir($ui_dir)) {
125 return _(
"unable to change back to working directory $ui_dir\n");
140 if ($this->
State != PLUGIN_STATE_READY) {
144 if (empty($Hightlight)) {
148 if (empty($ShowHeader)) {
157 if ($ThisMod && empty($_POST[
'licfile'])) {
158 $Fin = fopen(
"php://input",
"r");
159 $Ftmp = tempnam(NULL,
"fosslic-alo-");
160 $Fout = fopen($Ftmp,
"w");
161 while (!feof($Fin)) {
163 fwrite($Fout, $Line);
166 if (filesize($Ftmp) > 0) {
167 $_FILES[
'licfile'][
'tmp_name'] = $Ftmp;
168 $_FILES[
'licfile'][
'size'] = filesize($Ftmp);
169 $_FILES[
'licfile'][
'unlink_flag'] = 1;
175 if ($ThisMod && file_exists(@$_FILES[
'licfile'][
'tmp_name']) && ($Highlight != 1) && ($ShowHeader != 1)) {
180 if (!empty($_SESSION[Auth::USER_NAME])) {
182 if (array_key_exists(Auth::USER_LEVEL, $_SESSION) &&
184 menu_insert(
"Main::Upload::One-Shot Copyright/ Email/ URL Analysis", $this->MenuOrder, $this->Name, $this->MenuTarget);
195 if ($this->
State != PLUGIN_STATE_READY) {
204 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'tmp_name', $_FILES[
'licfile'])) {
205 $tmp_name = $_FILES[
'licfile'][
'tmp_name'];
208 $this->vars[
'styles'] .=
"<link rel='stylesheet' href='css/highlights.css'>\n";
209 if ($this->OutputType!=
'HTML' && file_exists($tmp_name)) {
210 $copyright_res = $this->AnalyzeOne();
212 foreach ($copyright_res as $copyright) {
213 $cont =
"$copyright\n";
219 if ($this->OutputType==
'HTML') {
222 if ($_FILES[
'licfile'][
'size'] <= 1024 * 1024 * 10) {
223 $this->vars[
'content'] = $this->AnalyzeOne();
225 $this->vars[
'message'] = _(
'file is to large for one-shot copyright analyze');
231 if (array_key_exists(
'licfile', $_FILES) && array_key_exists(
'unlink_flag',$_FILES[
'licfile'])) {
243 $V = _(
"This analyzer allows you to upload a single file for copyright/email/url analysis.\n");
245 $V.=
"<li>" . _(
"The analysis is done in real-time.");
246 $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");
247 $V.=
"<li>" . _(
"Results are <b>not</b> stored. As soon as you get your results, your uploaded file is removed from the system.\n");
250 $V.=
"<form enctype='multipart/form-data' method='post'>\n";
251 $V.= _(
"Select the file to upload:");
252 $V.=
"<br><input name='licfile' size='60' type='file' /><br />\n";
253 $V.=
"<input type='hidden' name='showheader' value='1'>";
255 $text = _(
"Upload and scan");
256 $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.