Yip
This commit is contained in:
		
							
								
								
									
										141
									
								
								diaspora-mod
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								diaspora-mod
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
CONFIG=/home/diaspora/diaspora/config/diaspora.toml
 | 
			
		||||
BT="yipyap.social"
 | 
			
		||||
h=8
 | 
			
		||||
w=60
 | 
			
		||||
 | 
			
		||||
function getBoolSetting(){
 | 
			
		||||
  [ "$(cat "$CONFIG" | grep "$1 =" | awk '{ print $3 }')" = "true" ] && echo "on" || echo "off"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function setBoolSetting(){
 | 
			
		||||
  Invites="false"
 | 
			
		||||
  Registrations="false"
 | 
			
		||||
 | 
			
		||||
  for arg in $@;
 | 
			
		||||
  do
 | 
			
		||||
    case $arg in
 | 
			
		||||
      "Invites")
 | 
			
		||||
        Invites="true"
 | 
			
		||||
        ;;
 | 
			
		||||
      "Registrations")
 | 
			
		||||
        Registration="true"
 | 
			
		||||
        ;;
 | 
			
		||||
    esac
 | 
			
		||||
  done
 | 
			
		||||
 | 
			
		||||
  sudo -u diaspora sed -i "s/open = .*/open = $Invites/" "$CONFIG"
 | 
			
		||||
  sudo -u diaspora sed -i "s/enable_registrations = .*/enable_registrations = $Registrations/" "$CONFIG"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function setInvitesToZeroForUser(){
 | 
			
		||||
  ret=$(sudo -u diaspora psql diaspora_production -c "UPDATE invitation_codes SET count=0 WHERE user_id = (SELECT id FROM users WHERE username = '$1');")
 | 
			
		||||
  if [[ "$ret" =~ ^UPDATE\ [1-9][0-9]*$ ]]; then
 | 
			
		||||
    dialog --backtitle "$BT" --msgbox "Invites has been set to zero." $h $w
 | 
			
		||||
  else
 | 
			
		||||
    dialog --backtitle "$BT" --msgbox "An error has occured:\n\"$ret\"" $h $w
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function queryUser(){
 | 
			
		||||
  if [[ "$1" =~ ^[0-9A-Za-z]+$ ]]; then
 | 
			
		||||
    user=$(sudo -u diaspora psql diaspora_production -c "SELECT username FROM users WHERE username LIKE '$1' LIMIT 1;" -At)
 | 
			
		||||
    if [ -n "$user" ]; then
 | 
			
		||||
      return 0
 | 
			
		||||
    else
 | 
			
		||||
      return 1
 | 
			
		||||
    fi
 | 
			
		||||
  else
 | 
			
		||||
    return 2
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function removeInvitesFromUserMenu(){
 | 
			
		||||
  username=$(dialog --backtitle "$BT" --title "Remove invites from user" --inputbox "Here you can remove the invites from a user.\nUsername:" $h $w 3>&1 1>&2 2>&3)
 | 
			
		||||
  if [ $? -eq 0 ]; then
 | 
			
		||||
    queryUser "$username"
 | 
			
		||||
    ret=$?
 | 
			
		||||
    case $ret in
 | 
			
		||||
      0)
 | 
			
		||||
        setInvitesToZeroForUser "$username"
 | 
			
		||||
        ;;
 | 
			
		||||
      1)
 | 
			
		||||
        dialog --backtitle "$BT" --msgbox "Username not found." $h $w
 | 
			
		||||
        removeInvitesFromUserMenu
 | 
			
		||||
        ;;
 | 
			
		||||
      2)
 | 
			
		||||
        dialog --backtitle "$BT" --msgbox "The username must be alphanumeric." $h $w
 | 
			
		||||
        removeInvitesFromUserMenu
 | 
			
		||||
        ;;
 | 
			
		||||
    esac
 | 
			
		||||
  fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function menu(){
 | 
			
		||||
 | 
			
		||||
  ACTION=$(dialog --backtitle "$BT" --title "Service menu" --menu "Henlo $USER. Whatcha wanna do?" 16 60 6 \
 | 
			
		||||
    1 "Settings" \
 | 
			
		||||
    2 "Remove invites from user" \
 | 
			
		||||
    3 "Restart Webservice" \
 | 
			
		||||
    4 "Restart Sidekiq" \
 | 
			
		||||
    3>&1 1>&2 2>&3
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  case $ACTION in 
 | 
			
		||||
    1)
 | 
			
		||||
      invites_enabled=$(getBoolSetting open)
 | 
			
		||||
      registration_enabled=$(getBoolSetting enable_registrations)
 | 
			
		||||
 | 
			
		||||
      options=$(dialog --backtitle "$BT" --nocancel --title "Settings" --checklist "Change the settings here!" 16 80 10 \
 | 
			
		||||
        "Invites" "Are invites enabled?" "$invites_enabled" \
 | 
			
		||||
        "Registrations" "Are registrations allowed?" "$registration_enabled" \
 | 
			
		||||
        3>&1 1>&2 2>&3
 | 
			
		||||
      )
 | 
			
		||||
 | 
			
		||||
      ret=$?
 | 
			
		||||
 | 
			
		||||
      case $ret in
 | 
			
		||||
        0)
 | 
			
		||||
          setBoolSetting $options
 | 
			
		||||
          dialog --backtitle "$BT" --infobox "Applying configuration by restarting the Webservice, pls wait..." $h $w
 | 
			
		||||
          sudo systemctl restart diaspora-web.service
 | 
			
		||||
          ;;
 | 
			
		||||
        255)
 | 
			
		||||
          dialog --backtitle "$BT" --infobox "Aborted." $h $w
 | 
			
		||||
          sleep 1
 | 
			
		||||
          ;;
 | 
			
		||||
      esac
 | 
			
		||||
      menu
 | 
			
		||||
      ;;
 | 
			
		||||
    2)
 | 
			
		||||
      removeInvitesFromUserMenu
 | 
			
		||||
      menu
 | 
			
		||||
      ;;
 | 
			
		||||
    3)
 | 
			
		||||
      dialog --backtitle "$BT" --infobox "Restarting Webservice, pls wait..." $h $w   
 | 
			
		||||
      sudo systemctl restart diaspora-web.service
 | 
			
		||||
      systemctl status diaspora-web > /tmp/mod_state
 | 
			
		||||
      dialog --backtitle "$BT" --textbox state 25 100
 | 
			
		||||
      rm /tmp/mod_state
 | 
			
		||||
      menu
 | 
			
		||||
      ;;
 | 
			
		||||
    4)
 | 
			
		||||
      dialog --backtitle "$BT" --infobox "Restarting Sidekiq, pls wait..." $h $w   
 | 
			
		||||
      sudo systemctl restart diaspora-sidekiq.service
 | 
			
		||||
      systemctl status diaspora-sidekiq > /tmp/mod_state
 | 
			
		||||
      dialog --backtitle "$BT" --textbox state 25 100
 | 
			
		||||
      rm /tmp/mod_state
 | 
			
		||||
      menu
 | 
			
		||||
      ;;
 | 
			
		||||
    *)
 | 
			
		||||
      ;;
 | 
			
		||||
  esac
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
menu
 | 
			
		||||
clear
 | 
			
		||||
echo -ne "Thank you for playing Wing Commander!\n\nC:\\WC1>"
 | 
			
		||||
		Reference in New Issue
	
	Block a user