60 $agent_list =
menu_find(
"Agents", $depth);
68 require_once(
"$MODDIR/lib/php/common-cli.php");
80 $usage = basename($argv[0]) .
" [options] 82 -h :: help, this message 84 -a :: list available agent tasks 85 -A string :: specify agent to schedule (default is everything from -a) 86 The string can be a comma-separated list of agent tasks. 87 -u :: list available upload ids 88 -U upload :: the upload identifier for scheduling agent tasks 89 The string can be a comma-separated list of upload ids. 90 Or, use 'ALL' to specify all upload ids. 91 -D upload :: the upload identifier for scheduling delete tasks 92 The string can either be 'ALL', a string (the upload_pk), 93 or an array of upload_pk's if multiple -D's were specified. 94 --username string :: user name 95 --password string :: password 96 --groupname string :: group name 97 -c string :: Specify the directory for the system configuration 100 $longopts = array(
"username:",
"password:",
"groupname:");
101 $options = getopt(
"c:haA:P:uU:D:v", $longopts);
103 if (empty($options)) {
107 if (array_key_exists(
"h", $options)) {
120 if (array_key_exists(
"username", $options)) {
121 $user = $options[
"username"];
124 if (array_key_exists(
"groupname", $options)) {
125 $group = $options[
"groupname"];
128 if (array_key_exists(
"password", $options)) {
129 $passwd = $options[
"password"];
133 $groupId = Auth::getGroupId();
139 if (array_key_exists(
"v", $options)) {
145 if (empty($agent_list)) {
146 echo
"ERROR! could not get list of agents\n";
147 echo
"Are Plugins configured?\n";
152 if (array_key_exists(
"a", $options)) {
153 if (empty($agent_list)) {
154 echo
"No agents configured\n";
156 echo
"The available agents are:\n";
157 $agent_count = count($agent_list);
158 for ($ac = 0;$ac < $agent_count;$ac++) {
159 $agent = ($agent_list[$ac]->URI);
160 if (!empty($agent)) {
168 $Skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
169 for ($ac=0; !empty($agent_list[$ac]->URI); $ac++) {
170 if (array_search($agent_list[$ac]->URI, $Skip) !==
false) {
171 unset($agent_list[$ac]);
176 $Skip = array(
"agent_unpack",
"agent_adj2nest",
"wget_agent");
177 if (array_key_exists(
"A", $options)) {
178 $agent_count = count($agent_list);
179 for ($ac = 0;$ac < $agent_count;$ac++) {
181 foreach (explode(
',', $options[
"A"]) as $Val) {
182 if (!strcmp($Val, $agent_list[$ac]->URI)) {
187 $agent_list[$ac]->URI = null;
193 if (array_key_exists(
"u", $options)) {
198 print
"# The following uploads are available (upload id: name)\n";
199 foreach ($FolderList as $Folder) {
200 $Label = $Folder[
'name'] .
" (" . $Folder[
'upload_desc'] .
')';
201 print $Folder[
'upload_pk'] .
": $Label\n";
207 $uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
209 if (array_key_exists(
"U", $options)) {
213 $upload_options = $options[
'U'];
214 $upload_pk_array = array();
215 if ($upload_options ==
'ALL') {
216 $SQL =
"SELECT upload_pk,upload_desc,upload_filename FROM upload ORDER BY upload_pk;";
219 while ($row = pg_fetch_assoc($result) && !empty($row[
'upload_pk'])) {
220 $upload_pk_array[] = $row[
'upload_pk'];
222 pg_free_result($result);
223 }
else if (is_array($upload_options)) {
224 $upload_pk_array = $upload_options;
226 $upload_pk_array[] = $upload_options;
230 $checked_list = array();
231 foreach ($upload_pk_array as $upload_pk) {
232 if (!$uploadDao->isEditable($upload_pk, $groupId)) {
233 print
"You have no permission to queue agents for upload $upload_pk in group $groupId\n";
236 $checked_list[] = $upload_pk;
238 $checked_list_str = implode(
",", $checked_list);
244 if (array_key_exists(
"D", $options)) {
248 $upload_options = $options[
'D'];
249 $upload_pk_array = array();
250 if ($upload_options ==
'ALL') {
251 $SQL =
"SELECT upload_pk,upload_desc,upload_filename FROM upload ORDER BY upload_pk;";
254 while ($row = pg_fetch_assoc($result) && !empty($row[
'upload_pk'])) {
255 $upload_pk_array[] = $row[
'upload_pk'];
257 pg_free_result($result);
258 }
else if (is_array($upload_options)) {
259 $upload_pk_array = $upload_options;
261 $upload_pk_array[] = $upload_options;
264 $checked_list = array();
265 foreach ($upload_pk_array as $upload_pk) {
266 if (!$uploadDao->isEditable($upload_pk, $groupId)) {
267 print
"You have no permission to delete upload " . $upload_pk .
"\n";
270 $checked_list[] = $upload_pk;
272 $checked_list_str = implode(
",", $checked_list);
account_check(&$user, &$passwd, &$group="")
check if this account is correct
QueueUploadsOnAgents($upload_pk_list, $agent_list, $Verbose)
Schedule agent tasks on upload ids.
GetUserRootFolder()
Get the top-of-tree folder_pk for the current user. Fail if there is no user session.
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
FolderListUploadsRecurse($ParentFolder=-1, $FolderPath= '', $perm=Auth::PERM_READ)
Get uploads and folder info, starting from $ParentFolder.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
QueueUploadsOnDelagents($upload_pk_list)
Schedule delagent on upload ids.
#define PERM_WRITE
Read-Write permission.