FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fo_copyright_list.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************
3  Copyright (C) 2013-2014 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
27 $Usage = "Usage: " . basename($argv[0]) . "
28  -u upload id :: required - upload id
29  -t uploadtree id :: required - uploadtree id
30  -c sysconfdir :: optional - Specify the directory for the system configuration
31  --type type :: optional - all/statement/url/email, default: all
32  --user username :: user name
33  --password password :: password
34  --container :: include container or not, 1: yes, 0: no (default)
35  -x copyright :: to match all that does not contain my copyright, (default): show all files
36  -X copyright :: to match my copyright, (default): show all files
37  -h help, this message
38 ";
39 
40 $upload = $item = "";
41 $typeCopyright = array("statement","email","url");
42 
43 $longopts = array("user:", "password:", "type:", "container:");
44 $options = getopt("c:u:t:hx:X:", $longopts);
45 if (($options === false) || empty($options) || ! is_array($options)) {
46  $text = _("Invalid option or missing argument.");
47  print "$text\n";
48  print $Usage;
49  return 1;
50 }
51 
52 $user = $passwd = "";
53 
55 
56 $cpLister = new CopyrightLister();
57 
58 foreach ($options as $option => $value) {
59  switch ($option) {
60  case 'c': // handled in fo_wrapper
61  break;
62  case 'u':
63  $upload = $value;
64  break;
65  case 't':
66  $item = $value;
67  break;
68  case 'h':
69  print $Usage;
70  return 1;
71  case 'user':
72  $user = $value;
73  break;
74  case 'password':
75  $passwd = $value;
76  break;
77  case 'type':
78  if (empty($value) || in_array($value, $typeCopyright)) {
79  $cpLister->setType($value);
80  } else {
81  print "Invalid argument '$value' for type.\n";
82  print $Usage;
83  return 1;
84  }
85  break;
86  case 'container':
87  $cpLister->setContainerInclusion($value);
88  break;
89  case 'x': // exclude my copyright
90  $cpLister->setExcludingCopyright($value);
91  break;
92  case 'X': // include my copyright
93  $cpLister->setIncludingCopyright($value);
94  break;
95  default:
96  print "unknown option $option\n";
97  print $Usage;
98  }
99 }
100 
102 if (is_numeric($item) && !is_numeric($upload)) {
103  $upload = GetUploadID($item);
104 }
105 
107 if (!is_numeric($upload)) {
108  print "Upload ID is empty or invalid.\n";
109  print $Usage;
110  return 1;
111 }
112 if (!empty($item) && !is_numeric($item)) {
113  print "Uploadtree ID is empty or invalid.\n";
114  print $Usage;
115  return 1;
116 }
117 
118 require_once("$MODDIR/lib/php/common-cli.php");
119 cli_Init();
120 account_check($user, $passwd); // check username/password
121 
122 $return_value = read_permission($upload, $user); // check if the user has the permission to read this upload
123 if (empty($return_value)) {
124  $text = _("The user '$user' has no permission to read the information of upload $upload\n");
125  echo $text;
126  return 1;
127 }
128 
130 $cpLister->getCopyrightList($item, $upload);
131 return 0;
account_check(&$user, &$passwd, &$group="")
check if this account is correct
Definition: common-auth.php:87
GetUploadID($uploadtreeid)
Get upload id through uploadtreeid.
Definition: common-ui.php:258
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
Definition: common-cli.php:36
read_permission($upload, $user)
Check if the user has the permission to read the copyright/license/etc information of this upload...