FOSSology  4.4.0
Open Source License Compliance by Open Source Software
fo_copyright_list.php
Go to the documentation of this file.
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2013-2014 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
16 $Usage = "Usage: " . basename($argv[0]) . "
17  -u upload id :: required - upload id
18  -t uploadtree id :: required - uploadtree id
19  -c sysconfdir :: optional - Specify the directory for the system configuration
20  --type type :: optional - all/statement/url/email, default: all
21  --user username :: user name
22  --password password :: password
23  --container :: include container or not, 1: yes, 0: no (default)
24  -x copyright :: to match all that does not contain my copyright, (default): show all files
25  -X copyright :: to match my copyright, (default): show all files
26  -h help, this message
27 ";
28 
29 $upload = $item = "";
30 $typeCopyright = array("statement","email","url");
31 
32 $longopts = array("user:", "password:", "type:", "container:");
33 $options = getopt("c:u:t:hx:X:", $longopts);
34 if (($options === false) || empty($options) || ! is_array($options)) {
35  $text = _("Invalid option or missing argument.");
36  print "$text\n";
37  print $Usage;
38  return 1;
39 }
40 
41 $user = $passwd = "";
42 
44 
45 $cpLister = new CopyrightLister();
46 
47 foreach ($options as $option => $value) {
48  switch ($option) {
49  case 'c': // handled in fo_wrapper
50  break;
51  case 'u':
52  $upload = $value;
53  break;
54  case 't':
55  $item = $value;
56  break;
57  case 'h':
58  print $Usage;
59  return 1;
60  case 'user':
61  $user = $value;
62  break;
63  case 'password':
64  $passwd = $value;
65  break;
66  case 'type':
67  if (empty($value) || in_array($value, $typeCopyright)) {
68  $cpLister->setType($value);
69  } else {
70  print "Invalid argument '$value' for type.\n";
71  print $Usage;
72  return 1;
73  }
74  break;
75  case 'container':
76  $cpLister->setContainerInclusion($value);
77  break;
78  case 'x': // exclude my copyright
79  $cpLister->setExcludingCopyright($value);
80  break;
81  case 'X': // include my copyright
82  $cpLister->setIncludingCopyright($value);
83  break;
84  default:
85  print "unknown option $option\n";
86  print $Usage;
87  }
88 }
89 
91 if (is_numeric($item) && !is_numeric($upload)) {
92  $upload = GetUploadID($item);
93 }
94 
96 if (!is_numeric($upload)) {
97  print "Upload ID is empty or invalid.\n";
98  print $Usage;
99  return 1;
100 }
101 if (!empty($item) && !is_numeric($item)) {
102  print "Uploadtree ID is empty or invalid.\n";
103  print $Usage;
104  return 1;
105 }
106 
107 require_once("$MODDIR/lib/php/common-cli.php");
108 cli_Init();
109 account_check($user, $passwd); // check username/password
110 
111 $return_value = read_permission($upload, $user); // check if the user has the permission to read this upload
112 if (empty($return_value)) {
113  $text = _("The user '$user' has no permission to read the information of upload $upload\n");
114  echo $text;
115  return 1;
116 }
117 
119 $cpLister->getCopyrightList($item, $upload);
120 return 0;
read_permission($upload, $user)
Check if the user has the permission to read the copyright/license/etc information of this upload.
account_check(&$user, &$passwd, &$group="")
check if this account is correct
Definition: common-auth.php:75
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
Definition: common-cli.php:25
GetUploadID($uploadtreeid)
Get upload id through uploadtreeid.
Definition: common-ui.php:272