Moved logging to use package level logger. Disabled by default.

This commit is contained in:
Justin Judd 2016-07-30 21:40:20 +09:00
parent a9e6dd5ffc
commit eb89e656d7
2 changed files with 13 additions and 14 deletions

View File

@ -1,7 +1,6 @@
package sshrpc package sshrpc
import ( import (
"log"
"net/rpc" "net/rpc"
"dev.justinjudd.org/justin/easyssh" "dev.justinjudd.org/justin/easyssh"
@ -98,10 +97,10 @@ func (c *Client) openRPCServerChannel(channelName string) error {
func acceptRPCServerRequest(rpcServer *rpc.Server, newChannel ssh.NewChannel) { func acceptRPCServerRequest(rpcServer *rpc.Server, newChannel ssh.NewChannel) {
channel, requests, err := newChannel.Accept() channel, requests, err := newChannel.Accept()
if err != nil { if err != nil {
log.Printf("could not accept channel (%s)", err) logger.Printf("could not accept channel (%s)", err)
return return
} }
log.Printf("Accepted channel") logger.Printf("Accepted channel")
// Channels can have out-of-band requests // Channels can have out-of-band requests
go func(in <-chan *ssh.Request) { go func(in <-chan *ssh.Request) {
@ -111,19 +110,19 @@ func acceptRPCServerRequest(rpcServer *rpc.Server, newChannel ssh.NewChannel) {
case easyssh.SubsystemRequest: case easyssh.SubsystemRequest:
ok = true ok = true
log.Printf("subsystem '%s'", req.Payload) logger.Printf("subsystem '%s'", req.Payload)
switch string(req.Payload[4:]) { switch string(req.Payload[4:]) {
//RPCSubsystem Request made indicates client desires RPC Server access //RPCSubsystem Request made indicates client desires RPC Server access
case RPCSubsystem: case RPCSubsystem:
go rpcServer.ServeConn(channel) go rpcServer.ServeConn(channel)
log.Printf("Started SSH RPC") logger.Printf("Started SSH RPC")
default: default:
log.Printf("Unknown subsystem: %s", req.Payload) logger.Printf("Unknown subsystem: %s", req.Payload)
} }
} }
if !ok { if !ok {
log.Printf("declining %s request...", req.Type) logger.Printf("declining %s request...", req.Type)
} }
req.Reply(ok, nil) req.Reply(ok, nil)
} }

View File

@ -2,7 +2,6 @@ package sshrpc
import ( import (
"fmt" "fmt"
"log"
"net/rpc" "net/rpc"
"dev.justinjudd.org/justin/easyssh" "dev.justinjudd.org/justin/easyssh"
@ -55,6 +54,7 @@ func (s *Server) StartServer(address string) {
} }
// HandleChannel implements easyssh.HandleChannelFunc allowing Server to Listen for and respond to all requests for a egistered SSH channel
func (s *Server) HandleChannel(newChannel ssh.NewChannel, channel ssh.Channel, reqs <-chan *ssh.Request, sshConn ssh.Conn) { func (s *Server) HandleChannel(newChannel ssh.NewChannel, channel ssh.Channel, reqs <-chan *ssh.Request, sshConn ssh.Conn) {
go func(in <-chan *ssh.Request) { go func(in <-chan *ssh.Request) {
for req := range in { for req := range in {
@ -63,30 +63,30 @@ func (s *Server) HandleChannel(newChannel ssh.NewChannel, channel ssh.Channel, r
case easyssh.SubsystemRequest: case easyssh.SubsystemRequest:
ok = true ok = true
log.Printf("subsystem '%s'", req.Payload[4:]) logger.Printf("subsystem '%s'", req.Payload[4:])
switch string(req.Payload[4:]) { switch string(req.Payload[4:]) {
//RPCSubsystem Request made indicates client desires RPC Server access //RPCSubsystem Request made indicates client desires RPC Server access
case RPCSubsystem: case RPCSubsystem:
go s.ServeConn(channel) go s.ServeConn(channel)
log.Printf("Started SSH RPC") logger.Printf("Started SSH RPC")
// triggers reverse RPC connection as well // triggers reverse RPC connection as well
clientChannel, err := openRPCClientChannel(sshConn, s.ChannelName+"-reverse") clientChannel, err := openRPCClientChannel(sshConn, s.ChannelName+"-reverse")
if err != nil { if err != nil {
log.Printf("Failed to create client channel: " + err.Error()) logger.Printf("Failed to create client channel: " + err.Error())
continue continue
} }
rpcClient := rpc.NewClient(clientChannel) rpcClient := rpc.NewClient(clientChannel)
if s.CallbackFunc != nil { if s.CallbackFunc != nil {
s.CallbackFunc(rpcClient, sshConn) s.CallbackFunc(rpcClient, sshConn)
} }
log.Printf("Started SSH RPC client") logger.Printf("Started SSH RPC client")
default: default:
log.Printf("Unknown subsystem: %s", req.Payload) logger.Printf("Unknown subsystem: %s", req.Payload)
} }
} }
if !ok { if !ok {
log.Printf("declining %s request...", req.Type) logger.Printf("declining %s request...", req.Type)
} }
req.Reply(ok, nil) req.Reply(ok, nil)
} }