Execute intercepts execution of command, implements authorizing user, validates it and poxing command to real terminal (gopherTerminal) method
(command string)
| 96 | // Execute intercepts execution of command, implements authorizing user, validates it and |
| 97 | // poxing command to real terminal (gopherTerminal) method |
| 98 | func (t *Terminal) Execute(command string) (resp string, err error) { |
| 99 | // If user allowed to execute send commands then, for example we can decide which terminal can be used, remote or local etc.. |
| 100 | // but for example we just creating new instance of terminal, |
| 101 | // set current user and send user command to execution in terminal |
| 102 | t.gopherTerminal = &GopherTerminal{User: t.currentUser} |
| 103 | |
| 104 | // For example our proxy can log or output intercepted execution... etc |
| 105 | fmt.Printf("PROXY: Intercepted execution of user (%s), asked command (%s)\n", t.currentUser, command) |
| 106 | |
| 107 | // Transfer data to original object and execute command |
| 108 | if resp, err = t.gopherTerminal.Execute(command); err != nil { |
| 109 | err = fmt.Errorf("I know only how to execute commands: say_hi, man") |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | // authorize validates user right to execute commands |
| 117 | func authorizeUser(user string) (err error) { |