You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dcs/ui/login2.js

350 lines
12 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

var express = require('express')
var path = require("path");
var mysql = require('mysql')
var alert = require('alert')
var router = express.Router()
var app = express()
const {get} = require('http')
const multer = require('multer')
var childProcess = require('child_process')
const bodyParser = require('body-parser')
const fs = require('fs')
app.use(express.static('./'))
//const document = require('document')
var jsdom = require("jsdom");
const { NULL } = require('mysql/lib/protocol/constants/types');
var JSDOM = jsdom.JSDOM;
var document = new JSDOM().window.document;
var execSync = require("child_process").execSync;
var sys = require('sys');
var exec = require('child_process').exec
const cp = require('child_process');
/**
* 配置MySql
*/
var connection = mysql.createConnection({
host : '10.129.16.173',
user : 'root',
password : '427318Aa',
database : 'test',
port:'3306'
});
connection.connect();
app.use('/public', express.static('public')); // 设置静态文件的中间件
app.use(bodyParser.urlencoded({ extended: false })); // 判断请求体是不是json不是的话把请求体转化为对象
app.use(multer({ dest: 'tmp/' }).array('file'));//multer中间件用于上传表单型数据基本属性为dest会添加file对象到request对象中包含对象表单上传的文件信息
app.get('/',function (req,res) {
res.sendfile(__dirname + "/login.html" );
})
/*app.get('/',function(req,res){
res.sendFile(path.join(__dirname,"/login.html"))
//_dirname:当前文件的路径path.join():合并路径
})
/**
* 实现登录验证功能
*/
var ppcookie = ''
var ppname = ''
var pppwd = ''
app.get('/login', function (req, res) {
var response = {
"name":req.query.name,
"password":req.query.pwd,
};
/*var selectSQL = "select * from UserInfoTest where User_Name = '" + name + "' and User_Password = '" + password + "'";*/
var selectSQL = "select uname,pwd from user where uname = '" + req.query.name + "' and pwd = '" + req.query.pwd + "'";
connection.query(selectSQL, function (err, result) {
if (err) {
console.log('[login ERROR] - ', err.message);
return;
}
if (result == '') {
console.log("帐号密码错误");
res.end("The account does not exist or the password is wrong!");
}
else {
console.log(result);
console.log("OK"+'123');
ppname = req.query.name
pppwd = req.query.pwd
res.redirect("/public/" + "ok1.html");//重定向到网页
// dummy = childProcess.spawn('python' ,['./tmp.py'] ,{cwd: path.resolve(__dirname, './')})
const ls = childProcess.spawn('python3' ,['./connect2.py', '--ip','10.129.16.173', '--port','7777','login','--user',req.query.name,'--password',req.query.pwd],{cwd: path.resolve(__dirname, './')})
ls.stdout.on('data', function (data){
//console.log('sdjfksjdfklajklfdjalkjfklda')
var a = data.toString()
a = a.trim()
ppcookie = a
console.log(ppcookie);
// console.log(a[]);
})
//execute('python tmp.py')
// execute('python connect.py --ip 10.129.16.173 --port 7777 login --user wufayuan --password 113818');
/* const ls = childProcess.spawn('python3' ,['connect.py', '--ip','192.168.43.241', '--port','7777','login','--user','wufayuan','--password','113818'],{cwd: path.resolve(__dirname, './')
})
ls.stdout.on('data', function(data){
sys.print(data);
});
ls.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});*/
}
});
console.log(response);
})
/**connection.query(selectSQL,function (err,rs) {
if (err) throw err;
console.log(rs);
console.log('OK');
res.sendfile(__dirname + "/public/" + "ok.html" );
})
})**/
app.get('/register.html',function (req,res) {
res.sendfile(__dirname+"/lndex.html");
})
/**
* 实现注册功能
*/
app.get('/register',function (req,res) {
var name=req.query.name;
var pwd = req.query.pwd;
var selectSQL = "select uname,pwd from user where uname = '" + req.query.name+"'";
connection.query(selectSQL, function (err, result) {
if (err) {
console.log('[login ERROR] - ', err.message);
return;
}
if (result.length) {
res.send("The account exist!");
}
else {
var user = { uname: name, pwd: pwd ,finame:NULL,email:NULL,phone:NULL};
connection.query('insert into user set ?', user, function (err, rs) {
// if (err) throw err;
console.log('ok');
res.redirect('login.html');
const ls = childProcess.spawn('python3' ,['./connect2.py', '--ip','10.129.16.173', '--port','7777','register','--user',name,'--password',pwd],{cwd: path.resolve(__dirname, './')
})
})
}
})
})
app.get('/ok1.html',function (req,res) {
res.redirect("/public/"+"ok1.html");
})
var server=app.listen(3300,function () {
console.log("start");
})
//const express = require('express');
/*const timeout = require('connect-timeout');
const { createProxyMiddleware } = require('http-proxy-middleware');
// HOST 指目标地址 PORT 服务端口
const HOST = 'http://10.129.77.113:7777', PORT = '3300';
// 超时时间
const TIME_OUT = 30 * 1e3;
// 设置端口
app.set('port', PORT);
// 设置超时 返回超时响应
app.use(timeout(TIME_OUT));
app.use((req, res, next) => {
if (!req.timedout) next();
});
// 设置静态资源路径
app.use('/', express.static('static'));
// 反向代理(这里把需要进行反代的路径配置到这里即可)
// eg:将/api 代理到 ${HOST}/api
// app.use(createProxyMiddleware('/api', { target: HOST }));
// 自定义代理规则
app.use(createProxyMiddleware('/api', {
target: HOST, // target host
changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets
pathRewrite: {
'^/api': '', // rewrite path
}
}));
// 监听端口
app.listen(app.get('port'), () => {
console.log(`server running ${PORT }`);
});*/
// 上传文件api
app.post('/file_upload', function (req, res) {
console.log(req.files[0]); // 上传的文件信息
var des_file = __dirname + "/0/" + req.files[0].originalname;
fs.readFile( req.files[0].path, function (err, data) {
fs.writeFile(des_file, data, function (err) {
if( err ){
console.log( err );
}else{
response = {
message:'File uploaded successfully',
filename:req.files[0].originalname
};
}
console.log( response );
res.end( JSON.stringify( response ) );
});
});
})
function execute(cmd) { //调用cmd命令
execSync(cmd, { cwd: './' }, function (error, stdout, stderr) {
if (error) {
console.error(error);
}
else {
console.log("executing success!")
}
})
}
app.get('/check', function (req, res) {
var logo=req.query.logo;
console.log(logo);
// console.log(ppcookie);
a = ppcookie
console.log(a);
//const ls = childProcess.spawn('python3' ,['./connect.py','--word',logo,'--cookie',a])
const ls = childProcess.spawn('python3' ,['./connect1.py','--ip','10.129.16.173','--port','7777','crawling','--word',logo,'--pages_start',1,'--pages_end',3,'--cookie',a])
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
ls.on('close', function(code){
res.redirect("/tmmps.html")
})
/*exec('python connect.py --ip 10.129.16.173 --port 7777 crawling --word '+logo +' --pages_start 1 --pages_end 3 --cookie '+a, {
// timeout: 0, // 超时时间
cwd: path.resolve(__dirname, './'), // 可以改变当前的执行路径
}, function (err, stdout, stderr) {
res.redirect("/tmmps.html")
return
// 执行结果
})*/
//execute('python connect.py --ip 192.168.43.64 --port 7777 crawling --word '+logo +' --pages_start 1 --pages_end 5 --cookie '+a);
//execute('python connect.py --ip 192.168.43.65 --port 7777 crawling --word computer --cookie b07f9e6461343a07635438925b0b93f9e0f9f084 --pages_start 1 --pages_end 3');
})
app.post('/cook', function (req, res) {
res.redirect('/public/ok2.html');
})
app.post('/cook2', function (req, res) {
res.redirect('/login.html');
ppname = '0'
pppwd = '0'
})
app.post('/check1',function (req, res) {
if(ppname != '0'){
const ls = childProcess.spawn('python3' ,['./ceshi03.py','--id',ppname],{cwd: path.resolve(__dirname, './')
})
ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
ls.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
ls.on('close', function(code){
res.redirect("/comment.html")
return;
})}
else{
res.send('未登录')
}
})
app.get('/std',function (req, res) {
var finame=req.query.finame;
var email = req.query.email;
var phone = req.query.phone;
var selectSQL = "select uname,pwd from user where uname = '" + ppname + "' and pwd = '" + pppwd + "'"
connection.query(selectSQL, function (err, result) {
var user = {finame: finame,email:email, phone:phone};
sql = "update user set ? where uname = '" + ppname + "' and pwd = '" + pppwd + "'"
connection.query(sql, user, function (err, rs) {
// if (err) throw err;
console.log('ok');
res.redirect('/public/ok1.html');
})
})
})
app.post('/std1',function (req, res) {
res.redirect('/public/ok3.html')
})
app.post('/std3',function (req, res) {
var delSql = "DELETE FROM user_info where user_name = '"+ ppname;
connection.query(delSql,function (err, result) {
if(err){
console.log('[DELETE ERROR] - ',err.message);
return;
}
});
res.redirect('/public/ok3.html')
})
app.get('/std2',function (req, res) {
var pwd1=req.query.pwd1;
var pwd2=req.query.pwd2;
var pwd3=req.query.pwd3;
if(pwd3 != pwd2){
console.log("error")
res.send("两次输入的密码不一样");
}
if(pwd3 == pwd2){
var selectSQL = "select pwd from user where uname = '" + ppname + "' and pwd = '" + pppwd + "'"
connection.query(selectSQL, function (err, result) {
if (pppwd != pwd1) {
res.send("当前密码输入错误");
console.log("error")
}
if(pppwd == pwd1){
var user = {pwd:pwd2};
sql = "update user set ? where uname = '" + ppname + "' and pwd = '" + pppwd + "'"
connection.query(sql, user, function (err, rs) {
// if (err) throw err;
console.log('ok');
res.redirect('/public/ok1.html');
pppwd = pwd2
})
var user1 = {user_password:pwd2}
q = "update user_info set ? where user_name = '" + ppname + "' and user_password = '" + pppwd + "'"
connection.query(q, user1, function (err, rs) {
// if (err) throw err;
console.log('ok');
//res.redirect('/public/ok1.html');
//pppwd = pwd2
})
}
})
}
})