đŸ Archived View for gemini.ctrl-c.club âș ~ssb22 âș adjuster.gmi captured on 2024-05-26 at 15:29:57. Gemini links have been rewritten to link to archived content
View Raw
More Information
âŹ
ïž Previous capture (2024-03-21)
âĄïž Next capture (2024-07-09)
đ§ View Differences
-=-=-=-=-=-=-
Web Adjuster
Web Adjuster is a Tornado-based, domain-rewriting proxy for applying custom processing to Web pages.âIt is particularly meant for users of smartphones etc as these might not support browser extensions.âWeb Adjuster can:
- Add a custom stylesheet to change size, layout and colours
- Add custom Javascript to all pages, allowing many desktop browser extensions to work as-is on a smartphone or tablet
- Run a custom program to change the markup, or to change or annotate text for language tools (see for example Annotator Generator)
- Render images for a language or text size not supported by the browser (this function requires the Python Imaging Library and suitable fonts)
- Down-sample MP3 audio to save bandwidth, and add plain text versions of PDF and EPUB files (helper programs are required for these functions)
- Remove problematic markup from pages, etc.
Domain rewriting means you do not need to be able to change the deviceâs proxy settingsâyou simply go to a different address.âHowever, only the domain part is different, so most in-site scripting should work as-is, without needing delicate alterations to its URI handling.âFor example, if you have a server called adjuster.example.org and you want to see www.example.com, simply go to www.example.com.adjuster.example.org.âYour server ideally needs a wildcard domain, but you can manage without one in some cases, and Web Adjuster can also be a ârealâ HTTP proxy for local use on a desktop etc.
Because it is based on a single-threaded event-driven Tornado server, Web Adjuster can efficiently handle connections even on a low-power machine like the original Raspberry Pi.â(Add-on programs run in other threads, but this is seldom a slow-down in practice.)âTornado also makes Web Adjuster easier to set up: it is a separate, self-contained server that doesnât need to be worked into the configuration of another oneâit can listen on an alternate port (and can be password protected)âbut if you prefer you *can* configure it to share port 80 with another server.
Installation
1. Make sure Python and Tornado are on the system.â(Web Adjuster has been tested in both Python 2 and Python 3, and with Tornado versions between 2.x and 6.x.)
- If you have root access to a GNU/Linux box, try sudo apt-get install python-tornado or sudo pip install tornado (on a Mac you might need sudo easy_install pip first)
- If you donât have root access, try pip install tornado --user and if all else fails, on Python 2.6 or 2.7 you can download the old version 2.4.1, unpack it and use its tornado subdirectory.
- On Windows, the easiest way is probably to install Cygwin, install its python package, and do something like wget http://peak.telecommunity.com/dist/ez_setup.py && python ez_setup.py && easy_install pip && pip install tornado
2. Download adjuster.py
- (You can also use pip install adjuster or pipx run adjuster if you prefer, and there is history on GitHub)
- Run it with the appropriate options (see below), or use it in a WSGI application.
adjuster.py
Options for Web Adjuster v3.237
General options
- --config Name of the configuration file to read, if any.âThe processâs working directory will be set to that of the configuration file so that relative pathnames can be used inside it.âAny option that would otherwise have to be set on the command line may be placed in this file as an option="value" or option='value' line (without any double-hyphen prefix).âMulti-line values are possible if you quote them in """...""", and you can use standard \ escapes.âYou can also set config= in the configuration file itself to import another configuration file (for example if you have per-machine settings and global settings).âIf you want there to be a default configuration file without having to set it on the command line every time, an alternative option is to set the ADJUSTER_CFG environment variable.
- --version Just print program version and exit
Network listening and security settings
- --port (default 28080) The port to listen on.âSetting this to 80 will make it the main Web server on the machine (which will likely require root access on Unix); setting it to 0 disables request-processing entirely (for if you want to use only the Dynamic DNS option); setting it to -1 selects a local port in the ephemeral port range, in which case address and port will be written in plain form to standard output if itâs not a terminal and --background is set (see also --just-me).
- --publicPort (default 0) The port to advertise in URLs etc, if different from âportâ (the default of 0 means no difference).âUsed for example if a firewall prevents direct access to our port but a server like nginx is configured to forward incoming connections.
- --address The address to listen on.âIf unset, will listen on all IP addresses of the machine.âYou could for example set this to localhost if you want only connections from the local machine to be received, which might be useful in conjunction with --real_proxy.
- --password The password.âIf this is set, nobody can connect without specifying ?p= followed by this password.âIt will then be sent to them as a cookie so they donât have to enter it every time.âNotes: (1) If wildcard_dns is False and you have multiple domains in host_suffix, then the password cookie will have to be set on a per-domain basis. (2) On a shared server you probably donât want to specify this on the command line where it can be seen by process-viewing tools; use a configuration file instead. (3) When not in HTML-only mode, browsers that send AJAX requests without cookies might have problems when password is set.
- --password-domain The domain entry in host_suffix to which the password applies.âFor use when wildcard_dns is False and you have several domains in host_suffix, and only one of them (perhaps the one with an empty default_site) is to be password-protected, with the others public.âIf this option is used then prominentNotice (if set) will not apply to the passworded domain.âYou may put the password on two or more domains by separating them with slash (/).
- --auth-error (default Authentication error) What to say when password protection is in use and a correct password has not been entered.âHTML markup is allowed in this message.âAs a special case, if this begins with http:// or https:// then it is assumed to be the address of a Web site to which the browser should be redirected.âIf the markup begins with a * then this is removed and the page is returned with code 200 (OK) instead of 401 (authorisation required).
- --open-proxy (default False) Whether or not to allow running with no password.âOff by default as a safeguard against accidentally starting an open proxy.
- --prohibit (default wiki.*action=edit) Comma-separated list of regular expressions specifying URLs that are not allowed to be fetched unless --real_proxy is in effect.âBrowsers requesting a URL that contains any of these will be redirected to the original site.âUse for example if you want people to go direct when posting their own content to a particular site (this is of only limited use if your server also offers access to any other site on the Web, but it might be useful when thatâs not the case).âInclude ^https in the list to prevent Web Adjuster from fetching HTTPS pages for adjustment and return over normal HTTP.âThis access is enabled by default now that many sites use HTTPS for public pages that donât really need to be secure, just to get better placement on some search engines, but if sending confidential information to the site then beware you are trusting the Web Adjuster machine and your connection to it, plus its certificate verification might not be as thorough as your browserâs.
- --prohibitUA (default TwitterBot) Comma-separated list of regular expressions which, if they occur in browser strings, result in the browser being redirected to the original site.âUse for example if you want certain robots that ignore robots.txt to go direct.
- --real-proxy (default False) Whether or not to accept requests with original domains like a ârealâ HTTP proxy.âWarning: this bypasses the password and implies open_proxy.âOff by default.
- --via (default True) Whether or not to update the Via: and X-Forwarded-For: HTTP headers when forwarding requests
- --uavia (default True) Whether or not to add to the User-Agent HTTP header when forwarding requests, as a courtesy to site administrators who wonder whatâs happening in their logs (and donât log Via: etc)
- --robots (default False) Whether or not to pass on requests for /robots.txt.âIf this is False then all robots will be asked not to crawl the site; if True then the original siteâs robots settings will be mirrored.âThe default of False is recommended.
- --just-me (default False) Listen on localhost only, and check incoming connections with an ident server (which must be running on port 113) to ensure they are coming from the same user.âThis is for experimental setups on shared Unix machines; might be useful in conjuction with --real_proxy.âIf an ident server is not available, an attempt is made to authenticate connections via Linux netstat and /proc.
- --one-request-only (default False) Shut down after handling one request.âThis is for use in inefficient CGI-like environments where you cannot leave a server running permanently, but still want to start one for something thatâs unsupported in WSGI mode (e.g. js_reproxy): run with --one_request_only and forward the request to its port.âYou may also wish to set --seconds if using this.
- --seconds (default 0) The maximum number of seconds for which to run the server (0 for unlimited).âIf a time limit is set, the server will shut itself down after the specified length of time.
- --stdio (default False) Forward standard input and output to our open port, in addition to being open to normal TCP connections.âThis might be useful in conjuction with --one-request-only and --port=-1.
- --upstream-proxy address:port of a proxy to send our requests through.âThis can be used to adapt existing proxy-only mediators to domain rewriting, or for a caching proxy.âNot used for ip_query_url options or fasterServer.âIf address is left blank (just :port) then localhost is assumed and https URLs will be rewritten into http with altered domains; youâll then need to set the upstream proxy to send its requests back through the adjuster (which will listen on localhost:port+1 for this purpose) to undo that rewrite.âThis can be used to make an existing HTTP-only proxy process HTTPS pages.
- --ip-messages Messages or blocks for specific IP address ranges (IPv4 only).âFormat is ranges|message|ranges|message etc, where ranges are separated by commas; can be individual IPs, or ranges in either ânetwork/maskâ or âmin-maxâ format; the first matching range-set is selected.âIf a message starts with * then its ranges are blocked completely (rest of message, if any, is sent as the only reply to any request), otherwise message is shown on a âclick-throughâ page (requires Javascript and cookies).âIf the message starts with a hyphen (-) then it is considered a minor edit of earlier messages and is not shown to people who selected âdo not show againâ even if they did this on a different version of the message.âMessages may include HTML.
DNS and website settings
- --host-suffix (default is the machineâs domain name) The last part of the domain name.âFor example, if the user wishes to change www.example.com and should do so by visiting www.example.com.adjuster.example.org, then host_suffix is adjuster.example.org.âIf you do not have a wildcard domain then you can still adjust one site by setting wildcard_dns to False, host_suffix to your non-wildcard domain, and default_site to the site you wish to adjust.âIf you have more than one non-wildcard domain, you can set wildcard_dns to False, host_suffix to all your domains separated by slash (/), and default_site to the sites these correspond to, again separated by slash (/); if two or more domains share the same default_site then the first is preferred in links and the others are assumed to be for backward compatibility.âIf wildcard_dns is False and default_site is empty (or if itâs a /-separated list and one of its items is empty), then the corresponding host_suffix gives a URL box and sets its domain in a cookie (and adds a link at the bottom of pages to clear this and return to the URL box), but this should be done only as a last resort: you can browse only one domain at a time at that host_suffix, and unless you use HTML-only mode, most links and HTTP redirects to other domains will leave the adjuster (which can negatively affect sites that use auxiliary domains for scripts etc and check Referer, unless you ensure these auxiliary domains are listed elsewhere in default_site), and browsers that donât include cookies in their AJAX requests will have problems.âAlso, the sites you visit at that host_suffix might be able to see some of each otherâs cookies etc (leaking privacy) although the URL box page will try to clear site cookies.
- --default-site The site to fetch from if nothing is specified before host_suffix, e.g. example.org (add .0 at the end to specify an HTTPS connection, but see the âprohibitâ option).âIf default_site is omitted then the user is given a URL box when no site is specified; if it is âerrorâ then an error is shown in place of the URL box (the text of the error depends on the settings of wildcard_dns and real_proxy).
- --search-sites Comma-separated list of search sites to be made available when the URL box is displayed (if default_site is empty).âEach item in the list should be a URL (which will be prepended to the search query), then a space, then a short description of the site.âThe first item on the list is used by default; the user can specify other items by making the first word of their query equal to the first word of the short description.âAdditionally, if some of the letters of that first word are in parentheses, the user may specify just those letters.âSo for example if you have an entry http://search.example.com/?q= (e)xample, and the user types âexample testâ or âe testâ, it will use http://search.example.com/?q=test
- --urlbox-extra-html Any extra HTML you want to place after the URL box (when shown), such as a paragraph explaining what your filters do etc.
- --urlboxPath (default /) The path of the URL box for use in links to it.âThis might be useful for wrapper configurations, but a URL box can be served from any path on the default domain.âIf however urlboxPath is set to something other than / then efforts are made to rewrite links to use it more often when in HTML-only mode with cookie domain, which might be useful for limited-server situations.âYou can force HTML-only mode to always be on by prefixing urlboxPath with *
- --wildcard-dns (default True) Set this to False if you do not have a wildcard domain and want to process only default_site.âSetting this to False does not actually prevent other sites from being processed (for example, a user could override their local DNS resolver to make up for your lack of wildcard domain); if you want to really prevent other sites from being processed then you should get nginx or similar to block incoming requests for the wrong domain.âSetting wildcard_dns to False does stop the automatic re-writing of links to sites other than default_site.âLeave it set to True to have all sitesâ links rewritten on the assumption that you have a wildcard domain.
General adjustment options
- --default-cookies Semicolon-separated list of name=value cookies to send to all remote sites, for example to set preferences.âAny cookies that the browser itself sends will take priority over cookies in this list.âNote that these cookies are sent to all sites.âYou can set a cookie only on a specific browser by putting (browser-string) before the cookie name, e.g. (iPad)x=y will set x=y only if âiPadâ occurs in the browser string (to match more than one browser-string keyword, you have to specify the cookie multiple times).
- --headAppend Code to append to the HEAD section of every HTML document that has a BODY.âUse for example to add your own stylesheet links and scripts.âNot added to documents that lack a BODY such as framesets.
- --headAppendCSS URL of a stylesheet to add to the HEAD section of every HTML document that has a BODY.âThis option automatically generates the LINK REL=... markup for it, and also tries to delete the string â!importantâ from other stylesheets, to emulate setting this stylesheet as a user CSS.âAdditionally, it is not affected by --js-upstream as headAppend is.âYou can also include one or more âfieldsâ in the URL, by marking them with %s and following the URL with options e.g. http://example.org/style%s-%s.css;1,2,3;A,B will allow combinations like style1-A.css or style3-B.css; in this case appropriate selectors are provided with the URL box (values may optionally be followed by = and a description), and any visitors who have not set their options will be redirected to the URL box to do so.
- --protectedCSS A regular expression matching URLs of stylesheets with are âprotectedâ from having their â!importantâ strings deleted by headAppendCSSâs logic.âThis can be used for example if you are adding scripts to allow the user to choose alternate CSS files in place of headAppendCSS, and you wish the alternate CSS files to have the same status as the one supplied in headAppendCSS.
- --cssName A name for the stylesheet specified in headAppendCSS, such as âHigh Contrastâ.âIf cssName is set, then the headAppendCSS stylesheet will be marked as âalternateâ, with Javascript links at the bottom of the page for browsers that lack their own CSS switching options.âIf cssName begins with a * then the stylesheet is switched on by default; if cssName begins with a # then the stylesheet is switched on by default only if the browser reports system dark mode; if cssName is not set then the stylesheet (if any) is always on.
- --cssNameReload (default IEMobile 6, IEMobile 7, IEMobile 8, Opera Mini, Opera Mobi, rekonq, MSIE 5, MSIE 6, MSIE 7, MSIE 9, MSIE 10) List of (old) browsers that require alternate code for the cssName option, which is slower as it involves reloading the page on CSS switches.âUse this if the CSS switcher provided by cssName does nothing on your browser.
- --cssHtmlAttrs Attributes to add to the BODY element of an HTML document when cssNameReload is in effect (or when it would be in effect if cssName were set).âThis is for old browsers that try to render the document first and apply CSS later.âExample: âtext=âyellowâ bgcolor=âblackââ (not as flexible as CSS but can still make the rendering process less annoying).âIf headAppendCSS has âfieldsâ then cssHtmlAttrs can list multiple sets of attributes separated by ; and each set corresponds with an option in the last field of headAppendCSS.
- --headAppendRuby (default False) Convenience option which adds CSS and Javascript code to the HTML body that tries to ensure simple RUBY markup displays legibly across all modern browsers; this might be useful if you used Annotator Generator to make the htmlFilter program.â(The option is named âheadâ because it used to add markup to the HEAD; this was moved to the BODY to work around browser bugs.)
- --highlighting Convenience option which adds CSS and Javascript code to add a text-highlighting option to some browsers.âIf set, this option should be set to a comma-separated list of available colours (please ensure thereâs at least one for each stylesheet colour scheme likely to be in use); wonât work well with --render because images are not highlighted.âHighlights are saved in the browser, but might load incorrectly if the pageâs text changes between sessions.
- --bodyAppend Code to append to the BODY section of every HTML document that has one.âUse for example to add a script that needs to be run after the rest of the body has been read, or to add a footer explaining how the page has been modified.âSee also prominentNotice.
- --bodyAppendGoesAfter If this is set to a regular expression matching some text or HTML code that appears verbatim in the body section, the code in bodyAppend will be inserted after the last instance of this regular expression (case sensitive) instead of at the end of the body.âUse for example if a site styles its pages such that the end of the body is not a legible place for a footer.
- --bodyPrepend Code to place at the start of the BODY section of every HTML document that has one.
- --prominentNotice Text to add as a prominent notice to processed sites (may include HTML).âIf the browser has sufficient Javascript support, this will float relative to the browser window and will contain an âacknowledgeâ button to hide it (for the current site in the current browsing session).âUse prominentNotice if you need to add important information about how the page has been modified.âIf you set prominentNotice to the special value âhtmlFilterâ, then the output of the htmlFilter option (if any) will be placed as a prominent notice; this can be used if you want to provide extra information or links derived from the content of the page.âNote: if you include Javascript document.write() code in prominentNotice, check that document.readyState is not âcompleteâ or you might find the document is erased on some website/browser combinations when a site script somehow causes your script to be re-run after the document stream is closed.âIn some rare cases you might also need to verify that document.cookie does not contain _WA_warnOK=1
- --staticDocs url#path of static documents to add to every website, e.g. /_myStatic/#/var/www (make sure the first part is something not likely to be used by the websites you visit).âThis can be used to supply extra Javascript (e.g. for bodyPrepend to load) if it needs to be served from the same domain.âThe password option does not apply to staticDocs.
- --delete Comma-separated list of regular expressions to delete from HTML documents.âCan be used to delete selected items of Javascript and other code if it is causing trouble for your browser.âWill also delete from the text of pages; use with caution.
- --delete-css Comma-separated list of regular expressions to delete from CSS documents (but not inline CSS in HTML); can be used to remove, for example, dimension limits that conflict with annotations you add, as an alternative to inserting CSS overrides.âIn rare cases you might want to replace the deleted regexp with another, in which case you can use @@ to separate the two, and a second @@ can be used to specify a string in the CSS URL that must be present for the operation to take effect (this could be combined with a codeChanges to add query parameters to the URL if you want the change to occur only when the CSS is loaded from specific HTML pages).
- --delete-doctype (default False) Delete the DOCTYPE declarations from HTML pages.âThis option is needed to get some old Webkit browsers to apply multiple CSS files consistently.
- --deleteOmit (default iPhone, iPad, Android, Macintosh) A list of browsers that do not need the delete and delete-doctype options to be applied.âIf any of these strings occur in the user-agent then these options are disabled for that request, on the assumption that these browsers are capable enough to cope with the âproblemâ code.âAny delete-css option is still applied however.
- --cacheOmit (default IEMobile) A list of browsers that cannot be trusted to provide correct Cache-Control headers.âUse this if your browser fails to renew data when you press Reload.
- --zeroWidthDelete (default IEMobile, MSIE 6) A list of (old) browsers that cannot be relied on to process Unicode zero-width space (U+200b) correctly and need it removed from websites
- --codeChanges Several lines of text specifying changes that are to be made to all HTML and Javascript code files on certain sites; use as a last resort for fixing a siteâs scripts.âThis option is best set in the configuration file and surrounded by r"""...""".âThe first line is a URL prefix (just âhttpâ matches all); append a # to match an exact URL instead of a prefix, and #+number (e.g. #1 or #2) to match an exact URL and perform the change only that number of times in the page.âThe second line is a string of code to search for, and the third is a string to replace it with.âFurther groups of URL/search/replace lines may follow; blank lines and lines starting with # are ignored.âIf the âURL prefixâ starts with a * then it is instead a string to search for within the code of the document body; any documents containing this code will match; thus itâs possible to write rules of the form âif the code contains A, then replace B with Câ. This processing takes place before any âdeleteâ option takes effect so itâs possible to pick up on things that will be deleted, and it occurs after the domain rewriting so itâs possible to change rewritten domains in the search/replace strings (but the URL prefix above should use the non-adjusted version).
- --boxPrompt (default Website to adjust) What to say before the URL box (when shown); may include HTML; for example if youâve configured Web Adjuster to perform a single specialist change that can be described more precisely with some word other than âadjustâ, you might want to set this.
- --viewsource (default False) Provide a âview sourceâ option.âIf set, you can see a pageâs pre-adjustment source code, plus client and server headers, by adding â.viewsourceâ to the end of a URL (after any query parameters etc)
- --htmlonly-mode (default True) Provide a checkbox allowing the user to see pages in âHTML-only modeâ, stripping out images, scripts and CSS; this might be a useful fallback for very slow connections if a siteâs pages bring in many external files and the browser cannot pipeline its requests.âThe checkbox is displayed by the URL box, not at the bottom of every page.
- --htmlonly-css (default False) Leave images and CSS in the page when in âHTML-only modeâ, removing only scripts
- --mailtoPath (default /@mail@to@__) A location on every adjusted website to put a special redirection page to handle mailto: links, showing the user the contents of the link first (in case a mail client is not set up).âThis must be made up of URL-safe characters starting with a / and should be a path that is unlikely to occur on normal websites and that does not conflict with renderPath.âIf this option is empty, mailto: links are not changed.â(Currently, only plain HTML mailto: links are changed by this function; Javascript-computed ones are not.)
- --mailtoSMS (default Opera Mini, Opera Mobi, Android, Phone, Mobile) When using mailtoPath, you can set a comma-separated list of platforms that understand sms: links.âIf any of these strings occur in the user-agent then an SMS link will be provided on the mailto redirection page, to place the suggested subject and/or body into a draft SMS message instead of an email.
External processing options
- --htmlFilter External program(s) to run to filter every HTML document.âIf more than one program is specified separated by # then the user will be given a choice (see htmlFilterName option).âAny shell command can be used; its standard input will get the HTML (or the plain text if htmlText is set), and it should send the new version to standard output.âMultiple copies of each program might be run at the same time to serve concurrent requests.âUTF-8 character encoding is used.âIf you are not able to run external programs then you could use a back-end server (specify an http:// or https:// URL and input is POSTed in the request body; if this back-end server is another Web Adjuster with submitPath and submitBookmarklet set then give its submitPath plus uA for its 1st filter, uB for its 2nd, etc), or use a Python function: specify * followed by the function name, and inject the function into the adjuster module from a wrapper script (which imports adjuster, sets adjuster.options.htmlFilter etc, injects the function and calls adjuster.main).âThe function should take a byte-string and return its modified version, and is run in the serving thread.âSee also htmlUrl and htmlonly_tell_filter options.
- --htmlFilterName A name for the task performed by htmlFilter.âIf this is set, the user will be able to switch it on and off from the browser via a cookie and some Javascript links at the bottom of HTML pages.âIf htmlFilter lists two or more options, htmlFilterName should list the same number plus one (again separated by #); the first is the name of the entire category (for example âfiltersâ), and the user can choose between any one of them or none at all (hence the number of options is one more than the number of filters); if this yields more than 3 options then all but the first two are hidden behind a âMoreâ option on some browsers.
- --htmlJson (default False) Try to detect HTML strings in JSON responses and feed them to htmlFilter.âThis can help when using htmlFilter with some AJAX-driven sites.âImportant: Unless you also set the âseparatorâ option, the external program must preserve all newline characters, because multiple HTML strings in the same JSON response will be given to it separated by newlines, and the newlines of the output determine which fragment to put back where.â(If you combine htmlJson with htmlText, the external program will see text in HTML in JSON as well as text in HTML, but it wonât see text in HTML in JSON in HTML.)
- --htmlText (default False) Causes the HTML to be parsed, and only the text parts (not the markup) will be sent to htmlFilter.âUseful to save doing HTML parsing in the external program.âThe external program is still allowed to include HTML markup in its output.âImportant: Unless you also set the âseparatorâ option, the external program must preserve all newline characters, because multiple text strings will be given to it separated by newlines, and the newlines of the output determine which modified string to put back where.
- --separator If you are using htmlFilter with htmlJson and/or htmlText, you can set separator to any text string to be used as a separator between multiple items of data when passing them to the external program.âBy default, newlines are used for this, but you can set it to any other character or sequence of characters that cannot be added or removed by the program.â(It does not matter if a websiteâs text happens to use the separator characters.)âIf separator is set, not only will it be used as a separator between items of data but also it will be added before the first and after the last item, thus allowing you to use an external program that outputs extra text before the first and after the last item.âThe extra text will be discarded.âIf however you do not set separator then the external program should not add anything extra before/after the document.
- --leaveTags (default script, style, title, textarea, option) When using htmlFilter with htmlText, you can set a comma-separated list of HTML tag names whose enclosed text should not be sent to the external program for modification.âFor this to work, the website must properly close these tags and must not nest them.â(This list is also used for character-set rendering.)
- --stripTags (default wbr) When using htmlFilter with htmlText, you can set a comma-separated list of HTML tag names which should be deleted if they occur in any section of running text.âFor example, âwbrâ (word-break opportunity) tags (listed by default) might cause problems with phrase-based annotators.
- --htmlUrl (default False) Add a line containing the documentâs URL to the start of what gets sent to htmlFilter (useful for writing filters that behave differently for some sites; not yet implemented for submitBookmarklet, which will show a generic URL).âThe URL line must not be included in the filterâs response.
- --htmlonly-tell-filter (default False) Add a line showing the current status of âHTML-only modeâ (see htmlonly_mode option) to the start of what gets sent to htmlFilter (before any htmlUrl if present), as âTrueâ or âFalseâ (must not be included in the filterâs response).âThis may be useful for filters that need to do extra processing if client-side scripts are removed.
- --submitPath If set, accessing this path (on any domain) will give a form allowing the user to enter their own text for processing with htmlFilter.âThe path should be one that websites are not likely to use (even as a prefix), and must begin with a slash (/). If you prefix this with a * then the * is removed and any password set in the âpasswordâ option does not apply to submitPath.âDetails of the text entered on this form is not logged by Web Adjuster, but short texts are converted to compressed GET requests which might be logged by proxies etc.
- --submitPrompt (default Type or paste in some text to adjust) What to say before the form allowing users to enter their own text when submitPath is set (compare boxPrompt)
- --submitBookmarklet (default True) If submitPath and htmlFilter is set, and if browser Javascript support seems sufficient, then add one or more âbookmarkletsâ to the âUpload Textâ page (named after htmlFilterName if provided), allowing the user to quickly upload text from other sites.âThis might be useful if for some reason those sites cannot be made to go through Web Adjuster directly.âThe bookmarklets should work on modern desktop browsers and on iOS and Android; they should cope with frames and with Javascript-driven changes to a page, and on some browsers an option is provided to additionally place the page into a frameset so that links to other pages on the same site can be followed without explicitly reactivating the bookmarklet (but this does have disadvantagesâpage must be reloaded + URL display gets âstuckââso itâs left to the user to choose).
- --submitBookmarkletFilterJS (default !c.nodeValue.match(/^[ -~\s]*$/)) A Javascript expression that evaluates true if a DOM text node âcâ should be processed by the âbookmarkletâ Javascript when submitPath and submitBookmarklet are set.âTo process all text, set this option to c.nodeValue.length, but if your htmlFilter will not change certain kinds of text then you can make the Javascript run more efficiently by not processing these (quote the expression carefully).âThe default setting will not process text that is all ASCII.
- --submitBookmarkletChunkSize (default 1024) Specifies the approximate number of characters at a time that the âbookmarkletâ Javascript will send to the server if submitPath and submitBookmarklet are set.âSetting this too high could impair browser responsiveness, but too low will be inefficient with bandwidth and pages will take longer to finish.
- --submitBookmarkletDomain If set, specifies a domain to which the âbookmarkletâ Javascript should send its XMLHttpRequests, and ensures that they are sent over HTTPS if the âbookmarkletâ is activated from an HTTPS page (this is needed by some browsers to prevent blocking the XMLHttpRequest). submitBookmarkletDomain should be a domain for which the adjuster (or an identically-configured copy) can receive requests on both HTTP and HTTPS, and which has a correctly-configured HTTPS front-end with valid certificate.
- --letsEncryptWarning (default False) Indicates that submitBookmarkletDomain (if set) has an HTTPS server that uses a certificate from LetsEncrypt, and we should warn users of certain old browsers that they wonât accept it by default now LetsEncryptâs X3 expired at the end of September 2021
- --submitBookmarkletRemoveExistingRuby (default True) Specifies that âbookmarkletsâ added to the âUpload textâ page should remove all existing ruby on a page before running.âUse this for example if you expect to replace the text with ruby of a different kind of annotation.
Javascript execution options
- --js-interpreter Execute Javascript on the server for users who choose âHTML-only modeâ.âYou can set js_interpreter to PhantomJS, HeadlessChrome, HeadlessFirefox, Chrome, Firefox, or edbrowse (experimental), and must have the appropriate one installed, along with an appropriate version of Selenium (and ChromeDriver or GeckoDriver if appropriate) if not using edbrowse.âNon-headless Chrome or Firefox requires a display (and might not respond to manual window close) but may help work around bugs in some headless versions.âIf you have multiple users, beware logins etc may be shared!âIf a URL box cannot be displayed (no wildcard_dns and default_site is full, or processing a ârealâ proxy request) then htmlonly_mode auto-activates when js_interpreter is set, thus providing a way to partially Javascript-enable browsers like Lynx.âIf --viewsource is enabled then js_interpreter URLs may also be followed by .screenshot
- --js-upstream (default False) Handle --headAppend, --bodyPrepend, --bodyAppend and --codeChanges upstream of our Javascript interpreter instead of making these changes as code is sent to the client, and make --staticDocs available to our interpreter as well as to the client.âThis is for running experimental âbookmarkletsâ etc with browsers like Lynx.
- --js-frames (default False) When using js_interpreter, append the content of all frames and iframes to the main document.âThis might help with bandwidth reduction and with sites that have complex cross-frame dependencies that can be broken by sending separate requests through the adjuster.
- --js-instances (default 1) The number of virtual browsers to load when js_interpreter is in use.âIncreasing it will take more RAM but may aid responsiveness if youâre loading multiple sites at once.
- --js-429 (default True) Return HTTP error 429 (too many requests) if js_interpreter queue is too long at page-prefetch time.âWhen used with --multicore, additionally close to new requests any core thatâs currently processing its full share of js_instances.
- --js-restartAfter (default 10) When js_interpreter is in use, restart each virtual browser after it has been used this many times (0=unlimited); might help work around excessive RAM usage in PhantomJS v2.1.1. If you have many --js-instances (and hardware to match) you could also try --js-restartAfter=1 (restart after every request) to work around runaway or unresponsive PhantomJS processes.
- --js-restartMins (default 10) Restart an idle js_interpreter instance after about this number of minutes (0=unlimited); use this to stop the last-loaded page from consuming CPU etc indefinitely if no more requests arrive at that instance.âNot applicable when --js-restartAfter=1.
- --js-timeout1 (default 30) When js_interpreter is in use, tell it to allow this number of seconds for initial page load.âMore time is allowed for XMLHttpRequest etc to finish (unless our client cuts the connection in the meantime).
- --js-timeout2 (default 100) When js_interpreter is in use, this value in seconds is treated as a âhard timeoutâ: if a webdriver process does not respond at all within this time, it is assumed hung and emergency restarted.
- --js-retry (default True) If a js_interpreter fails, restart it and try the same fetch again while the remote client is still waiting
- --js-fallback (default X-Js-Fallback) If this is set to a non-empty string and a js_interpreter fails (even after js_retry if set), serve the page without Javascript processing instead of serving an error.âThe HTTP header specified by this option can tell the client whether or not Javascript was processed when a page is served.
- --js-reproxy (default True) When js_interpreter is in use, have it send its upstream requests back through the adjuster on a different port.âThis allows js_interpreter to be used for POST forms, fixes its Referer headers when not using real_proxy, monitors AJAX for early completion, prevents problems with file downloads, and enables the js_prefetch option.
- --js-prefetch (default True) When running with js_reproxy, prefetch main pages to avoid holding up a js_interpreter instance if the remote server is down.âTurn this off if you expect most remote servers to be up and you want to detect js_429 issues earlier.
- --js-UA Custom user-agent string for js_interpreter requests, if for some reason you donât want to use the JS browserâs default (or the clientâs if js_reproxy is on and js_prefetch off).âIf you prefix js_UA with a * then the * is removed and the user-agent string is set by the upstream proxy (--js_reproxy) so scripts running in the JS browser itself will see its original user-agent.
- --js-images (default True) When js_interpreter is in use, instruct it to fetch images just for the benefit of Javascript execution.âSetting this to False saves bandwidth but misses out image onload events.
- --js-size (default 1024x768) The virtual screen dimensions of the browser when js_interpreter is in use (changing it might be useful for screenshots)
- --js-links (default True) When js_interpreter is in use, handle some Javascript links via special suffixes on href URLs.âTurn this off if you donât mind such links not working and you want to ensure URLs are unchanged modulo domain-rewriting.
- --js-multiprocess (default True) When js_interpreter is in use, handle the webdriver instances in completely separate processes (not just separate threads) when the multiprocessing module is available and working.âRecommended: if a webdriver instance gets âstuckâ in a way that somehow hangs its controlling process, we can detect and restart it.
- --ssl-fork (default False) (Unix only) Run SSL-helper proxies as separate processes to stop the main event loop from being stalled by buggy SSL libraries.âThis costs RAM, but adding --multicore too will limit the number of helpers to one per core instead of one per port, so --ssl-fork --multicore is recommended if you want more js_interpreter instances than cores.
Server control options
- --background (default False) (Unix only) Fork to the background as soon as the server has started.âYou might want to enable this if you will be running it from crontab, to avoid long-running cron processes.
- --restart (default False) (Unix only) Try to terminate any other process listening on our port number before we start.âUseful if Web Adjuster is running in the background and you want to quickly restart it with new options.âNote that no check is made to make sure the other process is a copy of Web Adjuster; whatever it is, if it has our port open, it is asked to stop.
- --stop (default False) (Unix only) Like ârestartâ, but donât replace the other process after stopping it.âThis option can be used to stop a background server (if itâs configured with the same port number) without starting a new one.
- --install (default False) Try to install the program in the current userâs Unix crontab as an @reboot entry, unless itâs already there.âThe arguments of the cron entry will be the same as the command line, with no directory changes, so make sure you are in the home directory before doing this.âThe program will continue to run normally after the installation attempt.â(If you are on Cygwin then you might need to run cron-config also.)
- --pidfile Write our process ID to this file when running in the background, so you can set up a systemd service with Type=forking and PIDFile=this instead of using crontab.â(Alternatively use âpip install sdnotifyâ and run in the foreground with Type=notify.)
- --browser The Web browser command to run.âIf this is set, Web Adjuster will run the specified command (which is assumed to be a web browser), and will exit when this browser exits.âThis is useful in conjunction with --real_proxy to have a personal proxy run with the browser.âYou still need to set the browser to use the proxy; this can sometimes be done via browser command line or environment variables.
- --run A command to run that is not a browser.âIf set, Web Adjuster will run the specified command and will restart it if it stops.âThe command will be stopped when Web Adjuster is shut down.âThis could be useful, for example, to run an upstream proxy.
- --runWait (default 1) The number of seconds to wait before restarting the ârunâ command if it fails
Media conversion options
- --bitrate (default 0) Audio bitrate for MP3 files, or 0 to leave them unchanged.âIf this is set to anything other than 0 then the âlameâ program must be present.âBitrate is normally a multiple of 8. If your mobile device has a slow link, try 16 for speech.
- --askBitrate (default False) If True, instead of recoding MP3 files unconditionally, try to add links to âlo-fiâ versions immediately after each original link so you have a choice.
- --pdftotext (default False) If True, add links to run PDF files through the âpdftotextâ program (which must be present if this is set).âA text link will be added just after any PDF link that is found, so that you have a choice of downloading PDF or text; note that pdftotext does not always manage to extract all text (you can use --pdfomit to specify URL patterns that should not get text links).âThe htmlJson setting will also be applied to the PDF link finder, and see also the guessCMS option.
- --pdfomit A comma-separated list of regular expressions which, if any are found in a PDF linkâs URL, will result in a text link not being generated for that PDF link (although a conversion can still be attempted if a user manually enters the modified URL).âUse this to avoid confusion for PDF files you know cannot be converted.
- --epubtotext (default False) If True, add links to run EPUB files through Calibreâs âebook-convertâ program (which must be present), to produce a text-only option (or a MOBI option if a Kindle is in use).âA text link will be added just after any EPUB link that is found, so that you have a choice of downloading EPUB or text.âThe htmlJson setting will also be applied to the EPUB link finder, and see also the guessCMS option.
- --epubtozip (default False) If True, add links to download EPUB files renamed to ZIP, as a convenience for platforms that donât have EPUB readers but can open them as ZIP archives and display the XHTML files they contain.âThe htmlJson setting will also be applied to the EPUB link finder, and see also the guessCMS option.
- --guessCMS (default False) If True, then the pdftotext, epubtotext and epubtozip options attempt to guess if a link is pointing to a PDF or EPUB file via a Content Management System (i.e. the URL does not end in .pdf or .epub, but contains something like ?format=PDF)
- --pdfepubkeep (default 200) Number of seconds to keep any generated text files from PDF and EPUB.âIf this is 0, the files will be deleted immediately, but that might be undesirable: if a mobile phone browser has a timeout that takes effect before ebook-convert has finished (this can sometimes be the case with Opera Mini for example), it might be best to allow the user to wait a short time and re-submit the request, this time getting a cached response.
- --waitpage (default True) If the browser seems to be an interactive one, generate a âplease waitâ page while converting PDF or EPUB files to text.âNot effective if pdfepubkeep is set too low.
Character rendering options
- --render (default False) Whether to enable the character-set renderer.âThis functionality requires the Python Imaging Library and suitable fonts.âThe settings of htmlJson and leaveTags will also be applied to the renderer.âText from computed Javascript writes might not be rendered as images.
- --renderFont The font file to use for the character-set renderer (if enabled).âThis should be a font containing all the characters you want to render, and it should be in .TTF, .OTF or other Freetype-supported format (.PCF is sometimes possible if renderSize is set correctly, e.g. 16 for wenquanyi_12pt.pcf)
- --renderInvert (default False) If True, the character-set renderer (if enabled) will use a black background.âUseful when you are also adding a stylesheet with a dark background.
- --renderSize (default 20) The height (in pixels) to use for the character-set renderer if it is enabled.
- --renderPath (default /@_) The location on every adjusted website to put the character-set rendererâs images, if enabled.âThis must be made up of URL-safe characters starting with a / and should be a short path that is unlikely to occur on normal websites.
- --renderFormat (default png) The file format of the images to be created by the character-set renderer if it is enabled, for example âpngâ or âjpegâ.
- --renderRange The lowest and highest Unicode values to be given to the character-set renderer if it is enabled.âFor example 3000:A6FF for most Chinese characters.âMultiple ranges are allowed.âAny characters not in one of the ranges will be passed to the browser to render.âIf the character-set renderer is enabled without renderRange being set, then all text will be rendered to images.
- --renderOmit (default iPhone, iPad, Android, CrOS, Macintosh, Windows NT 6, Windows NT 10, Windows Phone OS, Lynx/2) A list of platforms that do not need the character-set renderer.âIf any of these strings occur in the user-agent then the character set renderer is turned off even if it is otherwise enabled, on the assumption that these platforms either have enough fonts already, or wouldnât show the rendered images anyway.
- --renderOmitGoAway (default False) If set, any browsers that match renderOmit will not be allowed to use the adjuster.âThis is for servers that are set to do character rendering only and do not have enough bandwidth for people who donât need this function and just want a proxy.
- --renderCheck If renderOmit does not apply to the browser, it might still be possible to check for native character-set support via Javascript. renderCheck can be set to the Unicode value of a character to be checked (try 802F for complete Chinese support); if the browser reports its width differently from known unprintable characters, we assume it wonât need our renderer.
- --renderNChar (default 1) The maximum number of characters per image to be given to the character-set renderer if it is enabled.âKeeping this low means the browser cache is more likely to be able to re-use images, but some browsers might struggle if there are too many separate images.âDonât worry about Unicode âcombining diacriticâ codes: any found after a character that is to be rendered will be included with it without counting toward the renderNChar limit and without needing to be in renderRange.
- --renderWidth (default 0) The maximum pixel width of a âwordâ when using the character-set renderer.âIf you are rendering a language that uses space to separate words, but are using only one or two characters per image, then the browser might split some words in the middle.âSetting renderWidth to some value other than 0 can help to prevent this: any word narrower than renderWidth will be enclosed in a <nobr> element.â(This will however be ineffective if your stylesheet overrides the behaviour of <nobr>.) You should probably not set renderWidth if you intend to render languages that do not separate words with spaces.
- --renderDebug (default False) If the character-set renderer is having problems, try to insert comments in the HTML source to indicate why.âThe resulting HTML is not guaranteed to be well-formed, but it might help you debug a misbehaving htmlFilter.âThis option may also insert comments in bad HTML before the htmlFilter stage even when the renderer is turned off.
- --renderName (default Fonts) A name for a switch that allows the user to toggle character set rendering on and off from the browser (via a cookie and Javascript links at the bottom of HTML pages); if set to the empty string then no switch is displayed.âAt any rate none is displayed when renderOmit applies.
Dynamic DNS options
- --ip-change-command An optional script or other shell command to launch whenever the public IP address changes.âThe new IP address will be added as a parameter; ip_query_url must be set to make this work.âThe script can for example update any Dynamic DNS services that point to the server.
- --ip-change-tries (default 1) Number of times to run ip_change_command if it returns failure (0 means unlimited, which is not recommended).âFor example, you can have the script return failure if it doesnât get either an âUpdatedâ or an expected ânot changedâ response from a Dynamic DNS service (but it is not advisable to expect a host lookup to reflect the change immediately)
- --ip-change-delay (default 5) Number of seconds to delay between tries of ip_change_command if it fails
- --ip-query-url URL that will return your current public IP address, as a line of text with no markup added.âUsed for the ip_change_command option.âYou can set up a URL by placing a CGI script on a server outside your network and having it do: echo Content-type: text/plain;echo;echo $REMOTE_ADDR (but if you want your IPv4 address, ensure the adjuster machine and the outside server are not both configured for IPv6).âIf you have a known static IP address but still want to run an ip_change_command for it, you can set ip_query_url to the static IP address instead of a URL.
- --ip-query-url2 Optional additional URL that might sometimes return your public IP address along with other information.âThis can for example be a status page served by a local router (http://user:password@192.168... is accepted, and if the password is the name of an existing file then its contents are read instead).âIf set, the following behaviour occurs: Once ip_check_interval has passed since the last ip_query_url check, ip_query_url2 will be queried at an interval of ip_check_interval2 (which can be short), to check that the known IP is still present in its response.âOnce the known IP is no longer present, ip_query_url will be queried again.âThis arrangement can reduce the load on ip_query_url while allowing a reduced ip_check_interval for faster response to IP changes, while not completely trusting the local router to report the correct IP at all times.â(If itâs notoriously unleriable then it might be best not to reduce ip_check_interval, in which case at least youâll get a faster response once the initial ip_check_interval wait has passed after the previous IP change; this however might not be suitable if youâre behind a router that is frequently rebooting.)âSee also ip_query_aggressive if the router might report an IP change before connectivity is restored.âYou may also set ip_query_url2 to the special value âupnpâ if you want it to query a router via UPnP (miniupnpc package required).
- --ip-check-interval (default 8000) Number of seconds between checks of ip_query_url for the ip_change_command option
- --ip-check-interval2 (default 60) Number of seconds between checks of ip_query_url2 (if set), for the ip_change_command option
- --ip-query-aggressive (default False) If a query to ip_query_url fails with a connection error or similar, keep trying again until we get a response.âThis is useful if the most likely reason for the error is that our ISP is down: we want to get the new IP just as soon as weâre back online.âHowever, if the error is caused by a problem with ip_query_url itself then this option can lead to excessive traffic, so use with caution.â(Log entries are written when this option takes effect, and checking the logs is advisable.)
- --ip-force-interval (default 604800) Number of seconds before ip_change_command (if set) is run even if there was no IP change.âThis is to let Dynamic DNS services know that we are still around.âSet to 0 to disable forced updates (a forced update will occur on server startup anyway), otherwise an update will occur on the next IP check after ip_force_interval has elapsed.
- --pimote Use an Energenie Pi-mote home control system to power-cycle the router when its Internet connection appears to be stuck in a bad state.âThis option works only if Web Adjuster is running on the Raspberry Pi and as a user in the âgpioâ group.âIt must be set to R,S,I,D where R is the internal IP address of your router, S is the domain of your Internet service provider (assumed to be quick to look up), I is the IP provided by your routerâs built-in DNS when itâs having trouble (e.g. Post Office Broadbandâs AMG1302-derived router responds with 219.87.158.116 which is presumably Zyxelâs office in Taiwan), and D is the Pi-mote device ID (1 to 4 or all) used to switch it off and on again.âPower-cycling will be initiated if two queries to the routerâs DNS for its ISP domain either fail or return internalResponse, and itâs assumed router caching will let us check status frequently without causing traffic.
Speedup options
- --useLXML (default False) Use the LXML library for parsing HTML documents.âThis is usually faster, but it can fail if your system does not have a good installation of LXML and its dependencies.âUse of LXML libraries may also result in more changes to all HTML markup: this should be harmless for browsers, but beware when using options like bodyAppendGoesAfter then you might or might not be dealing with the original HTML depending on which filters are switched on.
- --usepycurl (default True) Use the pycurl library if a suitable version is available (setting this to False might save a little RAM at the expense of remote-server tolerance)
- --renderBlocks (default False) Treat all characters rendered by the character-set renderer as âblocksâ that are guaranteed to have the same dimensions (true for example if you are using the renderer for Chinese characters only).âThis is faster than checking words individually, but it may produce misprints if given a range of characters whose dimensions do differ.
- --fasterServer Address:port of another instance of Web Adjuster to which we forward all traffic whenever it is available.âWhen the other instance is not available, traffic will be handled by this one.âUse for example if you have a slower always-on machine and a faster not-always-on machine and you want the slower machine to delegate to the faster machine when available.âSee also ipTrustReal.
- --ipTrustReal IP address of a machine that we trust, for example a machine that is using us as fasterServer.âAny traffic coming from this machine with an X-Real-Ip header will be logged as though it originated at the value of its X-Real-Ip header.âSetting this to * will cause X-Real-Ip to be trusted from any connection.
- --trust-XForwardedFor (default False) Like ipTrustReal but trusts X-Forwarded-For header from any IP if set to True (use this in an environment where the adjuster can be reached only via a load balancer etc)
- --fasterServerNew (default True) If fasterServer is set, assume it is running Web Adjuster v0.17 or later and use a more lightweight method of checking its availability.âYou might need to set this to False if for some reason you canât upgrade the fasterServer first.
- --machineName A name for the current machine to insert into the âServerâ HTTP header for adjusted requests, for example to let users know if itâs your faster or your slower machine thatâs currently serving them (although theyâd need to inspect the headers to find out)
- --redirectFiles (default False) If, when not functioning as a ârealâ HTTP proxy, a URL is received that looks like it requires no processing on our part (e.g. an image or downloadable file that the user does not want converted), and if this is confirmed via a HEAD request to the remote server, then redirect the browser to fetch it directly and not via Web Adjuster.âThis takes bandwidth off the adjuster server, and should mean faster downloads, especially from sites that are better connected than the adjuster machine.âHowever it might not work with sites that restrict âdeep linkingâ.â(As a precaution, the confirmatory HEAD request is sent with a non-adjusted Referer header to simulate what the browser would send if fetching directly.âIf this results in an HTML âReferer deniedâ message then Web Adjuster will proxy the request in the normal way.âThis precaution might not detect all means of deep-linking denial though.)
- --upstream-guard (default True) Modify scripts and cookies sent by upstream sites so they do not refer to the cookie names that our own scripts use.âThis is useful if you chain together multiple instances of Web Adjuster, such as for testing another installation without coming out of your usual proxy.âIf however you know that this instance will not be pointed to another, you can set upstream_guard to False to save some processing.
- --skipLinkCheck Comma-separated list of regular expressions specifying URLs to which we wonât try to add or modify links for the pdftotext, epubtotext, epubtozip, askBitrate or mailtoPath options.âThis processing can take some time on large index pages with thousands of links; if you know that none of them are PDF, EPUB, MP3 or email links, or if you donât mind not processing any that are, then it saves time to skip this step for those pages.
- --extensions Name of a custom Python module to load to handle certain requests; this might be more efficient than setting up a separate Tornado-based server.âThe moduleâs handle() function will be called with the URL and RequestHandler instance as arguments, and should return True if it processed the request, but anyway it should return as fast as possible.âThis module does not take priority over forwarding the request to fasterServer.
- --loadBalancer (default False) Set this to True if you have a default_site set and you are behind any kind of âload balancerâ that works by issuing a GET / with no browser string.âThis option will detect such requests and avoid passing them to the remote site.
- --multicore (default False) (Linux and BSD) On multi-core CPUs, fork enough processes for all cores to participate in handling incoming requests.âThis increases RAM usage, but can help with high-load situations.âDisabled on Mac due to unreliability (other cores can still be used for htmlFilter etc)
- --num-cores (default 0) Set the number of CPU cores for the multicore option (0 for auto-detect)
- --internalPort (default 0) The first port number to use for internal purposes when ssl_fork is in effect.âInternal ports needed by real_proxy (for SSL) and js_reproxy are normally allocated from the ephemeral port range, but if ssl_fork delegates to independent processes then some of them need to be at known numbers.âThe default of 0 means one higher than âportâ; several unused ports may be needed starting at this number.âIf your Tornado is modern enough to support reuse_port then you can have multiple Adjuster instances listening on the same port (e.g. for one_request_only) provided they have different internalPort settings when run with ssl_fork.âNote however that the --stop and --restart options will not distinguish between different internalPort settings, only âportâ.
- --fixed-ports (default False) Do not allocate ports (even internal ports) from the ephemeral port range even when this is otherwise possible.âThis option might help if you are firewalling your loopback interface and want to write specific exceptions (although that still wonât work if youâre using js_interpreter=HeadlessChrome or similar which opens its own ephemeral ports as well: use containers if youâre concerned).âFixed ports may result in failures if internal ports are already taken.
- --compress-responses (default True) Use gzip to compress responses for clients that indicate they are compatible with it.âYou may want to turn this off if your serverâs CPU is more important than your network bandwidth (e.g. browser on same machine).
Logging options
- --profile (default 0) Log timing statistics every N seconds (only when not idle)
- --profile-lines (default 5) Number of lines to log when profile option is in use (not applicable if using --multicore)
- --renderLog (default False) Whether or not to log requests for character-set renderer images.âNote that this can generate a lot of log entries on some pages.
- --logUnsupported (default False) Whether or not to log attempts at requests using unsupported HTTP methods.âNote that this can sometimes generate nearly as many log entries as renderLog if some browser (or malware) tries to do WebDAV PROPFIND requests on each of the images.
- --logRedirectFiles (default True) Whether or not to log requests that result in the browser being simply redirected to the original site when the redirectFiles option is on.
- --ipNoLog A comma-separated list of IP addresses which can use the adjuster without being logged.âIf your network has a âfriendly probingâ service then you might want to use this to stop it filling up the logs.â(Any tracebacks it causes will still be logged however.)
- --squashLogs (default True) Try to remove some duplicate information from consecutive log entries, to make logs easier to check.âYou might want to set this to False if you plan to use automatic search tools on the logs.âCurrently not supported with multicore, and will automatically be set to False if multicore is enabled.
- --errorHTML (default Adjuster error has been logged) What to say when an uncaught exception (due to a misconfiguration or programming error) has been logged.âHTML markup is allowed in this message.âIf for some reason you have trouble accessing the log files, the traceback can usually be included in the page itself by placing {traceback} in the message.
- --logDebug (default False) Write debugging messages (to standard error if in the foreground, or to the logs if in the background).âUse as an alternative to --logging=debug if you donât also want debug messages from other Tornado modules.âOn Unix you may also toggle this at runtime by sending SIGUSR1 to the process(es).
Tornado-provided logging options are not listed above because they might vary across Tornado versions; run python adjuster.py --help to see a full list of the ones available on your setup.âThey typically include log_file_max_size, log_file_num_backups, log_file_prefix and log_to_stderr.
WSGI mode
Web Adjuster is best run as a standalone server (see above) or behind a proxy like nginx, but if you must use WSGI then you can do it like this:
2.1. In your wrapper Python script, import adjuster
2.2. Set options via adjuster.options. optionName = value (remembering to set port to 80; options are as above, but some of them, such as server control options, do not apply to WSGI mode)
2.3. Do myApp = adjuster.make_WSGI_application()
2.4. Do something with myApp, according to whatever WSGI framework you are using.
- To use AppEngine on a Standard second-generation runtime:
2.4.1. Make an app.yaml file like:
runtime: python312
automatic_scaling:
max_instances: 1
min_instances: 0
2.4.2. Place and/or symlink this app.yaml along with adjuster.py and your wrapper script, which you should call main.py and change myApp to app, and also copy or symlink the tornado subdirectory from a download of Tornado version 5.1.1 or below (this is so AppEngine will run gunicorn for you; version 6 dropped WSGI functionality; alternatively you can directly set up Tornado in non-WSGI mode but this is more difficult on AppEngine Standard).âYou might also need to create an empty âplaceholderâ version of fcntl.py (Tornado 3 also needs an empty ssl.py but this shouldnât be done if you downloaded Tornado 5)
2.4.3. If your settings need PIL or LXML, add a requirements.txt like
pillow
lxml
2.4.4. Deploy via gcloud app deploy app.yaml --project followed by the app ID you registered.âSince 2020, a payment method must be entered even if you use only the âfree tierâ.âGoogle said the above setting of max_instances:Â 1 âusually keeps your instance hour usage within the free tierâ but from 2023 gcloud app deploy started to replicate a âbucketâ across multiple regions using traffic thatâs no longer included in Googleâs âfree tierââit charges about a penny every time you update your app, invoiced as âNetworking Traffic Egress GCP Replication within Northern Americaâ and might cause problems later if your billing details are outdated (Iâve not figured out a way to make AppEngine plus buckets all single region); in some cases Google will hold back from actually debiting your bank until more than a few pennies are owed, which means youâll repeatedly get emailed monthly bills saying the amount is still outstanding.
Options that call external programs are unlikely to work in AppEngine Standard but you can use htmlFilter with Python functions (see above; if you have large modules not always used then you might want to import these *on demand*)
- If using Werkzeug, cherrypy.wsgiserver, or similar, do werkzeug.serving.run_simple(IP, port, myApp, threaded=True) or cherrypy.wsgiserver.CherryPyWSGIServer((IP, port), myApp).start() or whatever.âYou will need Tornado 5.1.1 or below (Tornado 6 doesnât support this) and it has to be installed properly rather than simply placing its tornado subdirectory into the current directory, unless itâs Tornado 2.4.1 on Python 2.6 or 2.7.
- You can also turn it into a CGI script via import wsgiref.handlers ; wsgiref.handlers.CGIHandler().run(myApp) but that will need a separate process for each concurrent request.âAgain you will need Tornado 5.1.1 or below (Tornado 6 doesnât support this), and it has to be installed properly rather than simply placing its tornado subdirectory into the current directory, unless itâs Tornado 2.4.1 on Python 2.6 or 2.7. If using Apache, put
ErrorDocument 404 /wrapper.cgi
Options -Indexes
ErrorDocument 403 /wrapper.cgi
in .htaccess (and ensure AllowOverride All is set in the config files) to send all requests to the CGI, which should then import adjuster from outside the webspace (e.g. by adding to sys.path first)âbut itâs not necessary to send other requests to the CGI if you set submitPath to the CGIâs path plus ? and want only the âenter your own textâ functionality.
To-do list
When dealing with a very slow site, it would be nice if Web Adjuster could start sending text to the browser *before* the upstream fetch has completed.
License
Web Adjuster is free software licensed under the Apache License, Version 2.0 (this is also the license used by Tornado itself).âIf you use it in a good project, Iâd appreciate hearing about it.
Citation
If you need to cite a peer-reviewed paper:
Silas S. Brown. Web Annotation with Modified-Yarowsky and Other Algorithms. Overload 112 (December 2012) pp.4-7
Legal
All material © Silas S. Brown unless otherwise stated. Android is a trademark of Google LLC. Apache is a registered trademark of The Apache Software Foundation. AppEngine is possibly a trademark of Google LLC. Energenie is a trademark of Sandal Plc. Firefox is a registered trademark of The Mozilla Foundation. GitHub is a trademark of GitHub Inc. Google is a trademark of Google LLC. iPhone is a trademark of Apple in some countries. Javascript is a trademark of Oracle Corporation in the US. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Mac is a trademark of Apple Inc. MP3 is a trademark that was registered in Europe to Hypermedia GmbH Webcasting but I was unable to confirm its current holder. Post Office is a registered trademark of Post Office Limited. Python is a trademark of the Python Software Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation. Unicode is a registered trademark of Unicode, Inc. in the United States and other countries. Unix is a trademark of The Open Group. Windows is a registered trademark of Microsoft Corp. Any other trademarks I mentioned without realising are trademarks of their respective holders.