mirror of
https://github.com/tinode/chat.git
synced 2025-03-14 10:05:07 +00:00
add missing option to assign ROOT auth_level
This commit is contained in:
@ -78,12 +78,13 @@ class Usermod(Macro):
|
|||||||
if cmd.suspend and cmd.unsuspend:
|
if cmd.suspend and cmd.unsuspend:
|
||||||
stdoutln("Cannot both suspend and unsuspend account")
|
stdoutln("Cannot both suspend and unsuspend account")
|
||||||
return None
|
return None
|
||||||
new_cmd = 'acc --user %s' % cmd.userid
|
new_cmd = 'acc --user %s --as_root' % cmd.userid
|
||||||
if cmd.suspend:
|
if cmd.suspend:
|
||||||
new_cmd += ' --suspend true'
|
new_cmd += ' --suspend true'
|
||||||
if cmd.unsuspend:
|
if cmd.unsuspend:
|
||||||
new_cmd += ' --suspend false'
|
new_cmd += ' --suspend false'
|
||||||
return [new_cmd]
|
return [new_cmd]
|
||||||
|
|
||||||
# Change theCard.
|
# Change theCard.
|
||||||
varname = cmd.varname if hasattr(cmd, 'varname') and cmd.varname else '$temp'
|
varname = cmd.varname if hasattr(cmd, 'varname') and cmd.varname else '$temp'
|
||||||
set_cmd = '.must ' + varname + ' set me'
|
set_cmd = '.must ' + varname + ' set me'
|
||||||
@ -96,7 +97,7 @@ class Usermod(Macro):
|
|||||||
if cmd.note is not None:
|
if cmd.note is not None:
|
||||||
set_cmd += ' --note="%s"' % cmd.note
|
set_cmd += ' --note="%s"' % cmd.note
|
||||||
if cmd.trusted is not None:
|
if cmd.trusted is not None:
|
||||||
set_cmd += ' --trusted="%s"' % cmd.trusted
|
set_cmd += ' --trusted="%s" --as_root' % cmd.trusted
|
||||||
old_user = tn_globals.DefaultUser if tn_globals.DefaultUser else ''
|
old_user = tn_globals.DefaultUser if tn_globals.DefaultUser else ''
|
||||||
return ['.use --user %s' % cmd.userid,
|
return ['.use --user %s' % cmd.userid,
|
||||||
'.must sub me',
|
'.must sub me',
|
||||||
@ -193,7 +194,7 @@ class Useradd(Macro):
|
|||||||
if cmd.note is not None:
|
if cmd.note is not None:
|
||||||
set_cmd += ' --note="%s"' % cmd.note
|
set_cmd += ' --note="%s"' % cmd.note
|
||||||
if cmd.trusted is not None:
|
if cmd.trusted is not None:
|
||||||
set_cmd += ' --trusted="%s"' % cmd.trusted
|
set_cmd += ' --trusted="%s" --as_root' % cmd.trusted
|
||||||
if cmd.tags:
|
if cmd.tags:
|
||||||
new_cmd += ' --tags="%s"' % cmd.tags
|
new_cmd += ' --tags="%s"' % cmd.tags
|
||||||
if cmd.avatar:
|
if cmd.avatar:
|
||||||
@ -253,7 +254,7 @@ class Userdel(Macro):
|
|||||||
def expand(self, id, cmd, args):
|
def expand(self, id, cmd, args):
|
||||||
if not cmd.userid:
|
if not cmd.userid:
|
||||||
return None
|
return None
|
||||||
del_cmd = 'del user --user %s' % cmd.userid
|
del_cmd = 'del user --user %s --as_root' % cmd.userid
|
||||||
if cmd.hard:
|
if cmd.hard:
|
||||||
del_cmd += ' --hard'
|
del_cmd += ' --hard'
|
||||||
return [del_cmd]
|
return [del_cmd]
|
||||||
|
@ -232,6 +232,10 @@ def parse_trusted(trusted):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# Create proto for ClientExtra
|
||||||
|
def pack_extra(cmd):
|
||||||
|
return pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser, auth_level=pb.ROOT if cmd.as_root else pb.NONE)
|
||||||
|
|
||||||
# Read a value in the server response using dot notation, i.e.
|
# Read a value in the server response using dot notation, i.e.
|
||||||
# $user.params.token or $meta.sub[1].user
|
# $user.params.token or $meta.sub[1].user
|
||||||
def getVar(path):
|
def getVar(path):
|
||||||
@ -362,7 +366,7 @@ def accMsg(id, cmd, ignored):
|
|||||||
desc=pb.SetDesc(default_acs=pb.DefaultAcsMode(auth=cmd.auth, anon=cmd.anon),
|
desc=pb.SetDesc(default_acs=pb.DefaultAcsMode(auth=cmd.auth, anon=cmd.anon),
|
||||||
public=cmd.public, private=cmd.private, trusted=encode_to_bytes(parse_trusted(cmd.trusted))),
|
public=cmd.public, private=cmd.private, trusted=encode_to_bytes(parse_trusted(cmd.trusted))),
|
||||||
cred=parse_cred(cmd.cred)),
|
cred=parse_cred(cmd.cred)),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {login}
|
# {login}
|
||||||
def loginMsg(id, cmd, args):
|
def loginMsg(id, cmd, args):
|
||||||
@ -406,14 +410,14 @@ def subMsg(id, cmd, ignored):
|
|||||||
sub=pb.SetSub(mode=cmd.mode),
|
sub=pb.SetSub(mode=cmd.mode),
|
||||||
tags=cmd.tags.split(",") if cmd.tags else None),
|
tags=cmd.tags.split(",") if cmd.tags else None),
|
||||||
get_query=cmd.get_query),
|
get_query=cmd.get_query),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {leave}
|
# {leave}
|
||||||
def leaveMsg(id, cmd, ignored):
|
def leaveMsg(id, cmd, ignored):
|
||||||
if not cmd.topic:
|
if not cmd.topic:
|
||||||
cmd.topic = tn_globals.DefaultTopic
|
cmd.topic = tn_globals.DefaultTopic
|
||||||
return pb.ClientMsg(leave=pb.ClientLeave(id=str(id), topic=cmd.topic, unsub=cmd.unsub),
|
return pb.ClientMsg(leave=pb.ClientLeave(id=str(id), topic=cmd.topic, unsub=cmd.unsub),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {pub}
|
# {pub}
|
||||||
def pubMsg(id, cmd, ignored):
|
def pubMsg(id, cmd, ignored):
|
||||||
@ -440,7 +444,7 @@ def pubMsg(id, cmd, ignored):
|
|||||||
|
|
||||||
return pb.ClientMsg(pub=pb.ClientPub(id=str(id), topic=cmd.topic, no_echo=True,
|
return pb.ClientMsg(pub=pb.ClientPub(id=str(id), topic=cmd.topic, no_echo=True,
|
||||||
head=head, content=encode_to_bytes(content)),
|
head=head, content=encode_to_bytes(content)),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {get}
|
# {get}
|
||||||
def getMsg(id, cmd, ignored):
|
def getMsg(id, cmd, ignored):
|
||||||
@ -460,7 +464,7 @@ def getMsg(id, cmd, ignored):
|
|||||||
what.append("cred")
|
what.append("cred")
|
||||||
return pb.ClientMsg(get=pb.ClientGet(id=str(id), topic=cmd.topic,
|
return pb.ClientMsg(get=pb.ClientGet(id=str(id), topic=cmd.topic,
|
||||||
query=pb.GetQuery(what=" ".join(what))),
|
query=pb.GetQuery(what=" ".join(what))),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {set}
|
# {set}
|
||||||
def setMsg(id, cmd, ignored):
|
def setMsg(id, cmd, ignored):
|
||||||
@ -486,7 +490,7 @@ def setMsg(id, cmd, ignored):
|
|||||||
sub=pb.SetSub(user_id=cmd.user, mode=cmd.mode),
|
sub=pb.SetSub(user_id=cmd.user, mode=cmd.mode),
|
||||||
tags=cmd.tags.split(",") if cmd.tags else None,
|
tags=cmd.tags.split(",") if cmd.tags else None,
|
||||||
cred=cred)),
|
cred=cred)),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# {del}
|
# {del}
|
||||||
def delMsg(id, cmd, ignored):
|
def delMsg(id, cmd, ignored):
|
||||||
@ -573,7 +577,7 @@ def delMsg(id, cmd, ignored):
|
|||||||
stdoutln("Unrecognized delete option '", cmd.what, "'")
|
stdoutln("Unrecognized delete option '", cmd.what, "'")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
msg = pb.ClientMsg(extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
msg = pb.ClientMsg(extra=pack_extra(cmd))
|
||||||
# Field named 'del' conflicts with the keyword 'del. This is a work around.
|
# Field named 'del' conflicts with the keyword 'del. This is a work around.
|
||||||
xdel = getattr(msg, 'del')
|
xdel = getattr(msg, 'del')
|
||||||
"""
|
"""
|
||||||
@ -631,7 +635,7 @@ def noteMsg(id, cmd, ignored):
|
|||||||
|
|
||||||
return pb.ClientMsg(note=pb.ClientNote(topic=cmd.topic, what=enum_what,
|
return pb.ClientMsg(note=pb.ClientNote(topic=cmd.topic, what=enum_what,
|
||||||
seq_id=cmd.seq, event=enum_event, payload=cmd.payload),
|
seq_id=cmd.seq, event=enum_event, payload=cmd.payload),
|
||||||
extra=pb.ClientExtra(on_behalf_of=tn_globals.DefaultUser))
|
extra=pack_extra(cmd))
|
||||||
|
|
||||||
# Upload file out of band over HTTP(S) (not gRPC).
|
# Upload file out of band over HTTP(S) (not gRPC).
|
||||||
def upload(id, cmd, args):
|
def upload(id, cmd, args):
|
||||||
@ -757,6 +761,9 @@ def parse_cmd(parts):
|
|||||||
parser.add_argument('filename', help='name of the file to upload')
|
parser.add_argument('filename', help='name of the file to upload')
|
||||||
elif macros:
|
elif macros:
|
||||||
parser = macros.parse_macro(parts)
|
parser = macros.parse_macro(parts)
|
||||||
|
|
||||||
|
if parser:
|
||||||
|
parser.add_argument('--as_root', action='store_true', help='execute command at ROOT auth level')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
# Parses command line into command and parameters.
|
# Parses command line into command and parameters.
|
||||||
|
Reference in New Issue
Block a user