implemented backend restrictions for cron object's actions
This commit is contained in:
parent
d4da408541
commit
578093ad23
|
|
@ -8,26 +8,9 @@
|
||||||
<script src="res/main.js"></script>
|
<script src="res/main.js"></script>
|
||||||
<script src="res/res.js"></script>
|
<script src="res/res.js"></script>
|
||||||
<script src="res/cron.js"></script>
|
<script src="res/cron.js"></script>
|
||||||
|
<script src="res/crondata.js"></script>
|
||||||
<title>~name~</title>
|
<title>~name~</title>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
timarr = [
|
|
||||||
~crontmr(0)~,
|
|
||||||
~crontmr(1)~,
|
|
||||||
~crontmr(2)~,
|
|
||||||
~crontmr(3)~,
|
|
||||||
~crontmr(4)~,
|
|
||||||
~crontmr(5)~,
|
|
||||||
~crontmr(6)~,
|
|
||||||
~crontmr(7)~,
|
|
||||||
~crontmr(8)~,
|
|
||||||
~crontmr(9)~,
|
|
||||||
~crontmr(10)~,
|
|
||||||
~crontmr(11)~,
|
|
||||||
~crontmr(12)~,
|
|
||||||
~crontmr(13)~,
|
|
||||||
~crontmr(14)~,
|
|
||||||
~crontmr(15)~
|
|
||||||
];
|
|
||||||
function showcronerr(err) {if(err != "") alert(err);}
|
function showcronerr(err) {if(err != "") alert(err);}
|
||||||
function dbgtmr(){PostData("tmrdbg=1", "application.html", false, false, false);}
|
function dbgtmr(){PostData("tmrdbg=1", "application.html", false, false, false);}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,31 @@
|
||||||
adapters.html
|
adapters.html
|
||||||
api
|
api
|
||||||
api/dbg.json
|
api/dbg.json
|
||||||
api/dbg2.json
|
api/dbg2.json
|
||||||
api/gendata.json
|
api/gendata.json
|
||||||
api/mem.json
|
api/mem.json
|
||||||
api/set1.json
|
api/set1.json
|
||||||
api/set2.json
|
api/set2.json
|
||||||
api/set3.json
|
api/set3.json
|
||||||
api/stat.json
|
api/stat.json
|
||||||
api/status.json
|
api/status.json
|
||||||
api/tmr.json
|
api/tmr.json
|
||||||
api/wifiscan.json
|
api/wifiscan.json
|
||||||
application.html
|
application.html
|
||||||
favicon.ico
|
favicon.ico
|
||||||
index.html
|
index.html
|
||||||
info.html
|
info.html
|
||||||
reboot.html
|
reboot.html
|
||||||
res
|
res
|
||||||
res/appstyles.css
|
res/appstyles.css
|
||||||
res/ca_cert.pem
|
res/ca_cert.pem
|
||||||
res/cron.js
|
res/cron.js
|
||||||
res/iconsfont.css
|
res/crondata.js
|
||||||
res/iconsfont.woff2
|
res/iconsfont.css
|
||||||
res/logo.png
|
res/iconsfont.woff2
|
||||||
res/main.js
|
res/logo.png
|
||||||
res/res.js
|
res/main.js
|
||||||
res/styles.css
|
res/res.js
|
||||||
services.html
|
res/styles.css
|
||||||
|
services.html
|
||||||
system.html
|
system.html
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
--bgr-color: #1D2327;
|
--bgr-color: #1D2327;
|
||||||
--panel-bgr-color: #2c3338;
|
--panel-bgr-color: #2c3338;
|
||||||
--menu-bgr-color: #3c434a;
|
--menu-bgr-color: #3c434a;
|
||||||
--header-bgr-color: #646970;
|
/* --header-bgr-color: #646970;
|
||||||
|
--header-bgr-color: #dba617;*/
|
||||||
--accent-color: #dba617;
|
--accent-color: #dba617;
|
||||||
--text-color:#F0F0F1;
|
--text-color:#F0F0F1;
|
||||||
|
|
||||||
|
|
|
||||||
47
HTML/res/crondata.js
Normal file
47
HTML/res/crondata.js
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
timarr = [
|
||||||
|
~crontmr(0)~,
|
||||||
|
~crontmr(1)~,
|
||||||
|
~crontmr(2)~,
|
||||||
|
~crontmr(3)~,
|
||||||
|
~crontmr(4)~,
|
||||||
|
~crontmr(5)~,
|
||||||
|
~crontmr(6)~,
|
||||||
|
~crontmr(7)~,
|
||||||
|
~crontmr(8)~,
|
||||||
|
~crontmr(9)~,
|
||||||
|
~crontmr(10)~,
|
||||||
|
~crontmr(11)~,
|
||||||
|
~crontmr(12)~,
|
||||||
|
~crontmr(13)~,
|
||||||
|
~crontmr(14)~,
|
||||||
|
~crontmr(15)~
|
||||||
|
];
|
||||||
|
|
||||||
|
cron_objs= [
|
||||||
|
~cronobjs(0)~,
|
||||||
|
~cronobjs(1)~,
|
||||||
|
~cronobjs(2)~,
|
||||||
|
~cronobjs(3)~,
|
||||||
|
~cronobjs(4)~,
|
||||||
|
~cronobjs(5)~,
|
||||||
|
~cronobjs(6)~,
|
||||||
|
~cronobjs(7)~,
|
||||||
|
~cronobjs(8)~,
|
||||||
|
~cronobjs(9)~,
|
||||||
|
~cronobjs(10)~,
|
||||||
|
~cronobjs(11)~,
|
||||||
|
~cronobjs(12)~,
|
||||||
|
~cronobjs(13)~,
|
||||||
|
~cronobjs(14)~,
|
||||||
|
~cronobjs(15)~
|
||||||
|
];
|
||||||
|
|
||||||
|
cron_acts = [
|
||||||
|
~cronacts(0)~,
|
||||||
|
~cronacts(1)~,
|
||||||
|
~cronacts(2)~,
|
||||||
|
~cronacts(3)~,
|
||||||
|
~cronacts(4)~,
|
||||||
|
~cronacts(5)~,
|
||||||
|
~cronacts(6)~
|
||||||
|
];
|
||||||
|
|
@ -48,7 +48,8 @@ img {
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: var(--header-bgr-color);
|
background-color: var(--accent-color);
|
||||||
|
|
||||||
padding: 0 1rem;
|
padding: 0 1rem;
|
||||||
z-index: var(--z-fixed);
|
z-index: var(--z-fixed);
|
||||||
}
|
}
|
||||||
|
|
@ -67,8 +68,12 @@ img {
|
||||||
}
|
}
|
||||||
|
|
||||||
.header__logo {
|
.header__logo {
|
||||||
color: var(--text-color);
|
color: var(--menu-bgr-color);
|
||||||
|
font-weight: var(--font-semi-bold);
|
||||||
|
|
||||||
|
/*color: var(--text-color);
|
||||||
font-weight: var(--font-medium);
|
font-weight: var(--font-medium);
|
||||||
|
*/
|
||||||
font-size: var(--large-font-size);
|
font-size: var(--large-font-size);
|
||||||
|
|
||||||
margin-left: 50px;
|
margin-left: 50px;
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit e6cb1512fd3fb4fdb07ee1132d625f861331447d
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
idf:
|
idf:
|
||||||
component_hash: null
|
component_hash: null
|
||||||
source:
|
source:
|
||||||
type: idf
|
type: idf
|
||||||
version: 4.4.4
|
version: 4.4.4
|
||||||
manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd
|
manifest_hash: f9b3d78d7d56685d1c543701158a0fab7a56c908117ed70644f77e4247c831ae
|
||||||
target: esp32
|
target: esp32
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
|
#include "CronTimers.h"
|
||||||
|
|
||||||
/// Application-dependent structure used to contain address information
|
/// Application-dependent structure used to contain address information
|
||||||
|
|
||||||
|
|
@ -38,34 +39,11 @@
|
||||||
* saved one. If find difference (due to eeprom memory distortions),\n
|
* saved one. If find difference (due to eeprom memory distortions),\n
|
||||||
* the default values will be loaded.
|
* the default values will be loaded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define CRON_TIMERS_NUMBER (16)
|
|
||||||
#define TIMER_NAME_LENGTH (16)
|
|
||||||
#define TIMER_CRONSTRING_LENGTH (32)
|
|
||||||
#define CRON_EXPRESS_MAX_LENGTH (128)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cron scheduler configuration structure
|
|
||||||
*/
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int num; /*!< Index of sheduler */
|
|
||||||
bool del; /*!< Flag of non valid record, free for future overwrite */
|
|
||||||
bool enab; /*!< Enable scheduler */
|
|
||||||
bool prev; /*!< Enable to execute nearest in the past sheduled action */
|
|
||||||
char name[TIMER_NAME_LENGTH]; /*!< Human readable name of scheduler */
|
|
||||||
int obj; /*!< Index of object scheduler affected on */
|
|
||||||
int act; /*!< Index of action with the object*/
|
|
||||||
char cron[TIMER_CRONSTRING_LENGTH]; /*!< Cron expression */
|
|
||||||
|
|
||||||
} cron_timer_t;
|
|
||||||
|
|
||||||
typedef struct appconf
|
typedef struct appconf
|
||||||
{
|
{
|
||||||
int test;
|
int test;
|
||||||
|
|
||||||
cron_timer_t Timers[CRON_TIMERS_NUMBER];
|
cron_timer_t Timers[CRON_TIMERS_NUMBER];
|
||||||
|
cron_obj_t CronObjects[CRON_OBJECTS_NUMBER];
|
||||||
} APP_CONFIG;
|
} APP_CONFIG;
|
||||||
|
|
||||||
void UserInitIO(void);
|
void UserInitIO(void);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright 2023 Bogdan Pilyugin
|
/* Copyright 2023 Bogdan Pilyugin
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -26,11 +26,46 @@
|
||||||
#include "jobs.h"
|
#include "jobs.h"
|
||||||
#include "ccronexpr.h"
|
#include "ccronexpr.h"
|
||||||
|
|
||||||
|
#define CRON_TIMERS_NUMBER (16)
|
||||||
|
#define TIMER_NAME_LENGTH (16)
|
||||||
|
#define TIMER_CRONSTRING_LENGTH (32)
|
||||||
|
#define CRON_EXPRESS_MAX_LENGTH (128)
|
||||||
|
|
||||||
|
#define CRON_OBJECTS_NUMBER (16)
|
||||||
|
#define CRON_OBJECT_NAME_LENGTH (16)
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
char objname[CRON_OBJECT_NAME_LENGTH];
|
||||||
|
} cron_obj_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cron scheduler configuration structure
|
||||||
|
*/
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int num; /*!< Index of sheduler */
|
||||||
|
bool del; /*!< Flag of non valid record, free for future overwrite */
|
||||||
|
bool enab; /*!< Enable scheduler */
|
||||||
|
bool prev; /*!< Enable to execute nearest in the past sheduled action */
|
||||||
|
char name[TIMER_NAME_LENGTH]; /*!< Human readable name of scheduler */
|
||||||
|
int obj; /*!< Index of object scheduler affected on */
|
||||||
|
int act; /*!< Index of action with the object*/
|
||||||
|
char cron[TIMER_CRONSTRING_LENGTH]; /*!< Cron expression */
|
||||||
|
|
||||||
|
} cron_timer_t;
|
||||||
|
|
||||||
esp_err_t InitCronSheduler();
|
esp_err_t InitCronSheduler();
|
||||||
esp_err_t ReloadCronSheduler();
|
esp_err_t ReloadCronSheduler();
|
||||||
char* GetCronError();
|
char* GetCronError();
|
||||||
void DebugTimer();
|
void DebugTimer();
|
||||||
|
|
||||||
|
char* GetCronObjectNameDef(int idx);
|
||||||
|
char* GetCronObjectName(int idx);
|
||||||
|
char* GetCronActionName(int idx);
|
||||||
|
char* GetCronActAvail(int idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Handle all actions under all objects
|
* \brief Handle all actions under all objects
|
||||||
* \param obj Index of the object
|
* \param obj Index of the object
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,12 @@ void ResetAppConfig(APP_CONFIG *Conf)
|
||||||
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < CRON_OBJECTS_NUMBER; i++ )
|
||||||
|
{
|
||||||
|
strcpy(GetAppConf()->CronObjects[i].objname, GetCronObjectNameDef(i));
|
||||||
|
GetAppConf()->CronObjects[i].idx = i;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t ReadNVSAppConfig(APP_CONFIG *AppConf)
|
esp_err_t ReadNVSAppConfig(APP_CONFIG *AppConf)
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,57 @@
|
||||||
|
|
||||||
#define TAG "CRON_TIMER"
|
#define TAG "CRON_TIMER"
|
||||||
|
|
||||||
const char *cron_objects[] = { "RELAY1", "RELAY2", "RELAY3", "RELAY4", "RELAY5", "SYSTEM" };
|
|
||||||
const char *cron_actions[] = { "ON", "OFF", "REBOOT" };
|
const char *cron_actions[] = { "ON", "OFF", "TOGGLE", "REBOOT" };
|
||||||
|
const char *cron_objects[] = {
|
||||||
|
"RELAY1",
|
||||||
|
"RELAY2",
|
||||||
|
"RELAY3",
|
||||||
|
"RELAY4",
|
||||||
|
"RELAY5",
|
||||||
|
"RELAY6",
|
||||||
|
"RELAY7",
|
||||||
|
"RELAY8",
|
||||||
|
"SYSTEM" };
|
||||||
|
const char *cron_act_avail[] = {
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[0,1,2]",
|
||||||
|
"[3]" };
|
||||||
|
|
||||||
|
char* GetCronObjectNameDef(int idx)
|
||||||
|
{
|
||||||
|
if(idx < 0 || idx >= sizeof(cron_objects)/sizeof(char*))
|
||||||
|
return "";
|
||||||
|
return (char*)cron_objects[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetCronObjectName(int idx)
|
||||||
|
{
|
||||||
|
if(idx < 0 || idx >= sizeof(cron_objects)/sizeof(char*))
|
||||||
|
return "";
|
||||||
|
return GetAppConf()->CronObjects[idx].objname;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetCronActionName(int idx)
|
||||||
|
{
|
||||||
|
if(idx < 0 || idx >= sizeof(cron_actions)/sizeof(char*))
|
||||||
|
return "";
|
||||||
|
return (char*)cron_actions[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
char* GetCronActAvail(int idx)
|
||||||
|
{
|
||||||
|
if(idx < 0 || idx >= sizeof(cron_act_avail)/sizeof(char*))
|
||||||
|
return "[]";
|
||||||
|
return (char*)cron_act_avail[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static cron_job *JobsList[CRON_TIMERS_NUMBER];
|
static cron_job *JobsList[CRON_TIMERS_NUMBER];
|
||||||
static char cron_express_error[CRON_EXPRESS_MAX_LENGTH];
|
static char cron_express_error[CRON_EXPRESS_MAX_LENGTH];
|
||||||
|
|
@ -114,9 +163,7 @@ static void ExecuteLastAction()
|
||||||
LogFile("cron.log", "Execute last action %d under object %d", act, obj);
|
LogFile("cron.log", "Execute last action %d under object %d", act, obj);
|
||||||
custom_cron_execute(obj, act);
|
custom_cron_execute(obj, act);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeObtainHandler(struct timeval *tm)
|
void TimeObtainHandler(struct timeval *tm)
|
||||||
|
|
@ -129,21 +176,6 @@ void TimeObtainHandler(struct timeval *tm)
|
||||||
|
|
||||||
void DebugTimer()
|
void DebugTimer()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
time_t now;
|
|
||||||
time(&now);
|
|
||||||
ESP_LOGW(TAG, "Timestamp %d", (unsigned int )now);
|
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
|
||||||
{
|
|
||||||
if (GetAppConf()->Timers[i].del)
|
|
||||||
continue;
|
|
||||||
ESP_LOGW(TAG, "Cron expression:%s", GetAppConf()->Timers[i].cron);
|
|
||||||
cron_expr cron_exp = { 0 };
|
|
||||||
cron_parse_expr(GetAppConf()->Timers[i].cron, &cron_exp, NULL);
|
|
||||||
ESP_LOGW(TAG, "Timer %d prev: %u", i, (unsigned int )cron_prev(&cron_exp, now));
|
|
||||||
ESP_LOGW(TAG, "Timer %d next: %u", i, (unsigned int )cron_next(&cron_exp, now));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
ExecuteLastAction();
|
ExecuteLastAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ static void HTTPPrint_crontmr(char *VarData, void *arg)
|
||||||
int idx = *((int*)(arg));
|
int idx = *((int*)(arg));
|
||||||
if(idx < CRON_TIMERS_NUMBER)
|
if(idx < CRON_TIMERS_NUMBER)
|
||||||
{
|
{
|
||||||
char data[256];
|
char data[MAX_DYNVAR_LENGTH];
|
||||||
cron_timer_t T;
|
cron_timer_t T;
|
||||||
memcpy(&T, &GetAppConf()->Timers[idx], sizeof(cron_timer_t));
|
memcpy(&T, &GetAppConf()->Timers[idx], sizeof(cron_timer_t));
|
||||||
jwOpen(data, sizeof(data), JW_OBJECT, JW_COMPACT);
|
jwOpen(data, sizeof(data), JW_OBJECT, JW_COMPACT);
|
||||||
|
|
@ -52,6 +52,26 @@ static void HTTPPrint_cronerr(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, GetCronError());
|
snprintf(VarData, MAX_DYNVAR_LENGTH, GetCronError());
|
||||||
}
|
}
|
||||||
|
static void HTTPPrint_cronobjs(char *VarData, void *arg)
|
||||||
|
{
|
||||||
|
char data[MAX_DYNVAR_LENGTH];
|
||||||
|
int idx = *((int*)(arg));
|
||||||
|
if(idx < CRON_OBJECTS_NUMBER)
|
||||||
|
{
|
||||||
|
jwOpen(data, sizeof(data), JW_OBJECT, JW_COMPACT);
|
||||||
|
jwObj_string("name", GetAppConf()->CronObjects[idx].objname);
|
||||||
|
jwObj_raw("acts", GetCronActAvail(idx));
|
||||||
|
jwEnd();
|
||||||
|
jwClose();
|
||||||
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void HTTPPrint_cronacts(char *VarData, void *arg)
|
||||||
|
{
|
||||||
|
int idx = *((int*) (arg));
|
||||||
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "\"%s\"", GetCronActionName(idx));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Default string if not found handler
|
//Default string if not found handler
|
||||||
static void HTTPPrint_DEF(char *VarData, void *arg)
|
static void HTTPPrint_DEF(char *VarData, void *arg)
|
||||||
|
|
@ -68,6 +88,9 @@ dyn_var_handler_t HANDLERS_ARRAY_CUST[] = {
|
||||||
|
|
||||||
{ "crontmr", sizeof("crontmr") - 1, &HTTPPrint_crontmr },
|
{ "crontmr", sizeof("crontmr") - 1, &HTTPPrint_crontmr },
|
||||||
{ "cronerr", sizeof("cronerr") - 1, &HTTPPrint_cronerr },
|
{ "cronerr", sizeof("cronerr") - 1, &HTTPPrint_cronerr },
|
||||||
|
{ "cronobjs", sizeof("cronobjs") - 1, &HTTPPrint_cronobjs },
|
||||||
|
{ "cronacts", sizeof("cronacts") - 1, &HTTPPrint_cronacts },
|
||||||
|
|
||||||
/*ERROR report*/
|
/*ERROR report*/
|
||||||
{ "status_fail", sizeof("status_fail") - 1, &HTTPPrint_status_fail },
|
{ "status_fail", sizeof("status_fail") - 1, &HTTPPrint_status_fail },
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user