测试页面1

This commit is contained in:
chang 2023-10-24 15:02:42 +08:00
parent dc313936a1
commit 126349aa24
11 changed files with 757 additions and 18 deletions

View File

@ -1,6 +1,108 @@
#include <stdio.h>
/**
* login.html
* 使.c文件可实现从名为router的数据库中
* users表
*/
#include <cjson/cJSON.h>
#include <fcntl.h>
#include <mysql/mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
// 连接到 MySQL 数据库
MYSQL* conn;
MYSQL_RES* res;
MYSQL_ROW row;
conn = mysql_init(NULL);
if (conn == NULL) {
fprintf(stderr, "mysql_init() failed\n");
exit(1);
}
if (mysql_real_connect(conn, "localhost", "root", "root", "router", 3306,
NULL, 0) == NULL) {
fprintf(stderr, "mysql_real_connect() failed\n");
mysql_close(conn);
exit(1);
}
// 获取前端传递的 JSON 数据
char request_data[128] = "";
fgets(request_data, 128, stdin);
// 解析 JSON 数据
cJSON* p = cJSON_Parse(request_data);
if (p == NULL) {
fprintf(stderr, "Error parsing JSON data\n");
mysql_close(conn);
return 1;
}
// 获取用户名和密码
cJSON* user = cJSON_GetObjectItemCaseSensitive(p, "name");
cJSON* pwd = cJSON_GetObjectItemCaseSensitive(p, "pwd");
if (user == NULL || pwd == NULL || !cJSON_IsString(user) ||
!cJSON_IsString(pwd)) {
fprintf(stderr,
"Error getting username and/or password from JSON data\n");
cJSON_Delete(p);
mysql_close(conn);
return 1;
}
char* username_from_frontend = user->valuestring;
char* password_from_frontend = pwd->valuestring;
// 构建查询语句
char query[1000];
sprintf(query, "SELECT * FROM users WHERE username='%s' AND password='%s'",
username_from_frontend, password_from_frontend);
if (mysql_query(conn, query)) {
fprintf(stderr, "SELECT query failed. Error: %s\n", mysql_error(conn));
cJSON_Delete(p);
mysql_close(conn);
return 1;
}
res = mysql_store_result(conn);
if (res == NULL) {
fprintf(stderr, "mysql_store_result() failed\n");
cJSON_Delete(p);
mysql_close(conn);
return 1;
}
cJSON* result_json = cJSON_CreateObject();
if ((row = mysql_fetch_row(res))) {
cJSON_AddNumberToObject(result_json, "code", 0);
cJSON_AddStringToObject(result_json, "nickname", "admin");
} else {
cJSON_AddNumberToObject(result_json, "code", 1);
cJSON_AddStringToObject(result_json, "msg", "用户名或密码错误");
}
char* result_json_string = cJSON_Print(result_json);
// 输出 JSON 结果
printf("content-type: application/json;charset=utf-8\r\n");
printf("\r\n");
printf("%s\n", result_json_string);
free(result_json_string);
cJSON_Delete(result_json);
cJSON_Delete(p);
mysql_free_result(res);
mysql_close(conn);
int main()
{
return 0;
}

BIN
cgi-bin/login.cgi Executable file

