mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Merge branch 'master' of github.com:node-red/node-red-nodes
This commit is contained in:
commit
d7dc9dae20
@ -17,27 +17,27 @@
|
|||||||
<script type="text/x-red" data-template-name="MySQLdatabase">
|
<script type="text/x-red" data-template-name="MySQLdatabase">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
|
<label for="node-config-input-host"><i class="fa fa-globe"></i> Host</label>
|
||||||
<input type="text" id="node-config-input-host" placeholder="localhost">
|
<input type="text" id="node-config-input-host">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-port"><i class="fa fa-random"></i> Port</label>
|
<label for="node-config-input-port"><i class="fa fa-random"></i> Port</label>
|
||||||
<input type="text" id="node-config-input-port" placeholder="3306">
|
<input type="text" id="node-config-input-port">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
|
<label for="node-config-input-user"><i class="fa fa-user"></i> User</label>
|
||||||
<input type="text" id="node-config-input-user" placeholder="JoeDemo">
|
<input type="text" id="node-config-input-user">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
|
<label for="node-config-input-pass"><i class="fa fa-lock"></i> Password</label>
|
||||||
<input type="password" id="node-config-input-pass" placeholder="mySecret">
|
<input type="password" id="node-config-input-password">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-db"><i class="fa fa-database"></i> Database</label>
|
<label for="node-config-input-db"><i class="fa fa-database"></i> Database</label>
|
||||||
<input type="text" id="node-config-input-db" placeholder="myDatabase">
|
<input type="text" id="node-config-input-db">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-tz"><i class="fa fa-clock-o"></i> Timezone</label>
|
<label for="node-config-input-tz"><i class="fa fa-clock-o"></i> Timezone</label>
|
||||||
<input type="text" id="node-config-input-tz" placeholder="local">
|
<input type="text" id="node-config-input-tz">
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -52,45 +52,13 @@
|
|||||||
db: {value:"",required:true},
|
db: {value:"",required:true},
|
||||||
tz: {value:""}
|
tz: {value:""}
|
||||||
},
|
},
|
||||||
|
credentials: {
|
||||||
|
user: {type: "text"},
|
||||||
|
password: {type: "password"}
|
||||||
|
},
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.db;
|
return this.db;
|
||||||
},
|
|
||||||
oneditprepare: function() {
|
|
||||||
$.getJSON('MySQLdatabase/'+this.id,function(data) {
|
|
||||||
if (data.user) {
|
|
||||||
$('#node-config-input-user').val(data.user);
|
|
||||||
}
|
}
|
||||||
if (data.hasPassword) {
|
|
||||||
$('#node-config-input-pass').val('__PWRD__');
|
|
||||||
} else {
|
|
||||||
$('#node-config-input-pass').val('');
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
},
|
|
||||||
oneditsave: function() {
|
|
||||||
var newUser = $('#node-config-input-user').val();
|
|
||||||
var newPass = $('#node-config-input-pass').val();
|
|
||||||
var credentials = {};
|
|
||||||
credentials.user = newUser;
|
|
||||||
if (newPass != '__PWRD__') {
|
|
||||||
credentials.password = newPass;
|
|
||||||
}
|
|
||||||
$.ajax({
|
|
||||||
url: 'MySQLdatabase/'+this.id,
|
|
||||||
type: 'POST',
|
|
||||||
data: credentials,
|
|
||||||
success:function(result){}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
ondelete: function() {
|
|
||||||
$.ajax({
|
|
||||||
url: 'MySQLdatabase/'+this.id,
|
|
||||||
type: 'DELETE',
|
|
||||||
success: function(result) {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -18,45 +18,6 @@ module.exports = function(RED) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var reconnect = RED.settings.mysqlReconnectTime || 30000;
|
var reconnect = RED.settings.mysqlReconnectTime || 30000;
|
||||||
var mysqldb = require('mysql');
|
var mysqldb = require('mysql');
|
||||||
var querystring = require('querystring');
|
|
||||||
|
|
||||||
RED.httpAdmin.get('/MySQLdatabase/:id',function(req,res) {
|
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
|
||||||
if (credentials) {
|
|
||||||
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!=="")}));
|
|
||||||
} else {
|
|
||||||
res.send(JSON.stringify({}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
RED.httpAdmin.delete('/MySQLdatabase/:id',function(req,res) {
|
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
|
||||||
res.send(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
RED.httpAdmin.post('/MySQLdatabase/:id',function(req,res) {
|
|
||||||
var body = "";
|
|
||||||
req.on('data', function(chunk) {
|
|
||||||
body+=chunk;
|
|
||||||
});
|
|
||||||
req.on('end', function(){
|
|
||||||
var newCreds = querystring.parse(body);
|
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
|
||||||
if (newCreds.user == null || newCreds.user === "") {
|
|
||||||
delete credentials.user;
|
|
||||||
} else {
|
|
||||||
credentials.user = newCreds.user;
|
|
||||||
}
|
|
||||||
if (newCreds.password === "") {
|
|
||||||
delete credentials.password;
|
|
||||||
} else {
|
|
||||||
credentials.password = newCreds.password||credentials.password;
|
|
||||||
}
|
|
||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
|
||||||
res.send(200);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function MySQLNode(n) {
|
function MySQLNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -67,21 +28,6 @@ module.exports = function(RED) {
|
|||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.connecting = false;
|
this.connecting = false;
|
||||||
|
|
||||||
var credentials = {};
|
|
||||||
if (n.user) {
|
|
||||||
credentials.user = n.user;
|
|
||||||
credentials.password = n.pass;
|
|
||||||
RED.nodes.addCredentials(n.id,credentials);
|
|
||||||
this.user = n.user;
|
|
||||||
this.password = n.pass;
|
|
||||||
} else {
|
|
||||||
credentials = RED.nodes.getCredentials(n.id);
|
|
||||||
if (credentials) {
|
|
||||||
this.user = credentials.user;
|
|
||||||
this.password = credentials.password;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dbname = n.db;
|
this.dbname = n.db;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
@ -90,8 +36,8 @@ module.exports = function(RED) {
|
|||||||
node.connection = mysqldb.createConnection({
|
node.connection = mysqldb.createConnection({
|
||||||
host : node.host,
|
host : node.host,
|
||||||
port : node.port,
|
port : node.port,
|
||||||
user : node.user,
|
user : node.credentials.user,
|
||||||
password : node.password,
|
password : node.credentials.password,
|
||||||
database : node.dbname,
|
database : node.dbname,
|
||||||
timezone : node.tz,
|
timezone : node.tz,
|
||||||
insecureAuth: true
|
insecureAuth: true
|
||||||
@ -124,16 +70,24 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on('close', function () {
|
this.on('close', function (done) {
|
||||||
if (this.tick) { clearTimeout(this.tick); }
|
if (this.tick) { clearTimeout(this.tick); }
|
||||||
if (this.connection) {
|
if (this.connection) {
|
||||||
node.connection.end(function(err) {
|
node.connection.end(function(err) {
|
||||||
if (err) { node.error(err); }
|
if (err) { node.error(err); }
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("MySQLdatabase",MySQLNode);
|
RED.nodes.registerType("MySQLdatabase",MySQLNode, {
|
||||||
|
credentials: {
|
||||||
|
user: {type: "text"},
|
||||||
|
password: {type: "password"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function MysqlDBNodeIn(n) {
|
function MysqlDBNodeIn(n) {
|
||||||
|
Loading…
Reference in New Issue
Block a user