From 9903c42a5e4a518bdf061c528b3dcc63283e55f2 Mon Sep 17 00:00:00 2001 From: dsainty Date: Mon, 17 Jun 2024 19:45:51 +1000 Subject: [PATCH] Extras -- checkmd5pwhash, setmd5pwhash, setdispw, delalluser --- goss-checkmd5pwhash.rb | 28 ++++++++++++++++++++++++++++ goss-delalluser-20240527.rb | 20 ++++++++++++++++++++ goss-setdispw.rb | 22 ++++++++++++++++++++++ goss-setmd5pwhash.rb | 23 +++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 goss-checkmd5pwhash.rb create mode 100644 goss-delalluser-20240527.rb create mode 100644 goss-setdispw.rb create mode 100644 goss-setmd5pwhash.rb diff --git a/goss-checkmd5pwhash.rb b/goss-checkmd5pwhash.rb new file mode 100644 index 0000000..68eb204 --- /dev/null +++ b/goss-checkmd5pwhash.rb @@ -0,0 +1,28 @@ +# Load the Discourse environment +require File.expand_path("../../../config/environment", __FILE__) + +# require_relative '/var/www/discourse/config/environment' + +def query_md5_password_custom_field(username) + user = User.find_by(username: username) + if user + md5_password = user.custom_fields['custom_password_md5'] + if md5_password + puts "MD5 password custom field for user #{username}: #{md5_password}" + else + puts "No MD5 password custom field set for user: #{username}" + end + puts "password_hash #{user.password_hash}" + puts "password_algorithm #{user.password_algorithm}" + puts "salt #{user.salt}" + puts "active #{user.active}" + puts "approved #{user.approved}" + else + puts "User not found: #{username}" + end +end + +# Replace 'username' with the actual username +username = 'davidpaulyoung' + +query_md5_password_custom_field(username) diff --git a/goss-delalluser-20240527.rb b/goss-delalluser-20240527.rb new file mode 100644 index 0000000..e987c96 --- /dev/null +++ b/goss-delalluser-20240527.rb @@ -0,0 +1,20 @@ +# Load the Discourse environment +require File.expand_path("../../../config/environment", __FILE__) + +# Define usernames to exclude from deletion +excluded_usernames = ["saint", "discobot", "system"] + +# Find all users except the excluded ones +users_to_delete = User.where.not(username: excluded_usernames) + +# Iterate over the users and delete each one +users_to_delete.each do |user| + begin +# puts "Deleting user: #{user.username}" + user.destroy + rescue => e + puts "Failed to delete user #{user.username}: #{e.message}" + end +end + +puts "User deletion process completed." diff --git a/goss-setdispw.rb b/goss-setdispw.rb new file mode 100644 index 0000000..8dfa7a1 --- /dev/null +++ b/goss-setdispw.rb @@ -0,0 +1,22 @@ +# Load the Discourse environment +require File.expand_path("../../../config/environment", __FILE__) + +# require_relative '/var/www/discourse/config/environment' + +def set_user_password(username, new_password) + user = User.find_by(username: username) + if user + # Use the `password=` method to properly hash the password + user.password = new_password + user.save! + puts "Password updated for user: #{username}" + else + puts "User not found: #{username}" + end +end + +# Replace 'username' and 'new_password' with actual values +username = 'davidpaulyoung' +new_password = 'T3s7P4ssw0rd.' + +set_user_password(username, new_password) diff --git a/goss-setmd5pwhash.rb b/goss-setmd5pwhash.rb new file mode 100644 index 0000000..8ec1a75 --- /dev/null +++ b/goss-setmd5pwhash.rb @@ -0,0 +1,23 @@ +# Load the Discourse environment +require File.expand_path("../../../config/environment", __FILE__) + +# require_relative '/var/www/discourse/config/environment' + +def set_md5_password_custom_field(username, md5_password) + user = User.find_by(username: username) + if user + user.custom_fields['custom_password_md5'] = md5_password + user.save! + puts "MD5 password custom field set for user: #{username}" + else + puts "User not found: #{username}" + end +end + +# Replace 'username' and 'md5_password_hash' with actual values +username = 'davidpaulyoung' +md5_password_hash = '$GT$i5ZNZdfX$077FK6JU70HIr2pR1/uLP1' +# md5_password_hash = 'i5ZNZdfX$077FK6JU70HIr2pR1/uLP1' + +set_md5_password_custom_field(username, md5_password_hash) +