int len;
bool ok = false;
bool found = false;
- BSOCK *sock = ua->UA_sock;
+ BSOCK *user = ua->UA_sock;
- Dmsg1(1400, "Dot command: %s\n", ua->UA_sock->msg);
+ Dmsg1(1400, "Dot command: %s\n", user->msg);
if (ua->argc == 0) {
return 1;
}
len = strlen(ua->argk[0]);
if (len == 1) {
+ if (ua->api) user->signal(BNET_CMD_BEGIN);
+ if (ua->api) user->signal(BNET_CMD_OK);
return 1; /* no op */
}
for (i=0; i<comsize; i++) { /* search for command */
if (strncasecmp(ua->argk[0], _(commands[i].key), len) == 0) {
bool gui = ua->gui;
+ /* Check if command permitted, but "quit" is always OK */
+ if (strcmp(ua->argk[0], NT_(".quit")) != 0 &&
+ !acl_access_ok(ua, Command_ACL, ua->argk[0], len)) {
+ break;
+ }
ua->gui = true;
- if (ua->api) sock->signal(BNET_CMD_BEGIN);
+ if (ua->api) user->signal(BNET_CMD_BEGIN);
ok = (*commands[i].func)(ua, cmd); /* go execute command */
ua->gui = gui;
found = true;
}
}
if (!found) {
- pm_strcat(sock->msg, _(": is an invalid command\n"));
- sock->msglen = strlen(sock->msg);
- sock->send();
- if (ua->api) sock->signal(BNET_INVALID_CMD);
+ pm_strcat(user->msg, _(": is an invalid command.\n"));
+ user->msglen = strlen(user->msg);
+ user->send();
}
- if (ua->api) sock->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
+ if (ua->api) user->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
return 1;
}
static bool jobscmd(UAContext *ua, const char *cmd)
{
- JOB *job = NULL;
+ JOB *job;
LockRes();
- while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
+ foreach_res(job, R_JOB) {
if (acl_access_ok(ua, Job_ACL, job->name())) {
bsendmsg(ua, "%s\n", job->name());
}
static bool filesetscmd(UAContext *ua, const char *cmd)
{
- FILESET *fs = NULL;
+ FILESET *fs;
LockRes();
- while ( (fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs)) ) {
+ foreach_res(fs, R_FILESET) {
if (acl_access_ok(ua, FileSet_ACL, fs->name())) {
bsendmsg(ua, "%s\n", fs->name());
}
static bool clientscmd(UAContext *ua, const char *cmd)
{
- CLIENT *client = NULL;
+ CLIENT *client;
LockRes();
- while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) {
+ foreach_res(client, R_CLIENT) {
if (acl_access_ok(ua, Client_ACL, client->name())) {
bsendmsg(ua, "%s\n", client->name());
}
{
MSGS *msgs = NULL;
LockRes();
- while ( (msgs = (MSGS *)GetNextRes(R_MSGS, (RES *)msgs)) ) {
+ foreach_res(msgs, R_MSGS) {
bsendmsg(ua, "%s\n", msgs->name());
}
UnlockRes();
static bool poolscmd(UAContext *ua, const char *cmd)
{
- POOL *pool = NULL;
+ POOL *pool;
LockRes();
- while ( (pool = (POOL *)GetNextRes(R_POOL, (RES *)pool)) ) {
+ foreach_res(pool, R_POOL) {
if (acl_access_ok(ua, Pool_ACL, pool->name())) {
bsendmsg(ua, "%s\n", pool->name());
}
static bool storagecmd(UAContext *ua, const char *cmd)
{
- STORE *store = NULL;
+ STORE *store;
LockRes();
- while ( (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)) ) {
+ foreach_res(store, R_STORAGE) {
if (acl_access_ok(ua, Storage_ACL, store->name())) {
bsendmsg(ua, "%s\n", store->name());
}
*/
static bool api_cmd(UAContext *ua, const char *cmd)
{
- /* Eventually we will probably have several levels or
- * capabilities enabled by this.
- */
- ua->api = 1;
+ if (ua->argc == 2) {
+ ua->api = atoi(ua->argk[1]);
+ } else {
+ ua->api = 1;
+ }
return true;
}
/*
* Return the backups for this client
+ *
+ * .backups client=xxx fileset=yyy
+ *
*/
static bool backupscmd(UAContext *ua, const char *cmd)
{
if (!open_client_db(ua)) {
return true;
}
- if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 || strcmp(ua->argk[2], "fileset") != 0) {
+ if (ua->argc != 3 || strcmp(ua->argk[1], "client") != 0 ||
+ strcmp(ua->argk[2], "fileset") != 0) {
return true;
}
if (!acl_access_ok(ua, Client_ACL, ua->argv[1]) ||