|
10 | 10 | * ******************************************************************************* |
11 | 11 | * |
12 | 12 | */ |
13 | | - |
| 13 | +const sqlite3 = require('sqlite3');//.verbose(); //use verbose in dev to get stack traces |
14 | 14 | const os = require('os'); |
15 | 15 | const execSync = require('child_process').execSync; |
16 | 16 | const fs = require('fs'); |
|
64 | 64 |
|
65 | 65 | fs.unlinkSync(installationVariablesFile); |
66 | 66 | } catch (e) { |
67 | | - console.log('no previous version') |
| 67 | + console.log('no previous version'); |
68 | 68 | } |
69 | 69 |
|
70 | 70 | //init db |
@@ -102,52 +102,46 @@ function moveFileIfExists(from, to) { |
102 | 102 |
|
103 | 103 | function insertSeeds() { |
104 | 104 | console.log(' inserting seeds meta info in db'); |
105 | | - const options = { |
106 | | - env: { |
107 | | - "PATH": process.env.PATH |
108 | | - }, |
109 | | - stdio: [process.stdin, process.stdout, process.stderr] |
110 | | - }; |
111 | | - |
112 | | - execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928110125-insert-registry.js');"`, options); |
113 | | - execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928111532-insert-catalog-item.js');"`, options); |
114 | | - execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928112152-insert-iofog-type.js');"`, options); |
115 | | - execSync(`sqlite3 ${prodDb} "insert into SequelizeMeta (name) values ('20180928121334-insert-catalog-item-image.js');"`, options); |
| 105 | + const sqlite3ProdDb = new sqlite3.Database(prodDb); |
| 106 | + const seeds = [ |
| 107 | + '20180928110125-insert-registry.js', |
| 108 | + '20180928111532-insert-catalog-item.js', |
| 109 | + '20180928112152-insert-iofog-type.js', |
| 110 | + '20180928121334-insert-catalog-item-image.js' |
| 111 | + ]; |
| 112 | + sqlite3ProdDb.serialize(function() { |
| 113 | + const stmt = sqlite3ProdDb.prepare("INSERT INTO SequelizeMeta (name) VALUES (?)"); |
| 114 | + seeds.map(s => stmt.run(s)); |
| 115 | + stmt.finalize(); |
| 116 | + }); |
| 117 | + sqlite3ProdDb.close(); |
116 | 118 | } |
117 | 119 |
|
118 | 120 | function updateEncryptionMethodForUsersPassword(decryptionFunc) { |
119 | | - const options = { |
120 | | - env: { |
121 | | - "PATH": process.env.PATH |
122 | | - } |
123 | | - }; |
124 | | - |
125 | | - const usersOutput = execSync(`sqlite3 ${prodDb} "select id, email, password from Users;"`, options).toString(); |
126 | | - const usersLines = usersOutput.match(/[^\r\n]+/g); |
127 | | - for (let line of usersLines) { |
128 | | - let id, email, oldEncryptedPassword; |
129 | | - try { |
130 | | - const vals = line.split('|'); |
131 | | - id = vals[0]; |
132 | | - email = vals[1]; |
133 | | - oldEncryptedPassword = vals[2]; |
134 | | - |
135 | | - const decryptedPassword = decryptionFunc(oldEncryptedPassword, email); |
136 | | - |
137 | | - const AppHelper = require('../src/helpers/app-helper'); |
138 | | - const newEncryptedPassword = AppHelper.encryptText(decryptedPassword, email); |
139 | | - |
140 | | - const options = { |
141 | | - env: { |
142 | | - "PATH": process.env.PATH |
143 | | - }, |
144 | | - stdio: [process.stdin, process.stdout, process.stderr] |
145 | | - }; |
146 | | - execSync(`sqlite3 ${prodDb} "update Users set password='${newEncryptedPassword}' where id=${id};"`, options); |
147 | | - } catch (e) { |
148 | | - console.log('db problem'); |
149 | | - } |
150 | | - } |
| 121 | + console.log(' updating encryption in DB'); |
| 122 | + const sqlite3ProdDb = new sqlite3.Database(prodDb); |
| 123 | + sqlite3ProdDb.all('select id, email, password from Users', function(err, rows) { |
| 124 | + const stmt = sqlite3ProdDb.prepare('update Users set password=? where id=?'); |
| 125 | + |
| 126 | + rows.map(user => { |
| 127 | + try { |
| 128 | + const id = user.id; |
| 129 | + const email = user.email; |
| 130 | + const oldEncryptedPassword = user.password; |
| 131 | + |
| 132 | + const decryptedPassword = decryptionFunc(oldEncryptedPassword, email); |
| 133 | + const AppHelper = require('../src/helpers/app-helper'); |
| 134 | + const newEncryptedPassword = AppHelper.encryptText(decryptedPassword, email); |
| 135 | + |
| 136 | + stmt.run(newEncryptedPassword, id); |
| 137 | + } catch (e) { |
| 138 | + console.log('db problem'); |
| 139 | + console.log(e); |
| 140 | + } |
| 141 | + }); |
| 142 | + stmt.finalize(); |
| 143 | + }); |
| 144 | + sqlite3ProdDb.close(); |
151 | 145 | } |
152 | 146 |
|
153 | 147 | function updateEncryptionMethodForEmailService(configFile, decryptionFunc) { |
@@ -191,6 +185,7 @@ function updateEncryptionMethod() { |
191 | 185 | } |
192 | 186 |
|
193 | 187 | updateEncryptionMethodForUsersPassword(decryptTextVer30); |
| 188 | + console.log(' updating encryption for email services in configs'); |
194 | 189 | updateEncryptionMethodForEmailService(defConfig, decryptTextVer30); |
195 | 190 | updateEncryptionMethodForEmailService(devConfig, decryptTextVer30); |
196 | 191 | updateEncryptionMethodForEmailService(prodConfig, decryptTextVer30); |
|
0 commit comments