Moved logging to use package level logger. Disabled by default.
This commit is contained in:
		
							parent
							
								
									a9e6dd5ffc
								
							
						
					
					
						commit
						eb89e656d7
					
				
							
								
								
									
										13
									
								
								client.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								client.go
									
									
									
									
									
								
							@ -1,7 +1,6 @@
 | 
			
		||||
package sshrpc
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/rpc"
 | 
			
		||||
 | 
			
		||||
	"dev.justinjudd.org/justin/easyssh"
 | 
			
		||||
@ -98,10 +97,10 @@ func (c *Client) openRPCServerChannel(channelName string) error {
 | 
			
		||||
func acceptRPCServerRequest(rpcServer *rpc.Server, newChannel ssh.NewChannel) {
 | 
			
		||||
	channel, requests, err := newChannel.Accept()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Printf("could not accept channel (%s)", err)
 | 
			
		||||
		logger.Printf("could not accept channel (%s)", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	log.Printf("Accepted channel")
 | 
			
		||||
	logger.Printf("Accepted channel")
 | 
			
		||||
 | 
			
		||||
	// Channels can have out-of-band requests
 | 
			
		||||
	go func(in <-chan *ssh.Request) {
 | 
			
		||||
@ -111,19 +110,19 @@ func acceptRPCServerRequest(rpcServer *rpc.Server, newChannel ssh.NewChannel) {
 | 
			
		||||
 | 
			
		||||
			case easyssh.SubsystemRequest:
 | 
			
		||||
				ok = true
 | 
			
		||||
				log.Printf("subsystem '%s'", req.Payload)
 | 
			
		||||
				logger.Printf("subsystem '%s'", req.Payload)
 | 
			
		||||
				switch string(req.Payload[4:]) {
 | 
			
		||||
				//RPCSubsystem Request made indicates client desires RPC Server access
 | 
			
		||||
				case RPCSubsystem:
 | 
			
		||||
					go rpcServer.ServeConn(channel)
 | 
			
		||||
					log.Printf("Started SSH RPC")
 | 
			
		||||
					logger.Printf("Started SSH RPC")
 | 
			
		||||
				default:
 | 
			
		||||
					log.Printf("Unknown subsystem: %s", req.Payload)
 | 
			
		||||
					logger.Printf("Unknown subsystem: %s", req.Payload)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
			if !ok {
 | 
			
		||||
				log.Printf("declining %s request...", req.Type)
 | 
			
		||||
				logger.Printf("declining %s request...", req.Type)
 | 
			
		||||
			}
 | 
			
		||||
			req.Reply(ok, nil)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								server.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								server.go
									
									
									
									
									
								
							@ -2,7 +2,6 @@ package sshrpc
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/rpc"
 | 
			
		||||
 | 
			
		||||
	"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) {
 | 
			
		||||
	go func(in <-chan *ssh.Request) {
 | 
			
		||||
		for req := range in {
 | 
			
		||||
@ -63,30 +63,30 @@ func (s *Server) HandleChannel(newChannel ssh.NewChannel, channel ssh.Channel, r
 | 
			
		||||
 | 
			
		||||
			case easyssh.SubsystemRequest:
 | 
			
		||||
				ok = true
 | 
			
		||||
				log.Printf("subsystem '%s'", req.Payload[4:])
 | 
			
		||||
				logger.Printf("subsystem '%s'", req.Payload[4:])
 | 
			
		||||
				switch string(req.Payload[4:]) {
 | 
			
		||||
				//RPCSubsystem Request made indicates client desires RPC Server access
 | 
			
		||||
				case RPCSubsystem:
 | 
			
		||||
					go s.ServeConn(channel)
 | 
			
		||||
					log.Printf("Started SSH RPC")
 | 
			
		||||
					logger.Printf("Started SSH RPC")
 | 
			
		||||
					// triggers reverse RPC connection as well
 | 
			
		||||
					clientChannel, err := openRPCClientChannel(sshConn, s.ChannelName+"-reverse")
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						log.Printf("Failed to create client channel: " + err.Error())
 | 
			
		||||
						logger.Printf("Failed to create client channel: " + err.Error())
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
					rpcClient := rpc.NewClient(clientChannel)
 | 
			
		||||
					if s.CallbackFunc != nil {
 | 
			
		||||
						s.CallbackFunc(rpcClient, sshConn)
 | 
			
		||||
					}
 | 
			
		||||
					log.Printf("Started SSH RPC client")
 | 
			
		||||
					logger.Printf("Started SSH RPC client")
 | 
			
		||||
				default:
 | 
			
		||||
					log.Printf("Unknown subsystem: %s", req.Payload)
 | 
			
		||||
					logger.Printf("Unknown subsystem: %s", req.Payload)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
			if !ok {
 | 
			
		||||
				log.Printf("declining %s request...", req.Type)
 | 
			
		||||
				logger.Printf("declining %s request...", req.Type)
 | 
			
		||||
			}
 | 
			
		||||
			req.Reply(ok, nil)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user