50 $agent_list =
menu_find(
"Agents", $depth);
58 require_once(
"$MODDIR/lib/php/common-cli.php");
70 $usage = basename($argv[0]) .
" [options]
72 -h :: help, this message
74 -a :: list available agent tasks
75 -A string :: specify agent to schedule (default is everything from -a)
76 The string can be a comma-separated list of agent tasks.
77 -u :: list available upload ids
78 -U upload :: the upload identifier for scheduling agent tasks
79 The string can be a comma-separated list of upload ids.
80 Or, use 'ALL' to specify all upload ids.
81 -D upload :: the upload identifier for scheduling delete tasks
82 The string can either be 'ALL', a string (the upload_pk),
83 or an array of upload_pk's if multiple -D's were specified.
84 --username string :: user name
85 --password string :: password
86 --groupname string :: group name
87 -c string :: Specify the directory for the system configuration
90 $longopts = array(
"username:",
"password:",
"groupname:");
91 $options = getopt(
"c:haA:P:uU:D:v", $longopts);
93 if (empty($options)) {
97 if (array_key_exists(
"h", $options)) {
110 if (array_key_exists(
"username", $options)) {
111 $user = $options[
"username"];
114 if (array_key_exists(
"groupname", $options)) {
115 $group = $options[
"groupname"];
118 if (array_key_exists(
"password", $options)) {
119 $passwd = $options[
"password"];
123 $groupId = Auth::getGroupId();
129 if (array_key_exists(
"v", $options)) {
135 if (empty($agent_list)) {
136 echo
"ERROR! could not get list of agents\n";
137 echo
"Are Plugins configured?\n";
142 if (array_key_exists(
"a", $options)) {
143 if (empty($agent_list)) {
144 echo
"No agents configured\n";
146 echo
"The available agents are:\n";
147 $agent_count = count($agent_list);
148 for ($ac = 0;$ac < $agent_count;$ac++) {
149 $agent = ($agent_list[$ac]->URI);
150 if (!empty($agent)) {
158 $Skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
159 for ($ac=0; !empty($agent_list[$ac]->URI); $ac++) {
160 if (array_search($agent_list[$ac]->URI, $Skip) !==
false) {
161 unset($agent_list[$ac]);
166 $Skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
167 if (array_key_exists(
"A", $options)) {
168 $agent_count = count($agent_list);
169 for ($ac = 0;$ac < $agent_count;$ac++) {
171 foreach (explode(
',', $options[
"A"]) as $Val) {
172 if (!strcmp($Val, $agent_list[$ac]->URI)) {
177 $agent_list[$ac]->URI =
null;
183 if (array_key_exists(
"u", $options)) {
188 print
"# The following uploads are available (upload id: name)\n";
189 foreach ($FolderList as $Folder) {
190 $Label = $Folder[
'name'] .
" (" . $Folder[
'upload_desc'] .
')';
191 print $Folder[
'upload_pk'] .
": $Label\n";
197 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
199 if (array_key_exists(
"U", $options)) {
203 $upload_options = $options[
'U'];
204 $upload_pk_array = array();
205 if ($upload_options ==
'ALL') {
206 $SQL =
"SELECT upload_pk,upload_desc,upload_filename FROM upload ORDER BY upload_pk;";
209 while ($row = pg_fetch_assoc($result) && !empty($row[
'upload_pk'])) {
210 $upload_pk_array[] = $row[
'upload_pk'];
212 pg_free_result($result);
213 }
else if (is_array($upload_options)) {
214 $upload_pk_array = $upload_options;
216 $upload_pk_array[] = $upload_options;
220 $checked_list = array();
221 foreach ($upload_pk_array as $upload_pk) {
222 if (!$uploadDao->isEditable($upload_pk, $groupId)) {
223 print
"You have no permission to queue agents for upload $upload_pk in group $groupId\n";
226 $checked_list[] = $upload_pk;
228 $checked_list_str = implode(
",", $checked_list);
234 if (array_key_exists(
"D", $options)) {
238 $upload_options = $options[
'D'];
239 $upload_pk_array = array();
240 if ($upload_options ==
'ALL') {
241 $SQL =
"SELECT upload_pk,upload_desc,upload_filename FROM upload ORDER BY upload_pk;";
244 while ($row = pg_fetch_assoc($result) && !empty($row[
'upload_pk'])) {
245 $upload_pk_array[] = $row[
'upload_pk'];
247 pg_free_result($result);
248 }
else if (is_array($upload_options)) {
249 $upload_pk_array = $upload_options;
251 $upload_pk_array[] = $upload_options;
254 $checked_list = array();
255 foreach ($upload_pk_array as $upload_pk) {
256 if (!$uploadDao->isEditable($upload_pk, $groupId)) {
257 print
"You have no permission to delete upload " . $upload_pk .
"\n";
260 $checked_list[] = $upload_pk;
262 $checked_list_str = implode(
",", $checked_list);
Contains the constants and helpers for authentication of user.
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...
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath='', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
QueueUploadsOnDelagents($upload_pk_list)
Schedule delagent on upload ids.
QueueUploadsOnAgents($upload_pk_list, $agent_list, $Verbose)
Schedule agent tasks on upload ids.
#define PERM_WRITE
Read-Write permission.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN