Compare commits

..

15 Commits

Author SHA1 Message Date
IACU 7de8ba599b Fit webnet to edu-arm32 and xidatong-arm32 from Tu_Yuyang
it is OK
2023-08-15 19:34:32 +08:00
涂煜洋 60a8a500b9 Merge branch 'xidatong' of https://gitlink.org.cn/xuos/WebNet_XiUOS into edu-arm32 2023-08-02 17:53:21 +08:00
涂煜洋 23ef71e8cc 23/08/02 Fit webnet to edu-arm32. 2023-08-02 17:43:56 +08:00
涂煜洋 2056a6d587 23/07/31 Fit Webnet to edu-arm32 2023-07-31 10:38:16 +08:00
涂煜洋 c7af2a767c 23/07/27 1.Add netdev module and for edu-arm32, fit Lwip to it; 2.Fit Webnet to edu-arm32; 2023-07-27 15:06:16 +08:00
龚祖望 c14b262e42 add update button and progress component 2022-11-22 16:19:08 +08:00
zhaoyun1215 42a888a7e7 change for posix 2022-09-15 19:08:51 -07:00
zhaoyun1215 135c842fb8 change for posix 2022-09-14 20:28:45 -07:00
zhaoyun1215 1dff04fd38 for webnet and netdev 2022-09-14 05:22:14 -07:00
zhaoyun1215 43aefd33cc Merge remote-tracking branch 'origin/xidatong' into xidatong
# Conflicts:
#	module/wn_module_alias.c
#	module/wn_module_asp.c
#	samples/uploaddata.c
#	src/webnet.c
2022-09-14 05:17:42 -07:00
zhaoyun1215 0ec3efb66f for webnet and netdev 2022-09-14 05:13:19 -07:00
zhaoyun1215 64e1a0fae7 can be runned in xizi kernel 2022-09-09 01:58:11 -07:00
chunyexixiaoyu 956eafa24b solve the bug compiling 2022-07-14 11:30:03 +08:00
chunyexixiaoyu 27df62c9de 1.add webnet web files
2.add source files adapt to the web.
3.the branch is specific version
2022-07-14 10:42:23 +08:00
chunyexixiaoyu 52811719f7 update the README.md on this branch 2022-07-14 10:32:53 +08:00
50 changed files with 2410 additions and 323 deletions

8
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"files.associations": {
"assert.h": "c",
"wn_utils.h": "c",
"webnet.h": "c",
"wn_module.h": "c"
}
}

3
Makefile Executable file
View File

@ -0,0 +1,3 @@
SRC_DIR += src module samples
include $(KERNEL_ROOT)/compiler.mk

18
README.md Normal file → Executable file
View File

@ -87,3 +87,21 @@ dns server #1: 223.5.5.5
WebNet 软件包使用需要文件系统和Lwip协议栈的支持。
webnet.c 文件中注意以下定义注意其他操作系统lwip协议栈的大小设置
```
#ifdef ADD_RTTHREAD_FETURES
#if defined(RT_USING_LWIP) && (RT_LWIP_TCPTHREAD_STACKSIZE < 1408)
#error The lwIP tcpip thread stack size(RT_LWIP_TCPTHREAD_STACKSIZE) must more than 1408
#endif
#endif
```
webnet文件夹为该分支的一个前端页面文件版本
for xizi:
1.需要同时打开SD卡和USB功能同时使用SD卡作为文件系统需要开启SEMC功能
单独使用SD卡会导致卡在网络配置界面单独使用USB卡会导致从U盘读取数据到内存的时候数据发生错误一部分数据没写入呈现出来的就是全0
2.注意使用的时候需要修改readcloseopen等系统调用的地方因为默认使用的是lwip中的readclose和open
3.需要单独开启netdev模块

View File

@ -53,9 +53,13 @@ if GetDepend(['WEBNET_USING_DAV']):
if GetDepend(['WEBNET_USING_SAMPLES']):
src += Glob('samples/wn_sample.c')
src += Glob('samples/deviceinfoasp.c')
src += Glob('samples/netsetting.c')
src += Glob('samples/uploaddata.c')
if GetDepend(['WEBNET_USING_SAMPLES']) and GetDepend(['WEBNET_USING_UPLOAD']):
src += Glob('samples/wn_sample_upload.c')
CPPPATH = [cwd + '/inc']

33
inc/webnet.h Normal file → Executable file
View File

@ -23,33 +23,58 @@
* Change Logs:
* Date Author Notes
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#ifndef __WEBNET_H__
#define __WEBNET_H__
#include <transform.h>
#include <xs_klist.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef wn_malloc
#define wn_malloc malloc
#define wn_malloc PrivMalloc
#endif
#ifndef wn_free
#define wn_free free
#define wn_free PrivFree
#endif
#ifndef wn_realloc
#define wn_realloc realloc
#define wn_realloc PrivRealloc
#endif
#ifndef wn_strdup
#define wn_strdup strdup
#define wn_strdup strdup
#endif
#ifndef wn_read
#define wn_read PrivRead
#endif
#ifndef wn_open
#define wn_open PrivOpen
#endif
#ifndef wn_close
#define wn_close PrivClose
#endif
// #define WEBNET_USING_LOG
// #define WEBNET_USING_AUTH
// #define WEBNET_USING_CGI
// #define WEBNET_USING_ASP
// #define WEBNET_USING_SSI
// #define WEBNET_USING_INDEX
// #define WEBNET_USING_ALIAS
// #define WEBNET_USING_UPLOAD
// #define WEBNET_CACHE_LEVEL 0
// #define WEBNET_USING_SAMPLES
#ifndef WEBNET_USING_RANGE
#define WEBNET_USING_RANGE
#endif

3
inc/wn_module.h Normal file → Executable file
View File

@ -22,7 +22,8 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#ifndef __WN_MODULE_H__

4
inc/wn_request.h Normal file → Executable file
View File

@ -19,13 +19,14 @@
* Change Logs:
* Date Author Notes
* 2022-05-10 chunyexixiaoyu the version the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#ifndef __WN_REQUEST_H__
#define __WN_REQUEST_H__
#include <transform.h>
#include <rtthread.h>
#include <wn_session.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
@ -124,6 +125,7 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int
void webnet_request_parse(struct webnet_request* request, char* buffer, int length);
bool webnet_request_has_query(struct webnet_request* request, char* name);
const char* webnet_request_get_query(struct webnet_request* request, char* name);
#ifdef __cplusplus

12
inc/wn_session.h Normal file → Executable file
View File

@ -18,7 +18,8 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#ifndef __WN_SESSION_H__
@ -27,11 +28,16 @@
#include <sys/select.h>
#include <wn_request.h>
#ifdef BSP_USING_LWIP
#include <sys_arch.h>
#include <sockets.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define WEBNET_SESSION_BUFSZ (4 * 1024)
#define WEBNET_SESSION_BUFSZ (8 * 1024)
/* close session */
#define WEBNET_EVENT_CLOSE (1 << 5)
@ -68,7 +74,7 @@ struct webnet_session
struct webnet_request* request;
/* session buffer */
uint16 buffer_length;
uint32 buffer_length;
uint16 buffer_offset;
uint8 buffer[WEBNET_SESSION_BUFSZ];

1
inc/wn_utils.h Normal file → Executable file
View File

@ -19,6 +19,7 @@
* Change Logs:
* Date Author Notes
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#ifndef __WN_UTILS_H__

11
module/Makefile Normal file
View File

@ -0,0 +1,11 @@
SRC_FILES += wn_module_alias.c \
wn_module_asp.c \
wn_module_auth.c \
wn_module_cgi.c \
wn_module_dav.c \
wn_module_index.c \
wn_module_log.c \
wn_module_ssi.c \
wn_module_upload.c
include $(KERNEL_ROOT)/compiler.mk

6
module/wn_module_alias.c Normal file → Executable file
View File

@ -18,11 +18,15 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <assert.h>
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_ALIAS

42
module/wn_module_asp.c Normal file → Executable file
View File

@ -19,12 +19,15 @@
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include<transform.h>
#include <assert.h>
#include <string.h>
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_ASP
@ -111,15 +114,12 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam
}
else if (strncmp(name, "TICK", 4) == 0)
{
int32 tick;
int32 tick;
int32 hour, min, second;
#ifdef ADD_RTTHREAD_FETURES
tick = rt_tick_get()/RT_TICK_PER_SECOND;
#endif
tick = PrivGetTickTime();
second = tick % 60;
min = (tick/60) % 60;
hour = tick / (60 * 60);
webnet_session_printf(session, "%02d:%02d:%02d", hour, min, second);
}
}
@ -137,6 +137,7 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
/* allocate read buffer */
buffer = (char*) wn_malloc (length);
memset(buffer,0,length);
if (buffer == NULL)
{
session->request->result_code = 500;
@ -146,7 +147,8 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
/* write page header */
webnet_session_set_header(session, "text/html", 200, "OK", -1);
/* read file to buffer */
if (read(fd, buffer, (uint32)length) != length) /* read failed */
if (wn_read(fd, buffer, (uint32)length) != length) /* read failed */
{
wn_free(buffer);
session->request->result_code = 500;
@ -180,7 +182,9 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
webnet_session_write(session, (const uint8*)offset, asp_begin - offset);
offset = asp_begin + 2;
while ((*offset == ' ') || (*offset == '\t')) offset ++;
while ((*offset == ' ') || (*offset == '\t')){
offset++;
}
/* extrace asp variable */
for (index = 0; index < _webnet_asp_vars_count; index ++)
@ -217,7 +221,7 @@ int webnet_module_asp(struct webnet_session* session, int event)
if (event == WEBNET_EVENT_URI_POST)
{
int fd;
int fd=-1;
/* check whether a asp file */
if ((strstr(request->path, ".asp") != NULL) ||
@ -225,11 +229,11 @@ int webnet_module_asp(struct webnet_session* session, int event)
{
/* try to open this file */
fd = open(request->path, O_RDONLY, 0);
fd = wn_open(request->path, O_RDONLY, 0);
if ( fd >= 0)
{
_webnet_asp_dofile(session, fd);
close(fd);
wn_close(fd);
return WEBNET_MODULE_FINISHED;
}
else
@ -248,14 +252,16 @@ int webnet_module_asp(struct webnet_session* session, int event)
if (asp_filename != NULL)
{
snprintf(asp_filename, WEBNET_PATH_MAX, "%s/index.asp", request->path);
fd = open(asp_filename, O_RDONLY, 0);
struct stat file_stat;
if (stat(asp_filename, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) {
fd = wn_open(asp_filename, O_RDONLY, 0);
if (fd >= 0)
{
wn_free(asp_filename);
_webnet_asp_dofile(session, fd);
close(fd);
return WEBNET_MODULE_FINISHED;
if (fd >= 0) {
wn_free(asp_filename);
_webnet_asp_dofile(session, fd);
wn_close(fd);
return WEBNET_MODULE_FINISHED;
}
}
}
wn_free(asp_filename);

6
module/wn_module_auth.c Normal file → Executable file
View File

@ -19,11 +19,14 @@
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <assert.h>
#include <string.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_AUTH
@ -77,7 +80,10 @@ void webnet_auth_set(const char* path, const char* username_password)
_auth_items[_auth_items_count - 1].path = wn_strdup(path);
_auth_items[_auth_items_count - 1].username_password = str_base64_encode(username_password);
}
#ifdef ADD_RTTHREAD_FETURES
RTM_EXPORT(webnet_auth_set);
#endif
/**
* Authorization module handler

11
module/wn_module_cgi.c Normal file → Executable file
View File

@ -18,13 +18,16 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <string.h>
#include <assert.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_CGI
@ -42,13 +45,13 @@ static uint32 _cgi_count = 0;
void webnet_cgi_set_root(const char* root)
{
if (strlen(root) > CGI_ROOT_PATH_MAX)
{
int root_len = strlen(root);
if (root_len > CGI_ROOT_PATH_MAX) {
assert(0);
return;
}
strncpy(_cgi_root, root, strlen(root));
strncpy(_cgi_root, root, root_len);
if (_cgi_root[strlen(_cgi_root)] != '/')
{
_cgi_root[strlen(_cgi_root) + 1] = '/';

28
module/wn_module_dav.c Normal file → Executable file
View File

@ -18,13 +18,17 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <webnet.h>
#include <wn_session.h>
#include <wn_module.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_DAV
struct webnet_module_put_entry
@ -100,10 +104,10 @@ int webnet_module_dav(struct webnet_session* session, int event)
printf("PROPFIND %s depth: %s", session->request->path,
session->request->depth?session->request->depth:"null");
fd = open(session->request->path, O_RDONLY, 0);
fd = wn_open(session->request->path, O_RDONLY, 0);
if (fd >= 0)
{
close(fd);
wn_close(fd);
exit_file = 1;
}
dir = opendir(session->request->path);
@ -276,9 +280,23 @@ static void print_propfind_element(struct webnet_session *session, const char *u
time_t t = file_stat->st_mtime;
#ifdef ADD_RTTHREAD_FETURES
PrivTaskenterCritical();
#endif
#ifdef ADD_XIZI_FEATURES
long lock;
lock = CriticalAreaLock();
#endif //ADD_XIZI_FEATURES
strftime(ctime_str, sizeof(ctime_str), "%a, %d %b %Y %H:%M:%S GMT", localtime(&t));
#ifdef ADD_RTTHREAD_FETURES
PrivTaskexitCritical();
#endif
#ifdef ADD_XIZI_FEATURES
CriticalAreaUnLock(lock);
#endif //ADD_XIZI_FEATURES
//printf("strftime: %s\n", ctime_str);
webnet_session_printf(session,
@ -296,7 +314,7 @@ static int put_open (struct webnet_session* session)
goto _exit;
}
fd = open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0);
fd = wn_open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0);
if(fd < 0)
{
session->session_phase = WEB_PHASE_CLOSE;
@ -319,7 +337,7 @@ static int put_close(struct webnet_session* session)
fd = (int)webnet_put_get_userdata(session);
if (fd < 0) return 0;
close(fd);
wn_close(fd);
return 0;
}

5
module/wn_module_index.c Normal file → Executable file
View File

@ -18,9 +18,12 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <assert.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_utils.h>

14
module/wn_module_log.c Normal file → Executable file
View File

@ -18,13 +18,16 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_LOG
int webnet_module_log(struct webnet_session* session, int event)
@ -42,7 +45,7 @@ int webnet_module_log(struct webnet_session* session, int event)
if (event == WEBNET_EVENT_INIT)
{
printf("server initialize success.");
printf("server initialize success.\n");
}
else if (event == WEBNET_EVENT_URI_PHYSICAL)
{
@ -75,7 +78,7 @@ int webnet_module_log(struct webnet_session* session, int event)
default:
break;
}
printf(" request: %s", request->path);
printf(" request: %s\n", request->path);
for (index = 0; index < request->query_counter; index ++)
{
printf(" query[%d]: %s => %s", index,
@ -85,8 +88,9 @@ int webnet_module_log(struct webnet_session* session, int event)
}
else if (event == WEBNET_EVENT_URI_POST)
{
printf("physical url: %s", request->path);
printf(" mime type: %s", mime_get_type(request->path));
printf("event post uri physical url: %s", request->path);
printf("mime type: %s\n", mime_get_type(request->path));
}
else if (event == WEBNET_EVENT_RSP_HEADER)
{

28
module/wn_module_ssi.c Normal file → Executable file
View File

@ -19,11 +19,15 @@
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <assert.h>
#include <webnet.h>
#include <wn_session.h>
#include <wn_module.h>
#include <wn_session.h>
#if defined(WEBNET_USING_SSI)
#define SSI_INCLUDE_STRING "<!--#include "
@ -39,7 +43,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
int file_length;
unsigned long size, readbytes;
fd = open(filename, O_RDONLY, 0);
fd = wn_open(filename, O_RDONLY, 0);
if (fd < 0) return; /* open file failed */
/* get file size */
@ -48,7 +52,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
lseek(fd, 0, SEEK_SET);
if (file_length <= 0)
{
close(fd);
wn_close(fd);
return ;
}
while (file_length)
@ -58,7 +62,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
else
size = file_length;
readbytes = read(fd, session->buffer, size);
readbytes = wn_read(fd, session->buffer, size);
if (readbytes <= 0)
/* no more data */
break;
@ -70,7 +74,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
}
/* close file */
close(fd);
wn_close(fd);
}
static void _webnet_ssi_dofile(struct webnet_session* session, int fd)
@ -102,14 +106,14 @@ static void _webnet_ssi_dofile(struct webnet_session* session, int fd)
/* write page header */
webnet_session_set_header(session, "text/html", 200, "OK", -1);
/* read file to buffer */
if (read(fd, buffer, length) != length) /* read failed */
if (wn_read(fd, buffer, length) != length) /* read failed */
{
session->request->result_code = 500;
close(fd);
wn_close(fd);
goto __exit;
}
/* close file */
close(fd);
wn_close(fd);
offset = buffer;
end = buffer + length;
@ -207,11 +211,11 @@ int webnet_module_ssi(struct webnet_session* session, int event)
if (strstr(request->path, ssi_extension[index]) != NULL)
{
/* try to open this file */
fd = open(request->path, O_RDONLY, 0);
fd = wn_open(request->path, O_RDONLY, 0);
if ( fd >= 0)
{
_webnet_ssi_dofile(session, fd);
close(fd);
wn_close(fd);
return WEBNET_MODULE_FINISHED;
}
else
@ -233,13 +237,13 @@ int webnet_module_ssi(struct webnet_session* session, int event)
if (ssi_filename != NULL)
{
snprintf(ssi_filename, WEBNET_PATH_MAX, "%s/index.shtm", request->path);
fd = open(ssi_filename, O_RDONLY, 0);
fd = wn_open(ssi_filename, O_RDONLY, 0);
if (fd >= 0)
{
wn_free(ssi_filename);
_webnet_ssi_dofile(session, fd);
close(fd);
wn_close(fd);
return WEBNET_MODULE_FINISHED;
}
}

8
module/wn_module_upload.c Normal file → Executable file
View File

@ -19,8 +19,11 @@
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <assert.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_utils.h>
@ -155,7 +158,7 @@ static char* memstrs(const char* str, uint32 length, int num, ...)
return ptr;
}
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/)
static void* memrchr(const void *s, int c, uint32 n)
{
register const char* t=s;
@ -174,7 +177,6 @@ static void* memrchr(const void *s, int c, uint32 n)
}
return (void*)last; /* man, what an utterly b0rken prototype */
}
#endif
static char* _webnet_module_upload_parse_header(struct webnet_session* session, char* buffer, uint32 length)
{
@ -748,7 +750,7 @@ int webnet_upload_file_close(struct webnet_session* session)
fd = upload_session->user_data;
if (fd >= 0)
{
return close(fd);
return wn_close(fd);
}
return -1;
}

7
samples/Makefile Normal file
View File

@ -0,0 +1,7 @@
SRC_FILES += deviceinfoasp.c \
wn_sample_upload.c \
uploaddata.c \
netsetting.c \
wn_sample.c
include $(KERNEL_ROOT)/compiler.mk

125
samples/deviceinfoasp.c Executable file
View File

@ -0,0 +1,125 @@
#include "deviceinfoasp.h"
#ifdef ADD_XIZI_FEATURES
extern void HwCpuReset();//reset machine
#endif //ADD_XIZI_FEATURES
#ifdef ADD_XIZI_FEATURES
deviceinfo xidatong_deviceinfo =
{
DEVICE_NUM_DEFUALT,
DEVICE_NAME_DEFUALT,
DEVICE_TYPE_DEFUALT,
DEVICE_SERIAL_DEFUALT,
XIZI_OS_KERNEL,
SYSTEM_VERSION,
WEB_VERSION
};
#endif //ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
deviceinfo xidatong_deviceinfo =
{
DEVICE_NUM_DEFUALT,
DEVICE_NAME_DEFUALT,
DEVICE_TYPE_DEFUALT,
DEVICE_SERIAL_DEFUALT,
RT_THREAD_KERNEL,
SYSTEM_VERSION,
WEB_VERSION
};
#endif
void deviceinfo_default()
{
/*
*/
//memset((char *)(&xidatong_deviceinfo),0,sizeof(xidatong_deviceinfo));
}
void asp_var_device_name(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%s";
webnet_session_printf(session, temp, xidatong_deviceinfo.name);
}
void asp_var_device_number(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%d" ;
webnet_session_printf(session, temp,xidatong_deviceinfo.number);
}
void asp_var_device_type(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%s";
webnet_session_printf(session, temp, xidatong_deviceinfo.type);
}
void asp_var_device_serial(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%s";
webnet_session_printf(session, temp, xidatong_deviceinfo.serial);
}
void asp_var_os_type(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%s";
webnet_session_printf(session, temp, xidatong_deviceinfo.ostype);
}
void asp_var_web_version(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body>%s";
webnet_session_printf(session, temp,xidatong_deviceinfo.webversion);
}
void asp_var_system_firmware(struct webnet_session* session)
{
assert(session != NULL);
static const char *temp = "<html><body><font size=\"+2\">系统固件 %s</font><br><br>";
webnet_session_printf(session, temp, xidatong_deviceinfo.system_firmware);
}
void cgi_device_reboot(struct webnet_session* session)
{
const char* mimetype;
const char *response = "{\"code\":0}";
static char order_sh[] = "reboot";
mimetype = mime_get_type(".html");
session->request->result_code = 200;
webnet_session_set_header(session, mimetype, 200, "Ok", -1);
webnet_session_printf(session, response);
#ifdef ADD_RTTHREAD_FETURES
extern int msh_exec(char *cmd, rt_size_t length);
printf("reboot !!!!! \n\r");
msh_exec(order_sh,rt_strlen(order_sh));
#endif
#ifdef ADD_XIZI_FEATURES
HwCpuReset();
#endif //ADD_XIZI_FEATURES
}
extern void mqttweb_default();
extern void private_prtweb_default();
void cgi_device_recovery(struct webnet_session* session)
{
const char* mimetype;
const char *response = "{\"code\":0}";
mimetype = mime_get_type(".html");
session->request->result_code = 200;
webnet_session_set_header(session, mimetype, 200, "Ok", -1);
webnet_session_printf(session, response);
mqttweb_default();
private_prtweb_default();
}

45
samples/deviceinfoasp.h Executable file
View File

@ -0,0 +1,45 @@
#ifndef _DEVICEINFO_H
#define _DEVICEINFO_H
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#include <assert.h>
#define RT_THREAD_KERNEL "rt-thread kenel"
#define NUTTX_OS_KERNEL "nuttx kenel"
#define XIZI_OS_KERNEL "xizi kenel"
#define DEVICE_NAME_DEFUALT "xidatong"
#define DEVICE_TYPE_DEFUALT "gateway"
#define DEVICE_SERIAL_DEFUALT "12345678910"
#define DEVICE_NUM_DEFUALT (1)
#define WEB_VERSION "1.0.0"
#define SYSTEM_VERSION "1.1.1"
typedef struct
{
int number;
char name[16];
char type[16];
char serial[16];
char ostype[16];
char system_firmware[8];
char webversion[8];
}deviceinfo;
void deviceinfo_default();
void asp_var_device_name(struct webnet_session* session);
void asp_var_device_number(struct webnet_session* session);
void asp_var_device_type(struct webnet_session* session);
void asp_var_device_serial(struct webnet_session* session);
void asp_var_os_type(struct webnet_session* session);
void asp_var_web_version(struct webnet_session* session);
void asp_var_system_firmware(struct webnet_session* session);
void cgi_device_reboot();
void cgi_device_recovery();
#endif

View File

@ -1,81 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> WebNet </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
</head>
<body>
<h1>WebNet</h1>
该组件是基于RT-Thread的Webnet进行移植修改 为小型嵌入式设备定制作为web server具有低资源占用扩展性好的特点。
<hr>
<h2>WebNet 功能</h2>
<ul>
<li>支持 HTTP 1.0/1.1 规范
<li>支持 AUTH 基本认证
<li>支持 CGI 事件处理
<li>支持 ASP 变量替换
<li>支持 SSI 文件嵌入
<li>支持 INDEX 目录显示
<li>支持 ALIAS 别名
<li>支持 upload 文件上传
</ul>
<hr>
<h3>1. AUTH Test</h3>
WebNet 基本认证功能设计成与 URL 目录相挂钩,在使用时可以<b>根据目录划分访问权限</b>
<br/><br/>
<a href="/admin/">基本认证功能测试:用户名及密码为 <b>admin:admin</b></a>
<br/><br/>
<hr>
<h3>2. CGI Test</h3>
WebNet CGI 功能可以让用户执行指定的函数CGI测试
<br/><br/>
<a href="/cgi-bin/hello">> hello world</a>
<br/>
<a href="/cgi-bin/calc">> calc</a>
<br/><br/>
<hr>
<h3>3. ASP Test</h3>
WebNet 实现的是一种简化方式的 ASP 变量替换,即当页面中有<b><% %></b> 标记出现时,将自动替换成用户注册的字符串并输。
<br/><br/>
<a href="/version.asp">ASP 功能测试:访问 version.asp 文件,打印当前 RT-Thread 系统版本号</a>
<br/><br/>
<hr>
<h3>4. SSI Test</h3>
SSI 功能模块可以用于执行服务器上程序或者插入文本内容到网页中页面代码中有 <b>#include virtual="/xxx"</b> 或者 <b>#include file="/xxx"</b> 标记存在时,将自动解析成对应文件中的信息。
<br/><br/>
<a href="/index.shtml">SSI 功能测试:访问 /version.shtml 页面,其中嵌套了 /index.html 页面</a>
<br/><br/>
<hr>
<h3>5. INDEX Test</h3>
INDEX 功能模块可以自动显示目录下文件列表,当访问目录中不存在 index.htm, index.html, index.asp 等文件时,将自动显示这个目录下的文件列表。
<br/><br/>
<a href="/admin/">INDEX 功能测试:访问/admin 目录,列出目录下所有文件</a>
<br/><br/>
<hr>
<h3>6. ALIAS Test</h3>
ALIAS 别名模块可以给当前资源文件夹设置多个别名,可以用于<b>长路径的简化操作</b>,方便用户对资源的访问。
<br/><br/>
<a href="/test/">ALIAS 功能测试:访问 /test 目录会跳转到 /admin 目录</a>
<br/><br/>
<hr>
<h3>7. Upload File Test</h3>
文件上传模块可以用于上传文件到指定的目录,这里上传到根目录下的 /upload 目录。
<br/><br/>
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload">
<input type="file" name="file1" >
<input type="submit" name="submit" value="上传">
</form>
<br/>
<a href="/upload/">点击浏览上传文件的目录</a>
<br/><br/>
</body>
</html>

View File

@ -1,14 +0,0 @@
<html>
<head>
<title> SSI Test </title>
</head>
<body>
<h1> SSI Test</h1>
<font size=\"+2\">The <b>index.html</b> page embedded in the following page</font>
<br/><br/>
<a href="javascript:history.go(-1);">Go back to root</a>
<hr>
<!--#include virtual="/index.html" -->
</body>
</html>

249
samples/netsetting.c Executable file
View File

@ -0,0 +1,249 @@
#include "netsetting.h"
#ifdef ADD_XIZI_FEATURES
#include <netdev.h>
#include <netdev_ipaddr.h>
#endif // ADD_XIZI_FEATURES
static mqttsetting mqttweb;
static local_tcpip local_tcpipweb;
static private_prt private_prtweb;
void mqttweb_default()
{
strcpy(mqttweb.server_addr,ALIYUN_SERVER_ADDR);
strcpy(mqttweb.server_port,ALIYUN_SERVER_PORT);
strcpy(mqttweb.topic,ALIYUN_SERVER_TOPIC);
strcpy(mqttweb.username,ALIYUN_USERNAME);
strcpy(mqttweb.password,ALIYUN_PASSWORD);
strcpy(mqttweb.clientid,ALIYUN_CLIENTID);
}
void local_tcpipweb_default()
{
strcpy(local_tcpipweb.local_ipaddr,LOCAL_IP_ADDR);
strcpy(local_tcpipweb.netmask_addr,LOCAL_NETMASK_ADDR);
strcpy(local_tcpipweb.gateway_addr,LOCAL_GATEWAY_MASK);
strcpy(local_tcpipweb.dns_server0,LOCAL_DNS_SERVER0);
strcpy(local_tcpipweb.dns_server1,LOCAL_DNS_SERVER1);
}
void private_prtweb_default()
{
strcpy(private_prtweb.server_addr,PRIVATE_SERVER_ADDR);
strcpy(private_prtweb.server_port,PRIVATE_SERVER_PORt);
strcpy(private_prtweb.username,PRIVATE_USERNAME);
strcpy(private_prtweb.passward,PRIVATE_PASSWORD);
}
char *json_create_mqtt_data(void)
{
char *json_data = NULL;
cJSON *root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "pub_topic", cJSON_CreateString(mqttweb.topic));
cJSON_AddItemToObject(root, "server_addr", cJSON_CreateString(mqttweb.server_addr));
cJSON_AddItemToObject(root, "server_port", cJSON_CreateString(mqttweb.server_port));
cJSON_AddItemToObject(root, "username", cJSON_CreateString(mqttweb.username));
cJSON_AddItemToObject(root, "password", cJSON_CreateString(mqttweb.password));
cJSON_AddItemToObject(root, "clientID", cJSON_CreateString(mqttweb.clientid));
json_data = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return json_data;
}
void cgi_mqtt_get_data(struct webnet_session *session)
{
cgi_head();
request = request;
body = json_create_mqtt_data();
webnet_session_printf(session, body);
free(body);
}
void cgi_mqtt_save_data(struct webnet_session *session)
{
cgi_head();
const char *response = "{\"code\":0}";
const char *tpub_topic = webnet_request_get_query(request, "pub_topic");
const char *tserver_addr = webnet_request_get_query(request, "server_addr");
const char *tserver_port = webnet_request_get_query(request, "server_port");
const char *tusername = webnet_request_get_query(request, "username");
const char *tpassword = webnet_request_get_query(request, "password");
const char *tclientID = webnet_request_get_query(request, "clientID");
/*configuration*/
memset((char*)(&mqttweb),0,sizeof(mqttweb));
strcpy(mqttweb.server_addr,tserver_addr);
strcpy(mqttweb.server_port,tserver_port);
strcpy(mqttweb.topic,tpub_topic);
strcpy(mqttweb.username,tusername);
strcpy(mqttweb.password,tpassword);
strcpy(mqttweb.clientid,tclientID);
printf("\n\r \
mqtt serveraddr: %s \n \
mqtt server_port: %s \n \
mqtt topic: %s \n \
mqtt username: %s \n \
mqtt password: %s \n \
mqtt clientid: %s \n \
",mqttweb.server_addr,mqttweb.server_port,mqttweb.topic, \
mqttweb.username,mqttweb.password,mqttweb.clientid);
webnet_session_printf(session, response);
}
static void device_get_tcpip_parameter()
{
char dev_name[3] = "hd\0";
struct netdev* netdev_device = NULL;
netdev_device = netdev_get_by_name(dev_name);
if (netdev_device == NULL) {
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Not found netdev by name %s\n", __func__, dev_name));
netdev_device = NETDEV_DEFAULT;
}
//printf("ip address: %s\n", inet_ntoa(netdev_device->ip_addr));
//printf("netmask address: %s\n", inet_ntoa(netdev_device->netmask));
//printf("gw address: %s\n", inet_ntoa(netdev_device->gw));
//printf("dns0 address: %s\n", inet_ntoa(netdev_device->dns_servers[0]));
//printf("dns1 address: %s\n", inet_ntoa(netdev_device->dns_servers[1]));
strcpy(local_tcpipweb.local_ipaddr, inet_ntoa(netdev_device->ip_addr));
strcpy(local_tcpipweb.netmask_addr, inet_ntoa(netdev_device->netmask));
strcpy(local_tcpipweb.gateway_addr, inet_ntoa(netdev_device->gw));
strcpy(local_tcpipweb.dns_server0, inet_ntoa(netdev_device->dns_servers[0]));
strcpy(local_tcpipweb.dns_server1, inet_ntoa(netdev_device->dns_servers[1]));
printf("ip address: %s\n", local_tcpipweb.local_ipaddr);
printf("netmask address: %s\n", local_tcpipweb.netmask_addr);
printf("gw address: %s\n", local_tcpipweb.gateway_addr);
printf("dns0 address: %s\n", local_tcpipweb.dns_server0);
printf("dns1 address: %s\n", local_tcpipweb.dns_server1);
}
#ifdef ADD_XIZI_FEATURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
device_get_tcpip_parameter,device_get_tcpip_parameter, device_get_tcpip_parameter);
#endif // ADD_XIZI_FEATURES
char *json_create_tcpip_data(void)
{
char *json_data = NULL;
cJSON *root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "local_ipaddr", cJSON_CreateString(local_tcpipweb.local_ipaddr));
cJSON_AddItemToObject(root, "netmask_addr", cJSON_CreateString(local_tcpipweb.netmask_addr));
cJSON_AddItemToObject(root, "gateway_addr", cJSON_CreateString(local_tcpipweb.gateway_addr));
cJSON_AddItemToObject(root, "dns_server0", cJSON_CreateString(local_tcpipweb.dns_server0));
cJSON_AddItemToObject(root, "dns_server1", cJSON_CreateString(local_tcpipweb.dns_server1));
json_data = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return json_data;
}
void cgi_tcpip_get_data(struct webnet_session *session)
{
cgi_head();
request = request;
device_get_tcpip_parameter();
body = json_create_tcpip_data();
webnet_session_printf(session, body);
free(body);
}
void cgi_tcpip_save_data(struct webnet_session *session)
{
cgi_head();
ip_addr_t addr;
const char *response = "{\"code\":0}";
const char *local_ipaddr = webnet_request_get_query(request, "local_ipaddr");
const char *netmask_addr = webnet_request_get_query(request, "netmask_addr");
const char *gateway_addr = webnet_request_get_query(request, "gateway_addr");
const char *dns_server0 = webnet_request_get_query(request, "dns_server0");
const char *dns_server1 = webnet_request_get_query(request, "dns_server1");
printf("ip address: %s\n", local_ipaddr);
printf("netmask address: %s\n", netmask_addr);
printf("gw address: %s\n", gateway_addr);
printf("dns0 address: %s\n", dns_server0);
printf("dns1 address: %s\n", dns_server1);
#ifdef ADD_RTTHREAD_FETURES
struct netdev *netdev_device = netdev_get_by_name("e0");
inet_aton(local_ipaddr, &addr);
netdev_set_ipaddr(netdev_device, &addr);
inet_aton(netmask_addr, &addr);
netdev_set_netmask(netdev_device, &addr);
inet_aton(gateway_addr, &addr);
netdev_set_gw(netdev_device, &addr);
inet_aton(dns_server0, &addr);
netdev_set_dns_server(netdev_device,0, &addr);
inet_aton(dns_server1, &addr);
netdev_set_dns_server(netdev_device,0, &addr);
#endif //ADD_RTTHREAD_FETURES
/*configuration*/
memset((char*)(&local_tcpipweb),0,sizeof(local_tcpipweb));
strcpy(local_tcpipweb.local_ipaddr,local_ipaddr);
strcpy(local_tcpipweb.netmask_addr,netmask_addr);
strcpy(local_tcpipweb.gateway_addr,gateway_addr);
strcpy(local_tcpipweb.dns_server0,dns_server0);
strcpy(local_tcpipweb.dns_server1,dns_server1);
printf("ip address: %s\n", local_tcpipweb.local_ipaddr);
printf("netmask address: %s\n", local_tcpipweb.netmask_addr);
printf("gw address: %s\n", local_tcpipweb.gateway_addr);
printf("dns0 address: %s\n", local_tcpipweb.dns_server0);
printf("dns1 address: %s\n", local_tcpipweb.dns_server1);
webnet_session_printf(session, response);
}
char *json_create_private_prt_data()
{
char *json_data = NULL;
cJSON *root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "server_addr", cJSON_CreateString(private_prtweb.server_addr));
cJSON_AddItemToObject(root, "server_port", cJSON_CreateString(private_prtweb.server_port));
cJSON_AddItemToObject(root, "username", cJSON_CreateString(private_prtweb.username));
cJSON_AddItemToObject(root, "passward", cJSON_CreateString(private_prtweb.passward));
json_data = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return json_data;
}
void cgi_private_prt_get_data(struct webnet_session *session)
{
cgi_head();
request = request;
body = json_create_private_prt_data();
webnet_session_printf(session, body);
free(body);
}
void cgi_private_prt_save_data(struct webnet_session *session)
{
cgi_head();
ip_addr_t addr;
const char *response = "{\"code\":0}";
const char *server_addr = webnet_request_get_query(request, "server_addr");
const char *server_port = webnet_request_get_query(request, "server_port");
const char *username = webnet_request_get_query(request, "username");
const char *passward = webnet_request_get_query(request, "passward");
/*configuration*/
memset((char*)(&private_prtweb),0,sizeof(private_prtweb));
strcpy(private_prtweb.server_addr,server_addr);
strcpy(private_prtweb.server_port,server_port);
strcpy(private_prtweb.username,username);
strcpy(private_prtweb.passward,passward);
webnet_session_printf(session, response);
}

