FOSSology  4.4.0
Open Source License Compliance by Open Source Software
agent-keyword.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
11 {
13  private $keywordDesc = "Performs file scanning to find text fragments that could be relevant for given keywords. Note: More keywords can be included using the configuration file.";
14 
15  public function __construct()
16  {
17  $this->Name = "agent_keyword";
18  $this->Title = _("Keyword Analysis <img src=\"images/info_16.png\" data-toggle=\"tooltip\" title=\"".$this->keywordDesc."\" class=\"info-bullet\"/>");
19  $this->AgentName = "keyword";
20 
21  parent::__construct();
22  }
23 
28  function AgentHasResults($uploadId=0)
29  {
30  return CheckARS($uploadId, $this->AgentName, "keyword scanner", "keyword_ars");
31  }
32 
33 
38  public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[],
39  $arguments=null, $request=null, $unpackArgs=null)
40  {
41  if ($request != null && !is_array($request)) {
42  $unpackArgs = intval($request->get('scm', 0)) == 1 ? '-I' : '';
43  } else {
44  $unpackArgs = intval(@$_POST['scm']) == 1 ? '-I' : '';
45  }
46  if ($this->AgentHasResults($uploadId) == 1) {
47  return 0;
48  }
49 
50  $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId);
51  if ($jobQueueId != 0) {
52  return $jobQueueId;
53  }
54 
55  $args = $unpackArgs;
56  if (!empty($unpackArgs)) {
57  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_mimetype"),$uploadId,$args,$request);
58  } else {
59  return $this->doAgentAdd($jobId, $uploadId, $errorMsg, array("agent_adj2nest"), $uploadId, null, $request);
60  }
61  }
62 
69  protected function isAgentIncluded($dependencies, $agentName)
70  {
71  foreach ($dependencies as $dependency) {
72  if ($dependency == $agentName) {
73  return true;
74  }
75  if (is_array($dependency) && $agentName == $dependency['name']) {
76  return true;
77  }
78  }
79  return false;
80  }
81 }
82 
83 register_plugin(new KeywordAgentPlugin());
doAgentAdd($jobId, $uploadId, &$errorMsg, $dependencies, $jqargs="", $jq_cmd_args=null, $request=null)
AgentHasResults($uploadId=0)
isAgentIncluded($dependencies, $agentName)
AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies=[], $arguments=null, $request=null, $unpackArgs=null)
CheckARS($upload_pk, $AgentName, $AgentDesc, $AgentARSTableName)
Check the ARS table to see if an agent has successfully scanned an upload.
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
Definition: common-job.php:378