Administrate Yourself Script

Started by Matthew K., October 14, 2010, 02:17:14 PM

Previous topic - Next topic

Matthew K.

I was reviewing some articles for the new wiki and noticed that to re-admin yourself is currently just a query you enter to the database. Simple enough right? Well, I decided to take it one step farther and make a tool so Admins who un-admin themselves on accident, or for any reason to re-admin themselves.

I wrote the script for SMF 2.0 RC3, but it should work with all versions of 2.0 RC. (I did add validation to it only runs on the proper version.)

I do not plan on backporting it back to 1.1; I was, however, I hit a bunch of problems with global variables I needed not working without editing other files, and I wanted this to be as simple as uploading it and visiting it, not making edits in addition.

The goal of this script is simple. Upload the file > Go to the URL > Enter your Database Password - And you're done.

Screenshots are attached of the main interface, two error messages, success message, as well as what it would look like if your forum has a smaller set width. (It follows your forums width that is set in your admin panel too.)

The script itself is also attached.

Labradoodle-360

Norv

Thank you for sharing. :)
A script of this kind can be useful IMHO. There are indeed cases when mistakes or other things happen, and people may lose their administrator accounts.
I believe there is a Feature Request for it, even ... though searching now I don't seem to find it.
To-do lists are for deferral. The more things you write down the later they're done... until you have 100s of lists of things you don't do.

File a security report | Developers' Blog | Bug Tracker


Also known as Norv on D* | Norv N. on G+ | Norv on Github

Matthew K.

Not a problem, I enjoyed writing it a lot.

I would appreciate suggestions or problems if anyone finds any.

Norv

Just two quick thoughts for the moment, if I may:
I don't think that $forum_version will work too well. You compare it against the length of smfVersion, which is only now 7, and which will change.
Then, IMHO the script is written too monolithically, without any separation between presentation and logic, that is, between templates (display stuff), and respectively updating database, and other processing.

I wonder if you wish to take a look at a script like repair_settings.php - though that one can be improved as well - and see how it separates between initialization, display, and actual work of updating the necessary data.
To-do lists are for deferral. The more things you write down the later they're done... until you have 100s of lists of things you don't do.

File a security report | Developers' Blog | Bug Tracker


Also known as Norv on D* | Norv N. on G+ | Norv on Github

Matthew K.

Regarding $forum_version, it actually defines $forum_version based off of $modSettings['smfVersion']. How do I check $modSettings for JUST "2.0" so it works with 2.0 RC1.2, 2.0 RC2, 2.0 RC3 and so fourth? As $modSettings['smfVersion'] outputs "2.0 RC3" and so on. That's why I did it based off of the character count, because for the RC's (At least 2 and 3) the count remains the same.

Edit: I know with MySQL queries you can do it as simple as 1.1% or 2.0%

In response to the lack of separation, I did take a look at repair_settings.php, first, actually and couldn't make a whole lot of sense out of it. Would you have any direct suggestions on how to truly separate the function from the presentation as it should be? Obviously within SMF, there are two files per action so it's fairly simple and straight forwards that way.

Thanks,
Labradoodle-360

SlammedDime

Quote from: Labradoodle-360 on October 14, 2010, 03:33:06 PM
Regarding $forum_version, it actually defines $forum_version based off of $modSettings['smfVersion']. How do I check $modSettings for JUST "2.0" so it works with 2.0 RC1.2, 2.0 RC2, 2.0 RC3 and so fourth? As $modSettings['smfVersion'] outputs "2.0 RC3" and so on. That's why I did it based off of the character count, because for the RC's (At least 2 and 3) the count remains the same.
version_compare

if (version_compare('1.99.99', $modSettings['smfVersion']) >= 0)
    die('failure, this is for 2.0+ only')
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Matthew K.

Thanks Slammed! I'll be updating it very shortly...any suggestions on how it should be separated more?

Matthew K.

#7
I updated administrate.php to "1.1".

Straightened up a couple places of the coding, as well as added version_compare rather than strlen for validating which version you were trying to run the script on.

Edit: I am actually working on a package of "Administrate Yourself" that will work with SMF 1.1 as well as another update for SMF 2.0 code of this script.

Latest: After having to re-write the script to change what is needed for SMF 1.1 versions, I found one bug, fixed some coding issues (including separating display from function), in addition, a couple things have also changed and been optimized. I am not quite done with the version for SMF 1.1, and then I still have to update the script for SMF 2.0 versions. So expect to see the updated versions within a day or so.

Labradoodle-360

Advertisement: