def speeddial_show(ctx, oformat, ostyle, table, userid, shortdial): """Show details for speed dial records \b Parameters: <userid> - username, AoR or SIP URI for user or alias [<shortdial>] - username, AoR or SIP URI for short dial (optional) """ udata = parse_user_spec(ctx, userid) e = create_engine(ctx.gconfig.get("db", "rwurl")) ctx.vlog( "Showing speed dial records for user [%s@%s]", udata["username"], udata["domain"], ) if not shortdial: res = e.execute( "select * from " + table + " where username=%s and domain=%s", udata["username"], udata["domain"], ) ioutils_dbres_print(ctx, oformat, ostyle, res) else: for s in shortdial: sdata = parse_user_spec(ctx, s) res = e.execute( "select * from " + table + " where username=%s and domain=%s " "and sd_username=%s and sd_domain=%s", udata["username"], udata["domain"], sdata["username"], sdata["domain"], ) ioutils_dbres_print(ctx, oformat, ostyle, res)
def speeddial_rm(ctx, table, userid, shortdial): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <shortdial> - username, AoR or SIP URI for short dial """ udata = parse_user_spec(ctx, userid) ctx.log( "Removing speed dial for record [%s@%s]", udata["username"], udata["domain"], ) e = create_engine(ctx.gconfig.get("db", "rwurl")) if not shortdial: e.execute( "delete from " + table + " where username=%s and domain=%s", udata["username"], udata["domain"], ) else: for s in shortdial: sdata = parse_user_spec(ctx, s) e.execute( "delete from " + table + " where username=%s and domain=%s " "and sd_username=%s and sd_domain=%s", udata["username"], udata["domain"], sdata["username"], sdata["domain"], )
def aliasdb_add(ctx, table, userid, aliasid): """Add a user-alias pair into database \b Parameters: <userid> - username, AoR or SIP URI for subscriber <aliasid> - username, AoR or SIP URI for alias """ udata = parse_user_spec(ctx, userid) adata = parse_user_spec(ctx, aliasid) ctx.vlog( "Adding user [%s@%s] with alias [%s@%s]", udata["username"], udata["domain"], adata["username"], adata["domain"], ) e = create_engine(ctx.gconfig.get("db", "rwurl")) e.execute( "insert into " + table + " (username, domain, alias_username, " "alias_domain) values (%s, %s, %s, %s)", udata["username"], udata["domain"], adata["username"], adata["domain"], )
def speeddial_add(ctx, table, userid, shortdial, targeturi, desc): """Add a speed dial record \b Parameters: <userid> - username, AoR or SIP URI for subscriber <shortdial> - username, AoR or SIP URI for short dial <targeturi> - username, AoR or SIP URI for target [<desc>] - description for speed dial record """ udata = parse_user_spec(ctx, userid) sdata = parse_user_spec(ctx, shortdial) tdata = parse_user_spec(ctx, targeturi) ctx.vlog('Adding for user [%s@%s] short dial [%s@%s] target [sip:%s@%s]', udata['username'], udata['domain'], sdata['username'], sdata['domain'], tdata['username'], tdata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) if not desc: e.execute('insert into ' + table + ' (username, domain, sd_username, sd_domain, new_uri) values (%s, %s, %s, %s, %s)', udata['username'], udata['domain'], sdata['username'], sdata['domain'], 'sip:' + tdata['username'] + '@' + tdata['domain']) else: e.execute('insert into ' + table + ' (username, domain, sd_username, sd_domain, new_uri, description) values (%s, %s, %s, %s, %s, %s)', udata['username'], udata['domain'], sdata['username'], sdata['domain'], 'sip:' + tdata['username'] + '@' + tdata['domain'], desc)
def aliasdb_add(ctx, table, userid, aliasid): """Add a user-alias pair into database \b Parameters: <userid> - username, AoR or SIP URI for subscriber <aliasid> - username, AoR or SIP URI for alias """ udata = parse_user_spec(ctx, userid) adata = parse_user_spec(ctx, aliasid) ctx.vlog('Adding user [%s@%s] with alias [%s@%s]', udata['username'], udata['domain'], adata['username'], adata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute('insert into ' + table + ' (username, domain, alias_username, alias_domain) values (%s, %s, %s, %s)', udata['username'], udata['domain'], adata['username'], adata['domain'])
def group_show(ctx, oformat, ostyle, userid): """Show details for subscribers \b Parameters: [<userid>] - username, AoR or SIP URI for subscriber - it can be a list of userids - if not provided then all subscribers are shown """ if not userid: ctx.vlog("Showing all records") e = create_engine(ctx.gconfig.get("db", "rwurl")) res = e.execute("select * from grp") ioutils_dbres_print(ctx, oformat, ostyle, res) else: for u in userid: udata = parse_user_spec(ctx, u) ctx.vlog( "Showing group membership for user [%s@%s]", udata["username"], udata["domain"], ) e = create_engine(ctx.gconfig.get("db", "rwurl")) res = e.execute( "select * from grp where username=%s and domain=%s", udata["username"], udata["domain"], ) ioutils_dbres_print(ctx, oformat, ostyle, res)
def ul_show(ctx, brief, table, userid): """Show details for location records in memory \b Parameters: [<userid>] - username, AoR or SIP URI for subscriber - it can be a list of userids - if not provided then all records are shown """ if not userid: ctx.vlog("Showing all records") if brief: command_ctl(ctx, "ul.dump", ["brief"]) else: command_ctl(ctx, "ul.dump", []) else: for u in userid: udata = parse_user_spec(ctx, u) ctx.vlog( "Showing record for [%s@%s]", udata["username"], udata["domain"], ) aor = udata["username"] + "@" + udata["domain"] command_ctl(ctx, "ul.lookup", [table, aor])
def aliasdb_show(ctx, oformat, ostyle, table, matchalias, userid): """Show details for user aliases \b Parameters: [<userid>] - username, AoR or SIP URI for user or alias - it can be a list of userids - if not provided then all aliases are shown """ if not userid: ctx.vlog('Showing all records') e = create_engine(ctx.gconfig.get('db', 'rwurl')) res = e.execute('select * from ' + table) ioutils_dbres_print(ctx, oformat, ostyle, res) else: for u in userid: udata = parse_user_spec(ctx, u) e = create_engine(ctx.gconfig.get('db', 'rwurl')) if matchalias: ctx.vlog('Showing records for alias [%s@%s]', udata['username'], udata['domain']) res = e.execute('select * from ' + table + ' where alias_username=%s and alias_domain=%s', udata['username'], udata['domain']) else: ctx.vlog('Showing records for user [%s@%s]', udata['username'], udata['domain']) res = e.execute('select * from ' + table + ' where username=%s and domain=%s', udata['username'], udata['domain']) ioutils_dbres_print(ctx, oformat, ostyle, res)
def subscriber_setattri(ctx, userid, attr, val): """Set an integer attribute a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <attribute> - the name of the attribute (column name in subscriber table) <value> - the value to be set for the attribute """ udata = parse_user_spec(ctx, userid) ctx.log( "Updating subscriber [%s@%s] with int attribute [%s]=[%s]", udata["username"], udata["domain"], attr, val, ) e = create_engine(ctx.gconfig.get("db", "rwurl")) e.execute("update subscriber set {0}={1} where username={2!r} and " "domain={3!r}".format( attr.encode("ascii", "ignore").decode(), val.encode("ascii", "ignore").decode(), udata["username"], udata["domain"], ))
def group_revoke(ctx, userid, groupid): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <groupid> - group name """ udata = parse_user_spec(ctx, userid) ctx.log("Removing ACL for user [%s@%s]", udata["username"], udata["domain"]) e = create_engine(ctx.gconfig.get("db", "rwurl")) if not groupid: e.execute( "delete from grp where username=%s and domain=%s", udata["username"], udata["domain"], ) else: e.execute( "delete from grp where username=%s and domain=%s and grp=%s", udata["username"], udata["domain"], groupid, )
def speeddial_add(ctx, table, userid, shortdial, targeturi, desc): """Add a speed dial record \b Parameters: <userid> - username, AoR or SIP URI for subscriber <shortdial> - username, AoR or SIP URI for short dial <targeturi> - username, AoR or SIP URI for target [<desc>] - description for speed dial record """ udata = parse_user_spec(ctx, userid) sdata = parse_user_spec(ctx, shortdial) tdata = parse_user_spec(ctx, targeturi) ctx.vlog( "Adding for user [%s@%s] short dial [%s@%s] target [sip:%s@%s]", udata["username"], udata["domain"], sdata["username"], sdata["domain"], tdata["username"], tdata["domain"], ) e = create_engine(ctx.gconfig.get("db", "rwurl")) uri = "sip:{}@{}".format(tdata["username"], tdata["domain"]) if not desc: e.execute( "insert into " + table + " %s (username, domain, sd_username, " "sd_domain, new_uri) values (%s, %s, %s, %s, %s)", udata["username"], udata["domain"], sdata["username"], sdata["domain"], uri, ) else: e.execute( "insert into " + table + " (username, domain, sd_username, " "sd_domain, new_uri, description) values (%s, %s, %s, %s, %s, %s)", udata["username"], udata["domain"], sdata["username"], sdata["domain"], uri, desc, )
def speeddial_rm(ctx, table, userid, shortdial): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <shortdial> - username, AoR or SIP URI for short dial """ udata = parse_user_spec(ctx, userid) ctx.log('Removing speed dial for record [%s@%s]', udata['username'], udata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) if not shortdial: e.execute('delete from ' + table + ' where username=%s and domain=%s', udata['username'], udata['domain']) else: for s in shortdial: sdata = parse_user_spec(ctx, s) e.execute('delete from ' + table + ' where username=%s and domain=%s and sd_username=%s and sd_domain=%s', udata['username'], udata['domain'], sdata['username'], sdata['domain'])
def subscriber_rm(ctx, userid): """Remove an existing subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber """ udata = parse_user_spec(ctx, userid) ctx.log('Removing subscriber [%s@%s]', udata['username'], udata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute('delete from subscriber where username=%s and domain=%s', udata['username'], udata['domain'])
def subscriber_setattrnull(ctx, userid, attr): """Set an attribute to NULL for a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <attribute> - the name of the attribute (column name in subscriber table) """ udata = parse_user_spec(ctx, userid) ctx.log('Updating subscriber [%s@%s] with attribute [%s]=NULL', udata['username'], udata['domain'], attr) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute('update subscriber set {0}=NULL where username={1!r} and domain={2!r}'.format(attr.encode('ascii','ignore'), udata['username'], udata['domain']))
def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods, userid, curi): """Add location record \b Parameters: <userid> - username, AoR or SIP URI for subscriber <contact-uri> - contact SIP URI """ udata = parse_user_spec(ctx, userid) ctx.vlog('Adding record for [%s@%s]', udata['username'], udata['domain']) aor = udata['username'] + '@' + udata['domain'] command_ctl(ctx, 'ul_add', [ table, aor, curi, expires, qval, cpath, flags, bflags, methods ])
def group_grant(ctx, userid, groupid): """Add a user into a group (grant privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <groupid> - group name """ udata = parse_user_spec(ctx, userid) ctx.vlog('Adding user [%s@%s] in group [%s]', udata['username'], udata['domain'], groupid) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute('insert into grp (username, domain, grp) values (%s, %s, %s)', udata['username'], udata['domain'], groupid)
def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods, userid, curi): """Add location record \b Parameters: <userid> - username, AoR or SIP URI for subscriber <contact-uri> - contact SIP URI """ udata = parse_user_spec(ctx, userid) ctx.vlog('Adding record for [%s@%s]', udata['username'], udata['domain']) aor = udata['username'] + '@' + udata['domain'] command_ctl(ctx, 'ul.add', [ table, aor, curi, expires, qval, cpath, flags, bflags, methods ])
def speeddial_show(ctx, oformat, ostyle, table, userid, shortdial): """Show details for speed dial records \b Parameters: <userid> - username, AoR or SIP URI for user or alias [<shortdial>] - username, AoR or SIP URI for short dial (optional) """ udata = parse_user_spec(ctx, userid) e = create_engine(ctx.gconfig.get('db', 'rwurl')) ctx.vlog('Showing speed dial records for user [%s@%s]', udata['username'], udata['domain']) if not shortdial: res = e.execute('select * from ' + table + ' where username=%s and domain=%s', udata['username'], udata['domain']) ioutils_dbres_print(ctx, oformat, ostyle, res) else: for s in shortdial: sdata = parse_user_spec(ctx, s) res = e.execute('select * from ' + table + ' where username=%s and domain=%s and sd_username=%s and sd_domain=%s', udata['username'], udata['domain'], sdata['username'], sdata['domain']) ioutils_dbres_print(ctx, oformat, ostyle, res)
def subscriber_setattri(ctx, userid, attr, val): """Set an integer attribute a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <attribute> - the name of the attribute (column name in subscriber table) <value> - the value to be set for the attribute """ udata = parse_user_spec(ctx, userid) ctx.log('Updating subscriber [%s@%s] with int attribute [%s]=[%s]', udata['username'], udata['domain'], attr, val) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute('update subscriber set {0}={1} where username={2!r} and domain={3!r}'.format(attr.encode('ascii','ignore'), val.encode('ascii','ignore'), udata['username'], udata['domain']))
def aliasdb_rm(ctx, table, matchalias, userid, aliasid): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <aliasid> - username, AoR or SIP URI for alias (optional) """ udata = parse_user_spec(ctx, userid) ctx.log('Removing alias for record [%s@%s]', udata['username'], udata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) if not aliasid: if matchalias: e.execute('delete from ' + table + ' where alias_username=%s and alias_domain=%s', udata['username'], udata['domain']) else: e.execute('delete from ' + table + ' where username=%s and domain=%s', udata['username'], udata['domain']) else: for a in aliasid: adata = parse_user_spec(ctx, a) e.execute('delete from ' + table + ' where username=%s and domain=%s and alias_username=%s and alias_domain=%s', udata['username'], udata['domain'], adata['username'], adata['domain'])
def aliasdb_rm(ctx, table, matchalias, userid, aliasid): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <aliasid> - username, AoR or SIP URI for alias (optional) """ udata = parse_user_spec(ctx, userid) ctx.log("Removing alias for record [%s@%s]", udata["username"], udata["domain"]) e = create_engine(ctx.gconfig.get("db", "rwurl")) if not aliasid: if matchalias: e.execute( "delete from " + table + " where alias_username=%s and " "alias_domain=%s", udata["username"], udata["domain"], ) else: e.execute( "delete from " + table + " where username=%s and domain=%s", udata["username"], udata["domain"], ) else: for a in aliasid: adata = parse_user_spec(ctx, a) e.execute( "delete from " + table + " where username=%s and domain=%s " "and alias_username=%s and alias_domain=%s", udata["username"], udata["domain"], adata["username"], adata["domain"], )
def group_revoke(ctx, userid, groupid): """Remove a user from groups (revoke privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <groupid> - group name """ udata = parse_user_spec(ctx, userid) ctx.log('Removing ACL for user [%s@%s]', udata['username'], udata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) if not groupid: e.execute('delete from grp where username=%s and domain=%s', udata['username'], udata['domain']) else: e.execute('delete from grp where username=%s and domain=%s and grp=%s', udata['username'], udata['domain'], groupid)
def subscriber_rm(ctx, userid): """Remove an existing subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber """ udata = parse_user_spec(ctx, userid) ctx.log("Removing subscriber [%s@%s]", udata["username"], udata["domain"]) e = create_engine(ctx.gconfig.get("db", "rwurl")) e.execute( "delete from subscriber where username=%s and domain=%s", udata["username"], udata["domain"], )
def subscriber_setattrnull(ctx, userid, attr): """Set an attribute to NULL for a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <attribute> - the name of the attribute (column name in subscriber table) """ udata = parse_user_spec(ctx, userid) ctx.log('Updating subscriber [%s@%s] with attribute [%s]=NULL', udata['username'], udata['domain'], attr) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute( 'update subscriber set {0}=NULL where username={1!r} and domain={2!r}'. format(attr.encode('ascii', 'ignore'), udata['username'], udata['domain']))
def subscriber_add(ctx, pwtext, userid, password): """Add a new subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <password> - the password """ udata = parse_user_spec(ctx, userid) ctx.vlog('Adding subscriber [%s] in domain [%s] with password [%s]', udata['username'], udata['domain'], password) ha1 = hashlib.md5(udata['username'] + ":" + udata['domain'] + ":" + password).hexdigest() ha1b = hashlib.md5(udata['username'] + "@" + udata['domain'] + ":" + udata['domain'] + ":" + password).hexdigest() e = create_engine(ctx.gconfig.get('db', 'rwurl')) if pwtext == 'yes' : e.execute('insert into subscriber (username, domain, password, ha1, ha1b) values (%s, %s, %s, %s, %s)', udata['username'], udata['domain'], password, ha1, ha1b) else: e.execute('insert into subscriber (username, domain, ha1, ha1b) values (%s, %s, %s, %s)', udata['username'], udata['domain'], ha1, ha1b)
def ul_add(ctx, table, expires, qval, cpath, flags, bflags, methods, userid, curi): """Add location record \b Parameters: <userid> - username, AoR or SIP URI for subscriber <contact-uri> - contact SIP URI """ udata = parse_user_spec(ctx, userid) ctx.vlog("Adding record for [%s@%s]", udata["username"], udata["domain"]) aor = udata["username"] + "@" + udata["domain"] command_ctl( ctx, "ul.add", [table, aor, curi, expires, qval, cpath, flags, bflags, methods], )
def subscriber_passwd(ctx, pwtext, userid, password): """Update password for a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <password> - the password """ udata = parse_user_spec(ctx, userid) ctx.log('Updating subscriber [%s@%s] with password [%s]', udata['username'], udata['domain'], password) ha1 = hashlib.md5(udata['username'] + ":" + udata['domain'] + ":" + password).hexdigest() ha1b = hashlib.md5(udata['username'] + "@" + udata['domain'] + ":" + udata['domain'] + ":" + password).hexdigest() e = create_engine(ctx.gconfig.get('db', 'rwurl')) if pwtext == 'yes' : e.execute('update subscriber set password=%s, ha1=%s, ha1b=%s where username=%s and domain=%s', password, ha1, ha1b, udata['username'], udata['domain']) else: e.execute('update subscriber set ha1=%s, ha1b=%s where username=%s and domain=%s', ha1, ha1b, udata['username'], udata['domain'])
def subscriber_setattri(ctx, userid, attr, val): """Set an integer attribute a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <attribute> - the name of the attribute (column name in subscriber table) <value> - the value to be set for the attribute """ udata = parse_user_spec(ctx, userid) ctx.log('Updating subscriber [%s@%s] with int attribute [%s]=[%s]', udata['username'], udata['domain'], attr, val) e = create_engine(ctx.gconfig.get('db', 'rwurl')) e.execute( 'update subscriber set {0}={1} where username={2!r} and domain={3!r}'. format(attr.encode('ascii', 'ignore'), val.encode('ascii', 'ignore'), udata['username'], udata['domain']))
def ul_rm(ctx, table, userid, curi): """Show details for location records in memory \b Parameters: <userid> - username, AoR or SIP URI for subscriber [<contact-uri>] - contact SIP URI - optional, it can be a list of URIs """ udata = parse_user_spec(ctx, userid) ctx.vlog("Showing record for [%s@%s]", udata["username"], udata["domain"]) aor = udata["username"] + "@" + udata["domain"] if curi: for c in curi: command_ctl(ctx, "ul.rm", [table, aor, c]) else: command_ctl(ctx, "ul.rm", [table, aor])
def ul_rm(ctx, table, userid, curi): """Show details for location records in memory \b Parameters: <userid> - username, AoR or SIP URI for subscriber [<contact-uri>] - contact SIP URI - optional, it can be a list of URIs """ udata = parse_user_spec(ctx, userid) ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain']) aor = udata['username'] + '@' + udata['domain'] if curi: for c in curi: command_ctl(ctx, 'ul_rm', [ table, aor, c ]) else: command_ctl(ctx, 'ul_rm', [ table, aor ])
def aliasdb_show(ctx, oformat, ostyle, table, matchalias, userid): """Show details for user aliases \b Parameters: [<userid>] - username, AoR or SIP URI for user or alias - it can be a list of userids - if not provided then all aliases are shown """ if not userid: ctx.vlog("Showing all records") e = create_engine(ctx.gconfig.get("db", "rwurl")) res = e.execute("select * from " + table) ioutils_dbres_print(ctx, oformat, ostyle, res) else: for u in userid: udata = parse_user_spec(ctx, u) e = create_engine(ctx.gconfig.get("db", "rwurl")) if matchalias: ctx.vlog( "Showing records for alias [%s@%s]", udata["username"], udata["domain"], ) res = e.execute( "select * from " + table + " where alias_username=%s " "and alias_domain=%s", udata["username"], udata["domain"], ) else: ctx.vlog( "Showing records for user [%s@%s]", udata["username"], udata["domain"], ) res = e.execute( "select * from " + table + " where username=%s and " "domain=%s", udata["username"], udata["domain"], ) ioutils_dbres_print(ctx, oformat, ostyle, res)
def ul_showdb(ctx, oformat, ostyle, userid): """Show details for location records in database \b Parameters: [<userid>] - username, AoR or SIP URI for subscriber - it can be a list of userids - if not provided then all records are shown """ if not userid: ctx.vlog('Showing all records') e = create_engine(ctx.gconfig.get('db', 'rwurl')) res = e.execute('select * from location') ioutils_dbres_print(ctx, oformat, ostyle, res) else: for u in userid: udata = parse_user_spec(ctx, u) ctx.vlog('Showing records for [%s@%s]', udata['username'], udata['domain']) e = create_engine(ctx.gconfig.get('db', 'rwurl')) res = e.execute('select * from location where username=%s and domain=%s', udata['username'], udata['domain']) ioutils_dbres_print(ctx, oformat, ostyle, res)
def ul_show(ctx, brief, table, userid): """Show details for location records in memory \b Parameters: [<userid>] - username, AoR or SIP URI for subscriber - it can be a list of userids - if not provided then all records are shown """ if not userid: ctx.vlog('Showing all records') if brief: command_ctl(ctx, 'ul.dump', [ 'brief' ]) else: command_ctl(ctx, 'ul.dump', [ ]) else: for u in userid: udata = parse_user_spec(ctx, u) ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain']) aor = udata['username'] + '@' + udata['domain'] command_ctl(ctx, 'ul.lookup', [ table, aor ])
def ul_show(ctx, brief, table, userid): """Show details for location records in memory \b Parameters: [<userid>] - username, AoR or SIP URI for subscriber - it can be a list of userids - if not provided then all records are shown """ if not userid: ctx.vlog('Showing all records') if brief: command_ctl(ctx, 'ul_dump', [ 'brief' ]) else: command_ctl(ctx, 'ul_dump', [ ]) else: for u in userid: udata = parse_user_spec(ctx, u) ctx.vlog('Showing record for [%s@%s]', udata['username'], udata['domain']) aor = udata['username'] + '@' + udata['domain'] command_ctl(ctx, 'ul_show_contact', [ table, aor ])
def subscriber_passwd(ctx, pwtext, userid, password): """Update password for a subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <password> - the password """ udata = parse_user_spec(ctx, userid) ctx.log( "Updating subscriber [%s@%s] with password [%s]", udata["username"], udata["domain"], password, ) dig = "{}:{}:{}".format(udata["username"], udata["domain"], password) ha1 = hashlib.md5(dig.encode()).hexdigest() dig = "{}@{}:{}:{}".format(udata["username"], udata["domain"], udata["domain"], password) ha1b = hashlib.md5(dig.encode()).hexdigest() e = create_engine(ctx.gconfig.get("db", "rwurl")) if pwtext == "yes": e.execute( "update subscriber set password=%s, ha1=%s, ha1b=%s where " "username=%s and domain=%s", password, ha1, ha1b, udata["username"], udata["domain"], ) else: e.execute( "update subscriber set ha1=%s, ha1b=%s where " "username=%s and domain=%s", ha1, ha1b, udata["username"], udata["domain"], )
def subscriber_add(ctx, pwtext, userid, password): """Add a new subscriber \b Parameters: <userid> - username, AoR or SIP URI for subscriber <password> - the password """ udata = parse_user_spec(ctx, userid) ctx.vlog( "Adding subscriber [%s] in domain [%s] with password [%s]", udata["username"], udata["domain"], password, ) dig = "{}:{}:{}".format(udata["username"], udata["domain"], password) ha1 = hashlib.md5(dig.encode()).hexdigest() dig = "{}@{}:{}:{}".format(udata["username"], udata["domain"], udata["domain"], password) ha1b = hashlib.md5(dig.encode()).hexdigest() e = create_engine(ctx.gconfig.get("db", "rwurl")) if pwtext == "yes": e.execute( "insert into subscriber (username, domain, password, ha1, ha1b) " "values (%s, %s, %s, %s, %s)", udata["username"], udata["domain"], password, ha1, ha1b, ) else: e.execute( "insert into subscriber (username, domain, ha1, ha1b) values " "(%s, %s, %s, %s)", udata["username"], udata["domain"], ha1, ha1b, )
def group_grant(ctx, userid, groupid): """Add a user into a group (grant privilege) \b Parameters: <userid> - username, AoR or SIP URI for subscriber <groupid> - group name """ udata = parse_user_spec(ctx, userid) ctx.vlog( "Adding user [%s@%s] in group [%s]", udata["username"], udata["domain"], groupid, ) e = create_engine(ctx.gconfig.get("db", "rwurl")) e.execute( "insert into grp (username, domain, grp) values (%s, %s, %s)", udata["username"], udata["domain"], groupid, )