Skip to content

Commit

Permalink
Merge pull request #274 from joergsteffens/dev/joergs/master/python
Browse files Browse the repository at this point in the history
python-bareos and dird commands improvments
  • Loading branch information
arogge committed Sep 24, 2019
2 parents 0c5489f + 9b27c77 commit 1c66663
Show file tree
Hide file tree
Showing 52 changed files with 1,358 additions and 109 deletions.
53 changes: 44 additions & 9 deletions core/src/cats/dml/0077_list_volumes_select_long_0
@@ -1,11 +1,46 @@
SELECT MediaId,VolumeName,Slot,PoolId,
MediaType,FirstWritten,LastWritten,LabelDate,VolJobs,
VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites,
VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention,
VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger,
EndFile,EndBlock,LabelType,StorageId,DeviceId,
LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId,
Comment,Name AS Storage
#
# List all volumes.
# Pool in column [4] is important for ACL checking.
#
SELECT Media.MediaId,
Media.VolumeName,
Media.Slot,
Media.PoolId,
(SELECT Name FROM Pool WHERE Pool.PoolId=Media.PoolId) AS Pool,
Media.MediaType,
Media.FirstWritten,
Media.LastWritten,
Media.LabelDate,
Media.VolJobs,
Media.VolFiles,
Media.VolBlocks,
Media.VolMounts,
Media.VolBytes,
Media.VolErrors,
Media.VolWrites,
Media.VolCapacityBytes,
Media.VolStatus,
Media.Enabled,
Media.Recycle,
Media.VolRetention,
Media.VolUseDuration,
Media.MaxVolJobs,
Media.MaxVolFiles,
Media.MaxVolBytes,
Media.InChanger,
Media.EndFile,
Media.EndBlock,
Media.LabelType,
Media.StorageId,
Media.DeviceId,
Media.LocationId,
Media.RecycleCount,
Media.InitialWrite,
Media.ScratchPoolId,
(SELECT Name FROM Pool WHERE Pool.PoolId=Media.ScratchPoolId) AS ScratchPool,
Media.RecyclePoolId,
(SELECT Name FROM Pool WHERE Pool.PoolId=Media.RecyclePoolId) AS RecyclePool,
Media.Comment,
Storage.Name AS Storage
FROM Media
LEFT JOIN Storage USING(StorageId)

