Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Gossh/Bin/gossh
Binary file not shown.
Binary file modified Gossh/Bin/gossh.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Gossh/Gossh.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Gossh'

# Version number of this module.
ModuleVersion = '2.0.2'
ModuleVersion = '2.1.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
17 changes: 12 additions & 5 deletions Gossh/Public/Invoke-Gossh.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ function Invoke-Gossh {
$EnableCredential,

[Parameter(Mandatory = $false)]
[bool]$ConfigFile = $false
[bool]$ConfigFile = $false,

[Parameter(Mandatory = $false)]
[string]$ConfigPath,

[Parameter(Mandatory = $false)]
[bool]$SecondaryLogin = $false
)

$VerbosePrefix = "Invoke-Gossh:"
Expand All @@ -42,6 +48,7 @@ function Invoke-Gossh {
if ($IsExecutable -notmatch 'true') {
$ExecutableCheckCommand = 'bash -c "chmod +x ' + $NixPath + '"'
$MakeExecutable = Invoke-Expression -Command $ExecutableCheckCommand
Write-Verbose $MakeExecutable
}
}
default {
Expand All @@ -59,7 +66,6 @@ function Invoke-Gossh {
#############################################################
# \gossh.exe -h 1.1.1.1 -u admin -p password -P 4001 -C "terminal pager 0/show run interface" -f=false -t 35

$GosshCommand = $Command -join '||'
$GosshUsername = $Credential.UserName
$GosshPassword = $Credential.GetNetworkCredential().Password

Expand All @@ -68,9 +74,10 @@ function Invoke-Gossh {
$GosshExpression += ' -u ' + $GosshUsername
$GosshExpression += ' -p ' + "'" + $GosshPassword + "'"
$GosshExpression += ' -P ' + $Port
$GosshExpression += ' -C "' + $GosshCommand + '"'
$GosshExpression += ' -f=' + $ConfigFile

if ($ConfigFile) { $GosshExpression += ' -f -d ' + $ConfigPath }else {
$GosshCommand = $Command -join '||' ; $GosshExpression += ' -C "' + $GosshCommand + '"'
}
if ($SecondaryLogin) { $GosshExpression += ' -s' }
if ($EnableCredential) {
#$EnableCredential = New-Object System.Management.Automation.PSCredential ('test', $EnablePassword)
$EnablePassword = $EnableCredential.GetNetworkCredential().Password
Expand Down
10 changes: 5 additions & 5 deletions go/MisFunctions.go → go/MisFunctions.go.old
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ func handleError(err error) {
fmt.Println(err)
}
}
func StringToArray1(CLIAurguments string) (CLIReturn []string) {
StringSplit := strings.Split(CLIAurguments, ",")
func StringToArray1(CLIArguments string) (CLIReturn []string) {
StringSplit := strings.Split(CLIArguments, ",")
var StringReturn []string
for _, stringssplit := range StringSplit {
StringReturn = append(StringReturn, stringssplit)
}
return StringReturn
}
func StringToArray(CLIAurguments string) (Commands []string) {
StringSplit := strings.Split(CLIAurguments, "||")
func StringToArray(CLIArguments string) (Commands []string) {
StringSplit := strings.Split(CLIArguments, "||")
var Count int
for i, _ := range StringSplit {
for i := range StringSplit {
Count = i
}
var array = make([]string, Count+1)
Expand Down
75 changes: 75 additions & 0 deletions go/MiscFunctions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"bufio"
"fmt"
"github.com/TwiN/go-color"
"os"
"strings"
)

func handleError(err error, fatal bool, message string) {
if nil != err {
switch {
case len([]rune(message)) == 0:
fmt.Println(color.Ize(color.Bold + color.Red,"uncategorized error raw error bellow:"))
fmt.Println(err)
case fatal:
fmt.Println(color.Ize(color.Bold + color.Red,"Fatal error encountered terminating execution : "+message))
fmt.Println(err)
os.Exit(1)

case len([]rune(message)) >= 1:
fmt.Println(color.Ize(color.Bold + color.Red,message))
fmt.Println(err)
}
}
}

func readConfigFile(filepath string) []string {
var ConfigArray []string
ConfigFile, err := os.Open(filepath)
handleError(err, true,"Error encountered opening config file")
defer func(ConfigFile *os.File) {
err := ConfigFile.Close()
handleError(err, true,"Error encountered closing config file")
}(ConfigFile)
FileScanner := bufio.NewScanner(ConfigFile)
for FileScanner.Scan() {
ConfigArray = append(ConfigArray, FileScanner.Text())
}
return ConfigArray
}

func writeBuffer2Txt(fileName string, text string, append bool) {
if append {
text += "\n"
}
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if nil != err {
handleError(err, true,"Error encountered opening log file")
}
if _, err := f.Write([]byte(text)); err != nil {
handleError(err, true, "Error encountered writing to log file")
}
if err := f.Close(); err != nil {
handleError(err, true,"Error encountered closing log file")
}

}

func stringToArray(CLIArguments string) (Commands []string) {
StringSplit := strings.Split(CLIArguments, "||")
var Count int
for i := range StringSplit {
Count = i
}
var array = make([]string, Count+1)
for i, stringsSplit := range StringSplit {
if stringsSplit != " " {
array[i] = strings.TrimRight(stringsSplit, " ")
}
}
if verbose {println(color.Ize(color.Yellow,"Commands array:\n" + strings.Join(array,"\n")))}
return array
}
86 changes: 48 additions & 38 deletions go/Run.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
package main

import (
"flag"
"fmt"
"github.com/TwiN/go-color"
"github.com/jessevdk/go-flags"
"os"
)

var Banner = false
var bannerchecked = false
var returnstring = ""
var returnStrings string
var options Options
var verbose bool
var secondaryLogin bool

type Options struct {
HostName string `short:"h" long:"hostname" description:"device url/ip"`
UserName string `short:"u" long:"username" description:"username used for authentication"`
PassWord string `short:"p" long:"password" description:"password used for authentication"`
EnablePassword string `short:"e" long:"enablepassword" description:"username used for authentication"`
Port int `short:"P" long:"port" description:"tcp port device is listening on" default:"22"`
TimeOut int `short:"t" long:"timeout" description:"timeout value in seconds for each command execution" default:"10"`
CliArguments string `short:"C" long:"cliarguments" description:"array containing cmdS to be run" `
DirectoryPath string `short:"d" long:"filePath" description:"filePath to document containing cmdS to be run"`
UseFile bool `short:"f" long:"usefile" description:"bool switch for using cmdS file"`
SecondaryLogin bool `short:"s" long:"secondarylogin" description:"bool switch for entering login credentials again as required by some cisco switches"`
Telnet bool `short:"T" long:"telnet" description:"option to use telnet instead of ssh"`
Help bool `short:"H" long:"help" description:"output help"`
Verbose bool `short:"v" long:"verbose" description:"print verbose"`
}

func main() {
var HostName string
var UserName string
var Password string
var EnablePassword string
var SSH bool
var File bool
var Port string
var CLIArguments string
var TimeoutValue int
//setting CLI Parameters//
flag.StringVar(&HostName, "h", "", "specify the host you are connecting to with either a hostname or ip address")
flag.StringVar(&UserName, "u", "", "specify device username")
flag.StringVar(&Password, "p", "", "specify device password")
flag.StringVar(&EnablePassword, "e", "", "specify device enable password")
flag.BoolVar(&SSH, "c", true, "specify connection type default is SSH")
flag.StringVar(&Port, "P", "22", "use this to specify port default is 22")
flag.StringVar(&CLIArguments, "C", "", "specify CLI commands to run on host device")
flag.BoolVar(&File, "f", false, "set to true of you are sending a config file")
flag.IntVar(&TimeoutValue, "t", 35, "change default timeout value")
flag.Parse()
switch File {
case false:
switch SSH {
case true:
InvokeSSH(HostName, Port, UserName, Password, StringToArray(CLIArguments), TimeoutValue)
case false:
//InvokeTelnet(HostName, UserName, Password, EnablePassword, Port, StringToArray1(CLIArguments))
}
case true:
switch SSH {
case true:
InvokeSSH(HostName, Port, UserName, Password, readLines(CLIArguments), TimeoutValue)
case false:
//InvokeTelnet(HostName, UserName, Password, EnablePassword, Port, StringToArray1(CLIArguments))
parser:= flags.NewParser(&options,flags.Default&^flags.HelpFlag)
_, err := parser.Parse()
if nil != err {handleError(err,true,"Error parsing CLI arguments")}
if options.Help{parser.WriteHelp(os.Stdout);os.Exit(0)}
//bytes := make([]byte, 32)
//if _, err := rand.Read(bytes); err != nil {
// handleError(err, true, "failed to create encryption key")
//}
//key := hex.EncodeToString(bytes)
verbose = options.Verbose
secondaryLogin = options.SecondaryLogin
switch {
case options.UseFile:
commandArguments := readConfigFile(options.DirectoryPath)
switch {
case options.Telnet:
//
default:
sshDial(options.HostName,options.Port,options.UserName,options.PassWord,commandArguments,options.TimeOut,options.EnablePassword)
}
case options.Telnet:
println(color.Ize(color.Red,"Telnet functions are not ready yet terminating application")); os.Exit(1)
default:
sshDial(options.HostName, options.Port, options.UserName, options.PassWord,stringToArray(options.CliArguments),options.TimeOut,options.EnablePassword)
}
fmt.Println(returnStrings)
}
Loading