17 require_once(
"$MODDIR/lib/php/common-cli.php");
20 $Usage =
"Usage: " . basename($argv[0]) .
"
21 -u upload id :: upload id
22 -t uploadtree id :: uploadtree id
23 -c sysconfdir :: Specify the directory for the system configuration
24 --type export type :: For License: license (default), For Copyright: copyright
25 --username username :: username
26 --password password :: password
27 --container :: include container or not, 1: yes, 0: no (default)
28 -x :: License from files which do not have unuseful license 'No_license_found' or no license
29 -y :: Copyrights from files which do not have license
30 Files without license refers to:
31 File had no license finding by agents and no license was added by users.
32 File had license findings by agents but were either removed or file was marked as irrelevant.
33 -X excluding :: Exclude files containing [free text] in the path
34 'mac/' should exclude all files in the mac directory.
35 'mac' and it should exclude all files in any directory containing the substring 'mac'
36 '/mac' and it should exclude all files in any directory that starts with 'mac'
42 $ignoreFilesWithoutLicense = 0;
43 $ignoreFilesWithLicense = 0;
46 $longopts = array(
"username:",
"password:",
"container:",
"type:");
47 $options = getopt(
"c:u:t:hxyX:", $longopts);
48 if (empty($options) || !is_array($options)) {
55 foreach ($options as $option => $value) {
78 $showContainer = $value;
81 $ignoreFilesWithoutLicense = 1;
84 $ignoreFilesWithLicense = 1;
90 print
"unknown option $option\n";
96 if (is_numeric($item) && !is_numeric($upload)) {
101 if (!is_numeric($upload) || (!empty($item) && !is_numeric($item))) {
102 print
"Upload ID or Uploadtree ID is not digital number\n";
110 if (empty($return_value)) {
111 $text = _(
"The user '$user' has no permission to read the information of upload $upload\n");
126 function GetLicenseList($uploadtree_pk, $upload_pk, $showContainer, $excluding, $ignore)
129 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
131 $uploadDao = $GLOBALS[
'container']->get(
"dao.upload");
133 $licenseDao = $GLOBALS[
'container']->get(
"dao.license");
135 if (empty($uploadtree_pk)) {
136 $uploadtreeRec = $dbManager->getSingleRow(
'SELECT uploadtree_pk FROM uploadtree WHERE parent IS NULL AND upload_fk=$1',
138 __METHOD__.
'.find.uploadtree.to.use.in.browse.link' );
139 $uploadtree_pk = $uploadtreeRec[
'uploadtree_pk'];
143 $AgentRec = AgentARSList(
"nomos_ars", $upload_pk, 1);
144 if ($AgentRec ===
false) {
145 echo _(
"No data available\n");
148 $agent_pk = $AgentRec[0][
"agent_fk"];
150 $uploadtreeTablename = getUploadtreeTableName($upload_pk);
152 $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadtree_pk, $uploadtreeTablename);
153 $licensesPerFileName = $licenseDao->getLicensesPerFileNameForAgentId(
154 $itemTreeBounds, array($agent_pk),
true, $excluding, $ignore);
156 foreach ($licensesPerFileName as $fileName => $licenseData) {
157 if ($licenseData ==
false) {
158 if ($showContainer) {
159 print($fileName.
"\n");
164 if (! array_key_exists(
'scanResults', $licenseData) || empty($licenseData[
'scanResults'])) {
168 $licenseNames = $licenseData[
'scanResults'];
169 if (($ignore && (empty($licenseNames) || in_array(
"No_license_found", $licenseNames) || in_array(
"Void", $licenseNames)))) {
173 print($fileName .
': '.implode($licenseNames,
', ').
"\n");
185 function GetCopyrightList($uploadtree_pk, $upload_pk, $exclude, $ignore)
188 $dbManager = $GLOBALS[
'container']->get(
'db.manager');
190 $uploadDao = $GLOBALS[
'container']->get(
"dao.upload");
192 $copyrightDao = $GLOBALS[
'container']->get(
"dao.copyright");
194 $treeDao = $GLOBALS[
'container']->get(
"dao.tree");
196 if (empty($uploadtree_pk)) {
198 $uploadtree_pk = $uploadDao->getUploadParent($upload_pk);
199 }
catch(Exception $e) {
205 $agentName =
"copyright";
206 $scanJobProxy =
new ScanJobProxy($GLOBALS[
'container']->
get(
'dao.agent'), $upload_pk);
207 $scanJobProxy->createAgentStatus([$agentName]);
208 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
209 $latestAgentId = $selectedScanners[$agentName];
210 $agentFilter =
' AND C.agent_fk='.$latestAgentId;
211 $uploadtreeTablename = getUploadtreeTableName($upload_pk);
212 $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadtree_pk,$uploadtreeTablename);
213 $extrawhere =
"UT.lft BETWEEN " . $itemTreeBounds->getLeft() .
" AND " .
214 $itemTreeBounds->getRight();
217 $copyrights = $copyrightDao->getScannerEntries($agentName, $uploadtreeTablename, $upload_pk,
null, $extrawhere . $agentFilter);
218 foreach ($copyrights as $copyright) {
220 $row[
"content"] = $copyright[
"content"];
221 $row[
"filePath"] = $treeDao->getFullPath($copyright[
"uploadtree_pk"], $uploadtreeTablename);
222 $lines[$row[
"filePath"]][] = $row;
224 $copyrights = $copyrightDao->getEditedEntries(
'copyright_decision', $uploadtreeTablename, $upload_pk, [], $extrawhere);
225 foreach ($copyrights as $copyright) {
227 $row[
"content"] = $copyright[
"textfinding"];
228 $row[
"filePath"] = $treeDao->getFullPath($copyright[
"uploadtree_pk"], $uploadtreeTablename);
229 $lines[$row[
"filePath"]][] = $row;
234 foreach (AgentRef::AGENT_LIST as $agentname => $value) {
235 $AgentRec = AgentARSList($agentname.
"_ars", $upload_pk, 1);
236 if (!empty($AgentRec)) {
237 $agentList[] = $AgentRec[0][
"agent_fk"];
240 removeCopyrightWithLicense($lines, $itemTreeBounds, $agentList, $exclude);
243 $reducedLines = array();
244 foreach ($lines as $line) {
245 foreach ($line as $copyright) {
246 $reducedLines[] = $copyright;
250 foreach ($reducedLines as $row) {
251 if (!empty($exclude) &&
false!==strpos(
"$row[filePath]", $exclude)) {
254 print($row[
'filePath'] .
": " . ($row[
'content']) .
"\n");
267 function removeCopyrightWithLicense(&$lines, $itemTreeBounds, $agentList, $exclude)
270 $clearingDao = $GLOBALS[
'container']->get(
"dao.clearing");
272 $clearingFilter = $GLOBALS[
'container']->get(
"businessrules.clearing_decision_filter");
274 $licenseDao = $GLOBALS[
'container']->get(
"dao.license");
276 $licensesPerFileName = array();
277 $allDecisions = $clearingDao->getFileClearingsFolder($itemTreeBounds, Auth::getGroupId());
278 $editedMappedLicenses = $clearingFilter->filterCurrentClearingDecisionsForCopyrightList($allDecisions);
279 $licensesPerFileName = $licenseDao->getLicensesPerFileNameForAgentId($itemTreeBounds, $agentList,
true, $exclude,
true, $editedMappedLicenses);
280 foreach ($licensesPerFileName as $fileName => $licenseNames) {
281 if ($licenseNames !==
false && count($licenseNames) > 0) {
282 if (array_key_exists(
'concludedResults', $licenseNames)) {
283 $consolidatedConclusions = array();
284 foreach ($licenseNames[
'concludedResults'] as $conclusion) {
285 $consolidatedConclusions = array_merge($consolidatedConclusions, $conclusion);
287 $conclusions = array_unique($consolidatedConclusions);
288 if (in_array(
"Void", $conclusions)) {
293 foreach (array_keys($lines) as $file) {
294 if (strpos($file, $fileName) !==
false) {
295 unset($lines[$file]);
300 if ((! empty($licenseNames[
'scanResults'])) && ! (in_array(
"No_license_found", $licenseNames[
'scanResults']) || in_array(
"Void", $licenseNames[
'scanResults']))) {
301 foreach (array_keys($lines) as $file) {
302 if (strpos($file, $fileName) !==
false) {
303 unset($lines[$file]);
313 if ($type==
"license") {
314 GetLicenseList($item, $upload, $showContainer, $excluding, $ignoreFilesWithoutLicense);
316 GetCopyrightList($item, $upload, $excluding, $ignoreFilesWithLicense);
Contains the constants and helpers for authentication of user.
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
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
GetUploadID($uploadtreeid)
Get upload id through uploadtreeid.