diff --git a/DEBIAN/control b/DEBIAN/control index 4cfed60..ff4fa1e 100644 --- a/DEBIAN/control +++ b/DEBIAN/control @@ -1,6 +1,6 @@ Package: multish -Version: 0.2.1 +Version: 0.3.0 Architecture: all Maintainer: Raul Tierno -Depends: tmux,sshpass +Depends: tmux,sshpass,nmap Description: multish allows you to connect and act in multiple ssh connection simultaneously diff --git a/DEBIAN/postinst b/DEBIAN/postinst new file mode 100755 index 0000000..69b5595 --- /dev/null +++ b/DEBIAN/postinst @@ -0,0 +1,24 @@ +#!/bin/bash +# file name preinst + +echo "Pre Installation code here ..." + + +function createFolderIfNotExists { + if [ ! -d $1 ]; then + mkdir -p $1 + fi +} + +function checkifDirectoryIsEmpty { + if [ -z "$(ls -A $1)" ]; then + echo "The directory $1 is empty" + cp /usr/share/multish/files/example $1/example + else + echo "The directory $1 is not empty. No Action" + fi +} + +FOLDER="/etc/multish/group" +createFolderIfNotExists $FOLDER +checkifDirectoryIsEmpty $FOLDER \ No newline at end of file diff --git a/README.md b/README.md index 1dc9e66..8a27d00 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,13 @@ al instalar tener por defecto en `/etc/multish/groups` los archivos de grupos a En la carpeta donde hayas descargado el archivo .deb apt/apt-get install instala el paquete y las dependencias. Poner './' para que sepa que es un archivo local y no un paquete de los repositorios ```sh -apt install ./multish_0.2.1_all.deb +apt install ./multish_0.3.0_all.deb ``` Si usas dpkg debes ejecutar despues apt para instalar las dependencias y finalizar la instalación ```sh -dpkg -i multish_X.Y.Z_all.deb +dpkg -i multish_0.3.0_all.deb apt-get -f install ``` diff --git a/multish_0.2.1_all.deb b/multish_0.3.0_all.deb similarity index 52% rename from multish_0.2.1_all.deb rename to multish_0.3.0_all.deb index 5b5f9e2..2acd0fc 100644 Binary files a/multish_0.2.1_all.deb and b/multish_0.3.0_all.deb differ diff --git a/usr/bin/multish b/usr/bin/multish index 05a0667..7f22830 100755 --- a/usr/bin/multish +++ b/usr/bin/multish @@ -3,7 +3,7 @@ # multissh - create a tmux-cssh connection from parameter or selected option # # Authors: Raul Tierno -# Fernando Lorenzo +# Fernando Lorenzo # # @@ -39,7 +39,7 @@ function checkargument { } function selectoption { - prompt="Select group: " + prompt="Select Option: " options=( $(find /etc/multish/group -type f -name "*" -print0 | xargs -0) ) echo "" @@ -47,13 +47,17 @@ function selectoption { echo "-----------------------------------------" PS3="$prompt " - select opt in "${options[@]}" "Copy SSH public key to group" "Quit" ; do - if (( REPLY == 2 + ${#options[@]} )) ; then + select opt in "${options[@]}" "Find hosts with port 22 open in network" "Copy SSH public key to group" "Quit" ; do + if (( REPLY == 3 + ${#options[@]} )) ; then break - elif (( REPLY == 1 + ${#options[@]} )); then + elif (( REPLY == 2 + ${#options[@]} )); then echo multish-copy-id exit + elif (( REPLY == 1 + ${#options[@]} )); then + echo + multish-discover-hosts + exit elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then echo "You picked $opt which is file $REPLY" cssh $opt diff --git a/usr/bin/multish-discover-hosts b/usr/bin/multish-discover-hosts new file mode 100755 index 0000000..2dea5d9 --- /dev/null +++ b/usr/bin/multish-discover-hosts @@ -0,0 +1,56 @@ +#!/bin/bash +# +# multissh-discovers-hosts - search for devices with 22 open port to store and connect to them +# +# Authors: Raul Tierno +# +# + +function findAllHostsWithPort22OpenInNetwork { + sudo nmap 192.168.1.1-254 -p22 -oG - | awk '/22\//{print $2 " # " $5}' +} + +function readFromCLIWithDefaultOption { + read -p "$1 [$2]: " result + if [ -z $result ]; then + result=$2 + fi + echo $result +} + +function getSuggestedNetwork { + echo $(ip -4 -o addr | awk ' {print $4}' | grep -v "127.0.0.1" | head -n 1) +} + +function getSuggestedName { + date +"%Y-%m-%d-%H-%M-%S-discover-results" +} + +function createFolderIfNotExists { + if [ ! -d $1 ]; then + mkdir -p $1 + fi +} + +SUGGESTEDNETWORK=$(getSuggestedNetwork) +SUGGESTEDNAME=$(getSuggestedName) + +NETWORK=$(readFromCLIWithDefaultOption "Define la red que quieres explorar" $SUGGESTEDNETWORK) +FILENAME=$(readFromCLIWithDefaultOption "Nombre de archivo donde se guardarán los resultados" $SUGGESTEDNAME) +FOLDER="/etc/multish/group/network-discoveries" + +echo "Explorando $NETWORK. Los resultados se guardarán en $FILENAME. Espere a que termine el proceso..." + +createFolderIfNotExists $FOLDER + +sudo nmap $NETWORK -p22 -oG - | awk '/22\/open/{print "root@" $2 " # " $5}' > $FOLDER/$FILENAME + +echo "Exploración Finalizada. Los resultados se han guardado en $FOLDER/$FILENAME" + +RUN=$(readFromCLIWithDefaultOption "¿Quieres conectarte ahora a los equipos encontrados? y/n " "y") +if [[ $RUN =~ ^[YySs]$ ]] +then + multish "$FOLDER/$FILENAME" +else + multish +fi \ No newline at end of file diff --git a/etc/multish/group/example b/usr/share/multish/files/example similarity index 100% rename from etc/multish/group/example rename to usr/share/multish/files/example