Reset Mango User Passwords
-
Hello Everyone,
I imported user settings via a json as I have in the past but this time I was unable to log in after rebooting. Now the original default information no longer works and the user/passwords from the imported settings also don't work.
I am wondering if anyone knows of a way that I could reset the passwords, this instance is on a MangoES which I do have CLI access to.
Any help would be appreciated.
Thank You,
Ed -
Hi Ed,
Yikes! One of those two passwords should definitely work. You will have an H2 backup of your database in Mango/backup/ most likely, and you can restore your H2 database by:
- Backup / Move your Mango/databases/mah2.h2.db file in case you require it
- Run the following command after changing the date to the date of your backup, and potentially adding in your user / password if they are specified in Mango/overrides/properties/env.properties:
java -cp /opt/mango/lib/h2-1.4.181.jar org.h2.tools.RunScript -url "jdbc:h2:/opt/mango/databases/mah2;MV_STORE=FALSE;MVCC=FALSE" -user "" -script /opt/mango/backup/core-database-H2-Jul-25-2016_000500.zip -options compression zip
Best to be careful when importing entire configurations for this very reason. Also, there is a bug in some versions that permits the database schema version to be imported, which causes SQL errors at the next startup, so it is not a good idea to import database schema versions in the systemSettings object between instances.
-
Also note that the password in the Users JSON is encrypted so that is not that actual password to use after the Users are imported. You still need to know what the original password was.
-
I was able to run the command but now I receive "This site can't be reached xxx.xxx.xxx.xxx refused to connect"
I still have access to the CLI.
Any advice?
Ed
-
Are there errors when you try to launch Mango?
-
I don't receive any errors.
I did just notice that when I stop/start the mango service I can initially get to the Mango loading screen but it stays at 0 and when I refresh I get the connection refused error from the browser.
-
That would strongly suggest to me that if you attempt to start Mango at the command line (sudo service mango stop; cd /opt/mango/bin/; sudo ./ma.sh start) you will get an error. Most likely it is having some issue with the database, since that's what we're playing with. Did you try to get a username and password for my java command, if they're set in your env.properties?
Alternatively: tail -n 100 /opt/mango/logs/ma.log
-
Phil,
The username/password was blank in this instance.
Just as you suspected I received an error when starting it via command line.
ERROR 2013-01-02 20:30:46,120 (com.serotonin.m2m2.Main.main:120) - Error during initialization
com.serotonin.ShouldNeverHappenException: org.springframework.jdbc.BadSqlGrammar Exception: StatementCallback; bad SQL grammar [CREATE TABLE jsonData (id int not null auto_increment, xid varchar(50) not null, name varchar(255) not null, read Permission varchar(255), editPermission varchar(255), data longtext, primary key (id)); ]; nested exception is org.h2.jdbc.JdbcSQLException: Table "JSONDATA" al ready exists; SQL statement:
CREATE TABLE jsonData (id int not null auto_increment, xid varchar(50) not null, name varchar(255) not null, readPermission varchar(255), editPermission varchar (255), data longtext, primary key (id)); [42101-181]
at com.serotonin.m2m2.db.upgrade.DBUpgrade.checkUpgrade(DBUpgrade.java:1 02)
at com.serotonin.m2m2.db.upgrade.DBUpgrade.checkUpgrade(DBUpgrade.java:3 4)
at com.serotonin.m2m2.db.DatabaseProxy.initialize(DatabaseProxy.java:180 )
at com.serotonin.m2m2.Lifecycle.databaseInitialize(Lifecycle.java:602)
at com.serotonin.m2m2.Lifecycle.initialize(Lifecycle.java:280)
at com.serotonin.m2m2.Main.main(Main.java:116)
Caused by: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; b ad SQL grammar [CREATE TABLE jsonData (id int not null auto_increment, xid varch ar(50) not null, name varchar(255) not null, readPermission varchar(255), editPe rmission varchar(255), data longtext, primary key (id)); ]; nested exception is org.h2.jdbc.JdbcSQLException: Table "JSONDATA" already exists; SQL statement:
CREATE TABLE jsonData (id int not null auto_increment, xid varchar(50) not null, name varchar(255) not null, readPermission varchar(255), editPermission varchar (255), data longtext, primary key (id)); [42101-181]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.d oTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslat or.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java: 415)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java: 439)
at com.serotonin.m2m2.db.H2Proxy.runScript(H2Proxy.java:146)
at com.serotonin.m2m2.db.upgrade.DBUpgrade.runScript(DBUpgrade.java:129)
at com.serotonin.m2m2.db.upgrade.DBUpgrade.runScript(DBUpgrade.java:143)
at com.serotonin.m2m2.db.upgrade.DBUpgrade.runScript(DBUpgrade.java:134)
at com.serotonin.m2m2.db.upgrade.Upgrade11.upgrade(Upgrade11.java:27)
at com.serotonin.m2m2.db.upgrade.DBUpgrade.checkUpgrade(DBUpgrade.java:9 8)
... 5 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "JSONDATA" already exists; SQL st atement:
CREATE TABLE jsonData (id int not null auto_increment, xid varchar(50) not null, name varchar(255) not null, readPermission varchar(255), editPermission varchar (255), data longtext, primary key (id)); [42101-181]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:111)
at org.h2.command.CommandContainer.update(CommandContainer.java:78)
at org.h2.command.Command.executeUpdate(Command.java:254)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:185)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:159)
at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback. doInStatement(JdbcTemplate.java:431)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java: 404)
... 12 more
INFO 2013-01-02 20:30:46,130 (com.serotonin.m2m2.Lifecycle.terminate:344) - Man go Lifecycle terminating...
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.infiniteautomation.nosql.MangoNoSqlProxy.shutdown(MangoNoSqlProxy .java:149)
at com.serotonin.m2m2.db.DatabaseProxy.terminate(DatabaseProxy.java:230)
at com.serotonin.m2m2.Lifecycle.databaseTerminate(Lifecycle.java:607)
at com.serotonin.m2m2.Lifecycle.terminate(Lifecycle.java:408)
at com.serotonin.m2m2.Main.main(Main.java:121)
Caused by: java.lang.IllegalStateException: Connection pool has been disposed.
at org.h2.jdbcx.JdbcConnectionPool.getConnectionNow(JdbcConnectionPool.j ava:221)
at org.h2.jdbcx.JdbcConnectionPool.getConnection(JdbcConnectionPool.java :199)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(D ataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(Dat aSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java: 615)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:68 0)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:71 2)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:72 2)
at com.serotonin.db.spring.ExtendedJdbcTemplate.queryForObject(ExtendedJ dbcTemplate.java:39)
at com.serotonin.db.spring.ExtendedJdbcTemplate.queryForObject(ExtendedJ dbcTemplate.java:63)
at com.serotonin.db.DaoUtils.queryForObject(DaoUtils.java:336)
at com.serotonin.m2m2.db.dao.SystemSettingsDao.getValue(SystemSettingsDa o.java:157)
at com.serotonin.m2m2.db.dao.SystemSettingsDao.getIntValue(SystemSetting sDao.java:177)
at com.infiniteautomation.nosql.MangoNoSqlBatchWriteBehindManager.<init> (MangoNoSqlBatchWriteBehindManager.java:97)
at com.infiniteautomation.nosql.MangoNoSqlBatchWriteBehindManager.<clini t>(MangoNoSqlBatchWriteBehindManager.java:91)
... 5 more -
FYI this unit was basically fresh out of the box so it doesn't have any information on it that would need to be salvaged.
-
Oh, that's much easier, then. You can just delete / move your Mango/databases/ directory and start up clean. Your configuration should have JSON exported itself into Mango/backup if it was on overnight.
You are very close though! To alleviate that error you can use the Mango/bin/h2-web-console.sh script (here's some information on that: http://help.infiniteautomation.com/support/solutions/articles/14000022661-about-the-h2-database ) and run either (but not both!) of these commands:
update systemSettings set settingvalue='12' where settingname='databaseSchemaVersion';
OR
drop table jsonData;Either would hopefully let you startup normally after being run.
-
Success!
Deleting the database did the trick.
Thanks a ton Phil!