admin lost permissions in 1.8+

admin lost permissions in 1.8+

by Oswald Zangerle -
Number of replies: 42
Hi,
one of my co-administrators was locked out after todays upgrade to 1.8 Beta (2007021401), I have done something stupid then: I reset the administrator role and have lost now all permissions and the admin block as well.
I have access to my database via phpMyAdmin.
Where can I change my permissions there?
Any help would be very appreciated...

Thanks
Oswald
Average of ratings: -
In reply to Oswald Zangerle

Re: admin lost permissions in 1.8+

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
hi!

How exactly did you manage to remove the permissions? Did the admin role have legacy:admin capability? The reset code works fine for me.

You can use following script to get back admin rights for user 'admin', just upload a file that contains the commands bellow (into the same dir as config.php) and execute it + logout/login as admin:


<?php
require 'config.php';

$systemcontext = get_context_instance(CONTEXT_SYSTEM);
$adminroleid = create_role('new admin6', 'admin6', 'delete me later', 'moodle/legacy:admin');
reset_role_capabilities($adminroleid);
$user = get_record('user', 'username', 'admin');
role_assign($adminroleid, $user->id, 0, $systemcontext->id);
echo 'done';
?>


BTW I am adding some improved warnings to prevent similar accidents in future.

skodak
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Oswald Zangerle -
Hi skodak,

your script has solved my problem lächelnd thanks!

"How exactly did you manage to remove the permissions? Did the admin role have legacy:admin capability?"
In /moodle/admin/roles/manage.php?roleid=1 I hit the reset button and all permissions went to "inherit" as far as I can remember.
I am not certain about legacy:admin capability - I believe it was "permitted"
until I hit reset...

Oswald

In reply to Oswald Zangerle

Re: admin lost permissions in 1.8+

by William Claps -
Will this work in Moodle 1.7? I am hiving trouble finding a forum post that will work.
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by tripp tuttle -
so, i did the same thing and removed the admin permissions. I just tried the script and it ran and retured "done" but I still don't have permissions. I'm running 1.8+. Do I need to edit the PHP code with my admin user name and password or does this script create a new user?

Please help!

Thank you!

Tripp
In reply to tripp tuttle

Re: admin lost permissions in 1.8+

by Jestin VanScoyoc -
Also using Moodle 1.8+. I too got "done" message but still can't get into my admin panel sad I think I locked myself out after changing roles. I thought I was only editing roles for "guest."
In reply to Jestin VanScoyoc

Re: admin lost permissions in 1.8+

by Jestin VanScoyoc -
Am I supposed to login as 'admin6' ? What do I enter as a password if so.

Thanks
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Tim Hobson -

Really quick question. How do you execute it?

In reply to Tim Hobson

Re: admin lost permissions in 1.8+

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Simply by calling it with your web browser, with the correct path.
In reply to Séverin Terrier

Re: admin lost permissions in 1.8+

by Matt Albert -
So I changed something in the permissions that modified all users that log in are students. This now deleted my admin rights and forced me to go directly to MyMoodle page. I have run this script and don't have any idea what I am supposed to use to log in. I need to get back into this system ASAP!!!!! help!!! I am running 1.9 beta+
In reply to Matt Albert

Re: admin lost permissions in 1.8+

by Oswald Zangerle -
Maybe you have to open an new thread for 1.9 beta+ to get a correct answer for your problem.
For me it worked fine like Skodak wrote: "You can use following script to get back admin rights for user 'admin', just upload a file that contains the commands bellow (into the same dir as config.php) and execute it + logout/login as admin:"
I simply put this script in wordpad, saved it as lost.php; put it via ftp on the server in my moodle directory. I run this script by calling www.mywebsite/lost.php, logged out and logged in as admin. If you use a different name for admin in your config.php I think you would have to adjust that name in this script.
In reply to Oswald Zangerle

Re: admin lost permissions in 1.9

by Vicktorya Stone -

Hi -

