controllers

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SSHclient            *ssh.Client
	SSHsession           *ssh.Session
	MockSSHServer        = false
	MockSSHHostString    = "sftp-mock-test"
	MockSSHUser          = "test"
	MockSSHPass          = "test"
	PinCode              string
	TimeToWaitInvalidPin time.Duration
	ApiConnections       = make(map[string]ApiConnectionStruct)
)

Defines global variables

Functions

func CompileJSONResult

func CompileJSONResult(result bool, message string, otherData ...map[string]interface{}) map[string]interface{}

CompileJSONResult returns map[string]interface{} from input. Function helps to compile result for JSON output

func ConnectSSH

func ConnectSSH(host, username, pass, port string) (string, error)

func DownloadDirectory

func DownloadDirectory(sourcePath, localPath, fileName string, session *ssh.Session) (string, error)

func DownloadFile

func DownloadFile(localPath, fileName, fileNamePost string, session *ssh.Session) (string, error)

func FormatBytes

func FormatBytes(size float64) string

FormatBytes returns formatted string of bytes (1024 bytes -> 1KB)

func GeneratePinCode

func GeneratePinCode()

func LocalHomeDirectory

func LocalHomeDirectory() string

func LocalPathCompletion

func LocalPathCompletion(path string) ([]map[string]interface{}, string, error)

func PublicKeyFile

func PublicKeyFile(file string) ssh.AuthMethod

PublicKeyFile returns ssh.AuthMethod which is needed to create additional AuthMethod from private key file

func RandStringBytes

func RandStringBytes(n int) string

func RemotePathCompletion

func RemotePathCompletion(session *ssh.Session, path string) ([]map[string]interface{}, string, error)

func Round

func Round(val float64, roundOn float64, places int) (newVal float64)

Round returns round of value.

func UnTarArchive

func UnTarArchive(name, path string) (string, error)

Types

type ApiConnectionStruct

type ApiConnectionStruct struct {
	Ip       string `json:"ip" example:"127.0.0.1" required:"true"`
	User     string `json:"user" example:"root"`
	Password string `json:"password"`
	Port     string `json:"port" example:"22"`
}

type ApiV1

type ApiV1 struct {
	*revel.Controller
}

func (ApiV1) Connect

func (c ApiV1) Connect() revel.Result

@Summary Connect via SSH @Description connect via SSH and store connection @ID connect @Accept json @Produce json @Param JSON body controllers.ApiConnectionStruct true "Connection information" @Success 200 {object} controllers.GeneralResponse "Success with connection ID in message" @Failure 403 {string} string "Not authorized!" @Router /connect [put]

func (ApiV1) Disconnect

func (c ApiV1) Disconnect(id string) revel.Result

@Summary Disconnect @Description remove stored connection @ID disconnect @Accept json @Produce json @Param id path string true "Connection ID" @Success 200 {object} controllers.GeneralResponse "Success" @Failure 403 {string} string "Not authorized!" @Router /disconnect/{id} [delete]

func (ApiV1) Download

func (c ApiV1) Download(id string) revel.Result

@Summary Download @Description download file or directory @ID download @Produce json @Param id path string true "Connection ID" @Param path query string true "Path to file OR directory" @Param save_to query string false "If not empty than download to.. otherwise file/directory will be downloaded to local home directory" @Success 200 {object} controllers.GeneralResponse "Success" @Failure 403 {string} string "Not authorized!" @Router /download/{id} [get]

func (ApiV1) GetConnections

func (c ApiV1) GetConnections(id string) revel.Result

@Summary Get connections @Description get list of stored connections @ID get-connections @Produce json @Success 200 {object} controllers.GetConnectionsStruct "Success" @Failure 403 {string} string "Not authorized!" @Router /getConnections [get]

func (ApiV1) GetLocalHomeDirectory

func (c ApiV1) GetLocalHomeDirectory(id string) revel.Result

@Summary Get local home directory @ID get-local-home-directory @Produce json @Success 200 {object} controllers.GeneralResponse "Success with local path in message" @Failure 403 {string} string "Not authorized!" @Router /getLocalHomeDirectory [get]

func (ApiV1) GetLocalPathCompletion

func (c ApiV1) GetLocalPathCompletion(id string) revel.Result

@Summary Get local path completion @Description list local directories like "double tab" @ID get-local-path-completion @Produce json @Param path query string true "Local path" @Success 200 {object} controllers.GetPathCompletionStruct "Success with list of items" @Failure 403 {string} string "Not authorized!" @Router /getLocalPathCompletion [get]

