Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
Lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalk0 committed Jan 6, 2023
1 parent 25338ac commit ca1fd89
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
8 changes: 6 additions & 2 deletions commands/rconnect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ case $user in
source rvsh.sh rconnect
prompt "connect" $machine $user;;
2 )
echo "$machine doesn't exist"
echo "$machine doesn't exist";;
6 )
echo "The machine name must only contain miniscule letters and digits"
esac;;
* )
source verifications.sh 2 $machine $user
Expand All @@ -23,6 +25,8 @@ case $user in
2 )
echo "$machine doesn't exist";;
4 )
echo "You don't have access to $machine"
echo "You don't have access to $machine";;
6 )
echo "The machine name must only contain miniscule letters and digits"
esac
esac
10 changes: 9 additions & 1 deletion commands/user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function add_machine {
return 1;;
4 )
sed -ri "s/^($user_name:.*:.*)( #.*|)$/\1,$machine_name\2/;s/:,/:/" $file
return 0
return 0;;
6 )
echo "The machine name must only contain miniscule letters and digits"
return 1
esac
}

Expand Down Expand Up @@ -55,6 +58,11 @@ case $? in
while [[ true ]]; do
read -p "Do you want to add or remove the permission to access a machine? " choice
read -p "Which machine do you want? " machine_name
source verifications.sh 0 $machine_name
if [[ $? == 6 ]]; then
echo "The machine name must only contain miniscule letters and digits"
continue
fi
case ${choice,,} in
"add" )
add_machine
Expand Down
12 changes: 12 additions & 0 deletions commands/write.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ if [[ $# -ge 4 ]]; then
user_name=$(echo $names | cut -d'@' -f1)
machine_name=$(echo $names | cut -d'@' -f2)

source verifications.sh 0 $machine_name
if [[ $? == 6 ]]; then
echo "The machine name must only contain miniscule letters and digits"
return
fi
source verifications.sh 1 $user_name
if [[ $? == 6 ]]; then
echo "The user name must only contain miniscule letters and digits"
return
fi

compt=0
while read ligne
do
if [[ $(echo $ligne | grep "$machine_name-$user_name") != '' ]]; then
Expand Down
2 changes: 1 addition & 1 deletion rvsh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ elif [ $# -eq 3 ] && [ $1 == "-connect" ]; then
4 )
echo "This user doesn't have access to this machine";;
6 )
echo "The user name must only contain miniscule letters and digits"
echo "The user name and machine name must only contain miniscule letters and digits"
esac
elif [ $# -eq 1 ] && [ $1 == "-help" ]; then
help
Expand Down
16 changes: 11 additions & 5 deletions verifications.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

function test_machine { #$1=machine
if [[ $1 =~ [^0-9a-z]+ ]]; then
return 6 #The user name or machine name contains not allowed characters
fi
file="./machines"
compt=0
while read -r ligne
Expand All @@ -22,7 +25,7 @@ function test_machine { #$1=machine

function test_user { #$1=user
if [[ $1 =~ [^0-9a-z]+ ]]; then
return 6 #The user name contains not allowed characters
return 6 #The user name or machine name contains not allowed characters
fi
file="./users"
compt=0
Expand All @@ -46,15 +49,18 @@ function test_user { #$1=user

function test_user_access_machine { #$1=machine $2=user
test_machine $1
if [[ $? != 0 ]]; then
return 2 #The machine doesn't exist
fi
case $? in
2 )
return 2;; #The machine doesn't exist
6 )
return 6 #The user name or machine name contains not allowed characters
esac
test_user $2
case $? in
3 )
return 3;; #The user doesn't exist
6 )
return 6;; #The user name contains not allowed characters
return 6 #The user name or machine name contains not allowed characters
esac
machines=$(sed -n "$ligne"p $file | cut -d ':' -f3)
if [[ $(echo $machines | grep $1) == '' ]]; then
Expand Down

0 comments on commit ca1fd89

Please sign in to comment.