I've been stuck for days now.  Read all the forums, still have 'limited' admin privileges  [   $release = '1.9';       // Human-friendly version name   ]

First thing that happened is I changed the default role for new users to 'authenticated user'.  I did this because no one other than admins could edit their profile. This was based upon some forum advice, 

What happened was all my admins now have limited capability (as if at a lower level, but not 'just' authenticated user, as some admin capability shows up. e.g.:

What this doesn't include also is capability to see some hidden courses.
 
I have been making several changes (all of which I suspected were legal options).  The school is not yet operational, and so if I need to do some serious reloading of default databases -- say, just for the roles capability, that wouldn't be inconvenient.
 

Update - I also did run the 'admin6' php user fix described in this thread. It seemed fine (resulting in "done"). However, I wasn't sure what to do next; to log in AS admin6 -- since as there is no password, I entered on my own admin account, and was able to add new user, 'admin6'  -- but of course this is stupid, because admin6 is now simply a new user account.

I am so stuck. Can someone please direct me as to how to reload all default role settings, so I have something workable?

 thanks a lot. Don't know what I'd do without this forum ...
divine intervention hasn't been working (yet).  smile
Vicktorya

 

 

In reply to Vicktorya Stone

Re: admin lost permissions in 1.9

by Vicktorya Stone -

Two more clues --

#1  here in my database I have warnings:

"PRIMARY and INDEX keys should not both be set for column `id`"

and looks like I have two of them?

(see screenshot .)

and, er ...

#2: I believe(!) I should have a file called --  mdl_user_admins 

? I do not.  (If I need one, how do I get me one?  I do have an earlier version, 1.8, on another site. Can I grab the file from there? Would it be compatible with 1.9?)

wink

wait, #3:

In the host server webpanel, I have received this on a few occasions when visiting the database:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@moryafederation.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 301 Moved Permanently error was encountered while trying to use an ErrorDocument to handle the request.

Could it be that I moved some file? Or, could the host have managed something? I have dreamhost.com, and think they're great, but there was an early 'bug' that they had on the initial install, and they then fixed that. (Funny enough, the server is called bugsy! -- bad call.) 

Now that was 1.8 when I loaded it.  While I realize upgrades don't happen automatically, (and I didn't do it) -- I do now have 1.9.

Should I talk to dreamhost folks about this? -- or am I into conspiracy theories?  smile

thanks!

vic

 

In reply to Vicktorya Stone

Re: admin lost permissions in 1.9: restored db

by Vicktorya Stone -
Well what a brainstorm. I went into myphpadmin and did a simple RESTORE of my backups. Man was THAT simple.

Good thing i did it now, as this problem has been going on for 5 days, and that's all the longer my server is set to store backups. Everything is back to how it was.

I still am not sure how to make sure I get the settings correct, on this default user being authenticated user or guest, but at least I am back with admin rights, how I was nearly a week ago. Whew!

So -- suggestion to anyone has lost their admin files or roles get really screwed up, just go into myphpadmin and find your backup/restore function for the tables, and 'restore'
-- and viola, back to how your were.

best,
Vic

In reply to Vicktorya Stone

Re: admin lost permissions in 1.9: restored db

by Vicktorya Stone -
well, I did it again. Both made the problem and was able to restore back slick as anything.

Problem of losing 'certain' admin settings, seems to come in with changing the default user, the options are 'none', 'authenticated user', and 'guest', or 'student'. I've seen suggestions for using any and all of these, depending on need.

Obviously I haven't figured this out yet, what is basic configuration. the reason why I've gone back in and changed this, and some of the define roles of these lesser settings and functions (calendar, blog, etc.) is because I want (whatever it is best to set it to, i.e., 'none', authenticated user, guest, ...) to not be able to 'change' calendar entries, as one example. However, if they see it, a guest user can go all the way in to change and export the calendar. That doesn't seem right, so I want to limit (either, and here's another question: which one is it?: of 'prohibit', 'not set', or 'prevent'.