Binary file not shown.

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<div id="main">
<div id="menu">
<a href="hemp_hum_first_info.html" target="content_frame1" class="menu_item">大棚1</a>
<a href="hemp_hum_second_info.html" target="content_frame1" class="menu_item">大棚2</a>
</div>
<div id="content" style="width: 100%;">
<iframe name="content_frame1" width="100%" height="100%"></iframe>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,341 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>智能农业大棚</title>
<style>
div,
input {
padding: 0;
margin: 0
}
input {
outline: none;
display: block
}
.container {
width: 650px;
height: 400px;
border-radius: 1em;
border: 1px solid #003333;
margin: 100px auto;
}
.title {
text-align: center
}
.data1 {
width: 60px;
height: 20px;
font-size: 14px;
background: pink;
border: 1px solid #ccc;
border-radius: .3em;
margin: 5px 10px;
float: left
}
.data2 {
width: 150px;
height: 20px;
font-size: 14px;
background: pink;
border: 1px solid #ccc;
border-radius: .3em;
margin: 5px 10px;
float: left
}
.active {
width: 50px;
height: 20px;
background: red;
font-size: 12px;
color: #fff;
border-radius: .3em;
text-align: center;
margin: 5px 10px;
float: right
}
.active_1 {
width: 160px;
height: 20px;
background: red;
font-size: 12px;
color: #fff;
border-radius: .3em;
text-align: center;
margin: 5px 10px;
float: center
}
.main {
height: 280px;
display: flex;
justify-content: space-around
}
.main div {
width: 180px;
height: 280px;
border: 1px solid #ccc;
border-radius: 1.5em
}
.wrap input {
width: 45px;
height: 15px;
display: inline;
margin: 4px 8px;
text-align: center
}
h6 a {
font-size: 14px;
margin: 0 8px
}
.middle p a {
font-size: 14px;
margin: 10px;
}
.middle p span {
font-size: 14px;
margin: 20px;
display: inline;
}
.main div.right {
width: 210px
}
.right p {
display: flex;
justify-content: space-around
}
.right p a {
font-size: 14px
}
.right p span {
display: inline-block;
width: 40px;
height: 20px;
font-size: 12px;
color: blue;
border: 1px solid #000;
border-radius: .5em;
text-align: center
}
body {
background-image: url(/image/background.png);
background-repeat: repeat-repeat;
background-size: 100%;
}
</style>
</head>
<script type="text/javascript" src="Arg_data.js"></script>
<body onload="init_getdata()">
<div class="schmenu">
<ul>
<li><a href="#top">返回首页</a></li>
<li><a onclick="on_button_show()">刷新</a></li>
<li><a onclick="historical_data()" target="_self">历史数据</a></li>
<!-- <li><a id="Refresh_auto" onclick="on_button_auto()">无刷新</a></li> -->
<li><a href="http://10.9.131.244/reward.html" target="_self">请打赏</a></li>
</ul>
</div>
<br><br><br>
<h1 style="text-align:center;">智能大棚控制系统
</h1>
<style type="text/css">
.schmenu {
height: 33px;
line-height: 33px;
background: #2c56a3;
opacity: 0.8;
width: 100%;
margin: 0 auto;
overflow: hidden;
cursor: pointer;
position: fixed;
top: 10px;
z-index: 100;
}
.schmenu ul {
width: 1180px;
margin: 0 auto;
overflow: hidden;
}
.schmenu ul li {
float: left;
list-style: none;
}
.schmenu ul li a {
height: 33px;
line-height: 33px;
display: block;
color: #fff;
font-size: 13px;
padding: 0 10px;
text-decoration: none;
}
.schmenu ul li a:hover {
color: #fff;
background: #000;
text-decoration: none;
-moz-transition: all 0.2s ease;
-webkit-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
transition: all 0.2s ease;
}
</style>
<input type="button" class="active" value="注销" onclick="cancellation()" />
<div class="container">
<p class="title">
<input type="button" class="data1" value="历史数据" onclick="historical_data()" />
<!-- <input type="button" class="data2" id='date_id' value=" 时间 " /> -->
<!-- <span class="store">5号</span> -->
<label id='device_id'>1</label>号棚
<input type="button" class="active" value="无刷新" id="button_1" onclick="on_button_auto()" />
<input type="button" class="active" value="刷新" onclick="on_button_show()" />
<input type="button" class="active" value="配置文件" onclick="on_button_show_conf()" />
</p>
<div class="main">
<div class="left">
<h6>
<a>最小值</a>
<a>最大值</a>
</h6>
<p class="wrap">
<input value="24" id="value_c_min" />
<input value="24" id="value_c_max" />
</p>
<br>
<p class="wrap">
<input value="24" id="value_h_min" />
<input value="24" id="value_h_max" />%
</p>
<br>
<p class="wrap">
<input value="24" id="value_i_min" />
<input value="24" id="value_i_max" />LUX
</p>
</div>
<div class="middle">
<h6>
<a>采集节点</a>
<a>当前值</a>
</h6>
<p>
<a>温度:</a>
<th><span id="value_c">10</span></th>
<label></label>
<!-- <span>28.2℃</span> -->
</p>
<br>
<p>
<a>湿度:</a>
<th><span id="value_h">30</span></th>
<label>%</label>
<!-- <span>60%</span> -->
</p>
<br>
<p>
<a>光照:</a>
<th><span id="value_i">10</span></th>
<label>LUX</label>
</p>
<br>
<br>
<br>
<br>
<br>
<th align="center">
<input type="button" class="active_1" value="保存配置" onclick="on_button_seve()" />
</th>
</div>
<div class="right">
<h6>
<a>控制节点</a>
<a>状态</a>
<a> 手动状态</a>
</h6>
<p>
<a>风扇:</a>
<!-- <span>关闭</span> -->
<!-- <i></i> -->
<!-- <a>手动</a> -->
<th><input type="button" name="close_1" value="关闭" id="close_1" onclick="on_button_close1()"></th>
<th></th>
<!-- <th><label>手动</label></th> -->
<th>
<select id="select_query_t" onchange="on_select1()">
<option value="auto_t">自动</option>
<option value="cur_t">手动</option>
</select>
</th>
</p>
<br>
<p>
<a>加湿器:</a>
<th><input type="button" name="close_2" value="关闭" id="close_2" onclick="on_button_close2()"></th>
<th></th>
<!-- <th><label>手动</label></th> -->
<th>
<select id="select_query_h" onchange="on_select2()">
<option value="auto_h">自动</option>
<option value="cur_h">手动</option>
</select>
</th>
</p>
<br>
<p>
<a>&nbsp;帘:</a>
<th><input type="button" name="close_3" value="关闭" id="close_3" onclick="on_button_close3()"></th>
<th></th>
<th>
<select id="select_query_i" onchange="on_select3()">
<option value="auto_i">自动</option>
<option value="cur_i">手动</option>
</select>
</th>
</p>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
hemp_hum_second_info
</body>
</html>

