mirror of https://github.com/jeelabs/esp-link.git
Merge 9fcee90baf
into b3d8072bae
commit
716f1d2793
@ -1,31 +1,28 @@ |
|||||||
# Travis-CI file for Esp-Link |
|
||||||
|
|
||||||
language: c |
language: c |
||||||
|
|
||||||
before_install: |
before_install: |
||||||
- curl -Ls http://s3.voneicken.com/xtensa-lx106-elf-20160330.tgx | tar Jxf - |
- curl -Ls http://s3.voneicken.com/xtensa-lx106-elf-20160330.tgx | tar Jxf - |
||||||
- curl -Ls http://s3.voneicken.com/esp_iot_sdk_v2.0.0.p1.tgx | tar -C .. -Jxf - |
- curl -Ls http://s3.voneicken.com/esp_iot_sdk_v2.0.0.p1.tgx | tar -C .. -Jxf - |
||||||
|
|
||||||
after_script: |
|
||||||
# upload to an S3 bucket, requires S3_BUCKET, AWS_ACCESS_KEY_ID and AWS_SECRET_KEY to be set |
|
||||||
# in environment using travis' repository settings |
|
||||||
- "if [[ -n \"$S3_BUCKET\" && -n \"$AWS_ACCESS_KEY_ID\" ]]; then |
|
||||||
echo Uploading *.tgz to $S3_BUCKET; |
|
||||||
curl -Ls https://github.com/rlmcpherson/s3gof3r/releases/download/v0.5.0/gof3r_0.5.0_linux_amd64.tar.gz | tar zxf - gof3r_0.5.0_linux_amd64/gof3r; |
|
||||||
mv gof3r*/gof3r .; |
|
||||||
ls *.tgz | xargs -I {} ./gof3r put -b $S3_BUCKET -k esp-link/{} --acl public-read -p {}; |
|
||||||
ls *.tgz | xargs -I {} echo \"URL: http://$S3_BUCKET/esp-link/{}\"; |
|
||||||
fi" |
|
||||||
|
|
||||||
compiler: gcc |
|
||||||
|
|
||||||
env: |
|
||||||
|
|
||||||
script: |
script: |
||||||
- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/ |
- printenv |
||||||
- export BRANCH=$TRAVIS_BRANCH |
- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/ |
||||||
#- export SDK_BASE=$PWD/esp_iot_sdk_v2.0.0.p1 |
- export BRANCH=$TRAVIS_BRANCH |
||||||
- make release |
- echo "Travis Branch is $TRAVIS_BRANCH" |
||||||
|
- echo "Travis Tag is $TRAVIS_TAG" |
||||||
|
- echo "Travis COMMIT is $TRAVIS_COMMIT" |
||||||
|
- echo "Travis COMMIT is $TRAVIS_COMMIT_RANGE" |
||||||
|
- echo "Dont forget to set VARIABLES for S3 to function. SEE gof3r README" |
||||||
|
- make release |
||||||
notifications: |
notifications: |
||||||
email: false |
email: false |
||||||
|
deploy: |
||||||
|
overwrite: true |
||||||
|
skip_cleanup: true |
||||||
|
provider: releases |
||||||
|
api_key: |
||||||
|
secure: unYyTCLpk1ixcNOyoUwroBqqx0yBhii56IXm57kjo5kl3umf1GRb3FUIE6la+B0njsNwAUNR/uLn6wF4FqYTUJzNQZskJDJfZjb53vwuoHaoa5j4K/bWB9zRlQ1XZBTkV48cxz8Ef2KyNduK2IciOHwsw3LQS0em3dpK7oG/20VzELt23Gx8uhBYa+OUzlr3Y+PYPynkwM30YwVQXpCy/GMgEbrcKheGbLTAIp7tms0KDAvbb98U0BI3tWBckE5GzAYYAmrXgyDXtEsU/poCMqUj/lpPl1s/5uxGVevTO7XuL4AYtF//AixsM20bPKtIZDHZS9b7JHtVhU655bY2aAfpMgf7xzkKbJkRzeAzT9HucFDjLY48yW4vztdJxBgkAL9d064gTHhThtn4hylZAYpHnqUiM0j4DKil5A0VG2F8EVEqZ7Q2tNzy6aqq37wzTuYXsYpz3mglpazaXXp/LoSurDHy1gz6aB/mdaeBoL3MX1q09LBE8lFGYBILQ8KUkrLyJathxAVvDBnl7nXFv2NWoZ2i7CfXdpCwmOVUN2WhudNfgbbaMung+voTFB+yLq9PBQP5gdP0MKU3zDTB/msmZo1pp/SbnNETCrKAdRtxNI+bxTQ98njAIkxI+7ZiVV8SMNEPyNcWq/6ViYDcIHJMR4Gq0DZunre1voEs1F4= |
||||||
|
file_glob: true |
||||||
|
file: esp-link-master-*.t*gz |
||||||
|
on: |
||||||
|
branch: master |
||||||
|
repo: fuzzball03/esp-link |
||||||
|
condition: "$TRAVIS_BRANCH = master" |
||||||
|
@ -0,0 +1,120 @@ |
|||||||
|
#include <esp8266.h> |
||||||
|
#include "cgi.h" |
||||||
|
#include "config.h" |
||||||
|
#include "serbridge.h" |
||||||
|
|
||||||
|
static char *portMode[] = { "open", "disabled", "secure" }; |
||||||
|
|
||||||
|
// Cgi to return choice of Telnet ports
|
||||||
|
int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) { |
||||||
|
char buff[80]; |
||||||
|
|
||||||
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted
|
||||||
|
|
||||||
|
int len; |
||||||
|
|
||||||
|
os_printf("Current telnet ports: port0=%d port1=%d\n", |
||||||
|
flashConfig.telnet_port0, flashConfig.telnet_port1); |
||||||
|
|
||||||
|
len = os_sprintf(buff, |
||||||
|
"{ \"port0\": \"%d\", \"port1\": \"%d\" }", |
||||||
|
flashConfig.telnet_port0, flashConfig.telnet_port1); |
||||||
|
|
||||||
|
jsonHeader(connData, 200); |
||||||
|
httpdSend(connData, buff, len); |
||||||
|
|
||||||
|
return HTTPD_CGI_DONE; |
||||||
|
} |
||||||
|
|
||||||
|
// Cgi to change choice of Telnet ports
|
||||||
|
int ICACHE_FLASH_ATTR cgiTelnetSet(HttpdConnData *connData) { |
||||||
|
char buf[80]; |
||||||
|
|
||||||
|
if (connData->conn==NULL) { |
||||||
|
return HTTPD_CGI_DONE; // Connection aborted
|
||||||
|
} |
||||||
|
|
||||||
|
int8_t ok = 0; |
||||||
|
uint16_t port0, port1; |
||||||
|
ok |= getUInt16Arg(connData, "port0", &port0); |
||||||
|
ok |= getUInt16Arg(connData, "port1", &port1); |
||||||
|
|
||||||
|
if (ok <= 0) { //If we get at least one good value, this should be >= 1
|
||||||
|
ets_sprintf(buf, "Unable to fetch telnet ports.\n Received: port0=%d port1=%d\n", |
||||||
|
flashConfig.telnet_port0, flashConfig.telnet_port1); |
||||||
|
os_printf(buf); |
||||||
|
errorResponse(connData, 400, buf); |
||||||
|
return HTTPD_CGI_DONE; |
||||||
|
} |
||||||
|
|
||||||
|
if (ok > 0) { |
||||||
|
// fill both port variables from flash or ajax provided value
|
||||||
|
if (!port0) port0 = flashConfig.telnet_port0; |
||||||
|
if (!port1) port1 = flashConfig.telnet_port1; |
||||||
|
|
||||||
|
// check whether ports are different
|
||||||
|
if (port0 == port1) { |
||||||
|
os_sprintf(buf, "Ports cannot be the same.\n Tried to set: port0=%d port1=%d\n", |
||||||
|
flashConfig.telnet_port0, flashConfig.telnet_port1); |
||||||
|
os_printf(buf); |
||||||
|
errorResponse(connData, 400, buf); |
||||||
|
return HTTPD_CGI_DONE; |
||||||
|
} |
||||||
|
|
||||||
|
// we're good, set flashconfig
|
||||||
|
flashConfig.telnet_port0 = port0; |
||||||
|
flashConfig.telnet_port1 = port1; |
||||||
|
os_printf("Telnet ports changed: port0=%d port1=%d\n", |
||||||
|
flashConfig.telnet_port0, flashConfig.telnet_port1); |
||||||
|
|
||||||
|
// save to flash
|
||||||
|
if (configSave()) { |
||||||
|
httpdStartResponse(connData, 204); |
||||||
|
httpdEndHeaders(connData); |
||||||
|
} else { |
||||||
|
httpdStartResponse(connData, 500); |
||||||
|
httpdEndHeaders(connData); |
||||||
|
httpdSend(connData, "Failed to save config", -1); |
||||||
|
} |
||||||
|
|
||||||
|
// apply the changes
|
||||||
|
serbridgeInit(); |
||||||
|
serbridgeStart(0, flashConfig.telnet_port0, flashDefault.telnet_port0mode); |
||||||
|
serbridgeStart(1, flashConfig.telnet_port1, flashDefault.telnet_port1mode); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return HTTPD_CGI_DONE; |
||||||
|
} |
||||||
|
|
||||||
|
int ICACHE_FLASH_ATTR cgiTelnet(HttpdConnData *connData) { |
||||||
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
|
||||||
|
if (connData->requestType == HTTPD_METHOD_GET) { |
||||||
|
return cgiTelnetGet(connData); |
||||||
|
} else if (connData->requestType == HTTPD_METHOD_POST) { |
||||||
|
return cgiTelnetSet(connData); |
||||||
|
} else { |
||||||
|
jsonHeader(connData, 404); |
||||||
|
return HTTPD_CGI_DONE; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static char *portMode2string(int8_t m) { //Should we put this into flash?
|
||||||
|
if (m < 0 || m > 2) return "?"; |
||||||
|
return portMode[m]; |
||||||
|
} |
||||||
|
|
||||||
|
// print various Telnet information into json buffer
|
||||||
|
int ICACHE_FLASH_ATTR printTelnetSecurity(char *buff) { |
||||||
|
int len; |
||||||
|
|
||||||
|
len = os_sprintf(buff, |
||||||
|
"{ \"port0mode\": \"%s\", \"port0portnumber\": \"%d\", \"port0pwd\": \"%s\", " |
||||||
|
"\"port1mode\": \"%s\", \"port1portnumber\": \"%d\", \"port1pwd\": \"%s\" }", |
||||||
|
portMode2string(flashConfig.telnet_port0mode), flashConfig.telnet_port0, flashConfig.telnet_port0pass, |
||||||
|
portMode2string(flashConfig.telnet_port1mode), flashConfig.telnet_port1, flashConfig.telnet_port1pass |
||||||
|
); |
||||||
|
|
||||||
|
return len; |
||||||
|
} |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
#ifndef CGITELNET_H |
||||||
|
#define CGITELNET_H |
||||||
|
|
||||||
|
#include "httpd.h" |
||||||
|
|
||||||
|
int cgiTelnet(HttpdConnData *connData); |
||||||
|
|
||||||
|
#endif // CGITELNET_H
|
Loading…
Reference in new issue