This was the latest problem, when I set the authenticated user to 'prevent' access to all these blocks and courses, in define roles, I then -- as ADMIN -- was unable to get back in.

I have my admin account set with the doanything, etc.

As well, with the blog settings, they seem to be able to go into and edit my blog entries.

So, I'm still trying to set basic role permissions. Before I fiddle again (I'll just live with what seem to be security or privacy breaches, as I can at this set up time).

At least if I can get the db restore process wired, I can undo each problem I create. This is perhaps the idea for a testing server? (sorry, this is now a vicktorya blog thread, as I am responsive to my own posts.)

In reply to Vicktorya Stone

Re: admin lost permissions in 1.9: restored db

by Gregg Ciabattoni -

Hello,

I’m using moodle 1.9 and I’m having the same issues. I’ve read all of the posts on these Forum related to this issue and no matter what I’ve tried I can’t get my admin tree back. Here is what I’ve tried.

Went into MYSQL and changed the defaultuserroleid value to 1. Logged out, restarted Apache and MYSQL and nothing. (update mdl_config set value =1 where name ='defaultuserroleid';)

Tried to go to http://myserver/moodle/admin

Added the line $CFG->defaultuserroleid = 1; to my config.php restarted Apache and MYSQL

Ran both versions I found of the createadmin.php script

Ran the rolesdebug.php it didn’t help either.

Used MySQL Admin to check permissions related to my default admin ID (2) in the mdl_role_assignments is has a value of 1 in the roleid field.

Checked that roleid 1 has permission 1 in the mdl_role_capabilities table

Checked that the doanything property in the mdl_config table was set to 1

Checked the mdl_block table and I can see that visible field is set to 1 for admin_tree

I even set up a new server and exported the default mdl_config table and compared it the one I’m using.

I’ve done everything I can think of and I can’t seem to get my admin tree back. Can anyone help me?

In reply to Gregg Ciabattoni

Re: admin lost permissions in 1.9: restored db

by Gregg Ciabattoni -

I finally figured it out!!!!.

I tried exporting various tables from my new installation and after I imported the mdl_block table I was able to see the admin tree again. As of now I’m not sure as to the which setting was causing it since I already checked it and the visible property was set to yes, but its back up and working.

In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Steven Putter -
hi i have the same problem used the code but nothing just cant get it working again, please anybody that can help it will really be appreciated
thanks very much
Steven
In reply to Steven Putter

Re: admin lost permissions in 1.8+

by Oswald Zangerle -
Hi Steven,

according to Ralf Hilgenstock there are two different reasons for losing the admin permissions.
1. the administrators permissions have been taken away
2. the admin role has been deleted.

Ralf mentioned, if the role has been deleted the script will help.
Otherwise you will get your permissions back by modifying mdl_user_admins in your database.
Please check in your database mdl_user_admins.
id should be 1.
userid your personal id number (you can see it with mouse over your name = URL + id= ).
If mdl_user_admins does not exist you can make a new entry but it is a clear sign that the role has been deleted and the script should work.

Oswald


In reply to Oswald Zangerle

Re: admin lost permissions in 1.8.2+

by Jacqui Wintle -
hi,

i have lost admin permissions and need to create a new entry in my database for mdl_user_admins (it does not exist in my database). i'm using moodle 1.8.2+

could someone please explain how to do this, my SQL knowledge is quite limited although i can find my way around the database.

will appreciate any help, thanks!

Jacqui
In reply to Oswald Zangerle

Re: admin lost permissions in 1.8+

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This advice only applies to Moodle 1.6 and earlier, so will not work in Moodle 1.8+
In reply to Tim Hunt

Re: admin lost permissions in 1.8+

by Jacqui Wintle -
Hi Tim,

Thanks for your reply. I've checked the role id, user id & context id of 'admin' in my database and they are correct but when i log in as 'admin' i don't see any of my administrative panels...

Any ideas? Thanks in advance
In reply to Jacqui Wintle

Re: admin lost permissions in 1.8+

