-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable TCP Telnet ports via web interface #205
base: master
Are you sure you want to change the base?
Changes from 38 commits
563957f
143eb24
eb7fde7
5cb0350
fb1bbd3
93ca100
02197a9
8919ff6
f315385
59edf88
6054496
a230f42
4bddea7
04bbccb
936951d
0009d8f
bead65f
c3a3b06
67a05de
1cf190a
6fb97bd
a01db32
157569e
fe95b4b
ffd13c6
3cb3804
a9f583e
7a93821
00d8b9f
973e4fb
b79a6d6
d887feb
e25d896
30658c5
8cd915f
1da3ce7
6a730e7
7d60520
338f983
3fdfe93
3f16121
2458e11
27e6b5d
36f15c9
59a4707
654f2ef
4b3293e
547540d
589158e
f3060e6
286e886
6596883
0b8368a
b8404a1
bda82de
623f7b4
5e346a3
b5243b0
6fd5938
25feca5
23a904f
1df972b
153f470
9fcee90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
# Travis-CI file for Esp-Link | ||
|
||
language: c | ||
|
||
before_install: | ||
- 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/xtensa-lx106-elf-20160330.tgx | tar 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" | ||
|
||
- '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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this change about? |
||
compiler: gcc | ||
|
||
env: | ||
|
||
env: | ||
script: | ||
- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/ | ||
- export BRANCH=$TRAVIS_BRANCH | ||
#- export SDK_BASE=$PWD/esp_iot_sdk_v2.0.0.p1 | ||
- make release | ||
|
||
- export XTENSA_TOOLS_ROOT=$PWD/xtensa-lx106-elf/bin/ | ||
- export BRANCH=$TRAVIS_BRANCH | ||
- make release | ||
notifications: | ||
email: false | ||
deploy: | ||
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: | ||
repo: fuzzball03/esp-link | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this change about? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore any Travis changes please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mhh, I'm not a fan of having to go and clean-up after you ;-) but I also see that the uploads aren't working for pull requests. I had thought that they would. I think the solution is for me to provide my S3 keys to anyone who wants to have the builds done automatically. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
#include <esp8266.h> | ||
#include "cgi.h" | ||
#include "espfs.h" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <esp8266.h> | ||
#include "cgi.h" | ||
#include "config.h" | ||
#include "serbridge.h" | ||
|
||
// Cgi to return choice of Telnet ports | ||
int ICACHE_FLASH_ATTR cgiTelnetGet(HttpdConnData *connData) { | ||
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted | ||
|
||
char buff[1024]; | ||
int len; | ||
|
||
os_printf("Current telnet ports: port1=%d port2=%d\n", | ||
flashConfig.telnet_port1, flashConfig.telnet_port2); | ||
|
||
len = os_sprintf(buff, | ||
"{ \"port1\": \"%d\", \"port2\": \"%d\" }", | ||
flashConfig.telnet_port1, flashConfig.telnet_port2); | ||
|
||
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) { | ||
if (connData->conn==NULL) { | ||
return HTTPD_CGI_DONE; // Connection aborted | ||
} | ||
|
||
char *coll; | ||
int8_t ok = 0; | ||
uint16_t port1, port2; | ||
ok |= getUInt16Arg(connData, "port1", &port1); | ||
ok |= getUInt16Arg(connData, "port2", &port2); | ||
if (ok < 0) { coll = "Failed to fetch ports. Are they valid?"; goto collision; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should perhaps be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's certainly something I was unaware of. I will try a better approach based on your recommendations sir. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no problem. I should go through the whole code and see where I can push constant strings into flash. Can never have too much memory on this thing... |
||
|
||
if (ok > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I heaven't dealt with the ajax stuff in a while and forgotten everything (oops), but I think you're gonna get one port at a time when you fill out one input field and hit enter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're right. Ill modify to have it check the flashconfig variables. |
||
// fill both port variables from flash or ajax provided value | ||
if (!port1) port1 = flashConfig.telnet_port1; | ||
if (!port2) port2 = flashConfig.telnet_port2; | ||
|
||
// check whether ports are different | ||
if (port1 == port2) { coll = "Ports cannot be the same!"; goto collision; } | ||
|
||
// we're good, set flashconfig | ||
flashConfig.telnet_port1 = port1; | ||
flashConfig.telnet_port2 = port2; | ||
os_printf("Telnet ports changed: port1=%d port2=%d\n", | ||
flashConfig.telnet_port1, flashConfig.telnet_port2); | ||
|
||
// 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(flashConfig.telnet_port1, flashConfig.telnet_port2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something that is missing here is to call a new serbridgeStop function that closes the current listening sockets and resets any serbridge state so you can call serbridgeInit again. The latter wasn't designed to be called multiple times... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Citrection, #206 is the code I was referring to of Randys |
||
} | ||
return HTTPD_CGI_DONE; | ||
|
||
collision: { | ||
char buff[128]; | ||
os_sprintf(buff, "Ports assignment for %s collides with another assignment", coll); | ||
errorResponse(connData, 400, buff); | ||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef CGITELNET_H | ||
#define CGITELNET_H | ||
|
||
#include "httpd.h" | ||
|
||
int cgiTelnet(HttpdConnData *connData); | ||
|
||
#endif // CGITELNET_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ FlashConfig flashDefault = { | |
.data_bits = EIGHT_BITS, | ||
.parity = NONE_BITS, | ||
.stop_bits = ONE_STOP_BIT, | ||
.telnet_port1 = 23, | ||
.telnet_port2 = 2323, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something that seems to be missing is to take care of the upgrade path. When someone upgrades the telnet_portN fields in flash will be 0, so something needs to detect that when loading from flash and set the defaults explicitly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ill take a look to see how that was done in some other code and proceed appropriately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tve So I looked into this a bit - as the code stands now, if I erase the flash... Then flash my current build, the default ports of 23 & 2323 are set(as they are set in this file). How is it accomplishing this? As far as I can tell, the configRestore() function is where checks for "0" values are checked. |
||
}; | ||
|
||
typedef union { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,29 @@ <h1>Info</h1> | |
<a href="https://github.com/jeelabs/esp-link/blob/master/README.md">the online README</a> | ||
for up-to-date help.</p> | ||
</div> | ||
<div class="card"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like the indent is off... |
||
<h1>Telnet Serial-Bridge</h1> | ||
<p style="margin-bottom:0;">There are two ports available for telnet to use by default: 23 & 2323 <br> | ||
Note - this time, only port1 may be changed & used sucessfully.</p> | ||
<div id="telnet-spinner" class="spinner spinner-small"></div> | ||
<table id="telnet-table" class="pure-table pure-table-horizontal" hidden><tbody> | ||
<tr><td>Current Telnet ports</td><td class="telnet-info"></td></tr> | ||
<tr><td colspan=2 class="popup-target">Telnet port 1:<br> | ||
<div class="click-to-edit telnet-port1"> | ||
<span class="edit-off" style="display:block; width:auto;"></span> | ||
<input class="edit-on" maxlength=5 hidden> </input> | ||
<div class="popup">Click to edit!<br>Default port: 23</div> | ||
</div> | ||
</td></tr> | ||
<tr><td colspan=2 class="popup-target">Telnet port 2:<br> | ||
<div class="click-to-edit telnet-port2"> | ||
<span class="edit-off" style="display:block; width:auto;"></span> | ||
<input class="edit-on" maxlength=5 hidden> </input> | ||
<div class="popup">Click to edit!<br>Default port: 2323</div> | ||
</div> | ||
</td></tr> | ||
</tbody></table> | ||
</div> | ||
</div> | ||
<!-- RIGHT COLUMN --> | ||
<div class="pure-u-1 pure-u-md-1-2"> | ||
|
@@ -152,9 +175,12 @@ <h1>System details</h1> | |
onLoad(function() { | ||
makeAjaxInput("system", "description"); | ||
makeAjaxInput("system", "name"); | ||
makeAjaxInput("telnet", "port1"); | ||
makeAjaxInput("telnet", "port2"); | ||
fetchPins(); | ||
getWifiInfo(); | ||
getSystemInfo(); | ||
getTelnetInfo(); | ||
bnd($("#pinform"), "submit", setPins); | ||
}); | ||
</script> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why all these formatting changes here? please don't make random formatting changes, it makes reviewing difficult, plus, I don't see why your formatting is better than mine...