allow landing page change via file & SIGHUP. Squash warnings. Update files to include link to telnet menu

This commit is contained in:
hummypkg 2017-01-13 11:02:10 +00:00
parent bd59666bf3
commit 79fa64b638
9 changed files with 126 additions and 16 deletions

View File

@ -14,7 +14,8 @@ OBJS= $(SRCS:.c=.o)
CC=gcc
CFLAGS=-O2 -g -DNDEBUG
#WARN=-pedantic -Wall -Wnested-externs -Wpointer-arith -Werror -Wno-unused
WARN=-pedantic -Wall -W -Wnested-externs -Wpointer-arith -Wno-long-long
WARN=-pedantic -Wall -W -Wnested-externs -Wpointer-arith -Wno-long-long \
-Wno-variadic-macros
INCS=
LIBS=-lpthread

View File

@ -28,6 +28,11 @@
<button onclick="window.location='/install';">
Download &amp; Install the Full Web Interface.
</button>
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -26,6 +26,11 @@
The system is still initialising.
<br><br>
<img src=/loading.gif> Please wait...
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -26,6 +26,11 @@
<button onclick="window.location='/exit';">
Exit maintenance mode and reboot.
</button>
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -23,11 +23,17 @@
<center>
To install the full web interface and supporting packages a suitably
formatted internal hard disk must be present and <b>none was detected</b>.
<br><br>
This is unexpected - a HDR-Fox T2 should have an internal disk which is
already formatted appropriately.
<br><br>
For help, please visit the
<a href=http://hummy.tv/>Hummy.tv Forums</a>
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -34,6 +34,11 @@
firmware, please see
<a href=http://wiki.hummy.tv/wiki/Converting_a_USB_Flash_Drive_to_EXT2_on_a_HD-Fox_T2>Converting a USB Flash Drive to EXT2 on a HD-Fox T2</a>
on the hummy.tv Wiki for instructions on how to set this up.
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -25,10 +25,15 @@
still present in flash but components that were on the hard disk have been
removed.
<br><br>
Install a standard Humax firmware to complete the removal of all
Install a standard Humax firmware file to complete the removal of all
traces of the custom firmware.
<br><br>
If you change your mind, you can clear RMA mode via the telnet menu.
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

View File

@ -27,6 +27,11 @@
<button onclick="window.location='/nosafe';">
Disable Safe Mode on next system boot.
</button>
<br><br>
<button onclick="window.open(window.location.protocol + '//' +
window.location.hostname + ':88/');">
Access Telnet Menu
</button>
</center>
</div>
</body>

101
main.c
View File

@ -20,7 +20,7 @@
#include <ctype.h>
#endif
#define VERSION "1.2"
#define VERSION "1.3"
#define CRLF "\r\n"
@ -35,14 +35,14 @@
/* How to cast fd_set structures on this OS */
#define FD_CAST (fd_set *)
/*******************************************************************
* Variables which are only written to before any additional threads
* are created. They are safe without any locking.
*/
/* The network socket on which we're listening */
/* The network socket on which we're listening - only written to by main
* thread before other threads are created. */
int listen_sock = -1;
/* Flag indicating reload required. Only accessed using atomic ops. */
int reload = 0;
/* Index page and its lock. */
char *xindex = "index.html";
pthread_mutex_t xindex_lock = PTHREAD_MUTEX_INITIALIZER;
/********************************************************************
* A fatal error has occured, log and exit.
@ -122,13 +122,13 @@ hexdump(char *s, unsigned long len)
#ifdef DEBUGMAX
#define debugmax(...) debug(__VA_ARGS__)
#else
#define debugmax(...) 0
#define debugmax(...)
#endif
#else /* !DEBUG */
#define debug(...) 0
#define debugmax(...) 0
#define debug(...)
#define debugmax(...)
#endif /* DEBUG */
@ -376,9 +376,14 @@ handle_request(void *arg)
*req = '\0';
if (!sscanf(line, "GET %80s HTTP", req))
{
debug("Could not extract req from first line.");
goto cleanup;
}
else
{
debug("Extracted req: %s", req);
}
/* Skip additional request headers. */
do
@ -388,6 +393,8 @@ handle_request(void *arg)
debugmax("Skipping request line: [%s]", line);
} while (strlen(line));
pthread_mutex_lock(&xindex_lock);
if (!strncmp(req, "/i/", 3))
send_image(fd, req + 3);
else if (!strcmp(xindex, "index.html") && !strncmp(req, "/install", 8))
@ -414,6 +421,8 @@ handle_request(void *arg)
else
send_file(fd, req + 1, "text/html", 0, 0, 0);
pthread_mutex_unlock(&xindex_lock);
cleanup:
shutdown(fd, SHUT_RDWR);
@ -473,6 +482,64 @@ setup_socket(int port_number, int type, int family)
return sockfd;
}
void
sighup_handler(int sig __attribute__((unused)))
{
/* Any thread can receive this signal so use atomic or to set
* the global reload variable. */
__sync_fetch_and_or(&reload, 1);
}
static void
setup_signals()
{
struct sigaction sa;
signal(SIGPIPE, SIG_IGN);
memset(&sa, '\0', sizeof(sa));
sa.sa_handler = sighup_handler;
/*sa.sa_flags = SA_RESTART; */
if (sigaction(SIGHUP, &sa, NULL) == -1)
perror("sigaction");
}
void
check_reload()
{
char buf[0x100];
int fd, n;
char *p;
if (!__sync_bool_compare_and_swap(&reload, 1, 0))
return;
debug("Reload requested.");
if ((fd = open("/tmp/.bootstrap", O_RDONLY)) == -1)
{
perror("open");
return;
}
if ((n = read(fd, buf, sizeof(buf) - 1)) > 0)
{
buf[n] = '\0';
if ((p = strpbrk(buf, "\n\r ")))
*p = '\0';
pthread_mutex_lock(&xindex_lock);
free(xindex);
xindex = strdup(buf);
pthread_mutex_unlock(&xindex_lock);
debug("Landing page set to '%s'", xindex);
}
else if (n == -1)
perror("read");
close(fd);
unlink("/tmp/.bootstrap");
}
int
main(int argc, char **argv)
{
@ -503,15 +570,18 @@ main(int argc, char **argv)
#endif /* DEBUG */
if (argc > 1)
xindex = strdup(argv[1]);
xindex = argv[1];
xindex = strdup(xindex);
debug("Installing signal handlers...");
setup_signals();
chdir(ROOT);
listen_sock = setup_socket(LISTEN_PORT, SOCK_STREAM, AF_INET);
debug("Listening...");
signal(SIGPIPE, SIG_IGN);
/* Main loop - wait for a connection on the socket then spawn a
* child thread to perform the health check.
*/
@ -533,6 +603,8 @@ main(int argc, char **argv)
#endif
delay.tv_usec = 0;
check_reload();
if (select(listen_sock + 1, FD_CAST&readfds, FD_CAST NULL,
FD_CAST&exfds, (struct timeval *)&delay) < 0)
{
@ -546,7 +618,8 @@ main(int argc, char **argv)
{
/* New connection, accept and spawn child. */
struct sockaddr_in addr;
int length, newfd;
int newfd;
socklen_t length;
pthread_t tid;
length = sizeof(addr);