View File

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>
</body>
</html>

171
html/login.html Normal file
View File

@ -0,0 +1,171 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="zifan">
<meta name="keywords" content="物联网">
<title>登录页面</title>
<style>
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
flex-direction: column;
justify-content: space-between;
}
#top {
height: 50px;
background-color: lightblue;
}
#foot {
height: 40px;
background-color: lightblue;
}
#main {
height: 100%;
background-color: lightcyan;
}
#top {
display: flex;
flex-direction: row;
justify-content: space-between;
justify-items: center;
align-items: center;
padding: 5px;
border-bottom: 1px solid lightgray;
}
#logo>img {
width: 180px;
height: 45px;
}
#foot {
border-top: 1px solid lightgray;
padding: 10px 0;
}
form {
width: 300px;
height: 300px;
background-color: rgba(41, 117, 117, 0.667);
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.5);
border-radius: 8px;
max-width: 100%;
padding: 0px 35px 0;
}
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.row {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: nowrap;
}
input {
padding: 10px 5px;
margin: 5px;
border-radius: 5px;
}
button {
width: 80px;
height: 30px;
border-radius: 3px;
}
#main {
display: flex;
flex-direction: row;
justify-content: space-between;
justify-items: center;
align-items: center;
}
#insert {
font-size: 60px;
font-family: "楷体";
writing-mode: vertical-rl;
/* 竖行模式 */
}
</style>
</head>
<body>
<div id="top">
<div id="logo">
<img src="/logo.png">
</div>
<div id="base_info">基础版</div>
</div>
<div id="main">
<div></div>
<div>
<span id="insert"><i>快速</i>&emsp;</span>
<span id="insert">&emsp;<i>畅联</i></span>
</div>
<div>
<form onsubmit="return login(this);">
<div class="row">
<input name="name" placeholder="请输入账号">
</div>
<div class="row">
<input name="pwd" type="password" placeholder="请输入密码">
</div>
<div class="row center">
<button>登录</button>
</div>
</form>
</div>
<div></div>
</div>
<div id="foot" style="text-align: center;">
<b>版本所有@FLY-NOOB</b>
</div>
<script>
function login(form) {
let login_data = {
name: form.name.value.trim(),
pwd: form.pwd.value.trim()
};
fetch("../cgi-bin/login.cgi", {
method: "POST",
body: JSON.stringify(login_data),
headers: {
"Content-Type": "application/json;charset=utf-8"
}
}).then(resp => resp.json()).then(data => {
console.log(data);
if (data.code == 0) {
window.localStorage.setItem("login_user", JSON.stringify(data));
open("/zhuti.html", "_self");
} else {
alert(data.msg);
}
})
return false;
}
</script>
</body>
</html>

BIN
html/logo.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
operation_history
</body>
</html>

53
html/zhuti.html Normal file
View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="">
<title>主页</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.content {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="top">
<div id="logo">
<img src="/logo.png" height="50px">
</div>
<div id="user_info"><span id="userName"></span>
<span class="logout" onclick="logout()">[登出]</span>
</div>
</div>
</div>
<div id="main">
<div id="menu">
<h3>功能</h3>
<a href="green_house_info.html" target="content_frame" class="menu_item">大棚</a>
<a href="record_of_operations_history.html" target="content_frame" class="menu_item">历史操作</a>
</div>
<div id="content" style="width: 100%; height: 100%;">
<iframe name="content_frame"></iframe>
</div>
<!-- </div>
<div id="foot" style="text-align: botton;">
<b>版本所有@FLY-NOOB</b>
</div> -->
</body>
</html>

33
html/zhuti1.html Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>系统日志</title>
<style>
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div class="container">
<iframe src="zhuti.html" id="info-frame" width="100%" height="100%"></iframe>
</div>
</body>
</html>