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