1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
|
<?php
/***********************************************************
Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************/
/*************************************************
Restrict usage: Every PHP file should have this
at the very beginning.
This prevents hacking attempts.
*************************************************/
global $GlobalReady;
if (!isset($GlobalReady)) { exit; }
/*************************************************************
Each plugin has a state to identify if it is invalid.
For example, if a plugin crashes then it should mark the state
as invalid.
*************************************************************/
define("PLUGIN_STATE_FAIL",-1); // mark it as a total failure
define("PLUGIN_STATE_INVALID",0);
define("PLUGIN_STATE_VALID",1); // used during install
define("PLUGIN_STATE_READY",2); // used during post-install
/*************************************************************
Each plugin has a state to identify the kind of access required.
Plugins should select the highest level of access.
*************************************************************/
define("PLUGIN_DB_NONE",0);
define("PLUGIN_DB_READ",1);
define("PLUGIN_DB_DOWNLOAD",2); /* file download permitted */
define("PLUGIN_DB_WRITE",3); /* DB writes permitted */
define("PLUGIN_DB_UPLOAD",4); /* file upload permitted */
define("PLUGIN_DB_ANALYZE",5); /* file analysis permitted */
define("PLUGIN_DB_DELETE",6); /* record deletion permitted */
define("PLUGIN_DB_DEBUG",7); /* see and run debug code */
define("PLUGIN_DB_USERADMIN",10); /* add/delete users */
error_reporting(E_NOTICE & E_STRICT);
/*************************************************************
This is the Plugin class. All plugins should:
1. Use this class or extend this class.
2. After defining the necessary functions and values, the plugin
must add the new element to the Plugins array.
For example:
$NewPlugin = new Plugin;
$NewPlugin->Name="Fred";
if ($NewPlugin->Initialize() != 0) { destroy $NewPlugin; }
*************************************************************/
class FO_Plugin
{
// All public fields can be empty, indicating that it does not apply.
var $State=PLUGIN_STATE_INVALID;
/*****
Name defines the official name of this plugin. Other plugins may
call this plugin based on this name.
*****/
var $Name="";
var $Version="1.0";
var $Title=""; // used for HTML title tags and window menu bars
/*****
Access level restrictions
*****/
var $DBaccess=PLUGIN_DB_NONE; /* what kind of access is needed? */
var $LoginFlag=1; /* Must you be logged in to access this plugin? 1=yes, 0=no */
/*****
Common for HTML output
*****/
var $NoMenu=0; /* 1 = Don't show the HTML menu at the top of page */
var $NoHeader=0; /* 1 = Don't show the HTML header at the top of page */
var $NoHTML=0; /* 1 = Don't add any HTML to the output */
/*****
This array lists plugin dependencies by name and initialization order.
These are used to call PostInitialize in the correct order.
PostInitialize will be called when all dependencies are ready.
InitOrder says "after all dependencies are ready, do higher value
items first." For example, this allows for menus to be initialized
before anything else. (You probably won't need to change InitOrder.)
*****/
var $PluginLevel=10; /* used for sorting plugins -- higher comes first after dependencies are met */
var $Dependency = array();
var $InitOrder=0;
/*****
Plugins may define a menu item.
The menu name defines where it belongs.
Each menu item belongs in a category (menu list) and could be in
subcategories (menu sublists). The MenuList identifies
the list (and sublists) where this item belongs. The menu heirarchy
is defined by a name and a "::" to denote a submenu item.
The MenuName defines the name for this item in the menu.
Finally, multiple plugins may place multiple items under the same menu.
The MenuOrder assigns a numeric ranking for items. All items
at the same level are sorted alphabetically by MenuName.
For example, to define an "About" menu item under the "Help" menu:
$MenuList = "Help::About";
$MenuOrder=0;
And a "delete" agent under the tool, administration menu would be:
$MenuList = "Tools::Administration::Delete";
$MenuOrder=0;
Since menus may link to results that belong in a specific window,
$MenuTarget can identify the window. If not defined, the UI will use
a default results window.
NOTES:
1. If the MenuList location does not exist, then it will be created.
2. If a plugin does not have a menulist item, then it will not appear
in any menus.
3. MenuList is case and SPACE sensitive. "Help :: About" defines
"Help " and " About". While "Help::About" defines "Help" and "About".
*****/
var $MenuList=NULL;
var $MenuOrder=0;
var $MenuTarget=NULL;
/*****
These next variables define required functionality.
If the functions exist, then they are called. However, plugins are
not required to define any of these.
*****/
/***********************************************************
Install(): This function (when defined) is only called when
the plugin is first installed. It should make sure all
requirements are available and create anything it needs to run.
It returns 0 on success, non-zero on failure.
A failed install is not inserted in the system.
NOTE: It may be called multiple times. It must check that
changes are needed BEFORE doing any changes.
Also, it must check for partial installs in case the user is
recovering from an installation failure.
The only dependency that can be assumed to work is "global $DB",
and even then, be sure to check if $DB is NULL before using it.
***********************************************************/
function Install()
{
return(0);
} // Install()
/***********************************************************
Remove(): This function (when defined) is only called once,
when the plugin is removed. It should uninstall and remove
all items that are only used by this plugin. There should be
no residues -- if the plugin is ever installed again, it should
act like a clean install. Thus, any DB, files, or state variables
specific to this plugin must be removed.
This function must always succeed.
***********************************************************/
function Remove()
{
return;
} // Remove()
/**
* base constructor. Most plugins will just use this
*
* Makes sure the plugin is in the correct state. If so, the plugin is
* inserted into the Plugins data structure.
*
* The constructor assumes that Install() was already run one time (possibly
* years ago and not during this object's creation).
*
* @return true on success, false on failure.
*
* On failure the plugin is not used by the system. NOTE: This function must
* NOT assume that other plugins are installed. See PostInitialize.
*
*/
public function __construct() {
global $Plugins;
if ($this->State != PLUGIN_STATE_INVALID) {
return(1); // don't re-run
}
if ($this->Name !== "") { // Name must be defined
$this->State=PLUGIN_STATE_VALID;
array_push($Plugins,$this);
}
return($this->State == PLUGIN_STATE_VALID);
}
/***********************************************************
Initialize(): dummy stub till all references are removed.
***********************************************************/
function Initialize()
{
return(TRUE);
} // Initialize()
/***********************************************************
PostInitialize(): This function is called before the plugin
is used and after all plugins have been initialized.
If there is any initialization step that is dependent on other
plugins, put it here.
Returns true on success, false on failure.
NOTE: Do not assume that the plugin exists! Actually check it!
***********************************************************/
function PostInitialize()
{
global $Plugins;
if ($this->State != PLUGIN_STATE_VALID) {
return(0);
} // don't run
if (empty($_SESSION['User']) && $this->LoginFlag) {
return(0);
}
// Make sure dependencies are met
foreach($this->Dependency as $key => $val) {
$id = plugin_find_id($val);
if ($id < 0) {
$this->Destroy();
return(0);
}
}
// Put your code here!
// If this fails, set $this->State to PLUGIN_STATE_INVALID.
// If it succeeds, then set $this->State to PLUGIN_STATE_READY.
// It worked, so mark this plugin as ready.
$this->State = PLUGIN_STATE_READY;
// Add this plugin to the menu
if ($this->MenuList !== "") {
menu_insert("Main::" . $this->MenuList,$this->MenuOrder,$this->Name,$this->MenuTarget);
}
return($this->State == PLUGIN_STATE_READY);
} // PostInitialize()
/***********************************************************
RegisterMenus(): While menus can be added to any time at or after
the PostInitialize phase, this is the standard location for
registering this item with menus.
NOTE 1: Menu registration may be plugin specific!
NOTE 2: This is intended for cross-plugin registration and not
for the main menu.
***********************************************************/
function RegisterMenus()
{
if ($this->State != PLUGIN_STATE_READY) { return(0); } // don't run
// Add your own menu items here.
// E.g., menu_insert("Menu_Name::Item");
}
/***********************************************************
Destroy(): This is a destructor called after the plugin
is no longer needed. It should assume that PostInitialize() was
already run one time (this session) and succeeded.
This function must always succeed.
***********************************************************/
function Destroy()
{
if ($this->State != PLUGIN_STATE_INVALID)
{
; // Put your cleanup here
}
$this->State=PLUGIN_STATE_INVALID;
return;
} // Destroy()
/*********************************************************************/
/*********************************************************************/
/*********************************************************************
The output functions generate "output" for use in a text CLI or web page.
For agents, the outputs generate status information.
*********************************************************************/
/*********************************************************************/
/*********************************************************************/
/* Possible values: Text, HTML, or XML. */
var $OutputType="Text";
var $OutputToStdout=0;
/***********************************************************
OutputOpen(): This function is called when user output is
requested. This function is responsible for assigning headers.
If $Type is "HTML" then generate an HTTP header.
If $Type is "XML" then begin an XML header.
If $Type is "Text" then generate a text header as needed.
The $ToStdout flag is "1" if output should go to stdout, and
0 if it should be returned as a string. (Strings may be parsed
and used by other plugins.)
***********************************************************/
function OutputOpen($Type,$ToStdout)
{
global $Plugins;
if ($this->State != PLUGIN_STATE_READY) { return(0); }
$this->OutputType=$Type;
$this->OutputToStdout=$ToStdout;
// Put your code here
switch($this->OutputType)
{
case "XML":
$V = "<xml>\n";
break;
case "HTML":
header('Content-type: text/html');
header("Pragma: no-cache"); /* for IE cache control */
header('Cache-Control: no-cache, must-revalidate, maxage=1, post-check=0, pre-check=0'); /* prevent HTTP/1.1 caching */
header('Expires: Expires: Thu, 19 Nov 1981 08:52:00 GMT'); /* mark it as expired (value from Apache default) */
if ($this->NoHTML) { return; }
$V = "";
if (($this->NoMenu == 0) && ($this->Name != "menus"))
{
$Menu = &$Plugins[plugin_find_id("menus")];
$Menu->OutputSet($Type,$ToStdout);
}
else { $Menu = NULL; }
/* DOCTYPE is required for IE to use styles! (else: css menu breaks) */
$V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "xhtml1-frameset.dtd">' . "\n";
// $V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
// $V .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Loose//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n";
// $V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "xhtml1-strict.dtd">' . "\n";
$V .= "<html>\n";
$V .= "<head>\n";
if ($this->NoHeader == 0)
{
/** Known bug: DOCTYPE "should" be in the HEADER
and the HEAD tags should come first.
Also, IE will ignore <style>...</style> tags that are NOT
in a <head>...</head> block.
**/
if (!empty($Title)) { $V .= "<title>" . htmlentities($Title) . "</title>\n"; }
$V .= "<link rel='stylesheet' href='fossology.css'>\n";
print $V; $V="";
if (!empty($Menu)) { print $Menu->OutputCSS(); }
$V .= "</head>\n";
$V .= "<body class='text'>\n";
print $V; $V="";
if (!empty($Menu)) { $Menu->Output($this->Title); }
}
break;
case "Text":
break;
default:
break;
}
if (!$this->OutputToStdout) { return($V); }
print $V;
return;
} // OutputOpen()
/***********************************************************
OutputClose(): This function is called when user output is done.
If $Type is "HTML" then display the HTML footer as needed.
If $Type is "XML" then end the XML.
If $Type is "Text" then generate a text footer as needed.
This uses $OutputType.
The $ToStdout flag is "1" if output should go to stdout, and
0 if it should be returned as a string. (Strings may be parsed
and used by other plugins.)
***********************************************************/
function OutputClose()
{
if ($this->State != PLUGIN_STATE_READY) { return(0); }
// Put your code here
$V = "";
switch($this->OutputType)
{
case "XML":
$V = "</xml>\n";
break;
case "HTML":
if ($this->NoHTML) { return; }
if (!$this->NoHeader)
{
$V = "</body>\n";
$V .= "</html>\n";
}
break;
case "Text":
break;
default:
break;
}
if (!$this->OutputToStdout) { return($V); }
print $V;
return;
} // OutputClose()
/***********************************************************
OutputSet(): Similar to OutputOpen, this sets the output type
for this object. However, this does NOT change any global
settings. This is called when this object is a dependency
for another object.
***********************************************************/
function OutputSet($Type,$ToStdout)
{
if ($this->State != PLUGIN_STATE_READY) { return(0); }
$this->OutputType=$Type;
$this->OutputToStdout=$ToStdout;
// Put your code here
$V= "";
switch($this->OutputType)
{
case "XML":
$V = "<xml>\n";
break;
case "HTML":
break;
case "Text":
break;
default:
break;
}
if (!$this->OutputToStdout) { return($V); }
print $V;
return;
} // OutputSet()
/***********************************************************
OutputUnSet(): Similar to OutputClose, this ends the output type
for this object. However, this does NOT change any global
settings. This is called when this object is a dependency
for another object.
***********************************************************/
function OutputUnSet()
{
if ($this->State != PLUGIN_STATE_READY) { return(0); }
// Put your code here
$V = "";
switch($this->OutputType)
{
case "XML":
$V = "</xml>\n";
break;
case "HTML":
break;
case "Text":
break;
default:
break;
}
if (!$this->OutputToStdout) { return($V); }
print $V;
return;
} // OutputUnSet()
/***********************************************************
Output(): This function is called when user output is
requested. This function is responsible for content.
(OutputOpen and Output are separated so one plugin
can call another plugin's Output.)
This uses $OutputType.
The $ToStdout flag is "1" if output should go to stdout, and
0 if it should be returned as a string. (Strings may be parsed
and used by other plugins.)
***********************************************************/
function Output()
{
if ($this->State != PLUGIN_STATE_READY) { return(0); }
// Put your code here
$V="";
switch($this->OutputType)
{
case "XML":
break;
case "HTML":
break;
case "Text":
break;
default:
break;
}
if (!$this->OutputToStdout) { return($V); }
print $V;
return;
} // Output()
/*********************************************************************/
/*********************************************************************/
/*********************************************************************
General actions.
These functions will likely be called by other plugins.
*********************************************************************/
/*********************************************************************/
/*********************************************************************/
/***********************************************************
Action(): This function is used to perform a specific action.
The $Command is a string containing the command.
Unlike ActionArg(), this does not separate the Command from the Target.
$Command and return value are plugin specific.
***********************************************************/
function Action($Command)
{
if ($this->State != PLUGIN_STATE_READY) { return(0); }
// Put your code here
return;
} // Action()
};
?>
|