v0.9.11
- added example docker-compose for minisrv + webone - update: wtv-home:/home: reduce size of title to fit longer version numbers - update: wtv-chat:/home: fix colors - update: login system: do not send tellyscript nor login headers to reconnecting (eg client:redial) client - fix: fixed tellyscript path for wtv-1800:/noflash (bf0app braindead) - update flashrom subsystem: - moved duplicate code into WTVFlashrom class - smarter part information detection - http(s) proxy updates: - allow ~ character - fix HTTPS when using HTTP proxy - include example webone.conf for external HTTP Proxy - update: app.js: enable graceful shutdown with SIGTERM - update: add service ip to wtv-tricks:/info
This commit is contained in:
22
docker-compose/docker-compose.yml
Normal file
22
docker-compose/docker-compose.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
webone:
|
||||||
|
build: ./webone
|
||||||
|
restart: unless-stopped
|
||||||
|
stop_signal: SIGKILL
|
||||||
|
volumes:
|
||||||
|
- /home/zefie/docker/wtvminisrv/webone.conf:/etc/webone.conf:ro
|
||||||
|
- /home/zefie/docker/wtvminisrv/webone.conf.d/:/etc/webone.conf.d/:ro
|
||||||
|
|
||||||
|
minisrv:
|
||||||
|
build: ./minisrv
|
||||||
|
restart: unless-stopped
|
||||||
|
links:
|
||||||
|
- webone
|
||||||
|
ports:
|
||||||
|
- "1600-1699:1600-1699"
|
||||||
|
volumes:
|
||||||
|
- /home/zefie/docker/wtvminisrv/user_config.json:/opt/minisrv/zefie_wtvp_minisrv/user_config.json:ro
|
||||||
|
- /home/zefie/docker/wtvminisrv/UserServiceVault:/opt/minisrv/zefie_wtvp_minisrv/UserServiceVault
|
||||||
|
|
||||||
|
|
||||||
11
docker-compose/minisrv/Dockerfile
Normal file
11
docker-compose/minisrv/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
RUN apk add git nodejs npm
|
||||||
|
RUN cd /opt && git clone --depth=1 https://github.com/zefie/zefie_wtvp_minisrv.git minisrv
|
||||||
|
RUN cd /opt/minisrv/zefie_wtvp_minisrv && npm install
|
||||||
|
|
||||||
|
COPY ./run.sh /opt/minisrv/zefie_wtvp_minisrv/run.sh
|
||||||
|
RUN chmod +x /opt/minisrv/zefie_wtvp_minisrv/run.sh
|
||||||
|
|
||||||
|
WORKDIR /opt/minisrv/zefie_wtvp_minisrv
|
||||||
|
CMD ./run.sh
|
||||||
3
docker-compose/minisrv/run.sh
Normal file
3
docker-compose/minisrv/run.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
git pull
|
||||||
|
node app.js
|
||||||
13
docker-compose/webone/Dockerfile
Normal file
13
docker-compose/webone/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM debian:latest
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install --yes curl && \
|
||||||
|
curl -L https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -o /tmp/packages-microsoft-prod.deb && \
|
||||||
|
apt-get install --yes /tmp/packages-microsoft-prod.deb && \
|
||||||
|
rm /tmp/packages-microsoft-prod.deb && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install --yes curl imagemagick ffmpeg jpegoptim
|
||||||
|
|
||||||
|
COPY ./setup.sh /tmp/setup.sh
|
||||||
|
RUN bash /tmp/setup.sh
|
||||||
|
|
||||||
|
CMD /usr/local/bin/webone
|
||||||
21
docker-compose/webone/setup.sh
Normal file
21
docker-compose/webone/setup.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
get_latest_release() {
|
||||||
|
curl --silent "https://api.github.com/repos/$1/releases/latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
debfile=$(get_latest_release atauenis/webone | \
|
||||||
|
grep "browser_download_url" | \
|
||||||
|
grep "amd64" | \
|
||||||
|
grep "deb" | \
|
||||||
|
sed -E 's/.*"([^"]+)".*/\1/')
|
||||||
|
|
||||||
|
if [ ! -z "${debfile}" ]; then
|
||||||
|
curl --silent -L "${debfile}" -o /tmp/webone.deb
|
||||||
|
if [ ! -f /bin/systemctl ]; then
|
||||||
|
# Create dummy systemctl
|
||||||
|
touch /bin/systemctl
|
||||||
|
chmod +x /bin/systemctl
|
||||||
|
fi
|
||||||
|
apt-get install --yes /tmp/webone.deb
|
||||||
|
rm /tmp/webone.deb
|
||||||
|
fi
|
||||||
332
docker-compose/webone/webone.conf
Normal file
332
docker-compose/webone/webone.conf
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
; WebOne Configuration File
|
||||||
|
; Its format is like INI, but also can contain raw lists inside some sections.
|
||||||
|
; For binary options use: 1/0, y/n, yes/no, on/off, enable/disable, true/false.
|
||||||
|
; Help and documentation: https://github.com/atauenis/webone/wiki/Configuration-file
|
||||||
|
|
||||||
|
[Server]
|
||||||
|
; Server settings
|
||||||
|
; Port=Port to listen
|
||||||
|
; DefaultHostName=Proxy's host name (set to valid IP or domain name for use with/on Linux or macOS)
|
||||||
|
; Authenticate=Set if the proxy needs to be protected by "login:password" or leave blank
|
||||||
|
; OutputEncoding=Codepage for patched output content (list of available: http://localhost/!codepages/)
|
||||||
|
; HideClientErrors=Hide client connection error messages in log (for Netscape 3 PNG rejections)
|
||||||
|
; SearchInArchive=Enable searching for unavailable pages (Server Not Found or 404) in archive.org
|
||||||
|
; ShortenArchiveErrors=Enable shortening of 404s on web.archive.org to get off large scipts and images
|
||||||
|
; SecurityProtocols=Forcely set SSL/TLS protocols that can be used for retrieving web content
|
||||||
|
; ValidateCertificates=Break network operations when the remote TLS certificate is bad
|
||||||
|
; UserAgent=Override user-agent string to fetch uncut content
|
||||||
|
; TemporaryDirectory=Directory which should be used for temporary files (%TEMP%, $TEMP or any other)
|
||||||
|
; LogFile=Path to server log file. To use a log file without erasing, use AppendLogFile instead
|
||||||
|
; DisplayStatusPage=Set status page display style (no, short, full)
|
||||||
|
Port=8080
|
||||||
|
DefaultHostName=%HostName%
|
||||||
|
;Authenticate=login:password
|
||||||
|
;OutputEncoding=AsIs
|
||||||
|
;OutputEncoding=Windows
|
||||||
|
;OutputEncoding=DOS
|
||||||
|
OutputEncoding=Apple
|
||||||
|
HideClientErrors=yes
|
||||||
|
SearchInArchive=yes
|
||||||
|
ShortenArchiveErrors=yes
|
||||||
|
;SecurityProtocols=4032
|
||||||
|
ValidateCertificates=yes
|
||||||
|
UserAgent=%Original% WebOne/%WOVer%
|
||||||
|
;UserAgent=Mozilla/4.75 [en] (Windows NT 5.0; U)
|
||||||
|
TemporaryDirectory=%TEMP%
|
||||||
|
LogFile=%SYSLOGDIR%/webone.log
|
||||||
|
;AppendLogFile=%SYSLOGDIR%/webone.log
|
||||||
|
DisplayStatusPage=short
|
||||||
|
|
||||||
|
|
||||||
|
[ForceHttps]
|
||||||
|
; list of domains that should be always accessed via HTTPS
|
||||||
|
phantom.sannata.org
|
||||||
|
www.phantom.sannata.org
|
||||||
|
login.vk.com
|
||||||
|
m.vk.com
|
||||||
|
vk.com
|
||||||
|
webdav
|
||||||
|
webdav.yandex.ru
|
||||||
|
web.archive.org
|
||||||
|
googlevideo.com
|
||||||
|
commondatastorage.googleapis.com
|
||||||
|
rutracker.org
|
||||||
|
www.vogons.org
|
||||||
|
|
||||||
|
|
||||||
|
[InternalRedirectOn]
|
||||||
|
; list of URLs where 302 redirections should be handled at all by WebOne, not browser
|
||||||
|
; (Empty)
|
||||||
|
|
||||||
|
|
||||||
|
[ForceUtf8]
|
||||||
|
; list of URLs that should be always downloaded as UTF-8
|
||||||
|
^http://.*yandex.ru/
|
||||||
|
|
||||||
|
|
||||||
|
[TextTypes]
|
||||||
|
; list of MIME type mask that means files which should be patched during transfer
|
||||||
|
text/
|
||||||
|
javascript
|
||||||
|
json
|
||||||
|
cdf
|
||||||
|
x-netcdf
|
||||||
|
xml
|
||||||
|
|
||||||
|
|
||||||
|
; Sets of traffic edits
|
||||||
|
[Edit:jquery.min.js]
|
||||||
|
; Redirect all requests to jQuery of versions other than 1.9.1 to Google's CDN with
|
||||||
|
; the last version supported by Firefox 3.6. This will not touch WebDAV traffic.
|
||||||
|
; Title: RegExp mask of URLs that should be touched by this Set of edits.
|
||||||
|
; IgnoreUrl: RegExp mask(s) of URLs which should NOT be touched by this Set of edits.
|
||||||
|
; OnUrl: additional URL RegExp masks not listed in section's title.
|
||||||
|
; AddRedirect: the destination URL of this redirection rule
|
||||||
|
IgnoreUrl=1.9.1
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
OnUrl=jquery2.js
|
||||||
|
OnUrl=jquery-[0-9]*\.[0-9]*\.[0-9]*\.min\.js
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddRedirect=http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
|
||||||
|
|
||||||
|
[Edit:jquery-ui.js]
|
||||||
|
; similar to jquery main file, but for jquery-ui
|
||||||
|
IgnoreUrl=1.9.1
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
OnUrl=jquery-ui[a-z0-9\.\-]*.js
|
||||||
|
AddRedirect=http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js
|
||||||
|
|
||||||
|
[Edit:bootstrap.min.js]
|
||||||
|
IgnoreUrl=2.3.1
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddRedirect=http://maxcdn.bootstrapcdn.com/bootstrap/2.3.1/js/bootstrap.min.js
|
||||||
|
|
||||||
|
|
||||||
|
[Edit:(^http://.*/styles/prosilver/theme/)(.*)]
|
||||||
|
; downgrade stylesheets of phpBB proSilver skin to version 3.0 on old browsers
|
||||||
|
OnHeader=User-Agent: .*MSIE [3456]
|
||||||
|
OnHeader=User-Agent: Mozilla/3
|
||||||
|
OnHeader=User-Agent: Mozilla/4
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddRedirect=http://atauenis.github.io/webone-webfixes/prosilver/theme/$2
|
||||||
|
|
||||||
|
|
||||||
|
[Edit:^http://super8russia.ning.com]
|
||||||
|
; another example of redirect, but to Wayback Machine
|
||||||
|
; IgnoreUrl is not need here (the RegExp used here is quite detailed)
|
||||||
|
AddRedirect=http://web.archive.org/web/2010/%URL%
|
||||||
|
|
||||||
|
|
||||||
|
[Edit::443]
|
||||||
|
; another example of redirect, but with remove of 443 port (final murder of SSL)
|
||||||
|
; the redirect is internal (hidden, seamless) so we're using AddInternalRedirect here
|
||||||
|
AddInternalRedirect=%UrlNoPort%
|
||||||
|
|
||||||
|
; Dead hosting providers
|
||||||
|
[Edit:^(http://www\.|http://)geocities.com/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2008/%URL%
|
||||||
|
|
||||||
|
[Edit:^http://web.ukonline.co.uk/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2007/%URL%
|
||||||
|
|
||||||
|
[Edit:^(http://www\.|http://)narod.ru/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2012/http://narod.yandex.ru/%UrlNoDomain%
|
||||||
|
|
||||||
|
[Edit:^http://narod.yandex.ru/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2012/%URL%
|
||||||
|
|
||||||
|
[Edit:^http://.*.by.ru/]
|
||||||
|
IgnoreUrl=web.archive.org
|
||||||
|
AddRedirect=http://web.archive.org/web/2011/%URL%Redirect=http://web.archive.org/web/2011/%URL%
|
||||||
|
|
||||||
|
|
||||||
|
; Microsoft software interactivity
|
||||||
|
[Edit:^http://ie.search.msn.com/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2000/%URL%
|
||||||
|
|
||||||
|
[Edit:^http://[a-z\.]*windowsmedia.com/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2002/%URL%
|
||||||
|
|
||||||
|
[Edit:^http://go.microsoft.com/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2005/%URL%
|
||||||
|
|
||||||
|
[Edit:^(http://www\.|http://)microsoft.com/isapi/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2005/%URL%
|
||||||
|
|
||||||
|
[Edit:^http://[a-z\.]*.windows.com/]
|
||||||
|
AddRedirect=http://web.archive.org/web/2005/%URL%
|
||||||
|
|
||||||
|
[Edit:^(http://www\.|http://)iechannelguide.com]
|
||||||
|
AddRedirect=http://web.archive.org/web/1997/%URL%
|
||||||
|
|
||||||
|
[Edit:^(http://www\.|http://)microsoft.com/IE/]
|
||||||
|
AddRedirect=http://web.archive.org/web/1997/%URL%
|
||||||
|
|
||||||
|
[Edit:\.cdf$]
|
||||||
|
IgnoreUrl=web.archive.org
|
||||||
|
AddRedirect=http://web.archive.org/web/1998/%URL%
|
||||||
|
|
||||||
|
; YouTube playback (youtube-dl & yt.bat)
|
||||||
|
; uncomment lines below to enable
|
||||||
|
;[Edit:^(http://www\.|http://)youtube.com/watch]
|
||||||
|
;AddRedirect=http://%Proxy%/!convert/?url=%Url%&util=yt.bat&type=video/x-ms-asf
|
||||||
|
;AddConvert=yt.bat
|
||||||
|
;AddResponseHeader=Content-Type: video/x-ms-asf
|
||||||
|
|
||||||
|
; YouTube playback (via original ViewTube)
|
||||||
|
; uncomment lines below to enable
|
||||||
|
;[Edit:^(http://www\.|http://).*.googlevideo.com/]
|
||||||
|
;AddRedirect=http://%Proxy%/!convert/?url=%Url%&util=ffmpeg&arg=-vcodec%20wmv1%20-acodec%20wmav1%20-f%20asf&type=video/x-ms-asf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; Content patches
|
||||||
|
; Apply some edits to page's content. Here are two edits, in example:
|
||||||
|
; 1. Replace "eval()" with direct calls for IE3/4
|
||||||
|
; 2. Fix work with _tmr JS variable in inline scripts (for IE4 too)
|
||||||
|
; AddFind: the find mask.
|
||||||
|
; AddReplace: the replacement.
|
||||||
|
[Edit:^http://old-dos.ru]
|
||||||
|
AddFind=eval\(('|")(.*?)\1\)
|
||||||
|
AddReplace=$2
|
||||||
|
AddFind=var _tmr = _tmr .* \[\];
|
||||||
|
AddReplace=var _tmr = _tmr;
|
||||||
|
|
||||||
|
[Edit:.*]
|
||||||
|
OnContentType=application/x-netcdf
|
||||||
|
AddFind=HREF="http://
|
||||||
|
AddReplace=HREF="http://web.archive.org/web/1998/
|
||||||
|
|
||||||
|
[Edit:\.cdf$]
|
||||||
|
AddFind= HREF="http://
|
||||||
|
AddReplace= HREF="http://web.archive.org/web/1998/
|
||||||
|
|
||||||
|
[Edit:^http(s?)://web.archive.org/web/]
|
||||||
|
AddFind=<script src="\/\/archive.org.*Include -->
|
||||||
|
AddReplace=
|
||||||
|
AddFind=<script><!--\n FILE.*\n-->
|
||||||
|
AddReplace=
|
||||||
|
;it's meaning that Web Archive scripts will not be delivered to client
|
||||||
|
|
||||||
|
; BBC news photo fix
|
||||||
|
[Edit:^http://www.bbc.co.uk/.*]
|
||||||
|
OnUrl=^http://www.bbc.com/.*
|
||||||
|
AddFind=<noscript><img
|
||||||
|
AddReplace=<img
|
||||||
|
AddFind=></noscript>
|
||||||
|
AddReplace=>
|
||||||
|
|
||||||
|
; Mobile VKontakte script fix
|
||||||
|
[Edit:^http://[a-zA-Z0-9\-\.]*vk.com/]
|
||||||
|
AddFind="cookie_secure":" Secure;"
|
||||||
|
AddReplace="cookie_secure":" WebOneEdited;"
|
||||||
|
|
||||||
|
|
||||||
|
; Firefox 3.5-16.0 CSS3 patches
|
||||||
|
[Edit]
|
||||||
|
OnContentType=text/css
|
||||||
|
OnHeader=User-Agent: .*rv\:(\b(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15)\b\.).*Gecko
|
||||||
|
AddFind=(background-size|box-shadow|text-shadow|border-radius|border-image|column-.*|animation-.*transition|transform|linear-gradient|flex)
|
||||||
|
AddReplace=-moz-$1
|
||||||
|
AddFind=to bottom
|
||||||
|
AddReplace=top
|
||||||
|
AddFind=to top
|
||||||
|
AddReplace=bottom
|
||||||
|
AddFind=to right
|
||||||
|
AddReplace=left
|
||||||
|
AddFind=to left
|
||||||
|
AddReplace=right
|
||||||
|
|
||||||
|
|
||||||
|
[Converters]
|
||||||
|
; Whitelist of known local format converters
|
||||||
|
; switch comments on next 2 lines to choose: tmp file or direct stdout processing
|
||||||
|
;convert %SRC% %ARG1% %DEST% %ARG2%
|
||||||
|
convert %SRC% %ARG1% %DESTEXT%:- %ARG2%
|
||||||
|
magick %SRC% %ARG1% %DEST% %ARG2%
|
||||||
|
; line below needs ffmpeg binaries to work
|
||||||
|
ffmpeg -i pipe: %ARG1% pipe:
|
||||||
|
; line below needs yt.bat script and youtube-dl to work (only for YouTube downloading)
|
||||||
|
yt.bat "%SRCURL%"
|
||||||
|
|
||||||
|
|
||||||
|
; PNG->GIF and WebP->GIF converting (for IE3, Netscape)
|
||||||
|
[Edit]
|
||||||
|
OnContentType=image/png
|
||||||
|
OnContentType=image/webp
|
||||||
|
OnCode=200
|
||||||
|
OnHeader=User-Agent: Mozilla/0
|
||||||
|
OnHeader=User-Agent: Mozilla/1
|
||||||
|
OnHeader=User-Agent: Mozilla/2
|
||||||
|
OnHeader=User-Agent: Mozilla/3
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddConvert=convert
|
||||||
|
AddConvertDest=gif
|
||||||
|
AddResponseHeader=Content-Type: image/gif
|
||||||
|
|
||||||
|
; uncomment section below to enable JPG recompression
|
||||||
|
[Edit]
|
||||||
|
OnContentType=image/jpeg
|
||||||
|
;OnContentType=image/png
|
||||||
|
;OnContentType=image/webp
|
||||||
|
OnCode=200
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddConvert=convert
|
||||||
|
AddConvertDest=jpg
|
||||||
|
AddConvertArg1=-quality 50
|
||||||
|
AddResponseHeader=Content-Type: image/jpeg
|
||||||
|
|
||||||
|
|
||||||
|
; Enforce security & spoof CORS
|
||||||
|
[Edit]
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddHeader=upgrade-insecure-requests: 1
|
||||||
|
AddHeader=sec-fetch-mode: navigate
|
||||||
|
AddHeader=sec-fetch-site: same-origin
|
||||||
|
AddHeader=sec-fetch-user: ?1
|
||||||
|
;AddResponseHeader=Access-Control-Allow-Origin: http://%UrlDomain%
|
||||||
|
|
||||||
|
; Disable CORS and SRI checks
|
||||||
|
[Edit]
|
||||||
|
OnContentType=html
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddFind=integrity=
|
||||||
|
AddReplace=disable-integrity=
|
||||||
|
AddFind=crossorigin=
|
||||||
|
AddReplace=disable-crossorigin=
|
||||||
|
|
||||||
|
; Remove CSP (mostly due to 'upgrade-insecure-requests')
|
||||||
|
[Edit]
|
||||||
|
IgnoreUrl=webdav
|
||||||
|
AddFind=<meta http-equiv="Content-Security-Policy"[a-zA-Z\ 0-9\'\"\-\=\;\*\:]*>
|
||||||
|
AddReplace=<!--Content-Security-Policy meta isn't need through WebOne-->
|
||||||
|
|
||||||
|
|
||||||
|
; HTTP request&response header saving (dumping)
|
||||||
|
; uncomment section below to enable header dumping
|
||||||
|
;[Edit]
|
||||||
|
;AddHeaderDumping=dump-%Url%.log
|
||||||
|
|
||||||
|
|
||||||
|
; Ad blocking
|
||||||
|
; uncomment section below to enable ad blocking
|
||||||
|
[Edit]
|
||||||
|
OnUrl=^http://mc.yandex.ru
|
||||||
|
OnUrl=^http://yandex.net/banner/
|
||||||
|
OnUrl=^http://st.yandexadexchange.net
|
||||||
|
OnUrl=^http://rareru.ru
|
||||||
|
OnUrl=^http://ad.mail.ru
|
||||||
|
OnUrl=^http://utarget.ru
|
||||||
|
OnUrl=^http://betweendigital.com
|
||||||
|
OnUrl=^http://marketgid.com
|
||||||
|
OnUrl=^http://googlesyndication.com
|
||||||
|
OnUrl=^http://doubleclick.net
|
||||||
|
OnUrl=^http://ads.google.com
|
||||||
|
OnUrl=/adsense
|
||||||
|
OnUrl=/adword
|
||||||
|
OnUrl=adriver.ru
|
||||||
|
AddRedirect=file://ROMCache/spacer.gif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[Include:%WOConfigDir%/*.conf]
|
||||||
@@ -25,7 +25,7 @@ wtv-client-time-zone: GMT -0000
|
|||||||
wtv-client-time-dst-rule: GMT
|
wtv-client-time-dst-rule: GMT
|
||||||
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
|
wtv-client-date: `+ strftime("%a, %d %b %Y %H:%M:%S", new Date(new Date().toUTCString())) + ` GMT`;
|
||||||
|
|
||||||
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/BF0APP/bf0app_boot_uncompressed.tok";
|
var file_path = __dirname + "/ServiceDeps/premade_tellyscripts/bf0app/bf0app_WTV_18006138199.tok";
|
||||||
|
|
||||||
if (file_path) {
|
if (file_path) {
|
||||||
request_is_async = true;
|
request_is_async = true;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var gourl = "wtv-head-waiter:/login?";
|
var gourl = "wtv-head-waiter:/login?";
|
||||||
if (request_headers.query.relogin) gourl += "relogin=true";
|
if (request_headers.query.relogin) gourl += "relogin=true";
|
||||||
|
if (request_headers.query.reconnect) gourl += "reconnect=true";
|
||||||
|
|
||||||
if (socket.ssid) {
|
if (socket.ssid) {
|
||||||
if (ssid_sessions[socket.ssid].data_store) {
|
if (ssid_sessions[socket.ssid].data_store) {
|
||||||
@@ -46,7 +47,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
|||||||
var send_tellyscripts = (minisrv_config.services[service_name].send_tellyscripts && !request_headers.query.relogin);
|
var send_tellyscripts = (minisrv_config.services[service_name].send_tellyscripts && !request_headers.query.relogin);
|
||||||
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
|
var wtv_script_id = parseInt(ssid_sessions[socket.ssid].get("wtv-script-id"));
|
||||||
var bootrom = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version");
|
var bootrom = ssid_sessions[socket.ssid].get("wtv-client-bootrom-version");
|
||||||
if (request_headers.query.relogin && wtv_script_id != 0) send_tellyscripts = false;
|
if ((request_headers.query.reconnect || request_headers.query.relogin) && wtv_script_id != 0) send_tellyscripts = false;
|
||||||
if (send_tellyscripts) {
|
if (send_tellyscripts) {
|
||||||
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
|
if (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist) {
|
||||||
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
|
var send_telly_to_ssid = (minisrv_config.services[service_name].send_tellyscript_ssid_whitelist.findIndex(element => element == socket.ssid) != -1)
|
||||||
@@ -101,10 +102,14 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
|||||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_headers["wtv-ticket"]) {
|
if (request_headers["wtv-ticket"] && !request_headers.query.reconnect) {
|
||||||
gourl = "wtv-head-waiter:/login-stage-two?relogin=true";
|
gourl = "wtv-head-waiter:/login-stage-two?relogin=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request_headers.query.reconnect) {
|
||||||
|
gourl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!file_path != null && !zquiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id);
|
if (!file_path != null && !zquiet) console.log(" * Sending TellyScript", file_path, "on socket", socket.id);
|
||||||
|
|
||||||
@@ -125,7 +130,7 @@ if (ssid_sessions[socket.ssid].data_store.wtvsec_login) {
|
|||||||
headers += getServiceString('wtv-flashrom') + "\n";
|
headers += getServiceString('wtv-flashrom') + "\n";
|
||||||
if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n";
|
if (bf0app_update) headers += "wtv-boot-url: " + gourl + "\n";
|
||||||
else headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n";
|
else headers += "wtv-boot-url: wtv-1800:/preregister?relogin=true\n";
|
||||||
headers += "wtv-visit: " + gourl + "\n";
|
if (gourl != null) headers += "wtv-visit: " + gourl + "\n";
|
||||||
if (!bf0app_update && ssid_sessions[socket.ssid].get("wtv-open-access")) headers += "wtv-open-isp-disabled: false\n";
|
if (!bf0app_update && ssid_sessions[socket.ssid].get("wtv-open-access")) headers += "wtv-open-isp-disabled: false\n";
|
||||||
headers += "wtv-client-time-zone: GMT -0000\n";
|
headers += "wtv-client-time-zone: GMT -0000\n";
|
||||||
headers += "wtv-client-time-dst-rule: GMT\n"
|
headers += "wtv-client-time-dst-rule: GMT\n"
|
||||||
|
|||||||
@@ -107,25 +107,25 @@ Chat Home (Testing)
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td abswidth="120">Server:</td>
|
<td abswidth="120">Server:</td>
|
||||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="host" value="${request_headers.query.host || "chat.irchat.tv"}"></td>
|
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="host" value="${request_headers.query.host || "chat.irchat.tv"}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Port:</td>
|
<td>Port:</td>
|
||||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="port" value="${request_headers.query.port || 6667}"></td>
|
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="port" value="${request_headers.query.port || 6667}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Channel:</td>
|
<td>Channel:</td>
|
||||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle type="text" name="channel" value="${request_headers.query.channel || "WebTV"}"></td>
|
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional type="text" name="channel" value="${request_headers.query.channel || "WebTV"}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>IRC Nick<sup>*</sup>:</td>
|
<td>IRC Nick<sup>*</sup>:</td>
|
||||||
<td><input width="240" bgcolor=262626 text=ffc342 cursor=cc9933 font=proportional usestyle maxlength=16 type="text" name="nick" value="${irc_nick}"></td>
|
<td><input width="240" bgcolor=262626 text=D6D6D6 cursor=cc9933 font=proportional maxlength=16 type="text" name="nick" value="${irc_nick}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" align="right">
|
<td colspan="2" align="right">
|
||||||
<input type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Connect" usestyle width=100>
|
<input type=submit borderimage="file://ROM/Borders/ButtonBorder2.bif" value="Connect" text=D6D6D6 width=100>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||||
|
request_is_async = true;
|
||||||
|
|
||||||
// this build can be local or on zefie's server
|
// this build can be local or on zefie's server
|
||||||
// to get the path from zefie's server, browse
|
// to get the path from zefie's server, browse
|
||||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||||
@@ -5,110 +8,23 @@
|
|||||||
// example is below
|
// example is below
|
||||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||||
|
|
||||||
headers = "200 OK\n";
|
|
||||||
var request_path = "";
|
var request_path = "";
|
||||||
var bf0app_update = true;
|
var bf0app_update = true;
|
||||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||||
else request_path = default_build_to_send;
|
else request_path = default_build_to_send;
|
||||||
request_is_async = true;
|
|
||||||
|
|
||||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||||
// assume old classic in flash mode, override user setting and send tellyscript
|
// assume old classic in flash mode, override user setting and send tellyscript
|
||||||
// because it is required to proceed in flash mode
|
// because it is required to proceed in flash mode
|
||||||
bf0app_update = true;
|
bf0app_update = true;
|
||||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||||
headers += "minisrv-use-carriage-return: false\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doLocalFlashROM(flashrom_file_path) {
|
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||||
// use local flashrom files;
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||||
try {
|
}
|
||||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
|
||||||
if (err) {
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||||
errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = err.toString();
|
|
||||||
}
|
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculatedPath(data, path, numparts = null) {
|
|
||||||
var data_128 = new Buffer.alloc(128);
|
|
||||||
data.copy(data_128, 0, 0, 128);
|
|
||||||
var flashrom_numparts = null;
|
|
||||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
|
||||||
|
|
||||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
|
||||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
|
||||||
|
|
||||||
var ind = new Array();
|
|
||||||
ind[0] = (path.indexOf("part") + 4);
|
|
||||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
|
||||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
|
||||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
|
||||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
|
||||||
if (flashrom_lastpart) {
|
|
||||||
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
|
||||||
} else {
|
|
||||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
|
||||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
|
||||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
|
||||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
|
||||||
}
|
|
||||||
return flashrom_next_rompath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
|
||||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
|
||||||
|
|
||||||
var flashrom_file_path = null;
|
|
||||||
Object.keys(service_vaults).forEach(function (g) {
|
|
||||||
if (flashrom_file_path != null) return;
|
|
||||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
|
||||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
|
||||||
});
|
});
|
||||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
|
||||||
// get flashrom files from archive.midnightchannel.net
|
|
||||||
var options = {
|
|
||||||
host: "archive.midnightchannel.net",
|
|
||||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
|
||||||
timeout: 5000,
|
|
||||||
method: 'GET'
|
|
||||||
}
|
|
||||||
const req = https.request(options, function (res) {
|
|
||||||
var data_hex = '';
|
|
||||||
res.setEncoding('hex');
|
|
||||||
|
|
||||||
res.on('data', d => {
|
|
||||||
data_hex += d;
|
|
||||||
})
|
|
||||||
|
|
||||||
res.on('end', function () {
|
|
||||||
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
|
||||||
if (res.statusCode == 200) {
|
|
||||||
data = Buffer.from(data_hex, 'hex');
|
|
||||||
} else if (res.statusCode == 404) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
} else {
|
|
||||||
var errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
}
|
|
||||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
} else {
|
|
||||||
doLocalFlashROM(flashrom_file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,117 +1,26 @@
|
|||||||
|
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||||
request_is_async = true;
|
request_is_async = true;
|
||||||
|
|
||||||
|
|
||||||
var bf0app_update = false;
|
var bf0app_update = false;
|
||||||
var request_path = unescape(request_headers.query.path);
|
var request_path = unescape(request_headers.query.path);
|
||||||
headers = "200 OK\n"
|
|
||||||
|
|
||||||
function doLocalFlashROM(flashrom_file_path) {
|
|
||||||
// use local flashrom files;
|
|
||||||
try {
|
|
||||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
|
||||||
if (err) {
|
|
||||||
errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = err.toString();
|
|
||||||
}
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||||
// assume old classic in flash mode, override user setting and send tellyscript
|
// assume old classic in flash mode, override user setting and send tellyscript
|
||||||
// because it is required to proceed in flash mode
|
// because it is required to proceed in flash mode
|
||||||
bf0app_update = true;
|
bf0app_update = true;
|
||||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||||
headers += "minisrv-use-carriage-return: false\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function calculatedPath(data, path, numparts = null) {
|
|
||||||
var data_128 = new Buffer.alloc(128);
|
|
||||||
data.copy(data_128, 0, 0, 128);
|
|
||||||
var flashrom_numparts = null;
|
|
||||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
|
||||||
|
|
||||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
|
||||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
|
||||||
|
|
||||||
var ind = new Array();
|
|
||||||
ind[0] = (path.indexOf("part") + 4);
|
|
||||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
|
||||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
|
||||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
|
||||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
|
||||||
if (flashrom_lastpart) flashrom_next_rompath = null;
|
|
||||||
else {
|
|
||||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
|
||||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
|
||||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
|
||||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
|
||||||
}
|
|
||||||
return flashrom_next_rompath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_headers.query.raw || bf0app_update) {
|
if (request_headers.query.raw || bf0app_update) {
|
||||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||||
|
|
||||||
var flashrom_file_path = null;
|
|
||||||
Object.keys(service_vaults).forEach(function (g) {
|
|
||||||
if (flashrom_file_path != null) return;
|
|
||||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
|
||||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
|
||||||
});
|
|
||||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
|
||||||
// get flashrom files from archive.midnightchannel.net
|
|
||||||
var options = {
|
|
||||||
host: "archive.midnightchannel.net",
|
|
||||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
|
||||||
timeout: 5000,
|
|
||||||
method: 'GET'
|
|
||||||
}
|
}
|
||||||
const req = https.request(options, function (res) {
|
|
||||||
var data_hex = '';
|
|
||||||
res.setEncoding('hex');
|
|
||||||
|
|
||||||
res.on('data', d => {
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||||
data_hex += d;
|
|
||||||
})
|
|
||||||
|
|
||||||
res.on('end', function () {
|
|
||||||
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
|
||||||
if (res.statusCode == 200) {
|
|
||||||
data = Buffer.from(data_hex, 'hex');
|
|
||||||
} else if (res.statusCode == 404) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
} else {
|
|
||||||
var errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
}
|
|
||||||
if (bf0app_update) {
|
|
||||||
var nextpath = calculatedPath(data, request_path, (request_headers.query.numparts || null));
|
|
||||||
if (nextpath != null) headers += "\nwtv-visit: " + nextpath;
|
|
||||||
}
|
|
||||||
else headers += "\nwtv-connection-close: true";
|
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
} else {
|
|
||||||
doLocalFlashROM(flashrom_file_path);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// no support for bf0app yet, but here we send the client to initiate-lc2-download
|
headers = "200 OK\n"
|
||||||
// to get the rom image
|
|
||||||
if (request_headers.query.path) {
|
if (request_headers.query.path) {
|
||||||
headers += "Content-type: text/html\n"
|
headers += "Content-type: text/html\n"
|
||||||
headers += "wtv-visit: wtv-flashrom:/initiate-lc2-download?path=" + request_headers.query.path;
|
headers += "wtv-visit: wtv-flashrom:/initiate-lc2-download?path=" + request_headers.query.path;
|
||||||
|
|||||||
@@ -1,113 +1,32 @@
|
|||||||
// todo, actual file logic
|
|
||||||
// - ready query param to get flashrom path, check for its existance
|
|
||||||
// - handle last part to redirect to lc2-download-complete
|
|
||||||
// - handle failures
|
|
||||||
request_is_async = true;
|
|
||||||
|
|
||||||
function doLocalFlashROM() {
|
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
var wtvflashrom;
|
||||||
try {
|
var flashrom_info;
|
||||||
var data_128 = new Buffer.alloc(128);
|
request_is_async = true;
|
||||||
data.copy(data_128, 0, 0, 128);
|
|
||||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
|
||||||
processLC2DownloadPage(request_headers.query.path, flashrom_message, (request_headers.query.numparts || null));
|
|
||||||
} catch (e) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!request_headers.query.path) {
|
if (!request_headers.query.path) {
|
||||||
var errpage = doErrorPage(400);
|
var errpage = doErrorPage(400);
|
||||||
headers = errpage[0];
|
headers = errpage[0];
|
||||||
data = errpage[1];
|
data = errpage[1];
|
||||||
} else {
|
} else {
|
||||||
|
var wtvflashrom = new WTVFlashrom(service_vaults, service_name, minisrv_config.services[service_name].use_zefie_server);
|
||||||
var request_path = unescape(request_headers.query.path);
|
var request_path = unescape(request_headers.query.path);
|
||||||
var flashrom_file_path = null;
|
|
||||||
Object.keys(service_vaults).forEach(function (g) {
|
|
||||||
if (flashrom_file_path != null) return;
|
|
||||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
|
||||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
// read 512 bytes of rom
|
||||||
// read first 256 bytes of flashrom file from archive.midnightchannel.net
|
flashrom_info = wtvflashrom.getFlashRom(request_path, function (data, headers = null) {
|
||||||
// to get `flashrom_message` and `numparts` if missing
|
processLC2DownloadPage(request_headers.query.path, data, (request_headers.query.numparts || null));
|
||||||
var options = {
|
}, 512);
|
||||||
host: "archive.midnightchannel.net",
|
|
||||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
|
||||||
method: 'GET',
|
|
||||||
timeout: 5000,
|
|
||||||
headers: {
|
|
||||||
'Range': 'bytes=0-256'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var chunk;
|
|
||||||
|
|
||||||
const req = https.request(options, function (res) {
|
|
||||||
var data = '';
|
|
||||||
res.setEncoding('hex');
|
|
||||||
|
|
||||||
res.on('data', function (d) {
|
|
||||||
data += d;
|
|
||||||
});
|
|
||||||
|
|
||||||
res.on('error', function (e) {
|
|
||||||
console.log(" * Upstream FlashROM Error:", e);
|
|
||||||
var errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.on('end', function () {
|
|
||||||
if (res.statusCode == 206) {
|
|
||||||
var flashrom_message = new Buffer.from(data.substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
|
||||||
processLC2DownloadPage(request_headers.query.path, flashrom_message, (request_headers.query.numparts || null));
|
|
||||||
return;
|
|
||||||
} else if (res.statusCode == 404) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
} else {
|
|
||||||
var errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
}
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
} else {
|
|
||||||
// use local flashrom files
|
|
||||||
doLocalFlashROM(flashrom_file_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processLC2DownloadPage(path, flashrom_message, numparts = null) {
|
async function processLC2DownloadPage(path, flashrom_info, numparts = null) {
|
||||||
var flashrom_numparts = null;
|
var flashrom_numparts = null;
|
||||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
||||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
if (!flashrom_numparts) flashrom_numparts = parseInt(flashrom_info.message.substring(flashrom_info.message.length - 4).replace(/\D/g, ''));
|
||||||
var ind = new Array();
|
|
||||||
ind[0] = (path.indexOf("part") + 4);
|
if (!flashrom_info.is_last_part) {
|
||||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
flashrom_info.next_rompath = flashrom_info.next_rompath.replace("get-by-path", "get-lc2-page").replace("&raw=true", "&numparts=" + parseInt(flashrom_numparts));
|
||||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
|
||||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
|
||||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path + '&raw=true';
|
|
||||||
var flashrom_isboot = (/\.brom$/).test(path);
|
|
||||||
if (flashrom_lastpart) {
|
|
||||||
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
|
||||||
} else {
|
|
||||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
|
||||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
|
||||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
|
||||||
var flashrom_next_rompath = flashrom_rompath.replace("part"+flashrom_part_num, "part"+flashrom_next_part_num).replace('get-by-path', 'get-lc2-page').replace("&raw=true", "&numparts=" + parseInt(flashrom_numparts));
|
|
||||||
}
|
}
|
||||||
if (!flashrom_part_num || !flashrom_lastpart || !flashrom_rompath || !flashrom_next_rompath || !flashrom_isboot) {
|
if (!flashrom_info.part_number || !flashrom_info.is_last_part || !flashrom_info.rompath || !flashrom_info.next_rompath || !flashrom_info.is_bootrom) {
|
||||||
|
|
||||||
headers = `200 OK
|
headers = `200 OK
|
||||||
Content-type: text/html`
|
Content-type: text/html`
|
||||||
@@ -163,7 +82,7 @@ Your WebTV Unit is being<br>updated automatically.
|
|||||||
<p> <font size=+1>
|
<p> <font size=+1>
|
||||||
This will take a while, and<br>then you can use your WebTV again.
|
This will take a while, and<br>then you can use your WebTV again.
|
||||||
`;
|
`;
|
||||||
if (flashrom_isboot && parseInt(flashrom_part_num) == 16) {
|
if (flashrom_info.is_bootrom && flashrom_info.part_number == 16) {
|
||||||
data += `<p>
|
data += `<p>
|
||||||
The system will pause for about 30 seconds at the end of this
|
The system will pause for about 30 seconds at the end of this
|
||||||
update. Please <strong>do not</strong> interrupt the system
|
update. Please <strong>do not</strong> interrupt the system
|
||||||
@@ -174,16 +93,20 @@ data += `
|
|||||||
</font>
|
</font>
|
||||||
<br><br><br><br><br>
|
<br><br><br><br><br>
|
||||||
<upgradeblock width=280 height=15
|
<upgradeblock width=280 height=15
|
||||||
nexturl="${flashrom_next_rompath}"
|
nexturl="${flashrom_info.next_rompath}"
|
||||||
errorurl="wtv-flashrom:/lc2-download-failed?"
|
errorurl="wtv-flashrom:/lc2-download-failed?"
|
||||||
blockurl="${flashrom_rompath}"
|
blockurl="${flashrom_info.rompath}"
|
||||||
lastblock="${flashrom_lastpart}"
|
lastblock="${flashrom_info.is_last_part}"
|
||||||
curblock="` + (parseInt(flashrom_part_num) + 1) + `"
|
curblock="` + (flashrom_info.part_number + 1) + `"
|
||||||
totalblocks="${flashrom_numparts}">
|
`
|
||||||
|
if (flashrom_numparts) {
|
||||||
|
data += `totalblocks="${flashrom_numparts}"`;
|
||||||
|
}
|
||||||
|
data += `>
|
||||||
<font size="-1" color="#D6DFD0">
|
<font size="-1" color="#D6DFD0">
|
||||||
<br>
|
<br>
|
||||||
<img src="wtv-flashrom:/ROMCache/Spacer.gif" width=2 height=10><br>
|
<img src="wtv-flashrom:/ROMCache/Spacer.gif" width=2 height=10><br>
|
||||||
${flashrom_message}
|
${flashrom_info.message}
|
||||||
<br><br>
|
<br><br>
|
||||||
<tr>
|
<tr>
|
||||||
<td width=104 valign=middle align=center>
|
<td width=104 valign=middle align=center>
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
const WTVFlashrom = require("./WTVFlashrom.js");
|
||||||
|
request_is_async = true;
|
||||||
|
|
||||||
// this build can be local or on zefie's server
|
// this build can be local or on zefie's server
|
||||||
// to get the path from zefie's server, browse
|
// to get the path from zefie's server, browse
|
||||||
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
// https://archive.midnightchannel.net/zefie/files/wtv-flashrom/content/artemis-webtv-000/
|
||||||
@@ -5,110 +8,23 @@
|
|||||||
// example is below
|
// example is below
|
||||||
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
var default_build_to_send = minisrv_config.services[service_name].bf0app_default_rom || "content/artemis-webtv-000/build7181/daily-nondebug/bf0app-part000.rom";
|
||||||
|
|
||||||
headers = "200 OK\n";
|
|
||||||
var request_path = "";
|
var request_path = "";
|
||||||
var bf0app_update = true;
|
var bf0app_update = true;
|
||||||
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
if (request_headers.query.path) request_path = unescape(request_headers.query.path);
|
||||||
else request_path = default_build_to_send;
|
else request_path = default_build_to_send;
|
||||||
request_is_async = true;
|
|
||||||
|
|
||||||
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
if (ssid_sessions[socket.ssid].get("wtv-client-rom-type") == "bf0app" && ssid_sessions[socket.ssid].get("wtv-client-bootrom-version") == "105") {
|
||||||
// assume old classic in flash mode, override user setting and send tellyscript
|
// assume old classic in flash mode, override user setting and send tellyscript
|
||||||
// because it is required to proceed in flash mode
|
// because it is required to proceed in flash mode
|
||||||
bf0app_update = true;
|
bf0app_update = true;
|
||||||
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
ssid_sessions[socket.ssid].set("bf0app_update", bf0app_update);
|
||||||
headers += "minisrv-use-carriage-return: false\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function doLocalFlashROM(flashrom_file_path) {
|
if (!ssid_sessions[socket.ssid].data_store.WTVFlashrom) {
|
||||||
// use local flashrom files;
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom = new WTVFlashrom(service_vaults, service_name, 0, minisrv_config.services[service_name].use_zefie_server, bf0app_update);
|
||||||
try {
|
}
|
||||||
fs.readFile(flashrom_file_path, null, function (err, data) {
|
|
||||||
if (err) {
|
ssid_sessions[socket.ssid].data_store.WTVFlashrom.getFlashRom(request_path, function (data, headers) {
|
||||||
errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = err.toString();
|
|
||||||
}
|
|
||||||
sendToClient(socket, headers, data);
|
sendToClient(socket, headers, data);
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculatedPath(data, path, numparts = null) {
|
|
||||||
var data_128 = new Buffer.alloc(128);
|
|
||||||
data.copy(data_128, 0, 0, 128);
|
|
||||||
var flashrom_numparts = null;
|
|
||||||
var flashrom_message = new Buffer.from(data_128.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
|
||||||
|
|
||||||
if (numparts != null) flashrom_numparts = parseInt(numparts);
|
|
||||||
if (!flashrom_numparts) flashrom_numparts = flashrom_message.substring(flashrom_message.length - 4).replace(/\D/g, '');
|
|
||||||
|
|
||||||
var ind = new Array();
|
|
||||||
ind[0] = (path.indexOf("part") + 4);
|
|
||||||
ind[1] = (path.indexOf(".", ind[0]) + 1);
|
|
||||||
var flashrom_part_num = path.substr(ind[0], (path.length - ind[1]));
|
|
||||||
var flashrom_lastpart = (flashrom_numparts == (parseInt(flashrom_part_num) + 1)) ? true : false;
|
|
||||||
var flashrom_rompath = 'wtv-flashrom:/get-by-path?path=' + path;
|
|
||||||
if (flashrom_lastpart) {
|
|
||||||
flashrom_next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
|
||||||
} else {
|
|
||||||
var flashrom_next_part_num = (parseInt(flashrom_part_num) + 1);
|
|
||||||
if (flashrom_next_part_num < 10) flashrom_next_part_num = "00" + flashrom_next_part_num; // 1s
|
|
||||||
else if (flashrom_next_part_num >= 10 && flashrom_next_part_num < 100) flashrom_next_part_num = "0" + flashrom_next_part_num; // 10s
|
|
||||||
var flashrom_next_rompath = flashrom_rompath.replace("part" + flashrom_part_num, "part" + flashrom_next_part_num) + "&numparts=" + parseInt(flashrom_numparts);
|
|
||||||
}
|
|
||||||
return flashrom_next_rompath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((/\.brom$/).test(request_path)) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
|
||||||
else headers += "Content-Type: binary/x-wtv-flashblock";
|
|
||||||
|
|
||||||
var flashrom_file_path = null;
|
|
||||||
Object.keys(service_vaults).forEach(function (g) {
|
|
||||||
if (flashrom_file_path != null) return;
|
|
||||||
flashrom_file_path = service_vaults[g] + "/" + service_name + "/" + request_path;
|
|
||||||
if (!fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
|
||||||
});
|
});
|
||||||
if (minisrv_config.services[service_name].use_zefie_server && !flashrom_file_path) {
|
|
||||||
// get flashrom files from archive.midnightchannel.net
|
|
||||||
var options = {
|
|
||||||
host: "archive.midnightchannel.net",
|
|
||||||
path: "/zefie/files/wtv-flashrom/" + request_path,
|
|
||||||
timeout: 5000,
|
|
||||||
method: 'GET'
|
|
||||||
}
|
|
||||||
const req = https.request(options, function (res) {
|
|
||||||
var data_hex = '';
|
|
||||||
res.setEncoding('hex');
|
|
||||||
|
|
||||||
res.on('data', d => {
|
|
||||||
data_hex += d;
|
|
||||||
})
|
|
||||||
|
|
||||||
res.on('end', function () {
|
|
||||||
if (!zquiet) console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
|
||||||
if (res.statusCode == 200) {
|
|
||||||
data = Buffer.from(data_hex, 'hex');
|
|
||||||
} else if (res.statusCode == 404) {
|
|
||||||
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
} else {
|
|
||||||
var errpage = doErrorPage(400)
|
|
||||||
headers = errpage[0];
|
|
||||||
data = errpage[1];
|
|
||||||
}
|
|
||||||
headers += "\nwtv-visit: " + calculatedPath(data, request_path);
|
|
||||||
sendToClient(socket, headers, data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
} else {
|
|
||||||
doLocalFlashROM(flashrom_file_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ wtv-wink-deferrer-retries: 3
|
|||||||
wtv-offline-mail-enable: false
|
wtv-offline-mail-enable: false
|
||||||
wtv-name-server: 8.8.8.8
|
wtv-name-server: 8.8.8.8
|
||||||
`;
|
`;
|
||||||
if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true') {
|
if (ssid_sessions[socket.ssid].get('wtv-need-upgrade') != 'true' && !request_headers.query.reconnect) {
|
||||||
headers += "wtv-settings-url: wtv-setup:/get\n";
|
headers += "wtv-settings-url: wtv-setup:/get\n";
|
||||||
}
|
}
|
||||||
headers += `wtv-visit: wtv-home:/splash?
|
headers += `wtv-visit: wtv-home:/splash?
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
var challenge_response, challenge_header = '';
|
var challenge_response, challenge_header = '';
|
||||||
|
|
||||||
|
var gourl = "wtv-head-waiter:/login-stage-two?";
|
||||||
|
if (request_headers.query.relogin) gourl += "relogin=true";
|
||||||
|
if (request_headers.query.reconnect) gourl += "reconnect=true";
|
||||||
|
|
||||||
if (socket.ssid !== null) {
|
if (socket.ssid !== null) {
|
||||||
var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login");
|
var wtvsec_login = ssid_sessions[socket.ssid].get("wtvsec_login");
|
||||||
if (request_headers["wtv-ticket"]) {
|
if (request_headers["wtv-ticket"]) {
|
||||||
@@ -56,10 +60,10 @@ Expires: Wed, 09 Oct 1991 22:00:00 GMT
|
|||||||
wtv-expire-all: wtv-head-waiter:
|
wtv-expire-all: wtv-head-waiter:
|
||||||
`+ getServiceString('wtv-log') + `
|
`+ getServiceString('wtv-log') + `
|
||||||
wtv-log-url: wtv-log:/log
|
wtv-log-url: wtv-log:/log
|
||||||
`+ challenge_header + `
|
${challenge_header}
|
||||||
wtv-relogin-url: wtv-1800:/preregister?relogin=true
|
wtv-relogin-url: wtv-1800:/preregister?relogin=true
|
||||||
wtv-reconnect-url: wtv-1800:/preregister?reconnect=true
|
wtv-reconnect-url: wtv-1800:/preregister?reconnect=true
|
||||||
wtv-visit: wtv-head-waiter:/login-stage-two?
|
wtv-visit: ${gourl}
|
||||||
Content-type: text/html`;
|
Content-type: text/html`;
|
||||||
data = '';
|
data = '';
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function go() {
|
|||||||
location.href=document.access.url.value;
|
location.href=document.access.url.value;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<h2>Welcome to `+ z_title + `</h2>
|
<h3>Welcome to `+ z_title + `</h3>
|
||||||
<b>Encryption Status</b>: ${cryptstatus}<br>
|
<b>Encryption Status</b>: ${cryptstatus}<br>
|
||||||
<b>Connection Speed</b>: &rate;
|
<b>Connection Speed</b>: &rate;
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ Content-Type: text/html`
|
|||||||
<td valign=top align=right><shadow>Client IP number:</shadow>
|
<td valign=top align=right><shadow>Client IP number:</shadow>
|
||||||
<td width=10>
|
<td width=10>
|
||||||
<td valign=top>${socket.remoteAddress}
|
<td valign=top>${socket.remoteAddress}
|
||||||
|
<tr>
|
||||||
|
<td valign=top align=right><shadow>Service IP number:</shadow>
|
||||||
|
<td width=10>
|
||||||
|
<td valign=top>${service_ip}
|
||||||
<tr>
|
<tr>
|
||||||
<td height=20>
|
<td height=20>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
179
zefie_wtvp_minisrv/WTVFlashrom.js
Normal file
179
zefie_wtvp_minisrv/WTVFlashrom.js
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
class WTVFlashrom {
|
||||||
|
|
||||||
|
fs = require('fs');
|
||||||
|
https = require('https');
|
||||||
|
use_zefie_server = true;
|
||||||
|
bf0app_update = false;
|
||||||
|
service_vaults = new Array();
|
||||||
|
service_name = "";
|
||||||
|
zdebug = false;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(service_vaults, service_name, use_zefie_server = true, bf0app_update = false, debug = false) {
|
||||||
|
this.service_vaults = service_vaults;
|
||||||
|
this.service_name = service_name;
|
||||||
|
this.use_zefie_server = use_zefie_server;
|
||||||
|
this.bf0app_update = bf0app_update;
|
||||||
|
this.zdebug = debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
async doLocalFlashROM(flashrom_file_path, callback, info_only = false) {
|
||||||
|
// use local flashrom files;
|
||||||
|
console.log(info_only);
|
||||||
|
var self = this;
|
||||||
|
try {
|
||||||
|
this.fs.readFile(flashrom_file_path, null, function (err, data) {
|
||||||
|
if (err) {
|
||||||
|
errpage = doErrorPage(400)
|
||||||
|
var headers = errpage[0];
|
||||||
|
data = err.toString();
|
||||||
|
callback(data, headers);
|
||||||
|
} else {
|
||||||
|
if (info_only) {
|
||||||
|
callback(self.getFlashromData(data, flashrom_file_path));
|
||||||
|
} else {
|
||||||
|
self.sendToClient(data, flashrom_file_path, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
var errpage = doErrorPage(404, "The service could not find the requested ROM.")
|
||||||
|
var headers = errpage[0];
|
||||||
|
var data = errpage[1];
|
||||||
|
callback(data, headers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatPartNum(partnum) {
|
||||||
|
if (partnum < 10) return "00" + partnum; // 1s
|
||||||
|
else if (partnum >= 10 && partnum < 100) return "0" + partnum; // 10s
|
||||||
|
else return partnum; // 100s
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getFlashromData(data, path) {
|
||||||
|
var flashrom_info = new Array();
|
||||||
|
var flashrom_magic = "96031889";
|
||||||
|
var part_header = new Buffer.alloc(32);
|
||||||
|
data.copy(part_header, 0, 0, 32);
|
||||||
|
flashrom_info.header_length = data.readUInt16BE(26);
|
||||||
|
|
||||||
|
flashrom_info.is_bootrom = (/\.brom$/).test(path);
|
||||||
|
|
||||||
|
// re-read entire header
|
||||||
|
var part_header = new Buffer.alloc(flashrom_info.header_length);
|
||||||
|
data.copy(part_header, 0, 0, flashrom_info.header_length);
|
||||||
|
|
||||||
|
flashrom_info.magic = part_header.toString('hex', 0, 4);
|
||||||
|
flashrom_info.valid_flashrom = false;
|
||||||
|
if (flashrom_info.magic == flashrom_magic) flashrom_info.valid_flashrom = true;
|
||||||
|
if (!flashrom_info.valid_flashrom) console.error(" * Warning! FlashROM File Magic (" + flashrom_info.magic + ") did not match expected magic (" + flashrom_magic + ")...");
|
||||||
|
|
||||||
|
if (this.zdebug) console.log(" # FlashROM File Magic (" + flashrom_info.magic + "), expected magic (" + flashrom_magic + "), OK = " + flashrom_info.valid_flashrom + "...");
|
||||||
|
flashrom_info.byte_progress = data.readUInt32BE(68);
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part Bytes Sent:", flashrom_info.byte_progress);
|
||||||
|
flashrom_info.compression_type = parseInt(part_header[16], 16);
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part Compression Type:", flashrom_info.compression_type);
|
||||||
|
flashrom_info.part_data_size = data.readUInt32BE(4);
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part Data Size:", flashrom_info.part_data_size);
|
||||||
|
flashrom_info.part_total_size = flashrom_info.part_data_size + flashrom_info.header_length;
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part Total Size:", flashrom_info.part_total_size);
|
||||||
|
|
||||||
|
flashrom_info.total_parts_size = data.readUInt32BE(32);
|
||||||
|
if (this.zdebug) console.log(" # Flashrom All Parts Total Size:", flashrom_info.total_parts_size);
|
||||||
|
|
||||||
|
// read current part number bit from part header
|
||||||
|
flashrom_info.part_number = data.readUInt16BE(28);
|
||||||
|
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Current Part Number:", flashrom_info.part_number);
|
||||||
|
|
||||||
|
// read current part display message from part header
|
||||||
|
flashrom_info.message = new Buffer.from(part_header.toString('hex').substring(36 * 2, 68 * 2), 'hex').toString('ascii').replace(/[^0-9a-z\ \.\-]/gi, "");
|
||||||
|
|
||||||
|
flashrom_info.is_last_part = ((flashrom_info.byte_progress + flashrom_info.part_total_size) == flashrom_info.total_parts_size) ? true : false;
|
||||||
|
flashrom_info.rompath = 'wtv-flashrom:/get-by-path?path=' + path + '&raw=true';
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part Bytes Sent (after this part):", flashrom_info.byte_progress + flashrom_info.part_total_size);
|
||||||
|
if (this.zdebug) console.log(" # Flashrom Part is Last Part", flashrom_info.is_last_part);
|
||||||
|
|
||||||
|
if (flashrom_info.is_last_part && this.bf0app_update) {
|
||||||
|
flashrom_info.next_rompath = null;
|
||||||
|
} else if (flashrom_info.is_last_part && !this.bf0app_update) {
|
||||||
|
flashrom_info.next_rompath = "wtv-flashrom:/lc2-download-complete?";
|
||||||
|
} else {
|
||||||
|
flashrom_info.next_part_number = this.formatPartNum(flashrom_info.part_number + 1);
|
||||||
|
flashrom_info.next_rompath = flashrom_info.rompath.replace("part" + this.formatPartNum(flashrom_info.part_number), "part" + flashrom_info.next_part_number);
|
||||||
|
}
|
||||||
|
return flashrom_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendToClient(data, request_path, callback) {
|
||||||
|
var headers = "200 OK\n";
|
||||||
|
if (this.bf0app_update) headers += "minisrv-use-carriage-return: false\n";
|
||||||
|
var flashrom_info = this.getFlashromData(data, request_path)
|
||||||
|
if (flashrom_info.is_bootrom) headers += "Content-Type: binary/x-wtv-bootrom"; // maybe?
|
||||||
|
else headers += "Content-Type: binary/x-wtv-flashblock";
|
||||||
|
if (flashrom_info.next_rompath != null) headers += "\nwtv-visit: " + flashrom_info.next_rompath;
|
||||||
|
callback(data, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFlashRom(request_path, callback, length = 0) {
|
||||||
|
var flashrom_file_path = null;
|
||||||
|
var self = this;
|
||||||
|
Object.keys(self.service_vaults).forEach(function (g) {
|
||||||
|
if (flashrom_file_path != null) return;
|
||||||
|
flashrom_file_path = self.service_vaults[g] + "/" + self.service_name + "/" + request_path;
|
||||||
|
if (!self.fs.existsSync(flashrom_file_path)) flashrom_file_path = null;
|
||||||
|
});
|
||||||
|
if (this.use_zefie_server && !flashrom_file_path) {
|
||||||
|
// get flashrom files from archive.midnightchannel.net
|
||||||
|
var options = {
|
||||||
|
host: "archive.midnightchannel.net",
|
||||||
|
path: "/zefie/files/wtv-flashrom/" + request_path,
|
||||||
|
timeout: 5000,
|
||||||
|
method: 'GET'
|
||||||
|
}
|
||||||
|
if (length > 0) {
|
||||||
|
options.headers = {
|
||||||
|
'Range': 'bytes=0-' + length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const req = this.https.request(options, function (res) {
|
||||||
|
var data_hex = '';
|
||||||
|
res.setEncoding('hex');
|
||||||
|
|
||||||
|
res.on('data', d => {
|
||||||
|
data_hex += d;
|
||||||
|
})
|
||||||
|
|
||||||
|
res.on('end', function () {
|
||||||
|
console.log(` * Zefie's FlashROM Server HTTP Status: ${res.statusCode} ${res.statusMessage}`)
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
var data = Buffer.from(data_hex, 'hex');
|
||||||
|
} else if (res.statusCode == 206) {
|
||||||
|
headers = "";
|
||||||
|
var data = self.getFlashromData(Buffer.from(data_hex, 'hex'), request_path);
|
||||||
|
} else if (res.statusCode == 404) {
|
||||||
|
var errpage = doErrorPage(404, "The service could not find the requested ROM on zefie's server.")
|
||||||
|
var headers = errpage[0];
|
||||||
|
var data = errpage[1];
|
||||||
|
} else {
|
||||||
|
var errpage = doErrorPage(400)
|
||||||
|
var headers = errpage[0];
|
||||||
|
var data = errpage[1];
|
||||||
|
}
|
||||||
|
if (res.statusCode == "206") {
|
||||||
|
self.sendToClient(data, request_path, callback);
|
||||||
|
} else {
|
||||||
|
callback(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
req.end();
|
||||||
|
} else {
|
||||||
|
this.doLocalFlashROM(flashrom_file_path, callback, ((length != 0) ? true : false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WTVFlashrom;
|
||||||
@@ -14,6 +14,20 @@ var WTVSec = require('./WTVSec.js');
|
|||||||
var WTVClientCapabilities = require('./WTVClientCapabilities.js');
|
var WTVClientCapabilities = require('./WTVClientCapabilities.js');
|
||||||
var WTVClientSessionData = require('./WTVClientSessionData.js');
|
var WTVClientSessionData = require('./WTVClientSessionData.js');
|
||||||
|
|
||||||
|
process
|
||||||
|
.on('SIGTERM', shutdown('SIGTERM'))
|
||||||
|
.on('SIGINT', shutdown('SIGINT'))
|
||||||
|
.on('uncaughtException', shutdown('uncaughtException'));
|
||||||
|
|
||||||
|
|
||||||
|
function shutdown(signal) {
|
||||||
|
return (err) => {
|
||||||
|
console.log("Received signal", signal);
|
||||||
|
if (err) console.error(err.stack || err);
|
||||||
|
process.exit(err ? 1 : 0);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Where we store our session information
|
// Where we store our session information
|
||||||
var ssid_sessions = new Array();
|
var ssid_sessions = new Array();
|
||||||
var socket_sessions = new Array();
|
var socket_sessions = new Array();
|
||||||
@@ -285,7 +299,7 @@ async function processURL(socket, request_headers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function doHTTPProxy(socket, request_headers) {
|
async function doHTTPProxy(socket, request_headers) {
|
||||||
var request_type = (request_headers.request_url.substring(0,5) == 'https') ? 'https' : 'http'
|
var request_type = (request_headers.request_url.substring(0, 5) == "https") ? "https" : "http";
|
||||||
if (zshowheaders) console.log(request_type.toUpperCase() +" Proxy: Client Request Headers on socket ID", socket.id, (await filterSSID(request_headers)));
|
if (zshowheaders) console.log(request_type.toUpperCase() +" Proxy: Client Request Headers on socket ID", socket.id, (await filterSSID(request_headers)));
|
||||||
switch (request_type) {
|
switch (request_type) {
|
||||||
case "https":
|
case "https":
|
||||||
@@ -304,7 +318,7 @@ async function doHTTPProxy(socket, request_headers) {
|
|||||||
request_data.port = request_data.host.split(':')[1];
|
request_data.port = request_data.host.split(':')[1];
|
||||||
request_data.host = request_data.host.split(':')[0];
|
request_data.host = request_data.host.split(':')[0];
|
||||||
} else {
|
} else {
|
||||||
if (request_type === 'https') request_data.port = 443;
|
if (request_type === "https") request_data.port = 443;
|
||||||
else request_data.port = 80;
|
else request_data.port = 80;
|
||||||
}
|
}
|
||||||
for (var i = 0; i < 3; i++) request_url_split.shift();
|
for (var i = 0; i < 3; i++) request_url_split.shift();
|
||||||
@@ -332,10 +346,11 @@ async function doHTTPProxy(socket, request_headers) {
|
|||||||
var ProxyAgent = require('proxy-agent');
|
var ProxyAgent = require('proxy-agent');
|
||||||
options.agent = new ProxyAgent("socks://" + (minisrv_config.services[request_type].external_proxy_host || "127.0.0.1") + ":" + minisrv_config.services[request_type].external_proxy_port);
|
options.agent = new ProxyAgent("socks://" + (minisrv_config.services[request_type].external_proxy_host || "127.0.0.1") + ":" + minisrv_config.services[request_type].external_proxy_port);
|
||||||
} else {
|
} else {
|
||||||
|
var proxy_agent = http;
|
||||||
options.host = minisrv_config.services[request_type].external_proxy_host;
|
options.host = minisrv_config.services[request_type].external_proxy_host;
|
||||||
options.port = minisrv_config.services[request_type].external_proxy_port;
|
options.port = minisrv_config.services[request_type].external_proxy_port;
|
||||||
options.path = request_headers.request.split(' ')[1];
|
options.path = request_headers.request.split(' ')[1];
|
||||||
options.headers.Host = request_data.host;
|
options.headers.Host = request_data.host + ":" + request_data.port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const req = proxy_agent.request(options, function (res) {
|
const req = proxy_agent.request(options, function (res) {
|
||||||
@@ -579,7 +594,7 @@ function headersAreStandard(string, verbose = false) {
|
|||||||
// in unencrypted headers, and returns true only if every character in the string matches
|
// in unencrypted headers, and returns true only if every character in the string matches
|
||||||
// the regex. Once we know the string is binary, we can better process it with the
|
// the regex. Once we know the string is binary, we can better process it with the
|
||||||
// raw base64 or hex data in processRequest() below.
|
// raw base64 or hex data in processRequest() below.
|
||||||
return /^([A-Za-z0-9\+\/\=\-\.\,\ \"\;\:\?\&\r\n\(\)\%\<\>\_]{8,})$/.test(string);
|
return /^([A-Za-z0-9\+\/\=\-\.\,\ \"\;\:\?\&\r\n\(\)\%\<\>\_\~]{8,})$/.test(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processRequest(socket, data_hex, skipSecure = false, encryptedRequest = false) {
|
async function processRequest(socket, data_hex, skipSecure = false, encryptedRequest = false) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "zefie_wtvp_minisrv",
|
"name": "zefie_wtvp_minisrv",
|
||||||
"version": "0.9.10",
|
"version": "0.9.11",
|
||||||
"description": "WebTV Service (WTVP) Emulation Server",
|
"description": "WebTV Service (WTVP) Emulation Server",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv",
|
"homepage": "https://github.com/zefie/zefie_wtvp_minisrv",
|
||||||
|
|||||||
@@ -221,6 +221,9 @@
|
|||||||
<Content Include="WTVClientCapabilities.js">
|
<Content Include="WTVClientCapabilities.js">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="WTVFlashrom.js">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Content>
|
||||||
<Content Include="WTVSec.js">
|
<Content Include="WTVSec.js">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
Reference in New Issue
Block a user