83
samples/netsetting.h Executable file
View File

@ -0,0 +1,83 @@
#ifndef _NETSETTING_H
#define _NETSETTING_H
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#include <cJSON.h>
#include <transform.h>
#define cgi_head() \
; \
const char *mimetype; \
struct webnet_request *request; \
static char *body = NULL; \
request = session->request; \
mimetype = mime_get_type(".html"); \
session->request->result_code = 200; \
webnet_session_set_header(session, mimetype, 200, "Ok", -1);
/*
mqtt platform macro
*/
#define ALIYUN_SERVER_ADDR "hf6mzwdVnJg.iot-as-mqtt.cn-shanghai.aliyuncs.com"
#define ALIYUN_SERVER_PORT "1883"
#define ALIYUN_SERVER_TOPIC "/broadcast/hf6mzwdVnJg/989898"
#define ALIYUN_USERNAME "test1&hf6mzwdVnJg"
#define ALIYUN_PASSWORD "F08C59D320BB72830B9ECC5ACF132BC22B55861B"
#define ALIYUN_CLIENTID "123|securemode=3,signmethod=hmacsha1|"
#define LOCAL_IP_ADDR "192.168.131.29"
#define LOCAL_NETMASK_ADDR "255.255.255.0"
#define LOCAL_GATEWAY_MASK "192.168.130.1"
#define LOCAL_DNS_SERVER0 "0.0.0.0"
#define LOCAL_DNS_SERVER1 "0.0.0.0"
#define PRIVATE_SERVER_ADDR "192.168.131.30"
#define PRIVATE_SERVER_PORt "9898"
#define PRIVATE_USERNAME "admin"
#define PRIVATE_PASSWORD "admin"
typedef struct
{
char topic[100]; //topic
char server_addr[100]; //服务器地址
char server_port[12]; //服务器端口
char username[50]; //用户名
char password[100]; //密码
char clientid[100]; //client id
}mqttsetting;
typedef struct
{
char local_ipaddr[16]; //本地ip
char netmask_addr[16]; //子网掩码
char gateway_addr[16]; //网关
char dns_server0[16];
char dns_server1[16];
}local_tcpip;
typedef struct
{
char server_addr[100]; //私有协议服务器地址
char server_port[12]; //端口号
char username[16]; //用户名
char passward[16]; //密码确认
}private_prt;
void mqttweb_default();
void local_tcpipweb_default();
void private_prtweb_default();
void cgi_mqtt_get_data(struct webnet_session *session);
void cgi_mqtt_save_data(struct webnet_session *session);
void cgi_tcpip_get_data(struct webnet_session *session);
void cgi_tcpip_save_data(struct webnet_session *session);
void cgi_private_prt_get_data(struct webnet_session *session);
void cgi_private_prt_save_data(struct webnet_session *session);
#endif