by Oswald Zangerle -
Hi,
Sorry about this!
the user_admins table's functionality is now in the role_assignments table. Also see the role table to see the id numbers of the actual roles

http://moodle.org/mod/forum/discuss.php?d=36856


Pierre Pichet gives some hints for the handling of the database upgrading to 1.7b

http://moodle.org/mod/forum/discuss.php?d=56302#256313

for how to change your database you may have a look

http://moodle.org/mod/forum/view.php?id=45

Oswald


In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Hemant Karandikar -
I tried the script. My role (originally it was admin) still remains that of guest!
see the script attached
Help!

Hemant
In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+

by Oswald Zangerle -
you executed it + logged out/logged in as admin?
maybe you have to change in your database the mdl_role_allow_assign.
Make sure that the roleid for your id is 1. e.g. for this (via script created) admin6 the values should be:
id 6
roleid 1
allowassign 6
In the role table `mdl_role` (mark "id" and show) you can see the id numbers of the actual roles. For admin it is '1' in my database; if it is different in your database please adapt the roleid in mdl_role_allow_assign as mentioned above.

BTW: you could try to repair your database with phpMyAdmin.

Oswald

In reply to Oswald Zangerle

Re: admin lost permissions in 1.8+ (second post)

by Hemant Karandikar -
See the attached screen dump after excuting the script attached in earlier post.

It appears that admin rights have somehow got disabled throught the moodle installation.

The tables seem to be right.

I hope that the screen dump helps in finding the cause.

I will appreciate to know a quick way to get full admin rights for either existing user or through a new account (we tried this but falied)

Hemant
In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+

by Hemant Karandikar -
I worked helped by Peter yesterday. We could not solve the problem:

we created new admin account with admin rights, still it got only guest rights.

we examined various tables (roles, capabilities etc.) they were in order.

I ran a script (attached) and receievd a long output which I shall attach in a separate post.

Hemant (see second post also)
In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+ (news!)

by Hemant Karandikar -
I have a news!

I could get back admin rights to admin logins by changing the table
mdl_config:

In the row with name =defaultuserroleid)
changing value from 5 (student) to 1 (admin)

Later after trying out other admin logins I switched back the default role for all logged in users to "student'.

Surprisingly, admin rights remain intact.

But there are more strange things that happen

One student login is still denied access to course with a message "..guest login"

Also one of the adminstartor user is denied access to a course with similar message!

Can someone guide me in sorting out these user rights (capabilities ) issues?

Hemant

In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+ (news!)

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Check that the 'mnethostid' field in your 'users' table is set to non-zero (should be 1). I've seen that cause problems, although I think they are usually login related.
In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+ (news!)

by Oswald Zangerle -
Congratulations on your workaround!

If Mikes suggestion has not fixed your new problem yet, it could be a problem of the account authentication method. "If users are unable to login following an upgrade to 1.8 then most likely their account authentication method requires enabling."
http://docs.moodle.org/en/Upgrading_to_Moodle_1.8#Multi_Authentication

Oswald
In reply to Hemant Karandikar

Re: admin lost permissions in 1.8+ (news!)