48 changes: 40 additions & 8 deletions core/src/cats/mysql_queries.inc
Expand Up @@ -964,14 +964,46 @@ const char *BareosDbMysql::query_definitions[] = {
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"SELECT Media.MediaId, "
"Media.VolumeName, "
"Media.Slot, "
"Media.PoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.PoolId) AS Pool, "
"Media.MediaType, "
"Media.FirstWritten, "
"Media.LastWritten, "
"Media.LabelDate, "
"Media.VolJobs, "
"Media.VolFiles, "
"Media.VolBlocks, "
"Media.VolMounts, "
"Media.VolBytes, "
"Media.VolErrors, "
"Media.VolWrites, "
"Media.VolCapacityBytes, "
"Media.VolStatus, "
"Media.Enabled, "
"Media.Recycle, "
"Media.VolRetention, "
"Media.VolUseDuration, "
"Media.MaxVolJobs, "
"Media.MaxVolFiles, "
"Media.MaxVolBytes, "
"Media.InChanger, "
"Media.EndFile, "
"Media.EndBlock, "
"Media.LabelType, "
"Media.StorageId, "
"Media.DeviceId, "
"Media.LocationId, "
"Media.RecycleCount, "
"Media.InitialWrite, "
"Media.ScratchPoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.ScratchPoolId) AS ScratchPool, "
"Media.RecyclePoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.RecyclePoolId) AS RecyclePool, "
"Media.Comment, "
"Storage.Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,
Expand Down
48 changes: 40 additions & 8 deletions core/src/cats/postgresql_queries.inc
Expand Up @@ -943,14 +943,46 @@ const char *BareosDbPostgresql::query_definitions[] = {
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"SELECT Media.MediaId, "
"Media.VolumeName, "
"Media.Slot, "
"Media.PoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.PoolId) AS Pool, "
"Media.MediaType, "
"Media.FirstWritten, "
"Media.LastWritten, "
"Media.LabelDate, "
"Media.VolJobs, "
"Media.VolFiles, "
"Media.VolBlocks, "
"Media.VolMounts, "
"Media.VolBytes, "
"Media.VolErrors, "
"Media.VolWrites, "
"Media.VolCapacityBytes, "
"Media.VolStatus, "
"Media.Enabled, "
"Media.Recycle, "
"Media.VolRetention, "
"Media.VolUseDuration, "
"Media.MaxVolJobs, "
"Media.MaxVolFiles, "
"Media.MaxVolBytes, "
"Media.InChanger, "
"Media.EndFile, "
"Media.EndBlock, "
"Media.LabelType, "
"Media.StorageId, "
"Media.DeviceId, "
"Media.LocationId, "
"Media.RecycleCount, "
"Media.InitialWrite, "
"Media.ScratchPoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.ScratchPoolId) AS ScratchPool, "
"Media.RecyclePoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.RecyclePoolId) AS RecyclePool, "
"Media.Comment, "
"Storage.Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,
Expand Down
48 changes: 40 additions & 8 deletions core/src/cats/sqlite_queries.inc
Expand Up @@ -949,14 +949,46 @@ const char *BareosDbSqlite::query_definitions[] = {
,

/* 0077_list_volumes_select_long_0 */
"SELECT MediaId,VolumeName,Slot,PoolId, "
"MediaType,FirstWritten,LastWritten,LabelDate,VolJobs, "
"VolFiles,VolBlocks,VolMounts,VolBytes,VolErrors,VolWrites, "
"VolCapacityBytes,VolStatus,Enabled,Recycle,VolRetention, "
"VolUseDuration,MaxVolJobs,MaxVolFiles,MaxVolBytes,InChanger, "
"EndFile,EndBlock,LabelType,StorageId,DeviceId, "
"LocationId,RecycleCount,InitialWrite,ScratchPoolId,RecyclePoolId, "
"Comment,Name AS Storage "
"SELECT Media.MediaId, "
"Media.VolumeName, "
"Media.Slot, "
"Media.PoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.PoolId) AS Pool, "
"Media.MediaType, "
"Media.FirstWritten, "
"Media.LastWritten, "
"Media.LabelDate, "
"Media.VolJobs, "
"Media.VolFiles, "
"Media.VolBlocks, "
"Media.VolMounts, "
"Media.VolBytes, "
"Media.VolErrors, "
"Media.VolWrites, "
"Media.VolCapacityBytes, "
"Media.VolStatus, "
"Media.Enabled, "
"Media.Recycle, "
"Media.VolRetention, "
"Media.VolUseDuration, "
"Media.MaxVolJobs, "
"Media.MaxVolFiles, "
"Media.MaxVolBytes, "
"Media.InChanger, "
"Media.EndFile, "
"Media.EndBlock, "
"Media.LabelType, "
"Media.StorageId, "
"Media.DeviceId, "
"Media.LocationId, "
"Media.RecycleCount, "
"Media.InitialWrite, "
"Media.ScratchPoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.ScratchPoolId) AS ScratchPool, "
"Media.RecyclePoolId, "
"(SELECT Name FROM Pool WHERE Pool.PoolId=Media.RecyclePoolId) AS RecyclePool, "
"Media.Comment, "
"Storage.Name AS Storage "
"FROM Media "
"LEFT JOIN Storage USING(StorageId) "
,
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ua_cmds.cc
Expand Up @@ -2702,8 +2702,8 @@ static bool WhoAmICmd(UaContext* ua, const char* cmd)
std::string message;
message = ua->user_acl ? ua->user_acl->corresponding_resource->resource_name_
: "root";
message += '\n';
return ua->UA_sock->fsend(message.c_str());
ua->send->ObjectKeyValue("whoami", message.c_str(), "%s\n");
return true;
}

static bool help_cmd(UaContext* ua, const char* cmd)
Expand Down
74 changes: 55 additions & 19 deletions core/src/dird/ua_output.cc
Expand Up @@ -180,6 +180,30 @@ static void ShowDisabledSchedules(UaContext* ua)
if (first) { ua->SendMsg(_("No disabled Schedules.\n")); }
}

/**
* Enter with Resources locked
*/
static void ShowAll(UaContext* ua, bool hide_sensitive_data, bool verbose)
{
for (int 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;
}
}
}