132
samples/uploaddata.c Executable file
View File

@ -0,0 +1,132 @@
#include "uploaddata.h"
#include <mqueue.h>
#include <transform.h>
char msg[] = "/mq_upload_web";
sensor_msg eg_temperature;
sensor_msg web_show;
static mqd_t mq_web = -1;
void *upload_receive_web_msg_thread()
{
int nbytes = 0;
while (1) {
nbytes = mq_receive(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), NULL);
if (nbytes < 0)
{
printf("mq_receive error: %d \n", nbytes);
#ifdef ADD_XIZI_FEATURES
break;
#endif // ADD_XIZI_FEATURES
} else {
printf("=============mq_receive success:==============\n");
printf(" \
name:%s\n \
brand %s\n \
unit %s\n \
value %s\n",
eg_temperature.name, eg_temperature.brand, eg_temperature.unit, eg_temperature.value);
memcpy(&web_show, &eg_temperature, sizeof(web_show));
}
}
}
int uploaddata_init()
{
struct mq_attr webmq_attr;
int result = 0;
webmq_attr.mq_flags = 0;
webmq_attr.mq_maxmsg = 20;
webmq_attr.mq_msgsize = 512;
webmq_attr.mq_curmsgs = 0;
mq_web = mq_open("/mq_web", O_RDONLY | O_CREAT, 0666, &webmq_attr);
if (mq_web < 0) {
printf("mq_open error: %d \n", mq_web);
} else {
printf("mq_open success: %d \n", mq_web);
}
pthread_t tid = 0;
pthread_attr_t attr;
struct sched_param prio;
#ifdef ADD_RTTHREAD_FETURES
prio.sched_priority = 8;
#endif // ADD_RTTHREAD_FETURES
#ifdef ADD_XIZI_FEATURES
prio.sched_priority = 25;
#endif // ADD_XIZI_FEATURES
size_t stack_size = 1024 * 11;
pthread_attr_init(&attr);
pthread_attr_setschedparam(&attr, &prio);
pthread_attr_setstacksize(&attr, stack_size);
result = pthread_create(&tid, &attr, upload_receive_web_msg_thread, NULL);
if (result >= 0) {
printf("thread_detect_entry successfully!\n");
} else {
printf("thread_detect_entry failed! error code is %d.\n", result);
}
/***********demo sensor set parameters***************/
strcpy(eg_temperature.name, "temperature");
strcpy(eg_temperature.brand, "hs300x");
strcpy(eg_temperature.unit, "°C");
}
void upload_send_web_msg()
{
static int seed_t = 20;
float temp = 25;
float tem_decimals = 0;
int nbytes = 0;
memset((char*)eg_temperature.value, 0, sizeof(eg_temperature.value));
srand(seed_t);
tem_decimals = ((float)(rand() % 100)) / 100.0;
temp = temp + tem_decimals;
sprintf(eg_temperature.value, "%f", temp);
printf("rand generate temperature %s \n\r", eg_temperature.value);
nbytes = mq_send(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), 0);
if (nbytes < 0) {
printf("mq_send error: %d \n", nbytes);
} else {
printf("mq_send success: times%d \n", seed_t);
}
seed_t++;
}
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(upload_send_web_msg, upload_send_web_msg);
#endif
#ifdef ADD_XIZI_FEATURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
upload_send_web_msg, upload_send_web_msg, upload_send_web_msg);
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
uploaddata_init, uploaddata_init, uploaddata_init);
#endif
char* json_create_datashow_data()
{
char* json_data = NULL;
cJSON* root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "name", cJSON_CreateString(web_show.name));
cJSON_AddItemToObject(root, "brand", cJSON_CreateString(web_show.brand));
cJSON_AddItemToObject(root, "unit", cJSON_CreateString(web_show.unit));
cJSON_AddItemToObject(root, "value", cJSON_CreateString(web_show.value));
json_data = cJSON_PrintUnformatted(root);
cJSON_Delete(root);
return json_data;
}
void cgi_dateshow_get_data(struct webnet_session *session)
{
cgi_head();
request = request;
body = json_create_datashow_data();
webnet_session_printf(session, body);
free(body);
}

18
samples/uploaddata.h Executable file
View File

@ -0,0 +1,18 @@
#ifndef _UPLOADDATA_
#define _UPLOADDATA_
#include "netsetting.h"
#include<transform.h>
typedef struct
{
char name[32]; //sensor name
char brand[32]; //sensor brand;
char unit[12]; //sensor unit
char value[12]; //sensor value
}sensor_msg;
int uploaddata_init();
void upload_send_web_msg();
void cgi_dateshow_get_data(struct webnet_session *session);
#endif

View File

@ -1,10 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> ASP Test </title>
</head>
<body>
<% version %>
</body>
</html>

114
samples/wn_sample.c Normal file → Executable file
View File

