Skip to content

Commit

Permalink
HTTPD cookies and auth.
Browse files Browse the repository at this point in the history
  • Loading branch information
vysocan committed Nov 12, 2021
1 parent f65ad63 commit 8632b34
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 48 deletions.
3 changes: 3 additions & 0 deletions lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@
#define LWIP_HTTPD_FILE_EXTENSION 1
#define LWIP_HTTPD_DYNAMIC_HEADERS 1
#define LWIP_HTTPD_SUPPORT_POST 1
#define LWIP_HTTPD_SUPPORT_COOKIES 1
#define LWIP_HTTPD_SUPPORT_FS_OPEN_AUTH 1
#define HTTPD_ADDITIONAL_CONTENT_TYPES {"wolf2", HTTP_CONTENT_TYPE("font/woff2")} // Adding our icon-font type to HTTPD
#define HTTPD_SERVER_AGENT "lwIP/" LWIP_VERSION_STRING // Make the HTTPD name a bit smaller
// DNS
#define LWIP_RAND() ((uint32_t)rand())
#define LWIP_DNS 1
Expand Down
3 changes: 2 additions & 1 deletion ohs_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define OHS_NAME "OHS"
#define OHS_MAJOR 1
#define OHS_MINOR 3
#define OHS_MOD 8
#define OHS_MOD 9

#define BACKUP_SRAM_SIZE 0x1000 // 4kB SRAM size

Expand All @@ -35,6 +35,7 @@
#define TRIGGER_SIZE 10 // # of timers
#define KEY_LENGTH 4 // sizeof(uint32_t) = size of hash
#define NAME_LENGTH 16 //
#define MIN_PASS_LNEGTH 4 // minimum password length
#define PHONE_LENGTH 14 //
#define EMAIL_LENGTH 32 //
#define URL_LENGTH 32 // URL address
Expand Down
1 change: 1 addition & 0 deletions ohs_http_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const char html_F[] = "<input type='submit' name='f' value='>'/>
const char html_Run[] = "<input type='submit' name='R' value='Run'/>";
const char html_Refresh[] = "<input type='submit' name='F' value='Refresh'/>";
const char html_Restart[] = "<input type='submit' name='S' value='Restart'/>";
const char html_Submit[] = "<input type='submit' name='S' value='Submit'/>";
const char html_textarea_1[] = "<textarea name='";
const char html_textarea_2[] = "' id='";
const char html_textarea_3[] = "' rows='";
Expand Down
77 changes: 55 additions & 22 deletions ohs_http_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

#ifndef OHS_HTTP_PRINT_H_
#define OHS_HTTP_PRINT_H_

// Helper macro
#define GET_BUTTON_STATE(x,y) (x==y)
/*
*
*/
void printOkNok(BaseSequentialStream *chp, const int8_t value) {
if (value == 1) chprintf(chp, "%s", html_i_OK);
else chprintf(chp, "%s", html_i_disabled);
}

