Ross Posted October 1, 2021 Share Posted October 1, 2021 Hi! We have the ProcessWire 2.3.1 version The old webmaster don't give us the logindetails. Is it possible to add the superuser role to a user with content-manager role through lines of code in php? We do not know the username and the administrator password but we have access to the hosting through cpanel, phpmyadmin and public html files. What do you recommend? How could we reset the admin password or how could we assign a superuser role to a content-manager user? Thank you Ross Link to comment Share on other sites More sharing options...
BitPoet Posted October 1, 2021 Share Posted October 1, 2021 Behind the scenes, the admin user is a page with the id 41, so you can determine the username by running the following sql query: select `name` from `pages` where `id` = 41; The quickest way to reset the password should be this: 2 Link to comment Share on other sites More sharing options...
bernhard Posted October 1, 2021 Share Posted October 1, 2021 My VSCode snippets extension has a snippet for that, that you can simply paste in site/ready.php: $admin = $users->get(41); $admin->setAndSave('pass', ''); $admin->setAndSave('name', ''); die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}"); 1 3 Link to comment Share on other sites More sharing options...
Ross Posted October 5, 2021 Author Share Posted October 5, 2021 On 10/1/2021 at 7:03 AM, bernhard said: My has a snippet for that, that you can simply paste in site/ready.php: $admin = $users->get(41); $admin->setAndSave('pass', ''); $admin->setAndSave('name', ''); die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}"); Thank You Bernhard! Your VSCode snippets extension serve only to reset the administrator password or does it also serve to add a new super user through code? Sorry for the questions, I'm a newbie. Link to comment Share on other sites More sharing options...
bernhard Posted October 5, 2021 Share Posted October 5, 2021 Just reset the name + password for the superuser, then you can login as that user and create other users or edit them and their roles. 1 Link to comment Share on other sites More sharing options...
Ross Posted October 6, 2021 Author Share Posted October 6, 2021 18 hours ago, bernhard said: Just reset the name + password for the superuser, then you can login as that user and create other users or edit them and their roles. We have the ProcessWire 2.3.1 version and only have the config.php file inside the site folder. Do I copy and paste the code in that file? Thank You Bernhard! Link to comment Share on other sites More sharing options...
kongondo Posted October 6, 2021 Share Posted October 6, 2021 (edited) 2 hours ago, Ross said: We have the ProcessWire 2.3.1 version and only have the config.php file inside the site folder. Do I copy and paste the code in that file? That's quite an old version of ProcessWire. ready.php and the likes were introduced in ProcessWire 2.6.7, so you cannot use ready.php in your version. You can still use the API to change your password. You will need to add the code to a template file. Pick one template file from your /site/templates folder, edit it, and add the following code. The steps are: Pick a template file. Open it for editing. Depending on your server, you might have to download it to edit it locally the upload the edited version. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc). Your password (and optionally user name) will be changed. Edit the template file in #1 and #2 above. Remove the password change code. Reupload the edited template file if it was edited locally. Go to your admin URL and login with your new password (and new name if you changed it as well). PHP code <?php namespace ProcessWire; #### DON'T ADD ABOVE TO YOUR TEMPLATE FILE. IT IS JUST FOR SYNTAX HIGHLIGHTING HERE #### ################# COPY CODE STARTS HERE ################# // get the default ProcessWire admin superuser $admin = $users->get(41); // turn output formatting off $admin->of(false); // change the password $admin->pass = "YOUR_VERY_STRONG_PASSWORD_HERE"; // change the user name (optional: comment out code if you know and want to use the existing user name) $admin->name = "YOUR_USER_NAME_HERE"; // SAVE YOUR CHANGES $admin->save(); ################# COPY CODE END HERE ################# Edited October 6, 2021 by kongondo 2 1 Link to comment Share on other sites More sharing options...
Ross Posted October 15, 2021 Author Share Posted October 15, 2021 On 10/6/2021 at 2:31 AM, kongondo said: That's quite an old version of ProcessWire. ready.php and the likes were introduced in ProcessWire 2.6.7, so you cannot use ready.php in your version. You can still use the API to change your password. You will need to add the code to a template file. Pick one template file from your /site/templates folder, edit it, and add the following code. The steps are: Pick a template file. Open it for editing. Depending on your server, you might have to download it to edit it locally the upload the edited version. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc). Your password (and optionally user name) will be changed. Edit the template file in #1 and #2 above. Remove the password change code. Reupload the edited template file if it was edited locally. Go to your admin URL and login with your new password (and new name if you changed it as well). PHP code <?php namespace ProcessWire; #### DON'T ADD ABOVE TO YOUR TEMPLATE FILE. IT IS JUST FOR SYNTAX HIGHLIGHTING HERE #### ################# COPY CODE STARTS HERE ################# // get the default ProcessWire admin superuser $admin = $users->get(41); // turn output formatting off $admin->of(false); // change the password $admin->pass = "YOUR_VERY_STRONG_PASSWORD_HERE"; // change the user name (optional: comment out code if you know and want to use the existing user name) $admin->name = "YOUR_USER_NAME_HERE"; // SAVE YOUR CHANGES $admin->save(); ################# COPY CODE END HERE ################# Hi! Thanks for helping. I'm going to try your steps. For example Pick a template file. Open it for editing. Add the code below. The code needs to be added within php code blocks within that template file. Do not delete your templates existing code. Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).www.mysite.com/basic-page.php Your password (and optionally user name) will be changed. Edit the template file in #1 and #2 above. Remove the password change code. Reupload the edited template file if it was edited locally. Go to your admin URL and login with your new password (and new name if you changed it as well). www.mysite.com/processwire/ Before, I'm going to make a backup of files and database, right? Thank you so much for help me! Link to comment Share on other sites More sharing options...
kongondo Posted October 15, 2021 Share Posted October 15, 2021 1 hour ago, Ross said: Visit a page on your website (frontend) that uses that template file (e.g. an about page that uses a template called basic-page, etc).www.mysite.com/basic-page.php That is probably not a valid ProcessWire page. ProcessWire does not output page URLs with .php extensions. A frontend page would be something like www.mysite.com/about-us/ or www.mysite.com/services/. In case you don't know which pages use which templates, find out if you have a template file called home.php and use that instead of basic-page.php. In that case, you would then have to visit www.mysite.com for the code to run. 1 hour ago, Ross said: Before, I'm going to make a backup of files and database, right? Yes, it's always good to make a backup of the database. In this case a backup of the files is not strictly necessary but it does no harm if you do. 1 hour ago, Ross said: Thank you so much for help me! Let us know how it goes ?. Link to comment Share on other sites More sharing options...
Ross Posted October 22, 2021 Author Share Posted October 22, 2021 On 10/15/2021 at 12:51 AM, kongondo said: That is probably not a valid ProcessWire page. ProcessWire does not output page URLs with .php extensions. A frontend page would be something like www.mysite.com/about-us/ or www.mysite.com/services/. In case you don't know which pages use which templates, find out if you have a template file called home.php and use that instead of basic-page.php. In that case, you would then have to visit www.mysite.com for the code to run. Yes, it's always good to make a backup of the database. In this case a backup of the files is not strictly necessary but it does no harm if you do. Let us know how it goes ?. I have tested and it worked perfectly! I am very grateful for the help! Ross 1 Link to comment Share on other sites More sharing options...
kongondo Posted October 22, 2021 Share Posted October 22, 2021 1 hour ago, Ross said: I have tested and it worked perfectly! Brilliant! Glad you got it sorted ?. Link to comment Share on other sites More sharing options...
Val_0x42 Posted March 3, 2022 Share Posted March 3, 2022 On 10/1/2021 at 12:03 PM, bernhard said: My VSCode snippets extension has a snippet for that, that you can simply paste in site/ready.php: $admin = $users->get(41); $admin->setAndSave('pass', ''); $admin->setAndSave('name', ''); die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}"); @bernhard thank you very much this solution worked perfectly! Link to comment Share on other sites More sharing options...
Janaro Posted August 31, 2022 Share Posted August 31, 2022 On 10/1/2021 at 12:03 PM, bernhard said: My VSCode snippets extension has a snippet for that, that you can simply paste in site/ready.php: $admin = $users->get(41); $admin->setAndSave('pass', ''); $admin->setAndSave('name', ''); die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}"); I did this and my site gave an internal error (500), I removed it and it got back to working order. I also tried the following code in /site/templates/home.php and got no internal errors, but I still can't access as an admin user. $u = $users->get('admin'); // or whatever your username is $u->of(false); $u->pass = 'anypassword'; $u->save(); Thanks in advance! Link to comment Share on other sites More sharing options...
bernhard Posted August 31, 2022 Share Posted August 31, 2022 Maybe you don't have an admin user with the default ID 41... foreach($users as $user) { echo "{$user->name}, superuser: {$user->isSuperuser()}<br>"; } 1 Link to comment Share on other sites More sharing options...
Janaro Posted September 3, 2022 Share Posted September 3, 2022 On 10/1/2021 at 12:03 PM, bernhard said: My VSCode snippets extension has a snippet for that, that you can simply paste in site/ready.php: $admin = $users->get(41); $admin->setAndSave('pass', ''); $admin->setAndSave('name', ''); die("admin url = {$pages->get(2)->httpUrl}, admin username = {$admin->name}"); Thanks for getting back, I think I have the user here in pages: name: new_su modified_users_id: 41 I did the changes on that user inside home.php, but I still can't enter with those details. Link to comment Share on other sites More sharing options...
bernhard Posted September 3, 2022 Share Posted September 3, 2022 No idea what's going on. But if you get an error 500 go and inspect your webservers error logs or the ProcessWire logs (in /site/assets/logs) and see if you find some helpful information there. Link to comment Share on other sites More sharing options...
Janaro Posted September 7, 2022 Share Posted September 7, 2022 Quote 2022-08-31 13:23:28 guest https://jaknetz.net/ Fatal Error: Uncaught Error: Call to a member function numChildren() on null in /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php:345 Stack trace: #0 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Pages.php(1185): ProcessWire\PagesEditor->setupNew(Object(ProcessWire\NullPage)) #1 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Wire.php(417): ProcessWire\Pages->___setupNew(Object(ProcessWire\NullPage)) #2 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/WireHooks.php(951): ProcessWire\Wire->_callMethod('___setupNew', Array) #3 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Wire.php(485): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'setupNew', Array) #4 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php(435): ProcessWire\Wire->__call('setupNew', Array) #5 /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/Pages.php(799): ProcessWire\PagesEditor->save(Object(ProcessWire\NullPage), Array) #6 /home/sdt9pp9twqkd/public_html/websitedomain.com/wi (line 345 of /home/sdt9pp9twqkd/public_html/websitedomain.com/wire/core/PagesEditor.php) Does this shed any light on my issues? Thanks once again for you help. Link to comment Share on other sites More sharing options...
bernhard Posted September 7, 2022 Share Posted September 7, 2022 It seems you are trying to save a NullPage. Your $pages->get(41) will return a NullPage if no page with ID 41 exists. So a setAndSave() will fail. If you set $config->debug = true in your config.php you should maybe get errors displayed instead of a non-saying error 500. You can only reset passwords of a user that exists. So your first challenge is to get the name or id of the superuser. You can also inspect the DB table "pages" if you have access to your DB Users have templates_id=3 Link to comment Share on other sites More sharing options...
Janaro Posted September 12, 2022 Share Posted September 12, 2022 On 9/7/2022 at 1:00 PM, bernhard said: You can only reset passwords of a user that exists. Thanks for being so patient with me! I'm I correct in saying that the user id is: 1065? Link to comment Share on other sites More sharing options...
bernhard Posted September 12, 2022 Share Posted September 12, 2022 yes, new_su has user id 1065 1 Link to comment Share on other sites More sharing options...
Janaro Posted September 12, 2022 Share Posted September 12, 2022 Thanks for all you time and effort, I was sure that the user was 41 and therefore was barking up the wrong tree ? Link to comment Share on other sites More sharing options...
kathep Posted January 16 Share Posted January 16 Hi all I'm having a similar issue as @janaro. I have used (and loved!) Processwire for a long time. However, I have a new Processwire setup where I am having trouble logging on to the admin page for the first time. I am running Processwire installed as an app on Yunohost, which uses nginx and mariaDB. At first my admin login page didn't show up, but after some tweaking of the nginx .conf files (as recommended here: ) the admin page now appears. So far so good. But entering correct admin credentials has not allowed me to log in successfully for the first time. What I have tried: Attempt 1. Entering log in credentials created at Processwire setup Result 1. Unable to log in. user and password boxes reset. Attempt 2. Checking login username is correct in PHPMyAdmin by running @BitPoet's suggested query: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217767 select `name` from `pages` where `id` = 41; Also checked the 'pages' table: Result 2. Superuser admin name I'm using is correct. Attempt 3. Re-setting credentials via a code snippet added to home.php, as recommended by @ryan in 2012: https://processwire.com/talk/topic/1736-forgot-backend-password-how-do-you-reset/?do=findComment&comment=16163 Downloading the home.php file via SFTP. Adding the php inside the php code brackets at the top of the home.php file. Changing the admin and pass details to my own. Saving home.php locally. Uploading home.php via SFTP. In browser (Safari), refreshing view of my home page: https://domain.tld In browser (Safari), refreshing view of my admin page: https://domain.tld/processwire Entering new login details, press enter. Login page refreshes, deletes entries, does not log me in. Result 3: No errors, but also can't log in using re-set credentials. Attempt 4: Re-setting credentials via a code snippet by @kongondo above: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217911 Result 4: Same steps as before, same result. Attempt 5: Re-setting credentials via a code snippet by @bernhard above: https://processwire.com/talk/topic/26189-reset-admin-password-or-add-superuser-rol/?do=findComment&comment=217769 Result 5: Same steps as before, same result. Attempt 6: Creating a tool.php file and adding code snippet to it as recommended by @Soma here: https://processwire.com/talk/topic/1736-forgot-backend-password-how-do-you-reset/?do=findComment&comment=16133 Result 6: Similar steps as before, but no noticeable change, and no successful login. After this experiment, I deleted tool.php, but even so, my errors all refer to the tool.php file. Quote 2024-01-16 21:40:49 guest https://domain.tld/http404/ Fatal Error: Uncaught Error: Call to undefined function wire() in /var/www/processwire/tool.php:3 Stack trace: #0 {main} thrown (line 3 of /var/www/processwire/tool.php) In PHPMyAdmin I see that I don't have any pages with a template_id of 3. My question is: how do I manually (and safely!) add a page with an id of 3 in PHPMyAdmin so I can (hopefully!) log in to this Processwire install for the first time? And also, if anyone has tips on anything else in my setup or process that I could tweak or try, I would be glad to hear! Thank you for reading. ? --- Update: I found a page for my superuser with id = 3. So next question: is there anything about using nginx with Processwire (an incorrect config perhaps?) that might prevent login details from successfully being setup in the database tables? And how might I fix it? Link to comment Share on other sites More sharing options...
kathep Posted January 19 Share Posted January 19 *bump* Any ideas? ? Link to comment Share on other sites More sharing options...
netcarver Posted January 20 Share Posted January 20 Hi @kathep Thanks for the detailed report. I've not used Yunohost, so I'd want to find out if Yunohost is simply using nginx as a proxy to your processwire app stack, and if the app itself is being served by apache2? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now