FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
maintagent.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
4  Copyright (C) 2019 Siemens AG
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 ***********************************************************/
19 
20 define("TITLE_MAINTAGENT", _("FOSSology Maintenance"));
21 
23 
28 class maintagent extends FO_Plugin {
29 
30  public function __construct()
31  {
32  $this->Name = "maintagent";
33  $this->Title = TITLE_MAINTAGENT;
34  $this->MenuList = "Admin::Maintenance";
35  $this->DBaccess = PLUGIN_DB_ADMIN;
36  parent::__construct();
37  }
38 
43  function QueueJob()
44  {
45  global $SysConf;
46 
47  /* Find all the maintagent options specified by the user.
48  * They look like _REQUEST["a"] = "a", _REQUEST["b"]="b", ...
49  */
50  $options = "-";
51  foreach ($_REQUEST as $key => $value) {
52  if ($key == $value) {
53  $options .= $value;
54  }
55  }
56 
57  /* Create the maintenance job */
58  $user_pk = Auth::getUserId();
59  $groupId = Auth::getGroupId();
60 
61  $job_pk = JobAddJob($user_pk, $groupId, "Maintenance");
62  if (empty($job_pk) || ($job_pk < 0)) { return _("Failed to insert job record");
63  }
64 
65  $jq_pk = JobQueueAdd($job_pk, "maintagent", NULL, NULL, NULL, NULL, $options);
66  if (empty($jq_pk)) { return _("Failed to insert task 'Maintenance' into job queue");
67  }
68 
69  /* Tell the scheduler to check the queue. */
70  $success = fo_communicate_with_scheduler("database", $output, $error_msg);
71  if (!$success) { return($error_msg . "\n" . $output);
72  }
73 
74  return _("The maintenance job has been queued");
75  }
76 
77 
82  function DisplayForm()
83  {
84  /* Array of maintagent options and description */
85  $Options = array("a"=>_("Run all non slow maintenance operations."),
86  "A"=>_("Run all maintenance operations."),
87  "F"=>_("Validate folder contents."),
88  // "g"=>_("Remove orphaned gold files."),
89  "E"=>_("Remove orphaned rows from database."),
90  "L"=>_("Remove orphaned log files from file system."),
91  "N"=>_("Normalize priority "),
92  // "p"=>_("Verify file permissions (report only)."),
93  // "P"=>_("Verify and fix file permissions."),
94  "R"=>_("Remove uploads with no pfiles."),
95  "T"=>_("Remove orphaned temp tables."),
96  "D"=>_("Vacuum Analyze the database."),
97  // "U"=>_("Process expired uploads (slow)."),
98  // "Z"=>_("Remove orphaned files from the repository (slow)."),
99  "I"=>_("Reindexing of database (This activity may take 5-10 mins. Execute only when system is not in use)."),
100  "v"=>_("verbose (turns on debugging output)")
101  );
102  $V = "";
103 
104  $V.= "<form method='post'>\n"; // no url = this url
105  $V.= "<ol>\n";
106 
107  foreach ($Options as $option=>$description)
108  {
109  $V.= "<li>";
110  $V.= "<input type='checkbox' name='$option' value='$option' > $description <p>\n";
111  }
112 
113  $V.= "</ol>\n";
114  $text = _("Queue the maintenance agent");
115  $V.= "<input type='submit' value='$text'>\n";
116 
117  $V.= "<p>";
118  $V.= _("More information about these operations can be found ");
119  $text = _("here.");
120  $V.= "<a href=http://www.fossology.org/projects/fossology/wiki/Maintagent> $text </a>";
121 
122  $V.= "<input type=hidden name=queue value=true>";
123 
124  $V.= "</form>\n";
125  return $V;
126  }
127 
128 
133  public function Output()
134  {
135  $V = "";
136  /* If this is a POST, then process the request. */
137  $queue = GetParm('queue', PARM_STRING);
138  if (!empty($queue))
139  {
140  $Msg = $this->QueueJob();
141  $V .= "<font style='background-color:gold'>" . $Msg . "</font>";
142  }
143  $V .= $this->DisplayForm();
144  return $V;
145  }
146 }
147 
148 $NewPlugin = new maintagent;
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
Definition: libfossology.h:51
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
Definition: common-job.php:159
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Definition: common-parm.php:57
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
Queue the maintenance agent with the requested parameters.
Definition: maintagent.php:28
const PARM_STRING
Definition: common-parm.php:29
This is the Plugin class. All plugins should:
Definition: FO_Plugin.php:67
DisplayForm()
Display the input form.
Definition: maintagent.php:82
QueueJob()
Queue the job.
Definition: maintagent.php:43
Output()
This function is called when user output is requested. This function is responsible for content...
Definition: maintagent.php:133