by Hemant Karandikar -
Sorry for being late in replying to Mike and Oswald. Having wrested back admin rights I was busy on the content side (that's my main work!)

Both the hints did not work. My status and questions are:


Admin rights are back with me and some more accounts I created just in case.

One student who had lost access (except guest level) has got it back after I deleted and recreated his account. I wish to know this happens?

My original admin account has access to admin menu and functions but has no access to the course! This account shows up as administrator in the browse user list and has admin roles. Why this happens? What should I do? (I wish to leave just two admin accounts and delete the dummy accounts)

I will appreciate help in this.

Hemant
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Peter Burden -
Hello,
Petr's script worked just fine for me. Just cut and paste the code into the
correct directory and typed (on the Linux command line)
php restoreadmin.php
Logged out as admin and logged back in, went to
  • Administration
  • Users
  • Permissions
  • Define roles
selected the "allow role assignments" tab and allowed the administrator to assign the "new admin6" role, then changed all the administrator role's capabilities to "allow". Logged out and logged back in as administrator and
removed the "new admin6" role - and, I hope, everything is back to how it was.

[Admittedly I had also tried the change default user role hack mentioned
elsewhere in this forum.]
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Jamie Tinley -
Hi Petr,

I ran this and got an error on line 2. I correctly pasted it into wordpad and saved as .php then went to http://mysite/adminfixPetr.php and got the error.
any ideas? I also tried Howard's adminfix without success. Still no admin settings. Thanks, James
In reply to Petr Skoda

Re: admin lost permissions in 1.8+

by Big Faced Boy -
I think I love you Petr. You've just fixed my problem! Thank you so much.
In reply to Big Faced Boy

Απάντηση: Re: admin lost permissions in 1.8+

by Harris ts -
Hi all!!


I apologize if i'm writing in wrong topic, but i think this is my last chance before compression!! I am working on moodle 1.9+, it was working as i wanted to, and today , i set some authanticated user roles. I saved the changes, and...Boom!!

I haven't administration permissions any more. The admin tree has been reduced only in some functionalities( as u can see in the attachments), and when i turn on the edit process, clicking in the "Assing roles" icon, i can see the error message "Sorry, but you do not currently have permissions to do that (Assign roles to users)".

My question is, should i modify some .php file in the admin directory? Could i restore the initial roles through phpmyadmin? I am glad for your help!! Thank you sad
Attachment admin_tree.jpg
In reply to Harris ts

Απάντηση: Re: admin lost permissions in 1.8+

by Harris ts -
It's ok guys, i fixed it, with the precious help of another post. Thanks u anyway!!
In reply to Harris ts

Re: Απάντηση: Re: admin lost permissions in 1.8+

by Jennifer Spivey -

I'm having this same problem how do I correct it?

In reply to Petr Skoda

Updated script for Moodle 2.x

by Paul Vaughan -

I realise I am replying to a seven year old thread, but no matter how much I Googled and for what, I always arrived back at this page (as Google ranks it highly), and couldn't find anything similar for Moodle 2.

I needed to assign admin capability to a user from outside of Moodle, and this script did the job.  I've updated it for Moodle 2.x (tested on 2.6) and added a check for the pre-existence of the newly-created role (which would cause a DB write error if run more than once).

https://github.com/vaughany/moodle_admin_assign

I hope someone out there finds this useful.

Cheers,

Paul.

In reply to Paul Vaughan

Re: Updated script for Moodle 2.x

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Paul, just curious as to why you're creating a role and giving it the 'doanything' capability, instead of adding the user to the list of site admins in $CFG->siteadmins? That's the way that site admins usually work in Moodle 2.x (or does this not work in your particular situation?)

(See admin/roles/admins.php to see how Moodle updates this list).

In reply to Davo Smith

Re: Updated script for Moodle 2.x

by Paul Vaughan -

Hi Davo.  Sorry for the delay in replying, I've not logged in for a while. 

I followed the same procedure as Petr's original script: create a new role with the required privileges, then assign the user to it.  I believe this was done originally (and this is certainly how I perceived it, and wrote this code to match) because the script's job is transient and temporary: it is to 'get access to Moodle by any means necessary', a means to an end, rather than permanently assigning a user as an admin.  

One benefit of this is that the newly created role can simply be deleted, which restores user's privileges to whatever they were beforehand (the temporary admin is demoted again).  This may not be what's always required (as you say, the user may require admin privileges permanently) but this was the role the script was written to do (in a bit of a hurry, for a colleague who had just been handed a Moodle database SQL dump with the admin users stripped out).

(As an aside, and by no means a criticism: I often find there are multiple ways of achieving the same goals in Moodle, and being a team of one here in terms of Moodle development, I have little to go on except best judgement.  Time was a factor here and the code does work, but I'll look into better best practices soon.)

Thanks for the heads-up, I'll investigate further now that the pressure's off to get a result.

Cheers,

Paul.