Extras -- checkmd5pwhash, setmd5pwhash, setdispw, delalluser
This commit is contained in:
parent
22526c4044
commit
9903c42a5e
28
goss-checkmd5pwhash.rb
Normal file
28
goss-checkmd5pwhash.rb
Normal file
@ -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)
|
20
goss-delalluser-20240527.rb
Normal file
20
goss-delalluser-20240527.rb
Normal file
@ -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."
|
22
goss-setdispw.rb
Normal file
22
goss-setdispw.rb
Normal file
@ -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)
|
23
goss-setmd5pwhash.rb
Normal file
23
goss-setmd5pwhash.rb
Normal file
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user