]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
ldap crm usercreate script
authorMichael Krause <michael.krause@digitaspixelpark.com>
Thu, 29 Feb 2024 09:15:04 +0000 (10:15 +0100)
committerMichael Krause <michael.krause@digitaspixelpark.com>
Thu, 29 Feb 2024 09:15:04 +0000 (10:15 +0100)
scripts/ldap_crm_usercreate.sh [new file with mode: 0644]

diff --git a/scripts/ldap_crm_usercreate.sh b/scripts/ldap_crm_usercreate.sh
new file mode 100644 (file)
index 0000000..088b75f
--- /dev/null
@@ -0,0 +1,194 @@
+#!/bin/bash
+# ldap user create for crm
+# v1.4
+# ppa mickraus
+# comment: check builduser()
+# need proper formating 
+# changelog: prep for better ldif build
+
+#setting global vars
+RUN=0          #counting the loop
+
+#function start main standalone
+function main_standalone() {
+printf "\033c"
+echo "`date`"
+echo -ne "this script is for creating crm ldap-users\n"
+getinputcli
+fixinputcli
+genuserpw
+outldapldif
+echo -ne "\n\n"
+read -p "Type 'q' to Quit; To redo press 'Enter': " REDO
+if [[ $REDO == "q" ]]; then
+return 1
+else
+printf "\033c"
+return 0
+fi
+}
+
+#function for getuser info from cli
+function getinputcli() {
+read -p "Given names: " GIVENNAMES
+read -p "Surname: " SURNAME
+read -p "Full LowerCase EMail: " LOWERCMAIL
+read -p "App right JIRA (y/n): " PPAPPJIRA
+read -p "App right Confluence (y/n): " PPAPPCONFLUENCE
+}
+
+#function for formating/fixing/building cli input
+function fixinputcli() {
+LOWERCMAIL=${LOWERCMAIL,,}
+if [[ $PPAPPJIRA == "y" ]]; then
+JIRAACCESS='ppapplicationright: jira:access'
+else
+JIRAACCESS=''
+fi
+
+if [[ $PPAPPCONFLUENCE == "y" ]]; then
+CONFLUENCEACCESS='ppapplicationright: extranet:access'
+else
+CONFLUENCEACCESS=''
+fi
+
+##for furture updates, need to check name for non ascii chars and empty space on VAR end
+}
+
+#funtion for creating a rnd user pw
+genuserpw() {
+PASSWORD=""
+while true; do
+PASSWORD=$(openssl rand 222 | tr -dc 'a-zA-Z0-9!=?#' | head -c 12)
+if [[ $PASSWORD =~ [0-9] ]] && [[ $PASSWORD =~ [!=?#] ]]; then
+break
+fi
+done
+CLEARPW=$PASSWORD
+CRYPTPW=`printf ${CLEARPW} | base64`
+}
+
+#function for creating a users ldif
+##this is a pretty dirty way to build the ldif at the moment
+outldapldif() {
+let RUN++
+
+
+if [[ $PPAPPJIRA == "n" && $PPAPPCONFLUENCE == "n" ]]; then
+#shell output
+printf "\033c"
+echo -ne "---\n"
+echo -ne "Username: $LOWERCMAIL\n"
+echo -ne "Password: $CLEARPW\n"
+echo -ne "---\n"
+echo -ne "\n\n"
+echo "dn: uid=$LOWERCMAIL,ou=People,ou=CRM,ou=Applications,o=Pixelpark,o=isp
+cn: $GIVENNAMES $SURNAME
+givenname: $GIVENNAMES
+mail: $LOWERCMAIL
+objectclass: inetOrgPerson
+objectclass: inetSubscriber
+objectclass: inetUser
+objectclass: ipUser
+objectclass: nsManagedPerson
+objectclass: organizationalPerson
+objectclass: person
+objectclass: ppPixelAccount
+objectclass: top
+sn: $SURNAME
+uid: $LOWERCMAIL
+userpassword:: $CRYPTPW " | tee -a "create_${GIVENNAMES,,}-${SURNAME,,}_nr${RUN}.ldif"
+return 1
+fi
+
+if [[ $PPAPPJIRA == "y" && $PPAPPCONFLUENCE == "y" ]]; then
+#shell output
+printf "\033c"
+echo -ne "---\n"
+echo -ne "Username: $LOWERCMAIL\n"
+echo -ne "Password: $CLEARPW\n"
+echo -ne "---\n"
+echo -ne "\n\n"
+echo "dn: uid=$LOWERCMAIL,ou=People,ou=CRM,ou=Applications,o=Pixelpark,o=isp
+cn: $GIVENNAMES $SURNAME
+givenname: $GIVENNAMES
+mail: $LOWERCMAIL
+objectclass: inetOrgPerson
+objectclass: inetSubscriber
+objectclass: inetUser
+objectclass: ipUser
+objectclass: nsManagedPerson
+objectclass: organizationalPerson
+objectclass: person
+objectclass: ppPixelAccount
+objectclass: top
+ppapplicationright: jira:access
+ppapplicationright: extranet:access
+sn: $SURNAME
+uid: $LOWERCMAIL
+userpassword:: $CRYPTPW " | tee -a "create_${GIVENNAMES,,}-${SURNAME,,}_nr${RUN}.ldif"
+return 1
+fi
+
+if [[ $PPAPPJIRA == "y" && $PPAPPCONFLUENCE != "y" ]]; then
+#shell output
+printf "\033c"
+echo -ne "---\n"
+echo -ne "Username: $LOWERCMAIL\n"
+echo -ne "Password: $CLEARPW\n"
+echo -ne "---\n"
+echo -ne "\n\n"
+echo "dn: uid=$LOWERCMAIL,ou=People,ou=CRM,ou=Applications,o=Pixelpark,o=isp
+cn: $GIVENNAMES $SURNAME
+givenname: $GIVENNAMES
+mail: $LOWERCMAIL
+objectclass: inetOrgPerson
+objectclass: inetSubscriber
+objectclass: inetUser
+objectclass: ipUser
+objectclass: nsManagedPerson
+objectclass: organizationalPerson
+objectclass: person
+objectclass: ppPixelAccount
+objectclass: top
+ppapplicationright: jira:access
+sn: $SURNAME
+uid: $LOWERCMAIL
+userpassword:: $CRYPTPW " | tee -a "create_${GIVENNAMES,,}-${SURNAME,,}_nr${RUN}.ldif"
+return 1
+fi
+
+if [[ $PPAPPCONFLUENCE == "y" && $PPAPPJIRA != "y" ]]; then
+#shell output
+printf "\033c"
+echo -ne "---\n"
+echo -ne "Username: $LOWERCMAIL\n"
+echo -ne "Password: $CLEARPW\n"
+echo -ne "---\n"
+echo -ne "\n\n"
+echo "dn: uid=$LOWERCMAIL,ou=People,ou=CRM,ou=Applications,o=Pixelpark,o=isp
+cn: $GIVENNAMES $SURNAME
+givenname: $GIVENNAMES
+mail: $LOWERCMAIL
+objectclass: inetOrgPerson
+objectclass: inetSubscriber
+objectclass: inetUser
+objectclass: ipUser
+objectclass: nsManagedPerson
+objectclass: organizationalPerson
+objectclass: person
+objectclass: ppPixelAccount
+objectclass: top
+ppapplicationright: extranet:access
+sn: $SURNAME
+uid: $LOWERCMAIL
+userpassword:: $CRYPTPW " | tee -a "create_${GIVENNAMES,,}-${SURNAME,,}_nr${RUN}.ldif"
+return 1
+fi
+
+}
+
+#starting main_standalone() or main_deamon()
+while true; do
+main_standalone || break
+done