/
ua_output.cc
1922 lines (1707 loc) · 54.4 KB
/
ua_output.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
/*
* Kern Sibbald, September MM
*/
/**
* @file
* User Agent Output Commands
*
* I.e. messages, listing database, showing resources, ...
*/
#include "include/bareos.h"
#include "dird.h"
#include "dird/dird_globals.h"
#include "dird/job.h"
#include "dird/ua_cmdstruct.h"
#include "cats/sql_pooling.h"
#include "dird/next_vol.h"
#include "dird/ua_db.h"
#include "dird/ua_output.h"
#include "dird/ua_select.h"
#include "lib/edit.h"
namespace directordaemon {
/* Imported subroutines */
/* Imported variables */
extern struct s_jl joblevels[];
/* Imported functions */
/* Forward referenced functions */
static bool DoListCmd(UaContext *ua, const char *cmd, e_list_type llist);
static bool ListNextvol(UaContext *ua, int ndays);
static bool ParseListBackupsCmd(UaContext *ua, const char *range, e_list_type llist);
/**
* Some defaults.
*/
#define DEFAULT_LOG_LINES 5
#define DEFAULT_NR_DAYS 50
/**
* Turn auto display of console messages on/off
*/
bool AutodisplayCmd(UaContext *ua, const char *cmd)
{
static const char *kw[] = {
NT_("on"),
NT_("off"),
NULL
};
switch (FindArgKeyword(ua, kw)) {
case 0:
ua->auto_display_messages = true;
break;
case 1:
ua->auto_display_messages = false;
break;
default:
ua->ErrorMsg(_("ON or OFF keyword missing.\n"));
break;
}
return true;
}
/**
* Turn GUI mode on/off
*/
bool gui_cmd(UaContext *ua, const char *cmd)
{
static const char *kw[] = {
NT_("on"),
NT_("off"),
NULL
};
switch (FindArgKeyword(ua, kw)) {
case 0:
ua->jcr->gui = ua->gui = true;
break;
case 1:
ua->jcr->gui = ua->gui = false;
break;
default:
ua->ErrorMsg(_("ON or OFF keyword missing.\n"));
break;
}
return true;
}
/**
* Enter with Resources locked
*/
static void ShowDisabledJobs(UaContext *ua)
{
JobResource *job;
bool first = true;
foreach_res(job, R_JOB) {
if (!ua->AclAccessOk(Job_ACL, job->name(), false)) {
continue;
}
if (!job->enabled) {
if (first) {
first = false;
ua->SendMsg(_("Disabled Jobs:\n"));
}
ua->SendMsg(" %s\n", job->name());
}
}
if (first) {
ua->SendMsg(_("No disabled Jobs.\n"));
}
}
/**
* Enter with Resources locked
*/
static void ShowDisabledClients(UaContext *ua)
{
ClientResource *client;
bool first = true;
foreach_res(client, R_CLIENT) {
if (!ua->AclAccessOk(Client_ACL, client->name(), false)) {
continue;
}
if (!client->enabled) {
if (first) {
first = false;
ua->SendMsg(_("Disabled Clients:\n"));
}
ua->SendMsg(" %s\n", client->name());
}
}
if (first) {
ua->SendMsg(_("No disabled Clients.\n"));
}
}
/**
* Enter with Resources locked
*/
static void ShowDisabledSchedules(UaContext *ua)
{
ScheduleResource *sched;
bool first = true;
foreach_res(sched, R_SCHEDULE) {
if (!ua->AclAccessOk(Schedule_ACL, sched->name(), false)) {
continue;
}
if (!sched->enabled) {
if (first) {
first = false;
ua->SendMsg(_("Disabled Schedules:\n"));
}
ua->SendMsg(" %s\n", sched->name());
}
}
if (first) {
ua->SendMsg(_("No disabled Schedules.\n"));
}
}
struct showstruct {
const char *res_name;
int type;
};
static struct showstruct avail_resources[] = {
{ NT_("directors"), R_DIRECTOR },
{ NT_("clients"), R_CLIENT },
{ NT_("counters"), R_COUNTER },
{ NT_("devices"), R_DEVICE },
{ NT_("jobs"), R_JOB },
{ NT_("jobdefs"), R_JOBDEFS },
{ NT_("storages"), R_STORAGE },
{ NT_("catalogs"), R_CATALOG },
{ NT_("schedules"), R_SCHEDULE },
{ NT_("filesets"), R_FILESET },
{ NT_("pools"), R_POOL },
{ NT_("messages"), R_MSGS },
{ NT_("profiles"), R_PROFILE },
{ NT_("consoles"), R_CONSOLE },
{ NT_("all"), -1 },
{ NT_("help"), -2 },
{ NULL, 0 }
};
/**
* Displays Resources
*
* show all
* show <resource-keyword-name> - e.g. show directors
* show <resource-keyword-name>=<name> - e.g. show director=HeadMan
* show disabled - shows disabled jobs, clients and schedules
* show disabled jobs - shows disabled jobs
* show disabled clients - shows disabled clients
* show disabled schedules - shows disabled schedules
*/
bool show_cmd(UaContext *ua, const char *cmd)
{
int i, j, type, len;
int recurse;
char *res_name;
CommonResourceHeader *res = NULL;
bool verbose = false;
bool hide_sensitive_data;
Dmsg1(20, "show: %s\n", ua->UA_sock->msg);
/*
* When the console has no access to the configure cmd then any show cmd
* will suppress all sensitive information like for instance passwords.
*/
hide_sensitive_data = !ua->AclAccessOk(Command_ACL, "configure", false);
if (FindArg(ua, NT_("verbose")) > 0) {
verbose = true;
}
LockRes(my_config);
for (i = 1; i < ua->argc; i++) {
/*
* skip verbose keyword, already handled earlier.
*/
if (Bstrcasecmp(ua->argk[i], NT_("verbose"))) {
continue;
}
if (Bstrcasecmp(ua->argk[i], _("disabled"))) {
if (((i + 1) < ua->argc) &&
Bstrcasecmp(ua->argk[i + 1], NT_("jobs"))) {
ShowDisabledJobs(ua);
} else if (((i + 1) < ua->argc) &&
Bstrcasecmp(ua->argk[i + 1], NT_("clients"))) {
ShowDisabledClients(ua);
} else if (((i + 1) < ua->argc) &&
Bstrcasecmp(ua->argk[i + 1], NT_("schedules"))) {
ShowDisabledSchedules(ua);
} else {
ShowDisabledJobs(ua);
ShowDisabledClients(ua);
ShowDisabledSchedules(ua);
}
goto bail_out;
}
type = 0;
res_name = ua->argk[i];
if (!ua->argv[i]) { /* was a name given? */
/*
* No name, dump all resources of specified type
*/
recurse = 1;
len = strlen(res_name);
for (j = 0; avail_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(avail_resources[j].res_name), len)) {
type = avail_resources[j].type;
if (type > 0) {
res = my_config->res_head_[type - my_config->r_first_];
} else {
res = NULL;
}
break;
}
}
} else {
/*
* Dump a single resource with specified name
*/
recurse = 0;
len = strlen(res_name);
for (j = 0; avail_resources[j].res_name; j++) {
if (bstrncasecmp(res_name, _(avail_resources[j].res_name), len)) {
type = avail_resources[j].type;
res = (CommonResourceHeader *)ua->GetResWithName(type, ua->argv[i], true);
if (!res) {
type = -3;
}
break;
}
}
}
switch (type) {
case -1: /* all */
for (j = my_config->r_first_; j <= my_config->r_last_; j++) {
switch (j) {
case R_DEVICE:
/*
* Skip R_DEVICE since it is really not used or updated
*/
continue;
default:
if (my_config->res_head_[j - my_config->r_first_]) {
my_config->DumpResourceCb_(j, my_config->res_head_[j - my_config->r_first_],
bsendmsg, ua, hide_sensitive_data, verbose);
}
break;
}
}
break;
case -2:
ua->SendMsg(_("Keywords for the show command are:\n"));
for (j = 0; avail_resources[j].res_name; j++) {
ua->ErrorMsg("%s\n", _(avail_resources[j].res_name));
}
goto bail_out;
case -3:
ua->ErrorMsg(_("%s resource %s not found.\n"), res_name, ua->argv[i]);
goto bail_out;
case 0:
ua->ErrorMsg(_("Resource %s not found\n"), res_name);
goto bail_out;
default:
my_config->DumpResourceCb_(recurse ? type : -type, res, bsendmsg, ua, hide_sensitive_data, verbose);
break;
}
}
bail_out:
UnlockRes(my_config);
return true;
}
/**
* List contents of database
*
* list jobs - lists all jobs run
* list jobid=nnn - list job data for jobid
* list ujobid=uname - list job data for unique jobid
* list job=name - list all jobs with "name"
* list jobname=name - same as above
* list jobmedia jobid=nnn
* list jobmedia ujobid=uname
* list joblog jobid=<nn>
* list joblog job=name
* list log [ limit=<number> [ offset=<number> ] ]
* list basefiles jobid=nnn - list files saved for job nn
* list basefiles ujobid=uname
* list files jobid=<nn> - list files saved for job nn
* list files ujobid=name
* list pools - list pool records
* list jobtotals - list totals for all jobs
* list media - list media for given pool (deprecated)
* list volumes - list Volumes
* list clients - list clients
* list nextvol job=xx - list the next vol to be used by job
* list nextvolume job=xx - same as above.
* list copies jobid=x,y,z
*/
/* Do long or full listing */
bool LlistCmd(UaContext *ua, const char *cmd)
{
return DoListCmd(ua, cmd, VERT_LIST);
}
/* Do short or summary listing */
bool list_cmd(UaContext *ua, const char *cmd)
{
return DoListCmd(ua, cmd, HORZ_LIST);
}
static int GetJobidFromCmdline(UaContext *ua)
{
int i, jobid;
JobDbRecord jr;
ClientDbRecord cr;
memset(&jr, 0, sizeof(jr));
i = FindArgWithValue(ua, NT_("ujobid"));
if (i >= 0) {
bstrncpy(jr.Job, ua->argv[i], MAX_NAME_LENGTH);
jr.JobId = 0;
if (ua->db->GetJobRecord(ua->jcr, &jr)) {
jobid = jr.JobId;
} else {
return -1;
}
} else {
i = FindArgWithValue(ua, NT_("jobid"));
if (i >= 0) {
jr.JobId = str_to_int64(ua->argv[i]);
} else {
jobid = 0;
goto bail_out;
}
}
if (ua->db->GetJobRecord(ua->jcr, &jr)) {
jobid = jr.JobId;
} else {
Dmsg1(200, "GetJobidFromCmdline: Failed to get job record for JobId %d\n", jr.JobId);
jobid = -1;
goto bail_out;
}
if (!ua->AclAccessOk(Job_ACL, jr.Name, true)) {
Dmsg1(200, "GetJobidFromCmdline: No access to Job %s\n", jr.Name);
jobid = -1;
goto bail_out;
}
if (jr.ClientId) {
cr.ClientId = jr.ClientId;
if (ua->db->GetClientRecord(ua->jcr, &cr)) {
if (!ua->AclAccessOk(Client_ACL, cr.Name, true)) {
Dmsg1(200, "GetJobidFromCmdline: No access to Client %s\n", cr.Name);
jobid = -1;
goto bail_out;
}
} else {
Dmsg1(200, "GetJobidFromCmdline: Failed to get client record for ClientId %d\n", jr.ClientId);
jobid = -1;
goto bail_out;
}
}
bail_out:
return jobid;
}
/**
* Filter convenience functions that abstract the actions needed to
* perform a certain type of acl or resource filtering.
*/
static inline void SetAclFilter(UaContext *ua, int column, int acltype)
{
if (ua->AclHasRestrictions(acltype)) {
ua->send->AddAclFilterTuple(column, acltype);
}
}
static inline void SetResFilter(UaContext *ua, int column, int restype)
{
ua->send->AddResFilterTuple(column, restype);
}
static inline void SetEnabledFilter(UaContext *ua, int column, int restype)
{
ua->send->AddEnabledFilterTuple(column, restype);
}
static inline void SetDisabledFilter(UaContext *ua, int column, int restype)
{
ua->send->AddDisabledFilterTuple(column, restype);
}
static inline void SetHiddenColumnAclFilter(UaContext *ua, int column, int acltype)
{
ua->send->AddHiddenColumn(column);
if (ua->AclHasRestrictions(acltype)) {
ua->send->AddAclFilterTuple(column, acltype);
}
}
static inline void SetHiddenColumn(UaContext *ua, int column)
{
ua->send->AddHiddenColumn(column);
}
static void SetQueryRange(PoolMem &query_range, UaContext *ua, JobDbRecord *jr)
{
int i;
/*
* Ensure query range is an empty string instead of NULL
* to avoid any issues.
*/
if (query_range.c_str() == NULL) {
PmStrcpy(query_range, "");
}
/*
* See if this is a second call to SetQueryRange() if so and any acl
* filters have been set we setup a new query_range filter including a
* limit filter.
*/
if (query_range.strlen()) {
if (!ua->send->has_acl_filters()) {
return;
}
PmStrcpy(query_range, "");
}
/*
* Apply any limit
*/
i = FindArgWithValue(ua, NT_("limit"));
if (i >= 0) {
PoolMem temp(PM_MESSAGE);
jr->limit = atoi(ua->argv[i]);
ua->send->AddLimitFilterTuple(jr->limit);
temp.bsprintf(" LIMIT %d", jr->limit);
PmStrcat(query_range, temp.c_str());
/*
* offset is only valid, if limit is given
*/
i = FindArgWithValue(ua, NT_("offset"));
if (i >= 0) {
jr->offset = atoi(ua->argv[i]);
ua->send->AddOffsetFilterTuple(jr->offset);
temp.bsprintf(" OFFSET %d", atoi(ua->argv[i]));
PmStrcat(query_range, temp.c_str());
}
}
}
static bool DoListCmd(UaContext *ua, const char *cmd, e_list_type llist)
{
JobDbRecord jr;
PoolDbRecord pr;
utime_t now;
MediaDbRecord mr;
int days = 0,
hours = 0,
jobstatus = 0,
joblevel = 0;
bool count,
last,
current,
enabled,
disabled;
int i, d, h, jobid;
time_t schedtime = 0;
char *clientname = NULL;
char *volumename = NULL;
char *poolname = NULL;
const int secs_in_day = 86400;
const int secs_in_hour = 3600;
PoolMem query_range(PM_MESSAGE);
if (!OpenClientDb(ua, true)) {
return true;
}
memset(&jr, 0, sizeof(jr));
memset(&pr, 0, sizeof(pr));
memset(&mr, 0, sizeof(mr));
Dmsg1(20, "list: %s\n", cmd);
/*
* days or hours given?
*/
d = FindArgWithValue(ua, NT_("days"));
h = FindArgWithValue(ua, NT_("hours"));
now = (utime_t)time(NULL);
if (d > 0) {
days = str_to_int64(ua->argv[d]);
schedtime = now - secs_in_day * days; /* Days in the past */
}
if (h > 0) {
hours = str_to_int64(ua->argv[h]);
schedtime = now - secs_in_hour * hours; /* Hours in the past */
}
current = FindArg(ua, NT_("current")) >= 0;
enabled = FindArg(ua, NT_("enabled")) >= 0;
disabled = FindArg(ua, NT_("disabled")) >= 0;
count = FindArg(ua, NT_("count")) >= 0;
last = FindArg(ua, NT_("last")) >= 0;
PmStrcpy(query_range, "");
SetQueryRange(query_range, ua, &jr);
i = FindArgWithValue(ua, NT_("client"));
if (i >= 0) {
if (ua->GetClientResWithName(ua->argv[i])) {
clientname = ua->argv[i];
} else {
ua->ErrorMsg(_("invalid client parameter\n"));
return false;
}
}
/*
* jobstatus=X
*/
if (!GetUserJobStatusSelection(ua, &jobstatus)) {
ua->ErrorMsg(_("invalid jobstatus parameter\n"));
return false;
}
/*
* joblevel=X
*/
if (!GetUserJobLevelSelection(ua, &joblevel)) {
ua->ErrorMsg(_("invalid joblevel parameter\n"));
return false;
}
/*
* Select what to do based on the first argument.
*/
if ((Bstrcasecmp(ua->argk[1], NT_("jobs")) && (ua->argv[1] == NULL)) ||
((Bstrcasecmp(ua->argk[1], NT_("job")) || Bstrcasecmp(ua->argk[1], NT_("jobname"))) && ua->argv[1])) {
/*
* List jobs or List job=xxx
*/
i = FindArgWithValue(ua, NT_("jobname"));
if (i < 0) {
i = FindArgWithValue(ua, NT_("job"));
}
if (i >= 0) {
jr.JobId = 0;
bstrncpy(jr.Name, ua->argv[i], MAX_NAME_LENGTH);
}
i = FindArgWithValue(ua, NT_("volume"));
if (i >= 0) {
volumename = ua->argv[i];
}
i = FindArgWithValue(ua, NT_("pool"));
if (i >= 0) {
poolname = ua->argv[i];
}
switch (llist) {
case VERT_LIST:
if (!count) {
SetAclFilter(ua, 2, Job_ACL); /* JobName */
SetAclFilter(ua, 7, Client_ACL); /* ClientName */
SetAclFilter(ua, 21, Pool_ACL); /* PoolName */
SetAclFilter(ua, 24, FileSet_ACL); /* FilesetName */
}
if (current) {
SetResFilter(ua, 2, R_JOB); /* JobName */
SetResFilter(ua, 7, R_CLIENT); /* ClientName */
SetResFilter(ua, 21, R_POOL); /* PoolName */
SetResFilter(ua, 24, R_FILESET); /* FilesetName */
}
if (enabled) {
SetEnabledFilter(ua, 2, R_JOB); /* JobName */
}
if (disabled) {
SetDisabledFilter(ua, 2, R_JOB); /* JobName */
}
break;
default:
if (!count) {
SetAclFilter(ua, 1, Job_ACL); /* JobName */
SetAclFilter(ua, 2, Client_ACL); /* ClientName */
}
if (current) {
SetResFilter(ua, 1, R_JOB); /* JobName */
SetResFilter(ua, 2, R_CLIENT); /* ClientName */
}
if (enabled) {
SetEnabledFilter(ua, 1, R_JOB); /* JobName */
}
if (disabled) {
SetDisabledFilter(ua, 1, R_JOB); /* JobName */
}
break;
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListJobRecords(ua->jcr, &jr, query_range.c_str(), clientname,
jobstatus, joblevel, volumename, poolname, schedtime, last, count, ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("jobtotals"))) {
/*
* List JOBTOTALS
*/
ua->db->ListJobTotals(ua->jcr, &jr, ua->send);
} else if ((Bstrcasecmp(ua->argk[1], NT_("jobid")) ||
Bstrcasecmp(ua->argk[1], NT_("ujobid"))) && ua->argv[1]) {
/*
* List JOBID=nn
* List UJOBID=xxx
*/
if (ua->argv[1]) {
jobid = GetJobidFromCmdline(ua);
if (jobid > 0) {
jr.JobId = jobid;
i = FindArgWithValue(ua, NT_("pool"));
if (i >= 0) {
poolname = ua->argv[i];
}
SetAclFilter(ua, 1, Job_ACL); /* JobName */
SetAclFilter(ua, 2, Client_ACL); /* ClientName */
if (current) {
SetResFilter(ua, 1, R_JOB); /* JobName */
SetResFilter(ua, 2, R_CLIENT); /* ClientName */
}
if (enabled) {
SetEnabledFilter(ua, 1, R_JOB); /* JobName */
}
if (disabled) {
SetDisabledFilter(ua, 1, R_JOB); /* JobName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListJobRecords(ua->jcr, &jr, query_range.c_str(), clientname,
jobstatus, joblevel, volumename, poolname, schedtime, last, count, ua->send, llist);
}
}
} else if (Bstrcasecmp(ua->argk[1], NT_("basefiles"))) {
/*
* List BASEFILES
*/
jobid = GetJobidFromCmdline(ua);
if (jobid > 0) {
ua->db->ListBaseFilesForJob(ua->jcr, jobid, ua->send);
} else {
ua->ErrorMsg(_("jobid not found in db, access to job or client denied by ACL, or client not found in db\n"));
}
} else if (Bstrcasecmp(ua->argk[1], NT_("files"))) {
/*
* List FILES
*/
jobid = GetJobidFromCmdline(ua);
if (jobid > 0) {
ua->db->ListFilesForJob(ua->jcr, jobid, ua->send);
} else {
ua->ErrorMsg(_("jobid not found in db, access to job or client denied by ACL, or client not found in db\n"));
}
} else if (Bstrcasecmp(ua->argk[1], NT_("fileset"))) {
int filesetid = 0;
/*
* List FileSet
*/
i = FindArgWithValue(ua, NT_("filesetid"));
if (i > 0) {
filesetid = str_to_int64(ua->argv[i]);
}
jobid = GetJobidFromCmdline(ua);
if (jobid > 0 || filesetid > 0) {
jr.JobId = jobid;
jr.FileSetId = filesetid;
SetAclFilter(ua, 1, FileSet_ACL); /* FilesetName */
if (current) {
SetResFilter(ua, 1, R_FILESET); /* FilesetName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListFilesets(ua->jcr, &jr, query_range.c_str(), ua->send, llist);
} else {
ua->ErrorMsg(_("jobid not found in db, access to job or client denied by ACL, or client not found in db or missing filesetid\n"));
}
} else if (Bstrcasecmp(ua->argk[1], NT_("filesets"))) {
/*
* List FILESETs
*/
SetAclFilter(ua, 1, FileSet_ACL); /* FilesetName */
if (current) {
SetResFilter(ua, 1, R_FILESET); /* FilesetName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListFilesets(ua->jcr, &jr, query_range.c_str(), ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("jobmedia"))) {
/*
* List JOBMEDIA
*/
jobid = GetJobidFromCmdline(ua);
if (jobid >= 0) {
ua->db->ListJobmediaRecords(ua->jcr, jobid, ua->send, llist);
} else {
ua->ErrorMsg(_("jobid not found in db, access to job or client denied by ACL, or client not found in db\n"));
}
} else if (Bstrcasecmp(ua->argk[1], NT_("joblog"))) {
/*
* List JOBLOG
*/
jobid = GetJobidFromCmdline(ua);
if (jobid >= 0) {
ua->db->ListJoblogRecords(ua->jcr, jobid, query_range.c_str(), count, ua->send, llist);
} else {
ua->ErrorMsg(_("jobid not found in db, access to job or client denied by ACL, or client not found in db\n"));
}
} else if (Bstrcasecmp(ua->argk[1], NT_("log"))) {
bool reverse;
/*
* List last <limit> LOG entries
* default is DEFAULT_LOG_LINES entries
*/
reverse = FindArg(ua, NT_("reverse")) >= 0;
if (strlen(query_range.c_str()) == 0) {
Mmsg(query_range, " LIMIT %d", DEFAULT_LOG_LINES);
}
if (ua->api != API_MODE_JSON) {
SetHiddenColumn(ua, 0); /* LogId */
SetHiddenColumnAclFilter(ua, 1, Job_ACL); /* JobName */
SetHiddenColumnAclFilter(ua, 2, Client_ACL); /* ClientName */
SetHiddenColumn(ua, 3); /* LogTime */
} else {
SetAclFilter(ua, 1, Job_ACL); /* JobName */
SetAclFilter(ua, 2, Client_ACL); /* ClientName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListLogRecords(ua->jcr, clientname, query_range.c_str(), reverse, ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("pool")) ||
Bstrcasecmp(ua->argk[1], NT_("pools"))) {
PoolDbRecord pr;
/*
* List POOLS
*/
memset(&pr, 0, sizeof(pr));
if (ua->argv[1]) {
bstrncpy(pr.Name, ua->argv[1], sizeof(pr.Name));
}
SetAclFilter(ua, 1, Pool_ACL); /* PoolName */
if (current) {
SetResFilter(ua, 1, R_POOL); /* PoolName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListPoolRecords(ua->jcr, &pr, ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("clients"))) {
/*
* List CLIENTS
*/
SetAclFilter(ua, 1, Client_ACL); /* ClientName */
if (current) {
SetResFilter(ua, 1, R_CLIENT); /* ClientName */
}
if (enabled) {
SetEnabledFilter(ua, 1, R_CLIENT); /* ClientName */
}
if (disabled) {
SetDisabledFilter(ua, 1, R_CLIENT); /* ClientName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListClientRecords(ua->jcr, NULL, ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("client")) && ua->argv[1]) {
/*
* List CLIENT=xxx
*/
SetAclFilter(ua, 1, Client_ACL); /* ClientName */
if (current) {
SetResFilter(ua, 1, R_CLIENT); /* ClientName */
}
if (enabled) {
SetEnabledFilter(ua, 1, R_CLIENT); /* ClientName */
}
if (disabled) {
SetDisabledFilter(ua, 1, R_CLIENT); /* ClientName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListClientRecords(ua->jcr, ua->argv[1], ua->send, llist);
} else if (Bstrcasecmp(ua->argk[1], NT_("storages"))) {
/*
* List STORAGES
*/
SetAclFilter(ua, 1, Storage_ACL); /* StorageName */
if (current) {
SetResFilter(ua, 1, R_STORAGE); /* StorageName */
}
if (enabled) {
SetEnabledFilter(ua, 1, R_STORAGE); /* StorageName */
}
if (disabled) {
SetDisabledFilter(ua, 1, R_STORAGE); /* StorageName */
}
SetQueryRange(query_range, ua, &jr);
ua->db->ListSqlQuery(ua->jcr, "SELECT * FROM Storage", ua->send, llist, "storages");
} else if (Bstrcasecmp(ua->argk[1], NT_("media")) ||
Bstrcasecmp(ua->argk[1], NT_("volume")) ||
Bstrcasecmp(ua->argk[1], NT_("volumes"))) {
/*
* List MEDIA or VOLUMES
*/
jobid = GetJobidFromCmdline(ua);
if (jobid > 0) {
ua->db->ListVolumesOfJobid(ua->jcr, jobid, ua->send, llist);
} else if (jobid == 0) {
/*
* List a specific volume?
*/
if (ua->argv[1]) {
bstrncpy(mr.VolumeName, ua->argv[1], sizeof(mr.VolumeName));
ua->send->ObjectStart("volume");
ua->db->ListMediaRecords(ua->jcr, &mr, query_range.c_str(), count, ua->send, llist);
ua->send->ObjectEnd("volume");
} else {
/*
* If no job or jobid keyword found, then we list all media
* Is a specific pool wanted?
*/
i = FindArgWithValue(ua, NT_("pool"));
if (i >= 0) {
bstrncpy(pr.Name, ua->argv[i], sizeof(pr.Name));
if (!GetPoolDbr(ua, &pr)) {
ua->ErrorMsg(_("Pool %s doesn't exist.\n"), ua->argv[i]);
return true;
}
SetQueryRange(query_range, ua, &jr);
mr.PoolId = pr.PoolId;
ua->send->ArrayStart("volumes");
ua->db->ListMediaRecords(ua->jcr, &mr, query_range.c_str(), count, ua->send, llist);
ua->send->ArrayEnd("volumes");
return true;
} else {
int num_pools;
uint32_t *ids;
/*
* List all volumes, flat
*/
if (FindArg(ua, NT_("all")) > 0) {
ua->send->ArrayStart("volumes");
SetAclFilter(ua, 1, Pool_ACL); /* PoolName */
if (current) {
SetResFilter(ua, 1, R_POOL); /* PoolName */
}
ua->db->ListMediaRecords(ua->jcr, &mr, query_range.c_str(), count, ua->send, llist);
ua->send->ArrayEnd("volumes");
} else {
/*
* List Volumes in all pools
*/
if (!ua->db->GetPoolIds(ua->jcr, &num_pools, &ids)) {
ua->ErrorMsg(_("Error obtaining pool ids. ERR=%s\n"), ua->db->strerror());
return true;
}
if (num_pools <= 0) {
return true;
}
ua->send->ObjectStart("volumes");
for (i = 0; i < num_pools; i++) {
pr.PoolId = ids[i];
if (ua->db->GetPoolRecord(ua->jcr, &pr)) {
if (ua->AclAccessOk(Pool_ACL, pr.Name, false)) {
ua->send->Decoration( "Pool: %s\n", pr.Name );
ua->send->ArrayStart(pr.Name);
mr.PoolId = ids[i];
ua->db->ListMediaRecords(ua->jcr, &mr, query_range.c_str(), count, ua->send, llist);
ua->send->ArrayEnd(pr.Name);
}
}