Corrigiendo errores de roles en moodle

Hola, para todos aquellos que la habéis cagado y os ha desaparecido el menú de admin, o os habéis equivocado con los roles.

Aqui está la solución:

<?php
/*
* fix admin role.
* Resets the admin role and creates a new user
* adminfix/adminfix and assigns it.
*
* You MUST remove this script after using it.
* It’s the biggest security hole known to man.
*
* Howard Miller – E-Learn Design Ltd.
*/

require_once( ‘config.php’ );
require_once( ‘lib/adminlib.php’ );

echo “<p>RESETING DEFAULT ROLES</p>”;

// assume admin is role number 1
reset_role_capabilities( 1 ); // administrator
reset_role_capabilities( 2 ); // course creator
reset_role_capabilities( 3 ); // teacher
reset_role_capabilities( 4 ); // non editing teacher
reset_role_capabilities( 5 ); // student
reset_role_capabilities( 6 ); // guest
reset_role_capabilities( 7 ); // authenticated user

// reload context
echo “<p>RELOADING CONTEXT</p>”;
$sitecontext = get_context_instance( CONTEXT_SYSTEM );
mark_context_dirty( $sitecontext->path );

// fix the primary admin
$admin = get_admin();
$adminusername = $admin->username;
echo “<p>PRIMARY ADMIN IS ‘$adminusername’, LOG IN WITH THIS</p>”;

// change the password
update_internal_user_password( $admin, ‘moodle’ );
echo “<p>PRIMARY ADMIN (‘$adminusername’) PASSWORD IS NOW ‘moodle’</p>”;

// remove the administrator from all roles
$roles = get_records(‘role’);
foreach( $roles as $role ) {
if ($role->id != 1) {
role_unassign( 0,$admin->id );
}
}
echo “<p>REMOVING ‘$adminusername’ FROM ALL ROLES</p>”;

// assign primary admin to admin role at site context
role_assign( 1,$admin->id,0,$sitecontext->id);
echo “<p>PRIMARY ADMIN IS (RE)ASSIGNED TO ADMIN ROLE AT SITE CONTEXT</p>”;

// reset anything we can think of back to default
echo “<p>RESETTING LOADS OF CONFIG SETTINGS BACK TO DEFAULT:”;
echo “<ul>”;

set_config(‘notloggedinroleid’,6); echo “<li>notloggedinroleid set to GUEST</li>”;
set_config(‘guestroleid’,6); echo “<li>guestroleid set to GUEST</li>”;
set_config(‘defaultuserroleid’,7); echo “<li>defaultuserroleid set to AUTHENTICATED USER</li>”;
set_config(‘defaultcourseroleid’,5); echo “<li>defaultcourseroleid set to STUDENT</li>”;
set_config(‘creatornewroleid’,3); echo “<li>creatornewroleid set to TEACHER</li>”;
set_config(‘defaultfrontpagerole’,0); echo “<li>defaultfrontpagerole to NONE</li>”;

echo “</ul>CONFIG SETTINGS COMPLETE</p>”;

echo “<p>ALL DONE</p>”;

Lo subís al FTP y hacéis

http://tusitio.com/adminfix.php y LISTO

Acordaros de borrar el fichero después del uso.

Fuente

Etiquetas: , , ,

Acerca de Marc Rivero López

Si alguien quiere saber como soy que se preocupe por averiguarlo.

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s