struct showstruct {
const char* res_name;
int type;
Expand All @@ -199,13 +223,15 @@ static struct showstruct avail_resources[] = {{NT_("directors"), R_DIRECTOR},
{NT_("messages"), R_MSGS},
{NT_("profiles"), R_PROFILE},
{NT_("consoles"), R_CONSOLE},
{NT_("users"), R_USER},
{NT_("all"), -1},
{NT_("help"), -2},
{NULL, 0}};

/**
* Displays Resources
*
* show
* show all
* show <resource-keyword-name> - e.g. show directors
* show <resource-keyword-name>=<name> - e.g. show director=HeadMan
Expand Down Expand Up @@ -234,13 +260,19 @@ bool show_cmd(UaContext* ua, const char* cmd)
if (FindArg(ua, NT_("verbose")) > 0) { verbose = true; }

LockRes(my_config);

/*
* Without parameter, show all ressources.
*/
if (ua->argc == 1) { ShowAll(ua, hide_sensitive_data, verbose); }

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 (Bstrcasecmp(ua->argk[i], NT_("disabled"))) {
if (((i + 1) < ua->argc) && Bstrcasecmp(ua->argk[i + 1], NT_("jobs"))) {
ShowDisabledJobs(ua);
} else if (((i + 1) < ua->argc) &&
Expand Down Expand Up @@ -295,22 +327,7 @@ bool show_cmd(UaContext* ua, const char* cmd)

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;
}
}
ShowAll(ua, hide_sensitive_data, verbose);
break;
case -2:
ua->SendMsg(_("Keywords for the show command are:\n"));
Expand Down Expand Up @@ -547,6 +564,11 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)

Dmsg1(20, "list: %s\n", cmd);

if (ua->argc <= 1) {
ua->ErrorMsg(_("%s command requires a keyword\n"), NPRT(ua->argk[0]));
return false;
}

/*
* days or hours given?
*/
Expand Down Expand Up @@ -907,9 +929,21 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
* List all volumes, flat
*/
if (FindArg(ua, NT_("all")) > 0) {
/*
* The result of "list media all"
* does not contain the Pool information,
* therefore checking the Pool_ACL is not possible.
* For this reason, we prevent this command.
*/
if (ua->AclHasRestrictions(Pool_ACL) && (llist != VERT_LIST)) {
ua->ErrorMsg(
_("Restricted permission. Use the commands 'list media' or "
"'llist media all' instead\n"));
return false;
}
ua->send->ArrayStart("volumes");
SetAclFilter(ua, 1, Pool_ACL); /* PoolName */
if (current) { SetResFilter(ua, 1, R_POOL); /* PoolName */ }
SetAclFilter(ua, 4, Pool_ACL); /* PoolName */
if (current) { SetResFilter(ua, 4, R_POOL); /* PoolName */ }
ua->db->ListMediaRecords(ua->jcr, &mr, query_range.c_str(), count,
ua->send, llist);
ua->send->ArrayEnd("volumes");
Expand Down Expand Up @@ -1013,9 +1047,11 @@ static bool DoListCmd(UaContext* ua, const char* cmd, e_list_type llist)
ua->db->ListJobstatisticsRecords(ua->jcr, jobid, ua->send, llist);
} else {
ua->ErrorMsg(_("no jobid given\n"));
return false;
}
} else {
ua->ErrorMsg(_("Unknown list keyword: %s\n"), NPRT(ua->argk[1]));
return false;
}

return true;
Expand Down

0 comments on commit 1c66663

Please sign in to comment.