FOSSology  4.4.0
Open Source License Compliance by Open Source Software
ReportImportAgentPlugin.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015-2017 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
11 {
12  private static $keys = array(
13  'addConcludedAsDecisions',
14  'addLicenseInfoFromInfoInFile',
15  'addLicenseInfoFromConcluded',
16  'addConcludedAsDecisionsOverwrite',
17  'addConcludedAsDecisionsTBD',
18  'addCopyrights',
19  'addNewLicensesAs',
20  'licenseMatch'
21  );
22 
23  public function __construct() {
24  $this->Name = "agent_reportImport";
25  $this->Title = _("Report Import");
26  $this->AgentName = "reportImport";
27 
28  parent::__construct();
29  }
30 
31  function preInstall()
32  {
33  // no AgentCheckBox
34  }
35 
36  public function setAdditionalJqCmdArgs($request)
37  {
38  $additionalJqCmdArgs = "";
39 
40  foreach(self::$keys as $key) {
41  if($request->get($key) !== NULL)
42  {
43  $additionalJqCmdArgs .= " --".$key."=".$request->get($key);
44  }
45  }
46 
47  return $additionalJqCmdArgs;
48  }
49 
50  public function addReport($report)
51  {
52  if ($report &&
53  is_array($report) &&
54  array_key_exists('error',$report) &&
55  $report['error'] == UPLOAD_ERR_OK)
56  {
57  if(!file_exists($report['tmp_name']))
58  {
59  throw new Exception('Uploaded tmpfile not found');
60  }
61 
62  global $SysConf;
63  $fileBase = $SysConf['FOSSOLOGY']['path']."/ReportImport/";
64  if (!is_dir($fileBase))
65  {
66  mkdir($fileBase,0755,true);
67  }
68  // TODO: validate filename
69  $targetFile = time().'_'.random_int(0, getrandmax()).'_'.$report['name'];
70  if (move_uploaded_file($report['tmp_name'], $fileBase.$targetFile))
71  {
72  return '--report='.$targetFile;
73  }
74  }elseif($report && is_string($report)){
75  return '--report='.$report;
76  }
77  return '';
78  }
79 }
80 
81 register_plugin(new ReportImportAgentPlugin());