refs #4974 Added updateODBC function and more

This commit is contained in:
Guillermo Bonet 2023-01-02 12:50:13 +01:00
parent 65fc298955
commit 127abd6fb8
3 changed files with 99 additions and 88 deletions

View File

@ -1,11 +1,11 @@
var odbcPath = 'HKCU\\Software\\ODBC\\ODBC.INI\\';
var Conf = { var Conf = {
appName: 'Verdnatura', appName: 'Verdnatura',
dsName: 'verdnatura', dsName: 'verdnatura',
dsPath: 'HKCU\\SOFTWARE\\ODBC\\ODBC.INI\\verdnatura', dsPath: odbcPath + 'verdnatura',
regPath: 'HKCU\\SOFTWARE\\Verdnatura\\vn-access', regPath: 'HKCU\\SOFTWARE\\Verdnatura\\vn-access',
remoteUrl: 'https://cdn.verdnatura.es/vn-access', remoteUrl: 'https://cdn.verdnatura.es/vn-access',
dbHost: 'db.verdnatura.es',
defaultModule: 'vn', defaultModule: 'vn',
defaultLocale: 'es', defaultLocale: 'es',
defaultBranch: 'master', defaultBranch: 'master',
@ -16,7 +16,6 @@ var Conf = {
defaultDatasource: 'production', defaultDatasource: 'production',
version: 4, version: 4,
cdnURL: 'https://cdn.verdnatura.es/vn-access', cdnURL: 'https://cdn.verdnatura.es/vn-access',
cdnURL: 'https://salix.verdnatura.es',
datasources: { datasources: {
production: { production: {
DESCRIPTION: 'production', DESCRIPTION: 'production',
@ -47,7 +46,7 @@ var Conf = {
var Locale = { var Locale = {
es: { es: {
"Enter a user name": "Enter a username":
"Introduce un nombre de usuario", "Introduce un nombre de usuario",
"Enter a password": "Enter a password":
"Introduce una contraseña", "Introduce una contraseña",
@ -79,7 +78,7 @@ var App = {
init: function() { init: function() {
// Specify the size of window // Specify the size of window
var width = 420; var width = 420;
var height = 560; var height = 550;
window.resizeTo(width, height); window.resizeTo(width, height);
window.moveTo((screen.width - width) / 2, (screen.height - height) / 2); window.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
}, },
@ -109,42 +108,24 @@ var App = {
var myVersion = this.regRead(Conf.regPath, 'version'); var myVersion = this.regRead(Conf.regPath, 'version');
if (!myVersion || myVersion != Conf.version) { if (!myVersion || myVersion != Conf.version) {
var path; var path = 'HKCU\\Software\\Microsoft\\Office\\11.0\\Access\\';
// Creates the Access configuration entries // Creates the Access configuration entries
path = 'HKCU\\Software\\Microsoft\\Office\\11.0\\Access\\Settings'; this.regWrites(path + 'Settings', {
this.regWrites(path, { 'Confirm Document Deletions': false,
'Confirm Document Deletions' : false, 'Confirm Action Queries': false,
'Confirm Action Queries' : false, 'Confirm Record Changes': false
'Confirm Record Changes' : false
}); });
this.regWrite(path + 'Security', 'Level', 1);
path = 'HKCU\\Software\\Microsoft\\Office\\11.0\\Access\\Security';
this.regWrite(path, 'Level', 1);
// Creates the MySQL ODBC connection // Creates the MySQL ODBC connection
var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath; this.createODBC(
odbcPath,
var params = {
Driver : driverPath,
DESCRIPTION : Conf.appName,
SERVER : Conf.dbHost,
DATABASE : Conf.dbName,
SSLCA : this.certFile,
SSLMODE : 'VERIFY_IDENTITY',
SSLCIPHER : 'AES256-SHA',
AUTO_RECONNECT : '1',
NO_PROMPT : '1',
ENABLE_CLEARTEXT_PLUGIN : '1'
};
this.createOdbc(
Conf.dsName, Conf.dsName,
Conf.odbcDriver, Conf.odbcDriver
params
); );
//Datasources creations //Datasources creation
this.createDatasources(); this.createDatasources();
// Upload the string value to version installed // Upload the string value to version installed
@ -186,7 +167,7 @@ var App = {
// Datasource options // Datasource options
this.$('datasource').value = this.getDatasource(); this.$('datasource').value = this.getDatasource();
this.onChangeDatasource(); this.onChangeDatasource(true);
}, },
resetForm: function(clearPassword) { resetForm: function(clearPassword) {
@ -197,10 +178,42 @@ var App = {
this.$('user').select(); this.$('user').select();
}, },
createOdbc: function(dsName, driverName, params) { createODBC: function(path, dsName, driverName) {
var odbcPath = 'HKCU\\Software\\ODBC\\ODBC.INI\\'; var driverPath = this.getEnv('ProgramFiles') + Conf.driverPath;
this.regWrites(odbcPath + dsName, params);
this.regWrite(odbcPath + 'ODBC Data Sources', dsName, driverName); var params = {
Driver: driverPath,
DESCRIPTION: Conf.appName,
SERVER: Conf.datasources.production.SERVER,
DATABASE: Conf.dbName,
SSLCA: this.certFile,
SSLMODE: 'VERIFY_IDENTITY',
SSLCIPHER: 'AES256-SHA',
AUTO_RECONNECT: 1,
NO_PROMPT: 1,
ENABLE_CLEARTEXT_PLUGIN: 1
};
this.regWrite(path + 'ODBC Data Sources', dsName, driverName);
this.regWrites(path + dsName, params);
},
updateODBC: function(path, dsName, datasource) {
var params;
if (datasource == 'production')
params = Conf.datasources.production
if (datasource == 'test')
params = Conf.datasources.test
if (datasource == 'dev')
params = Conf.datasources.dev
if (datasource == 'localhost')
params = Conf.datasources.localhost
this.regWrites(path + dsName, params);
}, },
disableUi: function(disabled, loadMessage) { disableUi: function(disabled, loadMessage) {
@ -256,16 +269,23 @@ var App = {
this.$('user').focus(); this.$('user').focus();
}, },
onChangeDatasource: function() { onChangeDatasource: function(isOnLoad) {
if (this.$("datasource").value == "production"||"test"||"dev") { var myDatasource = this.$("datasource").value;
this.$("datasourceButton").className = this.$("datasource").value; if (myDatasource == "production"||"test"||"dev") {
this.$("datasource").className = this.$("datasource").value; this.$("datasourceButton").className = myDatasource;
this.$("datasource").className = myDatasource;
} else { } else {
this.$("datasourceButton").className = null; this.$("datasourceButton").className = null;
this.$("datasource").className = null; this.$("datasource").className = null;
} }
this.updateDatasource(this.$("datasource").value); if (!isOnLoad) {
this.$('user').focus(); this.updateDatasource(myDatasource);
this.updateODBC(
odbcPath,
Conf.dsName,
myDatasource
);
}
var curDatasource = this.regRead(Conf.regPath, 'currentDatasource'); var curDatasource = this.regRead(Conf.regPath, 'currentDatasource');
var datasourcePath = Conf.regPath + '\\datasources\\' + curDatasource; var datasourcePath = Conf.regPath + '\\datasources\\' + curDatasource;
@ -276,6 +296,7 @@ var App = {
this.$('user').value = myUID; this.$('user').value = myUID;
this.$('password').value = myPWD; this.$('password').value = myPWD;
} }
this.$('user').focus();
}, },
cleanCache: function() { cleanCache: function() {
@ -324,18 +345,12 @@ var App = {
login: function() { login: function() {
try { try {
var user = this.$('user').value; var user = this.$('user').value;
var password = this.$('password').value; if (!user)
var branch = this.$('branch').value; throw new Error(_('Enter a username'));
var datasource = this.$('datasource').value;
if (!user || user === '') var password = this.$('password').value;
throw new Error(_('Enter a user name')); if (!password)
if (!password || password === '')
throw new Error(_('Enter a password')); throw new Error(_('Enter a password'));
if (!branch || branch === '')
throw new Error(_('Select a branch'));
if (!datasource || datasource === '')
throw new Error(_('Select a datasource'));
this.regWrite(Conf.dsPath, 'UID', user); this.regWrite(Conf.dsPath, 'UID', user);
this.regWrite(Conf.dsPath, 'PWD', password); this.regWrite(Conf.dsPath, 'PWD', password);
@ -372,15 +387,15 @@ var App = {
var mysqlConn = new ActiveXObject('ADODB.Connection');; var mysqlConn = new ActiveXObject('ADODB.Connection');;
try { try {
mysqlConn.open(this.getOdbcString({ mysqlConn.open(this.getODBCString({
Driver : '{'+ Conf.odbcDriver +'}', Driver: '{'+ Conf.odbcDriver +'}',
Server : Conf.dbHost, Server: Conf.datasources.production.SERVER,
Database : Conf.dbName, Database: Conf.dbName,
Uid : this.$('user').value, Uid: this.$('user').value,
Pwd : this.$('password').value, Pwd: this.$('password').value,
Sslca : this.certFile, Sslca: this.certFile,
SslMode : 'VERIFY_IDENTITY', SslMode: 'VERIFY_IDENTITY',
SslCipher : 'AES256-SHA', SslCipher: 'AES256-SHA',
ENABLE_CLEARTEXT_PLUGIN : 1 ENABLE_CLEARTEXT_PLUGIN : 1
})); }));
} catch (err) { } catch (err) {
@ -442,7 +457,8 @@ var App = {
'SELECT Version FROM tblVariables', 'SELECT Version FROM tblVariables',
'Version', parseInt 'Version', parseInt
); );
if (!localVersion) localVersion = false; if (!localVersion)
localVersion = false;
// Determines if should download // Determines if should download
return !localVersion || version === false || localVersion != version return !localVersion || version === false || localVersion != version
@ -455,7 +471,7 @@ var App = {
try { try {
if (this.fso.fileExists(this.mdbFile)) { if (this.fso.fileExists(this.mdbFile)) {
var mdbConn = new ActiveXObject('ADODB.Connection'); var mdbConn = new ActiveXObject('ADODB.Connection');
mdbConn.open(this.getOdbcString({ mdbConn.open(this.getODBCString({
'Provider': 'Microsoft.Jet.OLEDB.4.0', 'Provider': 'Microsoft.Jet.OLEDB.4.0',
'Data Source': this.mdbFile 'Data Source': this.mdbFile
})); }));
@ -473,7 +489,7 @@ var App = {
return value; return value;
}, },
getOdbcString: function(options) { getODBCString: function(options) {
var optionsArray = []; var optionsArray = [];
for (var option in options) for (var option in options)
optionsArray.push(option +'='+ options[option]); optionsArray.push(option +'='+ options[option]);
@ -485,7 +501,7 @@ var App = {
try { try {
if (request.status !== 200) if (request.status !== 200)
throw new Error('HTTP: '+ request.statusText); throw new Error('HTTP: '+ request.statusText + ' ' + request.status);
if (this.fso.fileExists(this.compressFile)) if (this.fso.fileExists(this.compressFile))
this.fso.deleteFile(this.compressFile); this.fso.deleteFile(this.compressFile);
@ -652,20 +668,19 @@ var App = {
this.regWrite(Conf.regPath, 'currentDatasource', datasource); this.regWrite(Conf.regPath, 'currentDatasource', datasource);
}, },
createDatasources: function() { createDatasources: function() {
this.regWrite(Conf.regPath + '\\datasources');
var params = { var params = {
'UID': null, 'UID': null,
'PWD': null 'PWD': null
} }
for (var datasource in Conf.datasources) { for (var datasource in Conf.datasources) {
var myPath = Conf.regPath + '\\datasources\\' + datasource
for (var stringValues in Conf.datasources[datasource]) { for (var stringValues in Conf.datasources[datasource]) {
this.regWrite(Conf.regPath + '\\datasources\\' + datasource, this.regWrite(myPath,
stringValues, stringValues,
Conf.datasources[datasource][stringValues] Conf.datasources[datasource][stringValues]
); );
} }
this.regWrites(Conf.regPath + '\\datasources\\' + datasource, params); this.regWrites(myPath, params);
}; };
}, },

View File

@ -41,12 +41,8 @@ option {
#inputs > div > * { #inputs > div > * {
display: block; display: block;
} }
label {
font-weight: normal;
font-size: .9em;
}
#inputs label { #inputs label {
color: #666; color: rgb(155, 155, 155);
font-size: .8em; font-size: .8em;
} }
input[type='text'], input[type='text'],
@ -58,7 +54,7 @@ input[type='password'] {
color: #333; color: #333;
padding-top: .5em; padding-top: .5em;
padding-bottom: .5em; padding-bottom: .5em;
padding-left: .2em; padding-left: .3em;
max-width: auto; max-width: auto;
} }
input[type='text']:focus, input[type='text']:focus,
@ -67,7 +63,7 @@ input[type='password']:focus {
} }
#notSignOut { #notSignOut {
margin-top: 1em; margin-top: 1em;
font-size: .9em; font-size: .8em;
margin-bottom: 2.5em; margin-bottom: 2.5em;
} }
#submit { #submit {
@ -86,7 +82,6 @@ input[type='password']:focus {
margin-top: 10px; margin-top: 10px;
} }
#clean:hover { #clean:hover {
text-decoration: underline; text-decoration: underline;
text-decoration-color: #44f; text-decoration-color: #44f;
} }
@ -124,6 +119,7 @@ button:hover {
#branchSelector { #branchSelector {
float: right; float: right;
margin-top: .7em; margin-top: .7em;
width: 107px;
display: none; display: none;
padding-left: .3em; padding-left: .3em;
padding-right: .8em; padding-right: .8em;
@ -132,7 +128,7 @@ button:hover {
float: left; float: left;
border-radius: 25px; border-radius: 25px;
color: black; color: black;
box-shadow: 0px 0px 5px 0px black; box-shadow: 0 0 .25em rgba(1,1,1,.6);
background-color: #8d8d8d; background-color: #8d8d8d;
} }
#branchButton:hover { #branchButton:hover {
@ -186,14 +182,14 @@ select.dev {
float: right; float: right;
display: none; display: none;
padding-right: .8em; padding-right: .8em;
margin-right: 0.5em; margin-right: .5em;
margin-top: -1.91em; margin-top: -1.91em;
} }
#datasourceButton { #datasourceButton {
float: right; float: right;
border-radius: 25px; border-radius: 25px;
color: black; color: black;
box-shadow: 0px 0px 5px 0px #000000; box-shadow: 0 0 .25em rgba(1,1,1,.6);
background-color: #8d8d8d; background-color: #8d8d8d;
} }
#datasourceButton:hover { #datasourceButton:hover {
@ -235,7 +231,7 @@ select.dev {
font-size: .8em; font-size: .8em;
display: none; display: none;
border-radius: 5px; border-radius: 5px;
box-shadow: 0 0 0.4em rgba(1,1,1,0.6); box-shadow: 0 0 .4em rgba(1,1,1,.6);
} }
#message.error { #message.error {
border-color: black; border-color: black;
@ -257,7 +253,7 @@ select.dev {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: black; background-color: black;
opacity: 0.7; opacity: .7;
filter: alpha(opacity=50); filter: alpha(opacity=50);
top: 0; top: 0;
left: 0; left: 0;

View File

@ -47,10 +47,10 @@
</div> </div>
</div> </div>
<div id="submit"> <div id="submit">
<button id="enter" onclick="App.onEnterClick()"> Iniciar sesión</button> <button id="enter" onclick="App.onEnterClick()">Iniciar sesión</button>
</div> </div>
<div id="cleanDiv"> <div id="cleanDiv">
<a id="clean" href="#" onclick="App.onCleanCacheClick()"> Limpiar caché </a> <a id="clean" href="#" onclick="App.onCleanCacheClick()">Limpiar caché </a>
</div> </div>
<div id="branchOptions"> <div id="branchOptions">
<div id="branchButton"> <div id="branchButton">
@ -78,7 +78,7 @@
App.onShowBranchOptionsClick()" App.onShowBranchOptionsClick()"
alt="Change datasource"/> alt="Change datasource"/>
<div id="datasourceSelector"> <div id="datasourceSelector">
<select id="datasource" onchange="App.onChangeDatasource()"> <select id="datasource" onchange="App.onChangeDatasource(false)">
<option value="production">production</option> <option value="production">production</option>
<option value="test">test</option> <option value="test">test</option>
<option value="dev">dev</option> <option value="dev">dev</option>