/*
*
*/
void printRadioButton(BaseSequentialStream *chp, const char *name, const uint8_t value,
const char *label, bool selected,
const uint8_t JSNumber, const uint8_t JSMask) {
Expand All @@ -29,8 +35,9 @@ void printRadioButton(BaseSequentialStream *chp, const char *name, const uint8_t
chprintf(chp, "%s%s%u", html_cbPart4a, name, value);
chprintf(chp, "%s%s%s", html_cbPart4b, label, html_cbPart5);
}

#define GET_BUTTON_STATE(x,y) (x==y)
/*
*
*/
void printTwoButton(BaseSequentialStream *chp, const char *name, const uint8_t state,
const uint8_t JSNumber, const uint8_t JSMask,
const char *text1, const char *text2) {
Expand All @@ -39,7 +46,9 @@ void printTwoButton(BaseSequentialStream *chp, const char *name, const uint8_t s
printRadioButton(chp, name, 1, text2, GET_BUTTON_STATE(state, 1), JSNumber, JSMask);
chprintf(chp, "%s", html_div_e);
}

/*
*
*/
// ((JSon >> 1) & 0b1) : enableJS
void printThreeButton(BaseSequentialStream *chp, const char *name, const uint8_t state,
const uint8_t JSNumber, const uint8_t JSMask,
Expand All @@ -52,7 +61,9 @@ void printThreeButton(BaseSequentialStream *chp, const char *name, const uint8_t
printRadioButton(chp, name, 2, text3, GET_BUTTON_STATE(state, 2), JSNumber, JSMask);
chprintf(chp, "%s", html_div_e);
}

/*
*
*/
void printFourButton(BaseSequentialStream *chp, const char *name, const uint8_t state,
const uint8_t JSNumber, const uint8_t JSMask,
const char *text1, const char *text2, const char *text3,
Expand All @@ -65,22 +76,28 @@ void printFourButton(BaseSequentialStream *chp, const char *name, const uint8_t
printRadioButton(chp, name, 3, text4, GET_BUTTON_STATE(state, 3), JSNumber, JSMask);
chprintf(chp, "%s", html_div_e);
}

/*
*
*/
void printOnOffButton(BaseSequentialStream *chp, const char *name, const uint8_t state) {
chprintf(chp, "%s", html_radio_s);
printRadioButton(chp, name, 1, text_On, state, 0, 0);
printRadioButton(chp, name, 0, text_Off, !state, 0, 0);
chprintf(chp, "%s", html_div_e);
}

/*
*
*/
void printOnOffButtonWJS(BaseSequentialStream *chp, const char *name, const uint8_t state,
const uint8_t JSNumber, const uint8_t JSMask) {
chprintf(chp, "%s", html_radio_s);
printRadioButton(chp, name, 1, text_On, state, JSNumber, JSMask);
printRadioButton(chp, name, 0, text_Off, !state, JSNumber, JSMask);
chprintf(chp, "%s", html_div_e);
}

/*
*
*/
void selectGroup(BaseSequentialStream *chp, uint8_t selected, char name) {
chprintf(chp, "%s%c%s%c%s", html_select, name, html_id_tag, name, html_e_tag);
for (uint8_t i = 0; i < ALARM_GROUPS; i++) {
Expand Down Expand Up @@ -117,59 +134,75 @@ void printNodeValue(BaseSequentialStream *chp, const uint8_t index) {
default: chprintf(chp, "%.2f", node[index].value); break;
}
}

void printTextInput(BaseSequentialStream *chp, const char name, const char *value, const uint8_t size){
/*
*
*/
void printTextInput(BaseSequentialStream *chp, const char name, const char *value,
const uint8_t size){
chprintf(chp, "%s%u%s%u%s", html_t_tag_1, size - 1, html_s_tag_2, size - 1, html_s_tag_3);
chprintf(chp, "%c%s%s", name, html_m_tag, value);
chprintf(chp, "%s%c%s", html_id_tag, name, html_e_tag);
}

/*
*
*/
void printTextInputWMin(BaseSequentialStream *chp, const char name, const char *value,
const uint8_t size, const uint8_t minSize){
chprintf(chp, "%s%u%s%u", html_t_tag_1, size - 1, html_s_tag_2, size - 1);
chprintf(chp, "%s%u%s", html_s_tag_4, minSize - 1, html_s_tag_3);
chprintf(chp, "%s%u%s%u", html_t_tag_1, size, html_s_tag_2, size);
chprintf(chp, "%s%u%s", html_s_tag_4, minSize, html_s_tag_3);
chprintf(chp, "%c%s%s", name, html_m_tag, value);
chprintf(chp, "%s%c%s", html_id_tag, name, html_e_tag);
}

/*
*
*/
void printPassInput(BaseSequentialStream *chp, const char name, const char *value,
const uint8_t size, const uint8_t minSize){
chprintf(chp, "%s%u%s%u", html_p_tag_1, size - 1, html_s_tag_2, size - 1);
chprintf(chp, "%s%u%s", html_s_tag_4, minSize - 1, html_s_tag_3);
chprintf(chp, "%s%u%s", html_s_tag_4, minSize, html_s_tag_3);
chprintf(chp, "%c%s%s", name, html_m_tag, value);
chprintf(chp, "%s%c%s", html_id_tag, name, html_e_tag);
}

/*
*
*/
void printIntInput(BaseSequentialStream *chp, const char name, const int16_t value,
const uint8_t size, const int32_t min, const int32_t max){
chprintf(chp, "%s%u", html_n_tag_1, size + 2);
chprintf(chp, "%s%d%s%d%s", html_n_tag_2, min, html_n_tag_3, max, html_s_tag_3);
chprintf(chp, "%c%s%d", name, html_m_tag, value);
chprintf(chp, "%s%c%s", html_id_tag, name, html_e_tag);
}

/*
*
*/
void printFloatInput(BaseSequentialStream *chp, const char name, const float value){
chprintf(chp, "%s6em%s", html_n_tag_1, html_s_tag_3);
chprintf(chp, "%c%s%.02f", name, html_m_tag, value);
chprintf(chp, "%s%c' step='0.01'>", html_id_tag, name);
}

/*
*
*/
void printTimeInput(BaseSequentialStream *chp, const char name, const uint8_t hour,
const uint8_t minute){
chprintf(chp, "%s%s%c", html_i_tag_1, html_s_tag_3, name);
chprintf(chp, "%s%c%s", html_id_tag, name, html_m_tag);
chprintf(chp, "%02u:%02u%s", hour, minute, html_i_tag_2);
}

// IPv4: <input type="text" minlength="7" maxlength="15" size="15" pattern="^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$">

/*
*
*/
void printTextArea(BaseSequentialStream *chp, const char name, const char *value,
const uint16_t maxSize, const uint8_t cols, const uint8_t rows){
chprintf(chp, "%s%c%s%c%s%u", html_textarea_1, name, html_textarea_2, name, html_textarea_3, rows);
chprintf(chp, "%s%u%s%u' class='input' spellcheck='false'>", html_textarea_4, cols, html_textarea_5, maxSize - 1);
chprintf(chp, "%s%s", value, html_textarea_e);
}

/*
*
*/
void printDurationSelect(BaseSequentialStream *chp, const char name, const uint8_t value){
chprintf(chp, "%s%c%s%c%s", html_select, name, html_id_tag, name, html_e_tag);
for (uint8_t i = 0; i < ARRAY_SIZE(durationSelect); i++) {
Expand Down
Loading

0 comments on commit 8632b34

Please sign in to comment.