Changeset 730 in code


Ignore:
Timestamp:
Dec 1, 2021, 10:03:27 AM (4 years ago)
Author:
contact
Message:

Add "sasl status" command

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/soju.1.scd

    r728 r730  
    345345        currently used with the network.
    346346
     347*sasl status* <network name>
     348        Show current SASL status.
     349
    347350*sasl set-plain* <network name> <username> <password>
    348351        Set SASL PLAIN credentials.
  • trunk/service.go

    r710 r730  
    242242                "sasl": {
    243243                        children: serviceCommandSet{
     244                                "status": {
     245                                        usage:  "<network name>",
     246                                        desc:   "show SASL status",
     247                                        handle: handleServiceSaslStatus,
     248                                },
    244249                                "set-plain": {
    245250                                        usage:  "<network name> <username> <password>",
     
    685690}
    686691
     692func handleServiceSaslStatus(ctx context.Context, dc *downstreamConn, params []string) error {
     693        if len(params) != 1 {
     694                return fmt.Errorf("expected exactly one argument")
     695        }
     696
     697        net := dc.user.getNetwork(params[0])
     698        if net == nil {
     699                return fmt.Errorf("unknown network %q", params[0])
     700        }
     701
     702        switch net.SASL.Mechanism {
     703        case "PLAIN":
     704                sendServicePRIVMSG(dc, fmt.Sprintf("SASL PLAIN enabled with username %q", net.SASL.Plain.Username))
     705        case "EXTERNAL":
     706                sendServicePRIVMSG(dc, "SASL EXTERNAL (CertFP) enabled")
     707        case "":
     708                sendServicePRIVMSG(dc, "SASL is disabled")
     709        }
     710
     711        if uc := net.conn; uc != nil {
     712                if uc.account != "" {
     713                        sendServicePRIVMSG(dc, fmt.Sprintf("Authenticated on upstream network with account %q", uc.account))
     714                } else {
     715                        sendServicePRIVMSG(dc, "Unauthenticated on upstream network")
     716                }
     717        } else {
     718                sendServicePRIVMSG(dc, "Disconnected from upstream network")
     719        }
     720
     721        return nil
     722}
     723
    687724func handleServiceSASLSetPlain(ctx context.Context, dc *downstreamConn, params []string) error {
    688725        if len(params) != 3 {
Note: See TracChangeset for help on using the changeset viewer.