Add "sasl status" command
This commit is contained in:
parent
23fd727618
commit
43c440e600
@ -344,6 +344,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
|
||||
Show SHA-1 and SHA-256 fingerprints for the certificate
|
||||
currently used with the network.
|
||||
|
||||
*sasl status* <network name>
|
||||
Show current SASL status.
|
||||
|
||||
*sasl set-plain* <network name> <username> <password>
|
||||
Set SASL PLAIN credentials.
|
||||
|
||||
|
37
service.go
37
service.go
@ -241,6 +241,11 @@ func init() {
|
||||
},
|
||||
"sasl": {
|
||||
children: serviceCommandSet{
|
||||
"status": {
|
||||
usage: "<network name>",
|
||||
desc: "show SASL status",
|
||||
handle: handleServiceSaslStatus,
|
||||
},
|
||||
"set-plain": {
|
||||
usage: "<network name> <username> <password>",
|
||||
desc: "set SASL PLAIN credentials",
|
||||
@ -684,6 +689,38 @@ func handleServiceCertFPFingerprints(ctx context.Context, dc *downstreamConn, pa
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleServiceSaslStatus(ctx context.Context, dc *downstreamConn, params []string) error {
|
||||
if len(params) != 1 {
|
||||
return fmt.Errorf("expected exactly one argument")
|
||||
}
|
||||
|
||||
net := dc.user.getNetwork(params[0])
|
||||
if net == nil {
|
||||
return fmt.Errorf("unknown network %q", params[0])
|
||||
}
|
||||
|
||||
switch net.SASL.Mechanism {
|
||||
case "PLAIN":
|
||||
sendServicePRIVMSG(dc, fmt.Sprintf("SASL PLAIN enabled with username %q", net.SASL.Plain.Username))
|
||||
case "EXTERNAL":
|
||||
sendServicePRIVMSG(dc, "SASL EXTERNAL (CertFP) enabled")
|
||||
case "":
|
||||
sendServicePRIVMSG(dc, "SASL is disabled")
|
||||
}
|
||||
|
||||
if uc := net.conn; uc != nil {
|
||||
if uc.account != "" {
|
||||
sendServicePRIVMSG(dc, fmt.Sprintf("Authenticated on upstream network with account %q", uc.account))
|
||||
} else {
|
||||
sendServicePRIVMSG(dc, "Unauthenticated on upstream network")
|
||||
}
|
||||
} else {
|
||||
sendServicePRIVMSG(dc, "Disconnected from upstream network")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleServiceSASLSetPlain(ctx context.Context, dc *downstreamConn, params []string) error {
|
||||
if len(params) != 3 {
|
||||
return fmt.Errorf("expected exactly 3 arguments")
|
||||
|
Loading…
Reference in New Issue
Block a user