Last active
October 23, 2018 09:17
-
-
Save forsvunnet/2a8ec26941beee2c13fd647b209762b1 to your computer and use it in GitHub Desktop.
Inject a admin account on a magento 1.x installation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mageFilename = 'public/app/Mage.php'; | |
if (!file_exists($mageFilename)) { | |
echo $mageFilename." was not found"; | |
exit; | |
} | |
require_once $mageFilename; | |
Mage::app(); | |
try { | |
//create new user by providing details below | |
$user = Mage::getModel('admin/user') | |
->setData(array( | |
'username' => 'eivin.landa', | |
'firstname' => 'Eivin', | |
'lastname' => 'Landa', | |
'email' => '[email protected]', | |
'password' => 'asd2g74fSasdyn14Ho9pLnDmzU123fo', | |
'is_active' => 1 | |
))->save(); | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
exit; | |
} | |
try { | |
//create new role | |
$role = Mage::getModel("admin/roles") | |
->setName('eivin.landa') | |
->setRoleType('G') | |
->save(); | |
//give "all" privileges to role | |
Mage::getModel("admin/rules") | |
->setRoleId($role->getId()) | |
->setResources(array("all")) | |
->saveRel(); | |
} catch (Mage_Core_Exception $e) { | |
echo $e->getMessage(); | |
exit; | |
} catch (Exception $e) { | |
echo 'Error while saving role.'; | |
exit; | |
} | |
try { | |
//assign user to role | |
$user->setRoleIds(array($role->getId())) | |
->setRoleUserId($user->getUserId()) | |
->saveRelations(); | |
} catch (Exception $e) { | |
echo $e->getMessage(); | |
exit; | |
} | |
echo "Done\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment