diff --git a/www/cgi-bin/c_mysql_user_pwd.c b/www/cgi-bin/c_mysql_user_pwd.c index 1a2e5a6..f99c3bd 100755 --- a/www/cgi-bin/c_mysql_user_pwd.c +++ b/www/cgi-bin/c_mysql_user_pwd.c @@ -8,23 +8,20 @@ #include #include -int main() -{ +int main() { // 连接到 MySQL 数据库 MYSQL *conn; MYSQL_RES *res; MYSQL_ROW row; conn = mysql_init(NULL); - if (conn == 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) - { + NULL, 0) == NULL) { fprintf(stderr, "mysql_real_connect() failed\n"); mysql_close(conn); exit(1); @@ -36,8 +33,7 @@ int main() // 解析 JSON 数据 cJSON *p = cJSON_Parse(request_data); - if (p == NULL) - { + if (p == NULL) { fprintf(stderr, "Error parsing JSON data\n"); mysql_close(conn); return 1; @@ -48,8 +44,7 @@ int main() cJSON *pwd = cJSON_GetObjectItemCaseSensitive(p, "pwd"); if (user == NULL || pwd == NULL || !cJSON_IsString(user) || - !cJSON_IsString(pwd)) - { + !cJSON_IsString(pwd)) { fprintf(stderr, "Error getting username and/or password from JSON data\n"); cJSON_Delete(p); @@ -65,8 +60,7 @@ int main() sprintf(query, "SELECT * FROM users WHERE username='%s' AND password='%s'", username_from_frontend, password_from_frontend); - if (mysql_query(conn, query)) - { + if (mysql_query(conn, query)) { fprintf(stderr, "SELECT query failed. Error: %s\n", mysql_error(conn)); cJSON_Delete(p); mysql_close(conn); @@ -74,8 +68,7 @@ int main() } res = mysql_store_result(conn); - if (res == NULL) - { + if (res == NULL) { fprintf(stderr, "mysql_store_result() failed\n"); cJSON_Delete(p); mysql_close(conn); @@ -84,13 +77,10 @@ int main() cJSON *result_json = cJSON_CreateObject(); - if ((row = mysql_fetch_row(res))) - { + if ((row = mysql_fetch_row(res))) { cJSON_AddNumberToObject(result_json, "code", 0); cJSON_AddStringToObject(result_json, "nickname", "admin"); - } - else - { + } else { cJSON_AddNumberToObject(result_json, "code", 1); cJSON_AddStringToObject(result_json, "msg", "用户名或口令错误"); } @@ -110,3 +100,5 @@ int main() return 0; } + +// 注释 \ No newline at end of file diff --git a/www/cgi-bin/creat_table.sql b/www/cgi-bin/creat_table.sql index e6b09c3..5f21c93 100755 --- a/www/cgi-bin/creat_table.sql +++ b/www/cgi-bin/creat_table.sql @@ -2,7 +2,7 @@ CREATE database if NOT EXISTS router; USE router; -- 创建用户登录密码表 -CREATE TABLE users ( +CREATE TABLE if not exists users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, password VARCHAR(255) NOT NULL @@ -10,10 +10,13 @@ CREATE TABLE users ( INSERT INTO users (username, password) VALUES ('admin', 'admin'); -- 创建ARP映射表 -CREATE TABLE ip_mac( +CREATE TABLE if not exists ip_mac( id INT AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(50) NOT NULL, mac VARCHAR(50) NOT NULL ); -- 创建防火墙表 -CREATE TABLE ip_fw(ip VARCHAR(50) NOT NULL); \ No newline at end of file +CREATE TABLE if not exists ip_fw( + id INT AUTO_INCREMENT PRIMARY KEY, + ip VARCHAR(50) NOT NULL +); \ No newline at end of file