@ -18,91 +18,47 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#include "deviceinfoasp.h"
#include "netsetting.h"
#include "uploaddata.h"
#define XiUOS_VERSION (1)
#define XiUOS_SUBVERSION (0)
#define XiUOS_REVERSION (0)
static void asp_var_version(struct webnet_session* session)
{
assert(session != NULL);
static const char *version = "<html><body><font size=\"+2\">RT-Thread %d.%d.%d</font><br><br>"
"<a href=\"javascript:history.go(-1);\">Go back to root</a></html></body>";
webnet_session_printf(session, version, XiUOS_VERSION, XiUOS_SUBVERSION, XiUOS_REVERSION);
}
static void cgi_calc_handler(struct webnet_session* session)
{
int a, b;
const char* mimetype;
struct webnet_request* request;
static const char* header = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; "
"charset=gb2312\" /><title> calc </title></head>";
static const char* body = "<body><form method=\"post\" action=\"/cgi-bin/calc\"><input type=\"text\" name=\"a\" value=\"%d\"> "
"+ <input type=\"text\" name=\"b\" value=\"%d\"> = %d<br><input type=\"submit\" value=\"\xBC\xC6\xCB\xE3\"></form>"
"<br><a href=\"/index.html\">Go back to root</a></body></html>\r\n";
assert(session != NULL);
request = session->request;
assert(request != NULL);
/* get mimetype */
mimetype = mime_get_type(".html");
a = 1;
b = 1;
/* set http header */
session->request->result_code = 200;
webnet_session_set_header(session, mimetype, 200, "Ok", -1);
webnet_session_write(session, (const uint8*)header, strlen(header));
if (request->query_counter)
{
const char *a_value, *b_value;
a_value = webnet_request_get_query(request, "a");
b_value = webnet_request_get_query(request, "b");
a = atoi(a_value);
b = atoi(b_value);
}
webnet_session_printf(session, body, a, b, a + b);
}
static void cgi_hello_handler(struct webnet_session* session)
{
const char* mimetype;
static const char* status = "<html><head><title> hello </title>"
"</head><body><font size=\"+2\">hello world</font><br><br>"
"<a href=\"javascript:history.go(-1);\">Go back to root</a></body></html>\r\n";
assert(session != NULL);
/* get mimetype */
mimetype = mime_get_type(".html");
/* set http header */
session->request->result_code = 200;
webnet_session_set_header(session, mimetype, 200, "Ok", strlen(status));
webnet_session_write(session, (const uint8*)status,strlen(status));
}
void webnet_test(void)
void webnet_start(void)
{
#ifdef WEBNET_USING_CGI
webnet_cgi_register("hello", cgi_hello_handler);
webnet_cgi_register("calc", cgi_calc_handler);
webnet_cgi_register("mqtt_get", cgi_mqtt_get_data);
webnet_cgi_register("mqtt_save", cgi_mqtt_save_data);
webnet_cgi_register("tcpip_get", cgi_tcpip_get_data);
webnet_cgi_register("tcpip_save", cgi_tcpip_save_data);
webnet_cgi_register("private_prt_get", cgi_private_prt_get_data);
webnet_cgi_register("private_prt_save", cgi_private_prt_save_data);
webnet_cgi_register("device_reboot", cgi_device_reboot);
webnet_cgi_register("device_recovery", cgi_device_recovery);
webnet_cgi_register("datashow", cgi_dateshow_get_data);
#endif
#ifdef WEBNET_USING_ASP
webnet_asp_add_var("version", asp_var_version);
webnet_asp_add_var("device_name", asp_var_device_name);
webnet_asp_add_var("device_number", asp_var_device_number);
webnet_asp_add_var("device_type", asp_var_device_type);
webnet_asp_add_var("device_serial", asp_var_device_serial);
webnet_asp_add_var("os_type", asp_var_os_type);
webnet_asp_add_var("system_firmware", asp_var_system_firmware);
webnet_asp_add_var("web_version", asp_var_web_version);
#endif
#ifdef WEBNET_USING_ALIAS
@ -110,7 +66,7 @@ void webnet_test(void)
#endif
#ifdef WEBNET_USING_AUTH
webnet_auth_set("/admin", "admin:admin");
webnet_auth_set("/", "admin:admin");
#endif
#ifdef WEBNET_USING_UPLOAD
@ -118,9 +74,19 @@ void webnet_test(void)
webnet_upload_add(&upload_entry_upload);
#endif
private_prtweb_default();
mqttweb_default();
// uploaddata_init();
webnet_init();
}
#ifdef ADD_RTTHREAD_FETURES
MSH_CMD_EXPORT(webnet_test, wenbet test);
#endif
MSH_CMD_EXPORT(webnet_start, wenbet test);
#endif //ADD_RTTHREAD_FETURES
#ifdef ADD_XIZI_FEATURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
webnet_start, webnet_start, wenbet test);
#endif //ADD_XIZI_FEATURES

13
samples/wn_sample_upload.c Normal file → Executable file
View File