func (ApiV1) GetRemoteHomeDirectory

func (c ApiV1) GetRemoteHomeDirectory(id string) revel.Result

@Summary Get remote home directory @Description get remote home directory path @ID get-remote-home-directory-path @Produce json @Param id path string true "Connection ID" @Success 200 {object} controllers.GeneralResponse "Success with home directory path in message" @Failure 403 {string} string "Not authorized!" @Router /getRemoteHomeDirectory/{id} [get]

func (ApiV1) GetRemotePathCompletion

func (c ApiV1) GetRemotePathCompletion(id string) revel.Result

@Summary Get remote path completion @Description list remote directories like "double tab" @ID get-remote-path-completion @Produce json @Param id path string true "Connection ID" @Param path query string true "Remote path" @Success 200 {object} controllers.GetPathCompletionStruct "Success with list of items" @Failure 403 {string} string "Not authorized!" @Router /getRemotePathCompletion/{id} [get]

func (ApiV1) Help

func (c ApiV1) Help() revel.Result

type App

type App struct {
	*revel.Controller
}

func (App) ConnectViaSSH

func (c App) ConnectViaSSH() revel.Result

ConnectViaSSH returns JSON which contains: result: true for success/false for any error message: empty if success, message if error remote_path: remote home directory local_path: local home directory errors: array of messages received during the whole process of connecting via SSH

func (App) CreateNewLocalDirectory

func (c App) CreateNewLocalDirectory() revel.Result

CreateNewLocalDirectory creates new local directory and returns JSON which contains: result: true for success/false for any error message: empty if success, message if error new_path: path to newly created directory

func (App) Download

func (c App) Download() revel.Result

Download returns JSON which contains: result: true for success/false for any error message: empty if success, message if error If success function downloads file or directory locally

func (App) EstablishSSHConnection

func (c App) EstablishSSHConnection() revel.Result

EstablishSSHConnection is a helper function which is used to connect via SSH and accepts ssh_ip, ssh_user, ssh_password, ssh_port

func (App) GetLocalPathCompletion

func (c App) GetLocalPathCompletion() revel.Result

GetLocalPathCompletion acts like double tab for local and returns JSON which contains: result: true for success/false for any error message: empty if success, message if error items: list of found files/folders

func (App) GetPath

func (c App) GetPath() revel.Result

GetPath returns JSON which contains: result: true for success/false for any error message: empty if success, message if error path: formatted path from input

func (App) GetRemotePathCompletion

func (c App) GetRemotePathCompletion() revel.Result

GetRemotePathCompletion acts like double tab for remote and returns JSON which contains: result: true for success/false for any error message: empty if success, message if error items: list of found files/folders

func (App) Index

func (c App) Index() revel.Result

Index returns just index page

func (App) LocalPathGoTo

func (c App) LocalPathGoTo() revel.Result

LocalPathGoTo returns JSON which contains: result: true for success/false for any error message: empty if success, message if error local_files: list of local files local_path_separator: local separator which is needed for navigation compatible with Windows/*nix based systems

func (App) RemotePathGoTo

func (c App) RemotePathGoTo() revel.Result

RemotePathGoTo returns JSON which contains: result: true for success/false for any error message: empty if success, message if error remote_files: list of remote files

func (App) SetPinCode

func (c App) SetPinCode() revel.Result

func (App) TestSSHConnection

func (c App) TestSSHConnection() revel.Result

TestSSHConnection returns if connection via SSH was made successfully or not it just executed function EstablishSSHConnection

type FileStructureStruct

type FileStructureStruct struct {
	Path      string
	Directory bool
	Symlink   bool
}

type GeneralResponse

type GeneralResponse struct {
	Result  bool   `json:"result"`
	Message string `json:"message"`
}

type GetConnectionsStruct

type GetConnectionsStruct struct {
	Result      bool                  `json:"result"`
	Message     string                `json:"message"`
	Connections []ApiConnectionStruct `json:"connections"`
}

type GetPathCompletionStruct

type GetPathCompletionStruct struct {
	Result  bool     `json:"result"`
	Message string   `json:"message"`
	Items   []string `json:"items"`
}

type PassThru

type PassThru struct {
	io.Reader
	// contains filtered or unexported fields
}

func (*PassThru) Read

func (pt *PassThru) Read(p []byte) (int, error)

Read implements PassThru struct. Used for displaying copying progress

type SSHSessionStruct

type SSHSessionStruct struct {
	Client   *ssh.Client
	Session  *ssh.Session
	ErrorErr error
	ErrorStr string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL