Bash Script to update the admin password for multiple Drupal sites on a multi-version server

I have a server running a lot of Drupal sites. Some of them are older and run on Drupal 5, and some are newer and running Drupal 6. We are also starting to implement Drupal 7.

Our organization uses one standard password to administer the website, which we distribute only to our employees for the maintenance of these websites. This may or may not be the best security practice, but that is how we do things at this time. Assume that this does not change.

The problem is that when we have employee turnover, we must change this password and apply the changes for each site that we launch to make sure that the employee cannot destroy our customers sites. This is more important for shooting, but we also do it for retirement as best practice.

In the past, I ran a basic PHP script that used mysql_list_dbs on our database server to iterate over each database and change the pass field of the users table, where name = admin. BASIC:

while ($row = mysql_fetch_object(mysql_list_dbs($sql_connection))) { mysql_query("UPDATE users SET pass=MD5('$newpassword') WHERE name='admin'", $row->Database); } 

This worked fine, but it has two problems:

  • These are hacks, and I hate hacking stuff. I would rather do something that uses the โ€œofficial wayโ€ to do things.
  • Drupal 7 uses a different hashing system than D5 and D6, so this will not work for Drupal 7 sites. Now I must first check that the existing pass value matches the hash of the old password before updating so that I don't accidentally break the Drupal 7 site. By the time I have not figured out how to implement this for Drupal 7 sites.

So I'm looking for an alternative solution. I really think that I need to use a bash script that either iterates through the virtual hosts from httpd.conf, or uses find or something else one way or another, cd to each site installation directory inside the "sites" folder of the installation platform itself (we have a rather dirty setting *) and drush upwd admin --password = $ newpassword starts

This will be completely platform independent and will allow Drupal to determine what happens when the password is changed.

I understand that Aegir may actually be a good solution for this, but we are not ready to implement Aegir yet, and I am looking for a faster and messier intermediate solution. I appreciate any input you may have.

* Just a sample of our messy setup:

 /www /cliena /drupal-5.x /sites /clienta.com <-- contains settings.php for Client A /clientb /drupal-5.x <-- contains old code base for Drupal 5 site that been migrated I shoudld probably have my drush/bash script ignore these sections.... /drupal-6.x <-- contains code base for current Drupal 6 site /sites /clientb.com <-- contains settings.php for Client B /clientc /drupal-6.x /sites /default <-- contains settings.php for clientc.com /sub1.clientc.com <-- contains settings.php for sub1.clientc.com /sub2.clientc.com <-- contains settings.php for sub2.clientc.com /sub3.clientc.com <-- contains settings.php for sub3.clientc.com /client_sites /drupal-5.x /sites /clientd.com <-- contains settings.php for clientd.com /cliente.com <-- contains settings.php for cliente.com /clientf.com <-- contains settings.php for clientf.com 

... etc .... you get the picture. Migration to Aegir is fine, but it will take some time to clear it.

+4
source share
3 answers

you can improve and continue writing this script below ...

 for FILE in $(find /www -type f -name system.module); do C_PATH=`dirname $FILE` C_VERSION=`grep "define('VERSION'," $FILE | awk -F "'" {'print $4'}` print "--- DEBUG --- " print "Current path: $C_PATH" print "Current version: $C_VERSION" # Your logic here... done 

[]

Felipe

+1
source

Felipe's script looks good, I took it to deal with multisite installation and drush. In my setup, he found every site in my installation. First try the non-destructive drush command:

 PASSWORD='secret' for FILE in $(find /www/ -type f -name settings.php); do PATH=`dirname $FILE` echo "Changing password for: $PATH" drush -r $PATH upwd admin --password=$PASSWORD done 
+1
source

Felipe and Nebel54 both gave me great starts. In the end, I mainly worked with Nebel, but still had to make some changes. I found two problems with your script, Nebel.

1) It seems that "PATH" is a reserved word. When I tried to use it as a variable, it did not work. So I changed it to "DPATH".

2) It seems that passing the -r option to drush is not enough. When I used this, he told me that to run my command I needed a higher level of bootstrapping. So I had to make a CD in $ DPATH before running my drush command.

For testing, I ran the sql-connect command because it simply displays the sql connection string for viewing and does not make any changes. I am going to start the password update now. Here is my last script:

 PASSWORD='newpass' for FILE in $(find /www/ -type f -name settings.php); do DPATH=`dirname $FILE` cd $DPATH echo "Changing password for: $DPATH" drush upwd admin --password=$PASSWORD done 
+1
source

Source: https://habr.com/ru/post/1382519/


All Articles