diff --git a/cgi-bin/login.c b/cgi-bin/login.c index c5d6809..f60e25f 100644 --- a/cgi-bin/login.c +++ b/cgi-bin/login.c @@ -1,6 +1,108 @@ -#include +/** + * 该文件用于匹配login.html + * 使用该.c文件可实现从名为router的数据库中 + * 查询存有登录名及密码的users表 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; -} +} \ No newline at end of file diff --git a/cgi-bin/login.cgi b/cgi-bin/login.cgi new file mode 100755 index 0000000..b152300 Binary files /dev/null and b/cgi-bin/login.cgi differ diff --git a/html/green_house_info.html b/html/green_house_info.html new file mode 100644 index 0000000..220b2fc --- /dev/null +++ b/html/green_house_info.html @@ -0,0 +1,25 @@ + + + + + + + Document + + + + +
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/html/hemp_hum_first_info.html b/html/hemp_hum_first_info.html new file mode 100644 index 0000000..e519322 --- /dev/null +++ b/html/hemp_hum_first_info.html @@ -0,0 +1,341 @@ + + + + + + + + 智能农业大棚 + + + + + + +


+

智能大棚控制系统 +

+ + + + +
+

+ + + + 号棚 + + + +

+
+
+
+ 最小值 + 最大值 +
+

+ + ℃ +

+
+

+ + % +

+
+ +

+ + LUX +

+ + + + +
+
+
+ 采集节点 + 当前值 +
+

+ 温度: + 10 + + +

+
+

+ 湿度: + 30 + + +

+
+

+ + 光照: + 10 + + + +

+
+
+
+
+
+ + + +
+
+
+ 控制节点 + 状态 +  手动状态 + +
+

+ 风扇: + + + + + + + + + +

+
+

+ 加湿器: + + + + + + +

+
+

+ + 卷 帘: + + + + + + +

+
+ + +
+
+ + + + \ No newline at end of file diff --git a/html/hemp_hum_second_info.html b/html/hemp_hum_second_info.html new file mode 100644 index 0000000..59803e8 --- /dev/null +++ b/html/hemp_hum_second_info.html @@ -0,0 +1,14 @@ + + + + + + + Document + + + + hemp_hum_second_info + + + \ No newline at end of file diff --git a/html/index.html b/html/index.html deleted file mode 100644 index ba8f00b..0000000 --- a/html/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - 菜鸟教程(runoob.com) - - - -

我的第一个标题

- -

我的第一个段落。

- - - diff --git a/html/login.html b/html/login.html new file mode 100644 index 0000000..2b29245 --- /dev/null +++ b/html/login.html @@ -0,0 +1,171 @@ + + + + + + + + 登录页面 + + + + + +
+ +
基础版
+
+
+
+
+ 快速 + 畅联 +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/html/logo.png b/html/logo.png new file mode 100755 index 0000000..410dfd3 Binary files /dev/null and b/html/logo.png differ diff --git a/html/record_of_operations_history.html b/html/record_of_operations_history.html new file mode 100644 index 0000000..8552c4e --- /dev/null +++ b/html/record_of_operations_history.html @@ -0,0 +1,14 @@ + + + + + + + Document + + + + operation_history + + + \ No newline at end of file diff --git a/html/zhuti.html b/html/zhuti.html new file mode 100644 index 0000000..d712be4 --- /dev/null +++ b/html/zhuti.html @@ -0,0 +1,53 @@ + + + + + + + 主页 + + + + + +
+ +
+ [登出] +
+
+ +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/html/zhuti1.html b/html/zhuti1.html new file mode 100644 index 0000000..d5aca7b --- /dev/null +++ b/html/zhuti1.html @@ -0,0 +1,33 @@ + + + + + + 系统日志 + + + + +
+ +
+ + + + \ No newline at end of file