FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
fo_folder.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 
22 
23 require_once("$MODDIR/lib/php/common-cli.php");
24 cli_Init();
25 
26 global $Plugins;
27 error_reporting(E_NOTICE & E_STRICT);
28 
29 $Usage = "Usage: " . basename($argv[0]) . " [options]
30  --username = user name
31  --password = password
32  --groupname = a group the user belongs to (default active group)
33  --folderId = id of folder (default root folder of user)
34  --linkFolder= create a link to this folder (id)
35  --linkUpload= create a link to this upload (id)\n";
36 
37 $opts = getopt("hc:", array("username:", "groupname:",
38  "folderId:",
39  "password:", "linkFolder:", "linkUpload:"));
40 if (array_key_exists('h', $opts)) {
41  print $Usage;
42  exit(0);
43 }
44 
45 $user = array_key_exists("username", $opts) ? $opts["username"] : '';
46 $group = array_key_exists("groupname", $opts) ? $opts["groupname"] : '';
47 $passwd = array_key_exists("password", $opts) ? $opts["password"] : null;
48 account_check($user, $passwd, $group);
49 
50 global $SysConf;
51 $userId = $_SESSION[Auth::USER_ID] = $SysConf['auth'][Auth::USER_ID];
52 $groupId = $_SESSION[Auth::GROUP_ID] = $SysConf['auth'][Auth::GROUP_ID];
53 
54 /* @var $folderDao FolderDao */
55 $folderDao = $GLOBALS['container']->get("dao.folder");
56 
57 if (array_key_exists("folderId", $opts)) {
58  $folderId = $opts["folderId"];
59 } else {
60  $folderId = $folderDao->getRootFolder($userId)->getId();
61 }
62 
63 $linkFolder = array_key_exists("linkFolder", $opts) ? $opts["linkFolder"] : null;
64 $linkUpload = array_key_exists("linkUpload", $opts) ? $opts["linkUpload"] : null;
65 if (!empty($linkFolder)) {
66  $folderDao->insertFolderContents($folderId,FolderDao::MODE_FOLDER,$linkFolder);
67 } elseif (!empty($linkUpload)) {
68  $folderDao->insertFolderContents($folderId,FolderDao::MODE_UPLOAD,$linkUpload);
69 } else {
70  $structure = $folderDao->getFolderStructure($folderId);
71  foreach ($structure as $folder) {
72  for ($i = 0; $i < $folder[FolderDao::DEPTH_KEY]; $i++) {
73  echo '-';
74  }
75  /* @var $theFolder Folder */
76  $theFolder = $folder[FolderDao::FOLDER_KEY];
77  echo $theFolder->getName().' (id='.$theFolder->getId().")\n";
78  }
79 
80 }
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