@ -18,13 +18,20 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
* 2022-09-07 zhaoyun the version transplanted for XiZi
*/
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_request.h>
#include <wn_utils.h>
#ifdef WEBNET_USING_UPLOAD
/**
@ -92,7 +99,7 @@ static int upload_open(struct webnet_session *session)
printf("save to: %s\r\n", file_path);
fd = open(file_path, O_WRONLY | O_CREAT, 0);
fd = wn_open(file_path, O_WRONLY | O_CREAT, 0);
if (fd < 0)
{
webnet_session_close(session);
@ -116,7 +123,7 @@ static int upload_close(struct webnet_session* session)
fd = (int)webnet_upload_get_userdata(session);
if (fd < 0) return 0;
close(fd);
wn_close(fd);
printf("Upload FileSize: %d\n", file_size);
return 0;
}

3
src/Makefile Normal file
View File

@ -0,0 +1,3 @@
SRC_FILES += webnet.c wn_mimetype.c wn_module.c wn_request.c wn_session.c wn_utils.c
include $(KERNEL_ROOT)/compiler.mk

43
src/webnet.c Normal file → Executable file
View File

@ -18,7 +18,7 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version from rt-thread
* 2022-05-09 chunyexixiaoyu the version from rt-thread
*/
@ -26,23 +26,18 @@
#include <stdint.h>
#include <webnet.h>
#include <wn_module.h>
#ifdef ADD_RTTHREAD_FETURES
#if defined(RT_USING_LWIP) && (RT_LWIP_TCPTHREAD_STACKSIZE < 1408)
#error The lwIP tcpip thread stack size(RT_LWIP_TCPTHREAD_STACKSIZE) must more than 1408
#endif
#endif
/*
other os kernel need to notice the point about lwip thread stack.
*/
#include <assert.h>
#include <sys.h>
static uint8 webnet_port = WEBNET_PORT;
static char webnet_root[64] = WEBNET_ROOT;
static bool init_ok = FALSE;
static bool init_ok = false;
void webnet_set_port(int port)
{
assert(init_ok == FALSE);
assert(init_ok == false);
webnet_port = port;
}
@ -65,7 +60,7 @@ const char* webnet_get_root(void)
/**
* webnet thread entry
*/
static void webnet_thread(void *parameter)
static void *webnet_thread(void *parameter)
{
int listenfd = -1;
fd_set readset, tempfds;
@ -88,11 +83,12 @@ static void webnet_thread(void *parameter)
webnet_saddr.sin_port = htons(webnet_port); /* webnet server port */
/* Set receive timeout for accept() */
if(setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, (void*)&rcv_to, sizeof(rcv_to)) == -1)
{
if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, (void*)&rcv_to, sizeof(rcv_to)) == -1) {
printf("Set SO_RCVTIMEO failed, errno=%d\n", errno);
goto __exit;
}
int flag = 1;
if (bind(listenfd, (struct sockaddr *) &webnet_saddr, sizeof(webnet_saddr)) == -1)
{
@ -128,7 +124,7 @@ static void webnet_thread(void *parameter)
/* use temporary fd set in select */
tempfds = readset;
tempwrtfds = writeset;
/* Wait for data or a new connection */
sock_fd = select(maxfdp1, &tempfds, &tempwrtfds, 0, 0);
if (sock_fd == 0)
{
@ -175,28 +171,29 @@ __exit:
int webnet_init(void)
{
int result = 0;
#ifdef ADD_XIZI_FEATURES
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
#endif // ADD_XIZI_FEATURES
pthread_t tid;
pthread_attr_t attr;
struct sched_param prio;
prio.sched_priority = WEBNET_PRIORITY;
size_t stack_size = WEBNET_THREAD_STACKSIZE;
pthread_attr_init(&attr);
pthread_attr_setschedparam(&attr, &prio);
pthread_attr_setstacksize(&attr, stack_size);
if (init_ok == TRUE)
{
printf("XiUOS webnet package is already initialized.");
return 0;
}
result = pthread_create(&tid, &attr, webnet_thread, NULL);
if (0 == result)
{
init_ok = TRUE;
init_ok = true;
printf("XiUOS webnet initialize success.");
}
else
{
printf("XiUOS webnet initialize failed.");
printf("XiUOS webnet initialize failed\n.");
return -1;
}

1
src/wn_mimetype.c Normal file → Executable file
View File

@ -43,6 +43,7 @@ static const struct webnet_mime_entry mime_tables[] =
{ "png", "image/png" },
{ "jpeg", "image/jpeg" },
{ "jpg", "image/jpeg" },
{ "ico", "image/x-icon" },
{ "svg", "image/svg+xml" },
{ "avi", "video/x-msvideo" },
{ "mp3", "audio/mpeg" },

66
src/wn_module.c Normal file → Executable file
View File

@ -21,12 +21,12 @@
* 2022-05-09 chunyexixiaoyu the version from rt-thread
*/
#include <assert.h>
#include <transform.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_utils.h>
#include <xs_kdbg.h>
static int _webnet_module_system_init(struct webnet_session *session, int event)
{
@ -107,21 +107,22 @@ static void _webnet_dofile_handle(struct webnet_session *session, int event)
{
length = WEBNET_SESSION_BUFSZ;
}
lseek(fd, session->request->pos_start, SEEK_SET);
session->request->pos_start += length;
lseek(fd, session->request->pos_start, SEEK_SET);
session->request->pos_start += length;
}
#endif
readbytes = read(fd, session->buffer, length);
readbytes = wn_read(fd, session->buffer, length);
if (readbytes <= 0) /* end of file */
goto __exit;
if (webnet_session_write(session, session->buffer, readbytes) == 0)
goto __exit;
return;
}
__exit:
close(fd);
wn_close(fd);
session->user_data = 0;
session->session_event_mask = 0; /* clean event */
/* destroy session */
@ -142,7 +143,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
int fd = -1; /* file descriptor */
struct stat file_stat;
const char *mimetype;
unsigned long file_length;
unsigned long file_length;
struct webnet_request *request;
#if WEBNET_CACHE_LEVEL > 0
@ -172,11 +173,23 @@ int webnet_module_system_dofile(struct webnet_session *session)
wn_free(path_gz);
}
if (stat_result == 0)
{
if (stat_result == 0) {
#ifdef ADD_XIZI_FEATURES
long lock;
lock = CriticalAreaLock();
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskenterCritical();
#endif // ADD_RTTHREAD_FETURES
strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime));
#ifdef ADD_XIZI_FEATURES
CriticalAreaUnLock(lock);
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskexitCritical();
#endif // ADD_RTTHREAD_FETURES
ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */
@ -191,21 +204,33 @@ int webnet_module_system_dofile(struct webnet_session *session)
/* .gz not exist, use raw. */
#endif /* WEBNET_USING_GZIP */
/* get Last-Modified. */
if (stat_result != 0)
{
struct stat file_stat;
stat_result = stat(request->path, &file_stat);
if (stat_result == 0)
{
if (stat_result == 0) {
#ifdef ADD_XIZI_FEATURES
x_base lock = CriticalAreaLock();
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskenterCritical();
#endif // ADD_RTTHREAD_FETURES
info = localtime((time_t *)&file_stat.st_mtime);
memset(gmtime_str,0,32);
strftime(gmtime_str,sizeof(ctime_str),"%a, %d %b %Y %H:%M:%S GMT",info);
strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime));
#ifdef ADD_XIZI_FEATURES
CriticalAreaUnLock(lock);
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskexitCritical();
#endif // ADD_RTTHREAD_FETURES
ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */
gmtime_str[strlen(gmtime_str)] = '\0'; /* clear the end \n */
@ -231,22 +256,21 @@ int webnet_module_system_dofile(struct webnet_session *session)
if (path_gz != NULL)
{
sprintf(path_gz, "%s.gz", request->path);
fd = open(path_gz, O_RDONLY, 0);
fd = wn_open(path_gz, O_RDONLY, 0);
wn_free(path_gz);
if (fd < 0)
{
/* .gz not exist, use raw. */
request->support_gzip = FALSE;
request->support_gzip = false;
}
}
}
/* .gz not exist, use raw. */
#endif /* WEBNET_USING_GZIP */
if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode))
{
fd = open(request->path, O_RDONLY, 0);
if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) {
fd = wn_open(request->path, O_RDONLY, 0);
}
if (fd < 0)
@ -386,7 +410,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
if (file_length <= 0)
{
close(fd);
wn_close(fd);
return WEBNET_MODULE_FINISHED;
}
@ -405,7 +429,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
_error_exit:
if (fd >= 0)
{
close(fd);
wn_close(fd);
}
return WEBNET_MODULE_FINISHED;
@ -491,11 +515,11 @@ int webnet_module_handle_event(struct webnet_session *session, int event)
}
/* default index file */
static const char *default_files[] =
{
static const char* default_files[] = {
"",
"deviceinfo.asp",
"/index.html",
"/index.htm",
// "/index.htm",
NULL
};

37
src/wn_request.c Normal file → Executable file
View File

@ -24,11 +24,13 @@
#include <transform.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <webnet.h>
#include <wn_request.h>
#include <wn_utils.h>
#include <assert.h>
#define POST_BUFSZ_MAX (8 * 1024)
/**
@ -108,7 +110,7 @@ static void _webnet_request_parse_query(struct webnet_request* request)
}
/**
* copy string from request and the field_copied set to TRUE
* copy string from request and the field_copied set to true
*/
static void _webnet_request_copy_str(struct webnet_request* request)
{
@ -141,7 +143,7 @@ static void _webnet_request_copy_str(struct webnet_request* request)
#ifdef WEBNET_USING_RANGE
if (request->Range) request->Range = wn_strdup(request->Range);
#endif /* WEBNET_USING_RANGE */
request->field_copied = TRUE;
request->field_copied = true;
}
/**
@ -154,10 +156,9 @@ bool webnet_request_has_query(struct webnet_request* request, char* name)
for (index = 0; index < request->query_counter; index ++)
{
if (strncmp(request->query_items[index].name, name, strlen(name)) == 0)
return TRUE;
return true;
}
return FALSE;
return false;
}
#ifdef ADD_RTTHREAD_FETURES
RTM_EXPORT(webnet_request_has_query);
@ -315,8 +316,8 @@ int webnet_request_parse_header(struct webnet_request *request, char* buffer, in
if(request->query != NULL) {
wn_free(request->query);
}
request->query = (char*) wn_malloc(request->content_length + 1);
rt_memset(request->query, 0, request->content_length + 1);
request->query = (char*) wn_malloc(request->content_length + 1);
memset(request->query, 0, request->content_length + 1);
request->query_offset = 0;
}
}
@ -461,7 +462,7 @@ int webnet_request_parse_header(struct webnet_request *request, char* buffer, in
if( (gzip != NULL))
{
request->support_gzip = TRUE;
request->support_gzip = true;
}
}
#endif /* WEBNET_USING_GZIP */
@ -495,7 +496,7 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int
if (request->query_offset + length > request->content_length)
length = request->content_length - request->query_offset;
rt_memcpy(&request->query[request->query_offset], buffer, length);
memcpy(&request->query[request->query_offset], buffer, length);
request->query_offset += length;
if (request->query_offset == request->content_length)
@ -678,8 +679,10 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng
{
/* end of http request */
request->result_code = 200;
session->buffer_offset = (rt_uint16_t)(length -
session->buffer_offset = (uint16_t)(length -
((uint32)request->query - (uint32)buffer));
/* move the buffer to the session */
if (session->buffer_offset > 0)
{
@ -687,7 +690,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng
* NOTIC: the rest of buffer must not be great than session buffer
* Therefore, the size of read buffer can equal to the size of session buffer.
*/
rt_memcpy(session->buffer, request->query, session->buffer_offset);
memcpy(session->buffer, request->query, session->buffer_offset);
}
request->query = NULL;
return;
@ -715,7 +718,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng
if (read_length > 0)
{
if (read_length > request->content_length) read_length = request->content_length;
rt_memcpy(read_ptr, request->query, read_length);
memcpy(read_ptr, request->query, read_length);
}
request->query = read_ptr;
@ -865,7 +868,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng
if( (gzip != NULL) && (end != NULL) && (gzip < end) )
{
request->support_gzip = TRUE;
request->support_gzip = true;
}
}
#endif /* WEBNET_USING_GZIP */
@ -906,8 +909,8 @@ struct webnet_request* webnet_request_create()
request = (struct webnet_request*) wn_malloc (sizeof(struct webnet_request));
if (request != NULL)
{
rt_memset(request, 0, sizeof(struct webnet_request));
request->field_copied = FALSE;
memset(request, 0, sizeof(struct webnet_request));
request->field_copied = false;
}
return request;
@ -917,7 +920,7 @@ void webnet_request_destory(struct webnet_request* request)
{
if (request != NULL)
{
// if (request->field_copied == TRUE)
// if (request->field_copied == true)
{
if (request->path != NULL) wn_free(request->path);
if (request->host != NULL) wn_free(request->host);

68
src/wn_session.c Normal file → Executable file
View File

@ -18,17 +18,23 @@
*
* Change Logs:
* Date Author Notes
* 2022-05-09 chunyexixiaoyu the version from rt-thread
* 2022-05-09 chunyexixiaoyu the version from rt-thread
*/
#include <transform.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <transform.h>
#include <xs_kdbg.h>
#include <webnet.h>
#include <wn_module.h>
#include <wn_utils.h>
#include <assert.h>
#ifdef ADD_RTTHREAD_FETURES
#include <finsh.h>
#endif //ADD_RTTHREAD_FETURES
static struct webnet_session *_session_list = 0;
@ -124,8 +130,9 @@ void webnet_session_close(struct webnet_session *session)
closesocket(session->socket);
/* Free webnet_session */
if (_session_list == session)
if (_session_list == session){
_session_list = session->next;
}
else
{
for (iter = _session_list; iter; iter = iter->next)
@ -182,6 +189,7 @@ RTM_EXPORT(webnet_session_printf);
int webnet_session_write(struct webnet_session *session, const uint8* data, uint32 size)
{
/* send data directly */
MdelayKTask(10);
send(session->socket, data, size, 0);
return size;
@ -458,7 +466,7 @@ static void _webnet_session_badrequest(struct webnet_session *session, int code)
title = "Method Not Allowed";
break;
case 500:
title = "Internal Server Error";
title = "Internal Server Error\n";
break;
case 501:
title = "Not Implemented";
@ -518,12 +526,14 @@ void webnet_sessions_set_err_callback(void (*callback)(struct webnet_session *se
void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset)
{
struct webnet_session *session, *next_session;
int num_sess = 0;
/* Go through list of connected session and process data */
for (session = _session_list; session; session = next_session)
{
/* get next session firstly if this session is closed */
next_session = session->next;
num_sess++;
if (FD_ISSET(session->socket, readset))
{
@ -546,7 +556,7 @@ void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset)
session->session_phase = WEB_PHASE_METHOD;
/* set the default session ops */
session->session_ops = &_default_session_ops;
session->user_data = NULL;
session->user_data = 0; // change from NULL
request->session = session;
request->result_code = 200; /* set the default result code to 200 */
@ -603,10 +613,12 @@ void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset)
}
}
}
SYS_KDEBUG_LOG(WEBNET_DEBUG, ("[%s] %d sessions in total\n", __func__, num_sess));
}
#ifdef ADD_RTTHREAD_FETURES
#ifdef RT_USING_FINSH
#include <finsh.h>
static void list_webnet(void)
{
@ -614,29 +626,47 @@ static void list_webnet(void)
char client_ip_str[16]; /* ###.###.###.### */
uint32 num = 0;
#ifdef ADD_XIZI_FEATURES
x_base lock = CriticalAreaLock();
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskenterCritical();
for (session = _session_list; session != NULL; session = session->next)
{
#endif // ADD_RTTHREAD_FETURES
for (session = _session_list; session != NULL; session = session->next) {
strcpy(client_ip_str,
inet_ntoa(*((struct in_addr*)&(session->cliaddr.sin_addr))));
inet_ntoa(*((struct in_addr*)&(session->cliaddr.sin_addr))));
printf("#%u client %s:%u \n",
num++,
client_ip_str,
ntohs(session->cliaddr.sin_port));
num++,
client_ip_str,
ntohs(session->cliaddr.sin_port));
if (session->request != NULL)
{
if (session->request != NULL) {
printf("path: %s\n", session->request->path);
}
printf("\r\n");
}
printf("Total Session Number: %d\n", num);
#ifdef ADD_XIZI_FEATURES
CriticalAreaUnLock(lock);
#endif // ADD_XIZI_FEATURES
#ifdef ADD_RTTHREAD_FETURES
PrivTaskexitCritical();
#endif // ADD_RTTHREAD_FETURES
}
#ifdef ADD_RTTHREAD_FETURES
#ifdef RT_USING_FINSH
#include <finsh.h>
#endif /* RT_USING_FINSH */
FINSH_FUNCTION_EXPORT(list_webnet, list webnet session);
#ifdef FINSH_USING_MSH
MSH_CMD_EXPORT(list_webnet, list webnet session);
#endif
#endif /* RT_USING_FINSH */
#endif
#endif //FINSH_USING_MSH
#endif //ADD_RTTHREAD_FETURES
#ifdef ADD_XIZI_FEATURES
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
list_webnet, list_webnet, list_webnet);
#endif //ADD_XIZI_FEATURES

5
src/wn_utils.c Normal file → Executable file
View File

@ -23,12 +23,11 @@
*/
#include <ctype.h>
#include <rtthread.h>
#include <webnet.h>
#include <wn_utils.h>
#include <transform.h>
rt_inline int tohex(char c)
inline int tohex(char c)
{
if (c >= '0' && c <= '9')
return c - '0';

154
webnet/chart.html Executable file
View File

@ -0,0 +1,154 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<!-- <link rel="icon" href="../../favicon.ico" /> -->
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"
></script>
<script src="./js/Chart.bundle.min.js"></script>
<!-- Bootstrap core CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous"
/>
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_30 {
margin-top: 30px;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li>
<a href="deviceinfo.asp">系统设置</a>
</li>
<li><a href="tcp.html">网络设置</a></li>
<li class="active"><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">数据显示</h1>
<div class="col-sm-12">
<canvas id="myChart"></canvas>
</div>
</div>
</div>
</div>
</body>
<script>
var ctx = $('#myChart');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
datasets: [
{
label: '',
data: [],
borderColor: ['rgba(255, 99, 132, 1)'],
fill: false,
borderWidth: 2,
},
],
},
options: {
elements: {
line: {
tension: 0, // 禁用贝塞尔曲线
},
},
scales: {
xAxes: [
{
type: 'time',
time: {
unit: 'minute',
},
scaleLabel: {
display: true,
labelString: '',
},
},
],
},
},
});
function getData() {
$.get(
'/cgi-bin/datashow',
function (data) {
const { name, brand, unit, value } = data;
myChart.data.datasets[0].label = name + '(' + unit + ')';
if (value) {
myChart.data.datasets[0].data.push({
x: Date.now(),
y: value,
});
}
myChart.options.scales.xAxes[0].scaleLabel.labelString = brand;
myChart.update();
},
'json'
);
}
$(function () {
getData();
setInterval(getData, 5000);
});
</script>
</html>

131
webnet/css/layout.css Executable file
View File

@ -0,0 +1,131 @@
/*
* Base structure
*/
/* Move down content because we have a fixed navbar that is 50px tall */
body {
padding-top: 50px;
}
/*
* Global add-ons
*/
.sub-header {
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
/*
* Top navigation
* Hide default border to remove 1px line.
*/
.navbar-fixed-top {
border: 0;
}
/*
* Sidebar
*/
/* Hide for mobile, show later */
.sidebar {
display: none;
}
@media (min-width: 768px) {
.sidebar {
position: fixed;
top: 51px;
bottom: 0;
left: 0;
z-index: 1000;
display: block;
padding: 20px;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
background-color: #f5f5f5;
border-right: 1px solid #eee;
}
}
/* Sidebar navigation */
.nav-sidebar {
margin-right: -21px; /* 20px padding + 1px border */
margin-bottom: 20px;
margin-left: -20px;
}
.nav-sidebar > li > a {
padding-right: 20px;
padding-left: 20px;
}
.nav-sidebar > .active > a,
.nav-sidebar > .active > a:hover,
.nav-sidebar > .active > a:focus {
color: #fff;
background-color: #428bca;
}
.navbar-brand{
color: #fff !important;
}
/*
* Main content
*/
.main {
padding: 20px;
}
@media (min-width: 768px) {
.main {
padding-right: 40px;
padding-left: 40px;
}
}
.main .page-header {
margin-top: 0;
}
/*
* Placeholder dashboard ideas
*/
.placeholders {
margin-bottom: 30px;
text-align: center;
}
.placeholders h4 {
margin-bottom: 0;
}
.placeholder {
margin-bottom: 20px;
}
.placeholder img {
display: inline-block;
border-radius: 50%;
}
a{
color: black;
}
.nav-sidebar{
font-size: 25px;
line-height: 2;
margin-top: 25vh;
}
.nav-tabs .active a{
color: #428bca !important;
}
.form-group{
display: flex;
align-items: center;
}
.navbar{
background-color: #428bca;
}

148
webnet/deviceinfo.asp Executable file
View File

@ -0,0 +1,148 @@
<%@Language="vbscript" Codepage="65001"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_15 {
margin-top: 15vh;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
id="navbarToggle"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
</ul>
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active">
<a href="deviceinfo.asp">系统设置</a>
</li>
<li><a href="tcp.html">网络设置</a></li>
<li><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">系统设置</h1>
<ul class="nav nav-tabs card-header-tabs">
<li role="presentation" class="active">
<a href="deviceinfo.asp">系统信息</a>
</li>
<li role="presentation">
<a href="systemModify.html">系统维护</a>
</li>
</ul>
<div class="col-sm-8 col-sm-offset-3 mt_15">
<form>
<div class="form-group row">
<label for="name" class="col-sm-3 col-xs-3 text-left"
>设备名称</label
>
<div class="col-sm-4">
<span class="form-control" id="name" disabled /><% device_name %>
</div>
</div>
<div class="form-group row">
<label for="no" class="col-sm-3 col-xs-3 text-left"
>设备编号</label
>
<div class="col-sm-4">
<span class="form-control" id="no" disabled /><% device_number %>
</div>
</div>
<div class="form-group row">
<label for="type" class="col-sm-3 col-xs-3 text-left"
>设备类型</label
>
<div class="col-sm-4">
<span class="form-control" id="type" disabled /><% device_type %>
</div>
</div>
<div class="form-group row">
<label for="seqNo" class="col-sm-3 col-xs-3 text-left"
>设备序列号</label
>
<div class="col-sm-4">
<span class="form-control" id="seqNo" disabled /><% device_serial %>
</div>
</div>
<div class="form-group row">
<label for="kernelType" class="col-sm-3 col-xs-3 text-left"
>内核类型</label
>
<div class="col-sm-4">
<span class="form-control" id="kernelType" disabled /><% os_type %>
</div>
</div>
<div class="form-group row">
<label for="webVersion" class="col-sm-3 col-xs-3 text-left"
>Web版本</label
>
<div class="col-sm-4">
<span class="form-control" id="webVersion" disabled /><% web_version %>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>

BIN
webnet/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

29
webnet/index_origin.html Executable file
View File

@ -0,0 +1,29 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>xidatong web server set page </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
</head>
<body>
<h1>xidatong web setting<h1>
<br/><br/>
<br/><br/>
<br/><br/>
<a href="/deviceinfo.asp"><EFBFBD><EFBFBD><EFBFBD>Ϣ</a>
<hr>
<br/><br/>
<br/><br/>
<a href="/netsetting.html"><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></a>
<h3>7. Upload File Test</h3>
<20>ļ<EFBFBD><C4BC>ϴ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ļ<EFBFBD><C4BC><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD> /upload Ŀ¼<C4BF><C2BC>
<br/><br/>
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload">
<input type="file" name="file1" >
<input type="submit" name="submit" value="<22>ϴ<EFBFBD>">
</form>
<br/>
<a href="/upload/"><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ŀ¼</a>
<br/><br/>
</body>
</html>

7
webnet/js/Chart.bundle.min.js vendored Executable file

File diff suppressed because one or more lines are too long

BIN
webnet/logo/logo.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

212
webnet/mqtt.html Executable file
View File

@ -0,0 +1,212 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<!-- <link rel="icon" href="../../favicon.ico" /> -->
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"
></script>
<!-- Bootstrap core CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous"
/>
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_15 {
margin-top: 15vh;
}
.mt_30 {
margin-top: 30px;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li>
<a href="deviceinfo.asp">系统设置</a>
</li>
<li class="active"><a href="tcp.html">网络设置</a></li>
<li><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">网络设置</h1>
<ul class="nav nav-tabs card-header-tabs">
<li role="presentation">
<a href="tcp.html">TCP/IP</a>
</li>
<li role="presentation" class="active">
<a href="mqtt.html">Mqtt云平台设置</a>
</li>
<li role="presentation">
<a href="privateProtocol.html">私有协议</a>
</li>
</ul>
<div class="col-sm-8 col-sm-offset-3 mt_15">
<form>
<div class="form-group row">
<label for="publish-topic" class="col-sm-3 col-xs-3 text-left"
>发布主题</label
>
<div class="col-sm-4">
<input class="form-control" id="publish-topic" />
</div>
</div>
<div class="form-group row">
<label for="server-addr" class="col-sm-3 col-xs-3 text-left"
>服务器地址</label
>
<div class="col-sm-4">
<input class="form-control" id="server-addr" />
</div>
</div>
<div class="form-group row">
<label for="server-port" class="col-sm-3 col-xs-3 text-left"
>端口号</label
>
<div class="col-sm-4">
<input class="form-control" id="server-port" />
</div>
</div>
<div class="form-group row">
<label for="username" class="col-sm-3 col-xs-3 text-left"
>用户名</label
>
<div class="col-sm-4">
<input class="form-control" id="username" />
</div>
</div>
<div class="form-group row">
<label for="password" class="col-sm-3 col-xs-3 text-left"
>密码</label
>
<div class="col-sm-4">
<input type="password" class="form-control" id="password" />
</div>
</div>
<div class="form-group row">
<label for="clientID" class="col-sm-3 col-xs-3 text-left"
>客户端id</label
>
<div class="col-sm-4">
<input class="form-control" id="clientID" />
</div>
</div>
<a
type="submit"
onclick="saveMQTT()"
class="col-sm-4 col-sm-offset-3 btn btn-primary mt_30"
>保存</a
>
</form>
</div>
</div>
</div>
</div>
</body>
<script>
var pubtopicDiv = $('#publish-topic');
var serverAddrDiv = $('#server-addr');
var serverPortDiv = $('#server-port');
var usernameDiv = $('#username');
var passwordDiv = $('#password');
var clientIDDiv = $('#clientID');
function getMQTT() {
$.get(
'/cgi-bin/mqtt_get',
function (data) {
const {
pub_topic,
server_addr,
server_port,
username,
password,
clientID,
} = data;
pubtopicDiv.val(pub_topic);
serverAddrDiv.val(server_addr);
serverPortDiv.val(server_port);
usernameDiv.val(username);
passwordDiv.val(password);
clientIDDiv.val(clientID);
},
'json'
);
}
function saveMQTT() {
serverAddrDiv.parent('div').removeClass('has-error');
$.post(
'/cgi-bin/mqtt_save',
{
pub_topic: pubtopicDiv.val(),
server_addr: serverAddrDiv.val(),
server_port: serverPortDiv.val(),
username: usernameDiv.val(),
password: passwordDiv.val(),
clientID: clientIDDiv.val(),
},
function (data) {
alert('保存成功');
}
);
}
$(function () {
getMQTT();
});
</script>
</html>

120
webnet/netsetting.html Executable file
View File

@ -0,0 +1,120 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>xidatong web server set page </title>
<link rel="icon" href="favicon.ico" />
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>网络设置<h1>
<br/><br/>
<br/><br/>
<br/><br/>
<div class="card-body main-card" >
<div class="card-title">MQTT代理服务器设置</div>
<form>
<div class="row">
<div class="form-group col-md-6">
<label for="publish-topic">发布主题</label>
<input type="text" class="form-control" id="publish-topic" required >
</div>
<div class="form-group col-md-6">
<label for="server-addr">服务器地址</label>
<input type="text" class="form-control" id="server-addr" required >
</div>
<div class="form-group col-md-6">
<label for="port">端口号</label>
<input type="text" class="form-control" id="server-port" required >
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="username">用户名</label>
<input type="text" class="form-control" id="username" required >
</div>
<div class="form-group col-md-6">
<label for="password">密码</label>
<input type="password" class="form-control" id="password" required >
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="receiver">客户端id</label>
<input type="text" class="form-control" id="clientID" required >
</div>
</div>
<button type="button" id="btnSaveSmtp" class="btn btn-outline-secondary btn-md btn-block"
onclick="saveMQTT()" >保存配置</button>
</form>
</div>
</body>
</html>
<script>
function saveMQTT() {
var pubtopicDiv = document.getElementById('publish-topic');
var serverAddrDiv = document.getElementById('server-addr');
var serverPortDiv = document.getElementById('server-port');
var usernameDiv = document.getElementById('username');
var passwordDiv = document.getElementById('password');
var clientIDDiv = document.getElementById('clientID');
if (serverAddrDiv.value == "" ||
serverPortDiv.value == "" ||
usernameDiv.value == "" ||
passwordDiv.value == "" ||
clientIDDiv.value == "" ||
pubtopicDiv.value == "") {
alert("设置项不能有空!");
} else {
$.ajax({
url: "/cgi-bin/mqtt_save",
type: "POST",
data: {
pub_topic: pubtopicDiv.value,
server_addr: serverAddrDiv.value,
server_port: serverPortDiv.value,
username: usernameDiv.value,
password: passwordDiv.value,
clientID: clientIDDiv.value,
},
dataType: "json",
success: function (data) {
alert('保存成功!');
}
});
}
}
function getMQTT(){
var pubtopicDiv = document.getElementById('publish-topic');
var serverAddrDiv = document.getElementById('server-addr');
var serverPortDiv = document.getElementById('server-port');
var usernameDiv = document.getElementById('username');
var passwordDiv = document.getElementById('password');
var clientIDDiv = document.getElementById('clientID');
$.ajax({
url: "/cgi-bin/mqtt_get",
type: "GET",
dataType: "json",
success: function (data) {
pubtopicDiv.value = data.pub_topic
serverAddrDiv.value = data.server_addr;
serverPortDiv.value = data.server_port;
usernameDiv.value = data.username;
passwordDiv.value = data.password;
clientIDDiv.value = data.clientID;
}
});
}
window.onload = function () {
getMQTT();
}
</script>

195
webnet/privateProtocol.html Executable file
View File

@ -0,0 +1,195 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<!-- <link rel="icon" href="../../favicon.ico" /> -->
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"
></script>
<!-- Bootstrap core CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous"
/>
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_15 {
margin-top: 15vh;
}
.mt_30 {
margin-top: 30px;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li>
<a href="deviceinfo.asp">系统设置</a>
</li>
<li class="active"><a href="tcp.html">网络设置</a></li>
<li><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">网络设置</h1>
<ul class="nav nav-tabs card-header-tabs">
<li role="presentation">
<a href="tcp.html">TCP/IP</a>
</li>
<li role="presentation">
<a href="mqtt.html">Mqtt云平台设置</a>
</li>
<li role="presentation" class="active">
<a href="privateProtocol.html">私有协议</a>
</li>
</ul>
<div class="col-sm-8 col-sm-offset-3 mt_15">
<form>
<div class="form-group row">
<label for="server_addr" class="col-sm-3 col-xs-3 text-left"
>服务器地址</label
>
<div class="col-sm-4">
<input class="form-control" id="server_addr" />
</div>
</div>
<div class="form-group row">
<label for="server_port" class="col-sm-3 col-xs-3 text-left"
>端口号</label
>
<div class="col-sm-4">
<input class="form-control" id="server_port" />
</div>
</div>
<div class="form-group row">
<label for="username" class="col-sm-3 col-xs-3 text-left"
>用户名</label
>
<div class="col-sm-4">
<input class="form-control" id="username" />
</div>
</div>
<div class="form-group row">
<label for="passward" class="col-sm-3 col-xs-3 text-left"
>密码</label
>
<div class="col-sm-4">
<input type="password" class="form-control" id="passward" />
</div>
</div>
<a
type="submit"
onclick="savePrivateProtocol()"
class="col-sm-4 col-sm-offset-3 btn btn-primary mt_30"
>保存</a
>
</form>
</div>
</div>
</div>
</div>
</body>
<script>
var serverAddr = $('#server_addr');
var serverPort = $('#server_port');
var userName = $('#username');
var passWard = $('#passward');
function validateIP(str) {
var pattern =
/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g;
return pattern.test(str);
}
function getPrivateProtocol() {
$.get(
'/cgi-bin/private_prt_get',
function (data) {
const { server_addr, server_port, username, passward } = data;
serverAddr.val(server_addr);
serverPort.val(server_port);
userName.val(username);
passWard.val(passward);
},
'json'
);
}
function savePrivateProtocol() {
let valid = validateIP(serverAddr.val());
if (valid) {
serverAddr.parent('div').removeClass('has-error');
$.post(
'/cgi-bin/private_prt_save',
{
server_addr: serverAddr.val(),
server_port: serverPort.val(),
username: userName.val(),
passward: passWard.val(),
},
function (data) {
alert('保存成功');
}
);
} else {
serverAddr.parent('div').addClass('has-error');
alert('服务器地址有误');
}
}
$(function () {
getPrivateProtocol();
});
</script>
</html>

165
webnet/systemModify.html Executable file
View File

@ -0,0 +1,165 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="favicon.ico" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<!-- <link rel="icon" href="../../favicon.ico" /> -->
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_15 {
margin-top: 15vh;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active">
<a href="deviceinfo.asp">系统设置</a>
</li>
<li><a href="tcp.html">网络设置</a></li>
<li><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">系统设置</h1>
<ul class="nav nav-tabs card-header-tabs">
<li role="presentation">
<a href="deviceinfo.asp">系统信息</a>
</li>
<li role="presentation" class="active">
<a href="systemModify.html">系统维护</a>
</li>
</ul>
<div class="col-sm-8 col-sm-offset-3 mt_15">
<form
name="upload"
method="POST"
enctype="multipart/form-data"
action="/upload"
target="stop"
>
<div class="form-group row">
<a href="#" onclick="restart()" class="col-sm-2 btn btn-default"
>重启</a
>
<span class="col-sm-offset-1">重新启动设备</span>
</div>
<div class="form-group row">
<a onclick="recovery()" class="col-sm-2 btn btn-default"
>简单恢复</a
>
<span class="col-sm-offset-1">简单恢复设备参数</span>
</div>
<div class="form-group row form-inline">
<input
type="file"
name="file1"
id="inputFile"
style="display: inline-block"
/>
<input
type="submit"
name="submit"
value="升级固件"
class="col-sm-offset-1 btn btn-primary"
onclick="test()"
></input
>
</div>
</form>
<div class="col-sm-9" style="margin-left: -30px;">
<div class="progress" style="display:none">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
<span class="val">0%</span>
</div>
</div>
</div>
<iframe name="stop" style="display:none"></iframe>
</div>
</div>
</div>
</div>
</body>
<script>
function restart() {
console.log('restart');
$.post('/cgi-bin/device_reboot', function (data) {
alert('重启成功');
});
}
function recovery() {
console.log('recovery');
$.post('/cgi-bin/device_recovery', function (data) {
alert('恢复成功');
});
}
function test(){
$('.progress').show()
let rate = 0
var interval = setInterval(()=>{
if(rate<=100){
$('.progress-bar').width(rate+'%')
$('.val').html(rate+'%')
rate++
}else{
rate = 0
clearInterval(interval)
restart()
}
},100)
}
$(function () {
});
</script>
</html>

213
webnet/tcp.html Executable file
View File

@ -0,0 +1,213 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Cache-Control" content="max-age=7200" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="xidatong webnet" />
<meta name="author" content="gong" />
<link rel="icon" href="favicon.ico" />
<title>xidatong web server set page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"
></script>
<!-- Bootstrap core CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous"
/>
<!-- Custom styles for this template -->
<link href="./css/layout.css" rel="stylesheet" />
<style>
.mt_15 {
margin-top: 15vh;
}
.mt_30 {
margin-top: 30px;
}
.form-group {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle collapsed"
data-toggle="collapse"
data-target="#navbar"
aria-expanded="false"
aria-controls="navbar"
>
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="./logo/logo.png" height="50px" />
<!-- <a class="navbar-brand" href="#"></a> -->
</div>
<!-- <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">账号</a></li>
</ul>
</div> -->
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li>
<a href="deviceinfo.asp">系统设置</a>
</li>
<li class="active"><a href="tcp.html">网络设置</a></li>
<li><a href="chart.html">数据显示</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">网络设置</h1>
<ul class="nav nav-tabs card-header-tabs">
<li role="presentation" class="active">
<a href="tcp.html">TCP/IP</a>
</li>
<li role="presentation">
<a href="mqtt.html">Mqtt云平台设置</a>
</li>
<li role="presentation">
<a href="privateProtocol.html">私有协议</a>
</li>
</ul>
<div class="col-sm-8 col-sm-offset-3 mt_15">
<form>
<div class="form-group row">
<label for="local_ipaddr" class="col-sm-3 col-xs-3 text-left"
>设备IPv4地址</label
>
<div class="col-sm-4">
<input class="form-control" id="local_ipaddr" />
</div>
</div>
<div class="form-group row">
<label for="netmask_addr" class="col-sm-3 col-xs-3 text-left"
>IPv4子网掩码</label
>
<div class="col-sm-4">
<input class="form-control" id="netmask_addr" />
</div>
</div>
<div class="form-group row">
<label for="gateway_addr" class="col-sm-3 col-xs-3 text-left"
>IPv4默认网关</label
>
<div class="col-sm-4">
<input class="form-control" id="gateway_addr" />
</div>
</div>
<div class="form-group row">
<label for="dns_server0" class="col-sm-3 col-xs-3 text-left"
>首选DNS服务器</label
>
<div class="col-sm-4">
<input class="form-control" id="dns_server0" />
</div>
</div>
<div class="form-group row">
<label for="dns_server1" class="col-sm-3 col-xs-3 text-left"
>备用DNS服务器</label
>
<div class="col-sm-4">
<input class="form-control" id="dns_server1" />
</div>
</div>
<a
type="submit"
onclick="saveTcpip()"
class="col-sm-4 col-sm-offset-3 btn btn-primary mt_30"
>保存</a
>
</form>
</div>
</div>
</div>
</div>
</body>
<script>
var localIpaddr = $('#local_ipaddr');
var netmaskAddr = $('#netmask_addr');
var gatewayAddr = $('#gateway_addr');
var dnsServer0 = $('#dns_server0');
var dnsServer1 = $('#dns_server1');
function validateIP(str) {
var pattern =
/((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g;
return pattern.test(str);
}
function getTcpip() {
$.get(
'/cgi-bin/tcpip_get',
function (data) {
const {
local_ipaddr,
netmask_addr,
gateway_addr,
dns_server0,
dns_server1,
} = data;
localIpaddr.val(local_ipaddr);
netmaskAddr.val(netmask_addr);
gatewayAddr.val(gateway_addr);
dnsServer0.val(dns_server0);
dnsServer1.val(dns_server1);
},
'json'
);
}
function saveTcpip() {
let valid = validateIP(localIpaddr.val());
if (valid) {
localIpaddr.parent('div').removeClass('has-error');
$.post(
'/cgi-bin/tcpip_save',
{
local_ipaddr: localIpaddr.val(),
netmask_addr: netmaskAddr.val(),
gateway_addr: gatewayAddr.val(),
dns_server0: dnsServer0.val(),
dns_server1: dnsServer1.val(),
},
function (data) {
alert('保存成功');
}
);
} else {
localIpaddr.parent('div').addClass('has-error');
alert('设备IPv4地址有误');
}
}
$(function () {
getTcpip();
});
</script>
</html>