Updated tools for new version and add agent scipt
This commit is contained in:
48
Server/Tools/latest/add-namespace
Executable file
48
Server/Tools/latest/add-namespace
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ $# -ne 2 ] && echo "Usage: $0 <namespace> <owner>" && exit 1
|
||||
|
||||
if [ ! -f "$(which uuidgen 2> /dev/null)" ]; then
|
||||
echo "$0 requires uuidgen but it's not installed. Aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NAMESPACE=$1
|
||||
OWNER=$2
|
||||
|
||||
[ -z "$TENANT_ID" ] && TENANT_ID=`uuidgen`
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
if ! echo $NAMESPACE | grep -q -E "^([a-zA-Z0-9]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*?$"; then
|
||||
echo "ERROR: namespace is not a valid RFC1123 hostname format"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EXISTS=$(mongo main --quiet --eval "db.namespaces.find({ name: '$NAMESPACE' })")
|
||||
|
||||
if [ -n "$EXISTS" ]; then
|
||||
echo "ERROR: namespace already exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OWNER_ID=`mongo main --quiet --eval "JSON.stringify(db.users.findOne({ name:'$OWNER' }))" | jq -r '._id."$oid" // empty'`
|
||||
|
||||
if [ -z "$OWNER_ID" ]; then
|
||||
echo "ERROR: owner not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INSERTED=`mongo main --quiet --eval "db.namespaces.insert({ name: '$NAMESPACE', owner: '$OWNER_ID', tenant_id: '$TENANT_ID', members: [ '$OWNER_ID' ], settings: {session_record: true}}).nInserted"`
|
||||
|
||||
if [ $INSERTED -eq 1 ]; then
|
||||
echo "Namespace added: $NAMESPACE"
|
||||
echo "Owner: $OWNER"
|
||||
echo "Tenant ID: $TENANT_ID"
|
||||
else
|
||||
echo "ERROR: Failed to add namespace"
|
||||
fi
|
||||
32
Server/Tools/latest/add-user
Executable file
32
Server/Tools/latest/add-user
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ $# -ne 3 ] && echo "Usage: $0 <username> <password> <email>" && exit 1
|
||||
|
||||
if [ ! -f "$(which uuidgen 2> /dev/null)" ]; then
|
||||
echo "$0 requires uuidgen but it's not installed. Aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
USERNAME=$1
|
||||
PASSWORD=`printf $2 | sha256sum | awk '{ print $1 }'`
|
||||
EMAIL=$3
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
EXISTS=$(mongo main --quiet --eval "db.users.find({ username: '$USERNAME' })")
|
||||
|
||||
if [ -n "$EXISTS" ]; then
|
||||
echo "ERROR: user already exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INSERTED=`mongo main --quiet --eval "db.users.insert({ name: '$USERNAME', username: '$USERNAME', password: '$PASSWORD', email: '$EMAIL' }).nInserted"`
|
||||
|
||||
if [ $INSERTED -eq 1 ]; then
|
||||
echo "User added: $USERNAME"
|
||||
else
|
||||
echo "ERROR: Failed to add user"
|
||||
fi
|
||||
34
Server/Tools/latest/add-user-namespace
Executable file
34
Server/Tools/latest/add-user-namespace
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ $# -ne 2 ] && echo "Usage: $0 <username> <namespace>" && exit 1
|
||||
|
||||
USERNAME=$1
|
||||
NAMESPACE=$2
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
ID=`mongo main --quiet --eval "JSON.stringify(db.users.findOne({ name:'$USERNAME' }))" | jq -r '._id."$oid" // empty'`
|
||||
|
||||
if [ -z "$ID" ]; then
|
||||
echo "ERROR: user does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TENANT_ID=`mongo main --quiet --eval "JSON.stringify(db.namespaces.findOne({ name:'$NAMESPACE' }))" | jq -r '.tenant_id // empty'`
|
||||
|
||||
if [ -z "$TENANT_ID" ]; then
|
||||
echo "ERROR: namespace does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MODIFIED=`mongo main --quiet --eval "db.namespaces.updateOne({ tenant_id: '$TENANT_ID' }, { \\$addToSet: { members: '$ID' } }).modifiedCount"`
|
||||
|
||||
if [ $MODIFIED -eq 1 ]; then
|
||||
echo "User $USERNAME added to namespace $NAMESPACE"
|
||||
else
|
||||
echo "ERROR: Failed to add user to namespace"
|
||||
fi
|
||||
26
Server/Tools/latest/del-namespace
Executable file
26
Server/Tools/latest/del-namespace
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -z $1 ] && echo "Usage: $0 <namespace>" && exit 1
|
||||
|
||||
NAMESPACE=$1
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
EXISTS=$(mongo main --quiet --eval "db.namespaces.find({ name: '$NAMESPACE' })")
|
||||
|
||||
if [ -z "$EXISTS" ]; then
|
||||
echo "ERROR: namespace does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REMOVED=`mongo main --quiet --eval "db.namespaces.remove({name: '$NAMESPACE'}).nRemoved"`
|
||||
|
||||
if [ $REMOVED -gt 0 ]; then
|
||||
echo "Namespace deleted"
|
||||
else
|
||||
echo "ERROR: Failed to delete namespace"
|
||||
fi
|
||||
26
Server/Tools/latest/del-user
Executable file
26
Server/Tools/latest/del-user
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -z $1 ] && echo "Usage: $0 <username>" && exit 1
|
||||
|
||||
USERNAME=$1
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
EXISTS=$(docker-compose exec -T mongo mongo main --quiet --eval "db.users.find({ username: '$USERNAME' })")
|
||||
|
||||
if [ -z "$EXISTS" ]; then
|
||||
echo "ERROR: user does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
REMOVED=`mongo main --quiet --eval "db.users.remove({username: '$USERNAME'}).nRemoved"`
|
||||
|
||||
if [ $REMOVED -gt 0 ]; then
|
||||
echo "User deleted"
|
||||
else
|
||||
echo "ERROR: Failed to delete user"
|
||||
fi
|
||||
34
Server/Tools/latest/del-user-namespace
Executable file
34
Server/Tools/latest/del-user-namespace
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ $# -ne 2 ] && echo "Usage: $0 <username> <namespace>" && exit 1
|
||||
|
||||
USERNAME=$1
|
||||
NAMESPACE=$2
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
ID=`mongo main --quiet --eval "JSON.stringify(db.users.findOne({ name:'$USERNAME' }))" | jq -r '._id."$oid" // empty'`
|
||||
|
||||
if [ -z "$ID" ]; then
|
||||
echo "ERROR: user does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TENANT_ID=`mongo main --quiet --eval "JSON.stringify(db.namespaces.findOne({ name:'$NAMESPACE' }))" | jq -r '.tenant_id // empty'`
|
||||
|
||||
if [ -z "$TENANT_ID" ]; then
|
||||
echo "ERROR: namespace does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MODIFIED=`mongo main --quiet --eval "db.namespaces.updateOne({ tenant_id: '$TENANT_ID' }, { \\$pull: { members: '$ID' } }).modifiedCount"`
|
||||
|
||||
if [ $MODIFIED -eq 1 ]; then
|
||||
echo "User $USERNAME removed from namespace $NAMESPACE"
|
||||
else
|
||||
echo "ERROR: Failed to remove user from namespace"
|
||||
fi
|
||||
27
Server/Tools/latest/reset-user-password
Executable file
27
Server/Tools/latest/reset-user-password
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -z $1 ] || [ -z $2 ] && echo "Usage: $0 <username> <password>" && exit 1
|
||||
|
||||
USERNAME=$1
|
||||
PASSWORD=`printf $2 | sha256sum | awk '{ print $1 }'`
|
||||
|
||||
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
||||
echo "ERROR: mongoDB service is not running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
EXISTS=$(mongo main --quiet --eval "db.users.find({ username: '$USERNAME' })")
|
||||
|
||||
if [ -z "$EXISTS" ]; then
|
||||
echo "ERROR: user does not exists!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MODIFIED=`mongo main --quiet --eval "db.users.update({ username: '$USERNAME' }, { \\$set: { password: '$PASSWORD' } }).nModified"`
|
||||
|
||||
if [ $MODIFIED -eq 1 ]; then
|
||||
echo "Password changed"
|
||||
else
|
||||
echo "User password not changed"
|
||||
fi
|
||||
@@ -71,11 +71,18 @@ systemctl start openresty mongod
|
||||
wget https://git.bprieshof.nl/ci/Releases/ShellHub/"$RelVer"/.env -O /opt/ShellHub/shellhub.env
|
||||
wget https://git.bprieshof.nl/ci/Releases/ShellHub/"$RelVer"/BinServices/ShellHubSSH-amd64 -O /opt/ShellHub/ShellHubSSH
|
||||
wget https://git.bprieshof.nl/ci/Releases/ShellHub/"$RelVer"/BinServices/ShellHubAPI-amd64 -O /opt/ShellHub/ShellHubAPI
|
||||
wget https://git.bprieshof.nl/ci/Releases/ShellHub/"$RelVer"/BinAgent/ShellHubAgent-amd64 -O /opt/ShellHub/ui/agent-amd64
|
||||
wget https://git.bprieshof.nl/ci/Releases/ShellHub/"$RelVer"/BinServices/webui.tar.gz -O /tmp/webui.tar.gz
|
||||
mv ../Agent/Kickstart_template /opt/ShellHub/ui/kickstart.sh
|
||||
chmod +x /opt/ShellHub/ShellHubAPI
|
||||
chmod +x /opt/ShellHub/ShellHubSSH
|
||||
tar -zxf /tmp/webui.tar.gz -C /opt/ShellHub/ui
|
||||
mv Tools/* /opt/ShellHub/tools/
|
||||
if [ "$RelVer" = "stable" ]
|
||||
mv Tools/stable/* /opt/ShellHub/tools/
|
||||
elif [ "$RelVer" = "latest" ] || [ "$RelVer" = "latest_Tested" ]; then
|
||||
$PKGM install -y jq
|
||||
mv Tools/latest/* /opt/ShellHub/tools/
|
||||
fi
|
||||
|
||||
##Generating keys
|
||||
openssl genrsa -out /opt/ShellHub/keys/api_private_key 2048
|
||||
|
||||
Reference in New Issue
Block a user