FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fossupload_status.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2015 Siemens AG
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 
24 
25 require_once("$MODDIR/lib/php/common-cli.php");
26 cli_Init();
27 
28 global $Plugins;
29 error_reporting(E_NOTICE & E_STRICT);
30 
31 $Usage = "Usage: " . basename($argv[0]) . " [options]
32  --help = display this help text
33  --username = user name
34  --password = password
35  --groupname = a group the user belongs to (default active group)
36  --uploadId = id of upload
37 ";
38 
39 $opts = getopt("c:", array("help", "username:", "groupname:", "uploadId:", "password:"));
40 
41 if (array_key_exists("help", $opts)) {
42  echo $Usage;
43  exit (1);
44 }
45 
46 if (!array_key_exists("uploadId", $opts)) {
47  echo "no uploadId supplied\n";
48  echo $Usage;
49  exit (1);
50 }
51 $uploadId = $opts["uploadId"];
52 
53 $user = array_key_exists("username", $opts) ? $opts["username"] : '';
54 $group = array_key_exists("groupname", $opts) ? $opts["groupname"] : '';
55 $passwd = array_key_exists("password", $opts) ? $opts["password"] : null;
56 account_check($user, $passwd, $group);
57 
58 global $SysConf;
59 $userId = $SysConf['auth']['UserId'];
60 $groupId = $SysConf['auth']['GroupId'];
61 
63 $jobDao = $GLOBALS['container']->get("dao.job");
64 $jobStatuses = $jobDao->getAllJobStatus($uploadId, $userId, $groupId);
65 $runningJobs = false;
66 foreach ($jobStatuses as $jobStatus) {
67  switch ($jobStatus) {
68  case JobStatus::FAILED:
69  print "status=ERROR\n";
70  exit(0);
71  case JobStatus::RUNNING;
72  $runningJobs = true;
73  break;
74  default:
75  break;
76  }
77 }
78 
79 if ($runningJobs) {
80  print "status=SCANNING\n";
81  exit(0);
82 }
83 
85 $dbManager = $GLOBALS['container']->get("db.manager");
86 $userPerm = 0;
87 $uploadBrowseProxy = new Fossology\Lib\Proxy\UploadBrowseProxy($groupId, $userPerm, $dbManager);
88 
90 $uploadDao = $GLOBALS['container']->get("dao.upload");
91 
92 if ($uploadDao->getUpload($uploadId) == null) {
93  $status = "NON_EXISTENT";
94 } else if (!$uploadDao->isAccessible($uploadId, $groupId)) {
95  $status = "INACCESSIBLE";
96 } else {
97  try {
98  switch($uploadBrowseProxy->getStatus($uploadId)) {
99  case UploadStatus::OPEN:
100  $status = "OPEN";
101  break;
102  case UploadStatus::IN_PROGRESS:
103  $status = "IN_PROGRESS";
104  break;
105  case UploadStatus::CLOSED:
106  $status = "CLOSED";
107  break;
108  case UploadStatus::REJECTED:
109  $status = "REJECTED";
110  break;
111  default:
112  $status = "ERROR: invalid status";
113  }
114  } catch(Exception $e) {
115  $status = "ERROR: ".$e->getMessage();
116  }
117 }
118 print "status=$status\n";
account_check(&$user, &$passwd, &$group="")
check if this account is correct
Definition: common-auth.php:87
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