summary refs log blame commit diff stats
path: root/post.go
blob: 5091a0e330b7479b6c962a096139414dd4d426e5 (plain) (tree)





























































                                                                   
package main

import (
	"fmt"
	"net/http"

	"github.com/getwtxt/registry"
)

// Requests to apiEndpointPOSTHandler are passed off to this
// function. apiPostUser then fetches the twtxt data, then if
// it's an individual user's file, adds it. If it's registry
// output, it scrapes the users/urls/statuses from the remote
// registry before adding each user to the local cache.
func apiPostUser(w http.ResponseWriter, r *http.Request) {
	if err := r.ParseForm(); err != nil {
		log400(w, r, err)
		return
	}
	nick := r.FormValue("nickname")
	urls := r.FormValue("url")
	if nick == "" || urls == "" {
		log400(w, r, fmt.Errorf("nickname or URL missing"))
		return
	}

	uip := getIPFromCtx(r.Context())

	out, remoteRegistry, err := registry.GetTwtxt(urls)
	if err != nil {
		log400(w, r, err)
		return
	}

	if remoteRegistry {
		remote.Mu.Lock()
		remote.List = append(remote.List, urls)
		remote.Mu.Unlock()

		err := twtxtCache.ScrapeRemoteRegistry(urls)
		if err != nil {
			log400(w, r, err)
			return
		}
		log200(r)
		return
	}

	statuses, err := registry.ParseUserTwtxt(out)
	if err != nil {
		log400(w, r, err)
		return
	}

	err = twtxtCache.AddUser(nick, urls, uip, statuses)
	if err != nil {
		log400(w, r, err)
		return
	}

	log200(r)
}
} /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# This file is part of ranger, the console file manager.
# License: GNU GPL version 3, see the file "AUTHORS" for details.

"""The File Manager, putting the pieces together"""

from __future__ import (absolute_import, print_function)

from time import time
from collections import deque
import logging
import mimetypes
import os.path
import pwd
import socket
import stat
import sys

import ranger.api
from ranger.core.actions import Actions
from ranger.core.tab import Tab
from ranger.container import settings
from ranger.container.tags import Tags, TagsDummy
from ranger.gui.ui import UI
from ranger.container.bookmarks import Bookmarks
from ranger.core.runner import Runner
from ranger.ext.img_display import (W3MImageDisplayer, ITerm2ImageDisplayer,
                                    URXVTImageDisplayer, URXVTImageFSDisplayer, ImageDisplayer)
from ranger.core.metadata import MetadataManager
from ranger.ext.rifle import Rifle
from ranger.container.directory import Directory
from ranger.ext.signals import SignalDispatcher
from ranger.core.loader import Loader
from ranger.ext import logutils


LOG = logging.getLogger(__name__)


class FM(Actions,  # pylint: disable=too-many-instance-attributes,abstract-method
         SignalDispatcher):
    input_blocked = False
    input_blocked_until = 0
    mode = 'normal'  # either 'normal' or 'visual'.
    search_method = 'ctime'

    _previous_selection = None
    _visual_reverse = False
    _visual_start = None
    _visual_start_pos = None

    def __init__(self, ui=None, bookmarks=None, tags=None, paths=None):
        """Initialize FM."""
        Actions.__init__(self)
        SignalDispatcher.__init__(self)
        self.ui = ui if ui is not None else UI()
        self.start_paths = paths if paths is not None else ['.']
        self.directories = dict()
        self.bookmarks = bookmarks
        self.current_tab = 1
        self.tabs = {}
        self.tags = tags
        self.restorable_tabs = deque([], ranger.MAX_RESTORABLE_TABS)
        self.py3 = sys.version_info >= (3, )
        self.previews = {}
        self.default_linemodes = deque()
        self.loader = Loader()
        self.copy_buffer = set()
        self.do_cut = False
        self.metadata = MetadataManager()
        self.image_displayer = None

        try:
            self.username = pwd.getpwuid(os.geteuid()).pw_name
        except Exception:
            self.username = 'uid:' + str(os.geteuid())
        self.hostname = socket.gethostname()
        self.home_path = os.path.expanduser('~')

        mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
        mimetypes.knownfiles.append(self.relpath('data/mime.types'))
        self.mimetypes = mimetypes.MimeTypes()

    def initialize(self):
        """If ui/bookmarks are None, they will be initialized here."""

        self.tabs = dict((n + 1, Tab(path)) for n, path in
                         enumerate(self.start_paths))
        tab_list = self._get_tab_list()
        if tab_list:
            self.current_tab = tab_list[0]
            self.thistab = self.tabs[self.current_tab]
        else:
            self.current_tab = 1
            self.tabs[self.current_tab] = self.thistab = Tab('.')

        if not ranger.args.clean and os.path.isfile(self.confpath('rifle.conf')):
            rifleconf = self.confpath('rifle.conf')
        else:
            rifleconf = self.relpath('config/rifle.conf')
        self.rifle = Rifle(rifleconf)
        self.rifle.reload_config()

        def set_image_displayer():
            self.image_displayer = self._get_image_displayer()
        set_image_displayer()
        self.settings.signal_bind('setopt.preview_images_method',
                                  set_image_displayer,
                                  priority=settings.SIGNAL_PRIORITY_AFTER_SYNC)

        if not ranger.args.clean and self.tags is None:
            self.tags = Tags(self.confpath('tagged'))
        elif ranger.args.clean:
            self.tags = TagsDummy("")  # pylint: disable=redefined-variable-type

        if self.bookmarks is None:
            if ranger.args.clean:
                bookmarkfile = None
            else:
                bookmarkfile = self.confpath('bookmarks')
            self.bookmarks = Bookmarks(
                bookmarkfile=bookmarkfile,
                bookmarktype=Directory,
                autosave=self.settings.autosave_bookmarks)
            self.bookmarks.load()

        self.ui.setup_curses()
        self.ui.initialize()

        self.rifle.hook_before_executing = lambda a, b, flags: \
            self.ui.suspend() if 'f' not in flags else None
        self.rifle.hook_after_executing = lambda a, b, flags: \
            self.ui.initialize() if 'f' not in flags else None
        self.rifle.hook_logger = self.notify
        old_preprocessing_hook = self.rifle.hook_command_preprocessing

        # This hook allows image viewers to open all images in the current
        # directory, keeping the order of files the same as in ranger.
        # The requirements to use it are:
        # 1. set open_all_images to true
        # 2. ensure no files are marked
        # 3. call rifle with a command that starts with "sxiv " or "feh "
        def sxiv_workaround_hook(command):
            import re
            from ranger.ext.shell_escape import shell_quote

            if self.settings.open_all_images and \
                    len(self.thisdir.marked_items) == 0 and \
                    re.match(r'^(feh|sxiv|imv|pqiv) ', command):

                images = [f.relative_path for f in self.thisdir.files if f.image]
                escaped_filenames = " ".join(shell_quote(f)
                                             for f in images if "\x00" not in f)

                if images and self.thisfile.relative_path in images and \
                        "$@" in command:
                    new_command = None

                    if command[0:5] == 'sxiv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("sxiv ",
                                                      "sxiv -n %d " % number, 1)

                    if command[0:4] == 'feh ':
                        new_command = command.replace("feh ",
                                                      "feh --start-at %s " %
                                                      shell_quote(self.thisfile.relative_path), 1)

                    if command[0:4] == 'imv ':
                        number = images.index(self.thisfile.relative_path) + 1
                        new_command = command.replace("imv ",
                                                      "imv -n %d " % number, 1)

                    if command[0:5] == 'pqiv ':
                        number = images.index(self.thisfile.relative_path)
                        new_command = command.replace("pqiv ",
                                                      "pqiv --action \"goto_file_byindex(%d)\" " %
                                                      number, 1)

                    if new_command:
                        command = "set -- %s; %s" % (escaped_filenames,
                                                     new_command)
            return old_preprocessing_hook(command)

        self.rifle.hook_command_preprocessing = sxiv_workaround_hook

        def mylogfunc(text):
            self.notify(text, bad=True)
        self.run = Runner(ui=self.ui, logfunc=mylogfunc, fm=self)

        self.settings.signal_bind('setopt.metadata_deep_search',
                                  lambda signal: setattr(signal.fm.metadata, 'deep_search',
                                                         signal.value))

    def destroy(self):
        debug = ranger.args.debug
        if self.ui:
            try:
                self.ui.destroy()
            except Exception:
                if debug:
                    raise
        if self.loader:
            try:
                self.loader.destroy()
            except Exception:
                if debug:
                    raise

    @staticmethod
    def get_log():
        """Return the current log

        The log is returned as a list of string
        """
        for log in logutils.log_queue:
            for line in log.split('\n'):
                yield line

    def _get_image_displayer(self):
        if self.settings.preview_images_method == "w3m":
            return W3MImageDisplayer()
        elif self.settings.preview_images_method == "iterm2":
            return ITerm2ImageDisplayer()
        elif self.settings.preview_images_method == "urxvt":
            return URXVTImageDisplayer()
        elif self.settings.preview_images_method == "urxvt-full":
            return URXVTImageFSDisplayer()
        else:
            return ImageDisplayer()

    def _get_thisfile(self):
        return self.thistab.thisfile

    def _set_thisfile(self, obj):
        self.thistab.thisfile = obj

    def _get_thisdir(self):
        return self.thistab.thisdir

    def _set_thisdir(self, obj):
        self.thistab.thisdir = obj

    thisfile = property(_get_thisfile, _set_thisfile)
    thisdir = property(_get_thisdir, _set_thisdir)

    def block_input(self, sec=0):
        self.input_blocked = sec != 0
        self.input_blocked_until = time() + sec

    def input_is_blocked(self):
        if self.input_blocked and time() > self.input_blocked_until:
            self.input_blocked = False
        return self.input_blocked

    def copy_config_files(self, which):
        if ranger.args.clean:
            sys.stderr.write("refusing to copy config files in clean mode\n")
            return
        import shutil
        from errno import EEXIST

        def copy(src, dest):
            if os.path.exists(self.confpath(dest)):
                sys.stderr.write("already exists: %s\n" % self.confpath(dest))
            else:
                sys.stderr.write("creating: %s\n" % self.confpath(dest))
                try:
                    os.makedirs(ranger.args.confdir)
                except OSError as err:
                    if err.errno != EEXIST:  # EEXIST means it already exists
                        print("This configuration directory could not be created:")
                        print(ranger.args.confdir)
                        print("To run ranger without the need for configuration")
                        print("files, use the --clean option.")
                        raise SystemExit()
                try:
                    shutil.copy(self.relpath(src), self.confpath(dest))
                except Exception as ex:
                    sys.stderr.write("  ERROR: %s\n" % str(ex))
        if which == 'rifle' or which == 'all':
            copy('config/rifle.conf', 'rifle.conf')
        if which == 'commands' or which == 'all':
            copy('config/commands_sample.py', 'commands.py')
        if which == 'commands_full' or which == 'all':
            copy('config/commands.py', 'commands_full.py')
        if which == 'rc' or which == 'all':
            copy('config/rc.conf', 'rc.conf')
        if which == 'scope' or which == 'all':
            copy('data/scope.sh', 'scope.sh')
            os.chmod(self.confpath('scope.sh'),
                     os.stat(self.confpath('scope.sh')).st_mode | stat.S_IXUSR)
        if which in ('all', 'rifle', 'scope', 'commands', 'commands_full', 'rc'):
            sys.stderr.write("\n> Please note that configuration files may "
                             "change as ranger evolves.\n  It's completely up to you to "
                             "keep them up to date.\n")
            if os.environ.get('RANGER_LOAD_DEFAULT_RC', 0) != 'FALSE':
                sys.stderr.write("\n> To stop ranger from loading "
                                 "\033[1mboth\033[0m the default and your custom rc.conf,\n"
                                 "  please set the environment variable "
                                 "\033[1mRANGER_LOAD_DEFAULT_RC\033[0m to "
                                 "\033[1mFALSE\033[0m.\n")
        else:
            sys.stderr.write("Unknown config file `%s'\n" % which)

    @staticmethod
    def confpath(*paths):
        """returns the path relative to rangers configuration directory"""
        if ranger.args.clean:
            assert 0, "Should not access relpath_conf in clean mode!"
        else:
            return os.path.join(ranger.args.confdir, *paths)

    @staticmethod
    def relpath(*paths):
        """returns the path relative to rangers library directory"""
        return os.path.join(ranger.RANGERDIR, *paths)

    def get_directory(self, path):
        """Get the directory object at the given path"""
        path = os.path.abspath(path)
        try:
            return self.directories[path]
        except KeyError:
            obj = Directory(path)
            self.directories[path] = obj
            return obj

    def garbage_collect(
            self, age,
            tabs=None):  # tabs=None is for COMPATibility pylint: disable=unused-argument
        """Delete unused directory objects"""
        for key in tuple(self.directories):
            value = self.directories[key]
            if age != -1:
                if not value.is_older_than(age) \
                        or any(value in tab.pathway for tab in self.tabs.values()):
                    continue
            del self.directories[key]
            if value.is_directory:
                value.files = None
        self.settings.signal_garbage_collect()
        self.signal_garbage_collect()

    def loop(self):
        """The main loop of ranger.

        It consists of:
        1. reloading bookmarks if outdated
        2. letting the loader work
        3. drawing and finalizing ui
        4. reading and handling user input
        5. after X loops: collecting unused directory objects
        """

        self.enter_dir(self.thistab.path)

        # for faster lookup:
        ui = self.ui
        throbber = ui.throbber
        loader = self.loader
        has_throbber = hasattr(ui, 'throbber')
        zombies = self.run.zombies

        ranger.api.hook_ready(self)

        try:  # pylint: disable=too-many-nested-blocks
            while True:
                loader.work()
                if has_throbber:
                    if loader.has_work():
                        throbber(loader.status)
                    else:
                        throbber(remove=True)

                ui.redraw()

                ui.set_load_mode(not loader.paused and loader.has_work())

                ui.draw_images()

                ui.handle_input()

                if zombies:
                    for zombie in tuple(zombies):
                        if zombie.poll() is not None:
                            zombies.remove(zombie)

                # gc_tick += 1
                # if gc_tick > ranger.TICKS_BEFORE_COLLECTING_GARBAGE:
                    # gc_tick = 0
                    # self.garbage_collect(ranger.TIME_BEFORE_FILE_BECOMES_GARBAGE)

        except KeyboardInterrupt:
            # this only happens in --debug mode. By default, interrupts
            # are caught in curses_interrupt_handler
            raise SystemExit

        finally:
            self.image_displayer.quit()
            if ranger.args.choosedir and self.thisdir and self.thisdir.path:
                # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                # '\udcf6' in position 42: surrogates not allowed
                open(ranger.args.choosedir, 'w').write(self.thisdir.path)
            self.bookmarks.remember(self.thisdir)
            self.bookmarks.save()
f it is currently disabled for this entry. .It Cm js show all Shows all persistent and session entries in the JS whitelist. .It Cm js show persistent Shows all persistent entries in the JS whitelist. .It Cm js show session Shows all session entries in the JS whitelist. .It Cm js toggle, js toggle fqdn Toggle Java Script execution for the current FQDN. .It Cm js toggle domain Toggle Java Script execution for the current top level domain. .It Cm loadimages If auto_load_images is disabled, load all images for current site. .It Cm open , op , o URL Open URL. .It Cm plugin The .Cm plugin command is used to manipulate the plugin whitelist. Used by itself it expands to .Cm plugin show all . .It Cm plugin save, save fqdn Saves the FQDN to the persistent whitelist. For example, the www.peereboom.us domain would result in saving .www.peereboom.us. .It Cm plugin save domain Saves the top level domain name to the persistent whitelist. For example, the www.peereboom.us domain would result in saving .peereboom.us. .Pp This action enables plugins if they are currently disabled for this entry. .It Cm plugin show all Shows all persistent and session entries in the plugin whitelist. .It Cm plugin show persistent Shows all persistent entries in the plugin whitelist. .It Cm plugin show session Shows all session entries in the plugin whitelist. .It Cm plugin toggle, plugin toggle fqdn Toggle plugin execution for the current FQDN. .It Cm plugin toggle domain Toggle plugin execution for the current top level domain. .It Cm print Print page. .It Cm proxy The .Cm proxy command is used to manipulate the currently set proxy. Used by itself it expands to .Cm proxy show . .It Cm proxy show Displays the current .Cm http_proxy setting. .It Cm proxy toggle Enables or disables the proxy for .Nm . Note that .Cm http_proxy must be set before it can be toggled. .It Cm qa , qall , quitall Quit .Nm . .It Cm quit , q Close current tab and quit .Nm if it is the last tab. .It Cm restart Restart .Nm and reload all current tabs. .It Cm run_script [path_to_script] Runs the script path_to_script with the current uri as the argument. If path_to_script is not provided, the value of default_script is used instead. .It Cm script [filename] Run an external JavaScript script file in the current tab context. .It Cm session , Cm session show Display the current session name. By default the session name is main_session. To create a new session use the .Cm session save command. A session is defined as the lifetime of the browser application. .It Cm session delete <session_name> Delete session session_name from persistent storage. If session_name is the current session then the session will revert to main_session. .It Cm session open <session_name> Open session_name and close all currently open tabs. Going forward this session is named session_name. .It Cm session save <session_name> Save current tabs to session_name session. This will close the current session and going forward this session is named session_name. .It Cm set The set command is used to inspect, clear or change runtime options. There are 3 methods to use .Cm :set . When used by itself as .Cm :set the command displays all options as currently set. .Pp To set a value use .Cm :set option=value . For example, .Cm :set http_proxy=http://127.0.0.1:8080 . .Pp To clear a value use .Cm :set option= . For example, .Cm :set http_proxy= . .Pp Note, not all options can be set at runtime. .It Cm stats Show blocked cookie statistics. These statistics vary based on settings and are not persistent. .It Cm statustoggle , statust Toggle status bar. .It Cm stop Stop loading the current web page. .It Cm tabclose Close current tab. .It Cm tabhide Hide tabs. .It Cm tabnew , tabedit [URL] Create new tab and optionally open provided URL. .It Cm tabnext Go to the next tab. .It Cm tabprevious Go to the previous tab. .It Cm tabshow Show tabs in GUI. .It Cm toplevel , toplevel toggle Toggle the top level domain name cookie and JS session whitelist. This is to enable/disable short lived full site functionality without permanently adding the top level domain to the persistent whitelist. .It Cm urlhide , urlh Hide url entry and tool bar. .It Cm urlshow , urls Show url entry and tool bar. .It Cm w Save open tabs to current session. The tabs will be restored next time the session is opened. See the session command for additional details. .It Cm wq Save open tabs and quit. The tabs will be restored next time .Nm the session is opened. See the session command for additional details. .El .Sh BUFFER COMMANDS In addition to shortcuts and commands .Nm provides buffer commands. Buffer commands are short, multi character vi-like commands, often requiring an argument. Partial buffer commands are displayed in the buffer command statusbar element (see .Cm statusbar_elems ) . Pressing Esc or switching to another tab cancels a partially entered buffer command. In the following list .Cm arg denotes the argument a buffer command accepts. Buffer commands are defined as extended regular experssions. Note that if a character is used as a shortcut it will not be interpreted as the beginning of a buffer command. This is the case with .Cm 0 . .Pp .Bl -tag -width "['][a-zA-Z0-9]XXX" -offset indent -compact .It Cm gg go to the top of the page .It Cm gG go to the bottom of the page .It Cm [0-9]+% go to the .Cm arg percent of the page .It Cm zz go to 50% of the page .It Cm [0-9]*gu go .Cm arg levels up. If .Cm arg is missing, 1 is assumed. Going a level up means going to a URI obtained from the current one by removing the last slash ('/') character and everything that follows it .It Cm gU go to the root level, i.e. going up as many levels as possible. .It Cm gh open the home page in the current tab .It Cm m[a-zA-Z0-9] set a mark denoted by .Cm arg at the current page position. These marks behave like those in vi or less. .It Cm ['][a-zA-Z0-9] go to the position where mark .Cm arg was set .It Cm M[a-zA-Z0-9] set the current uri as quickmark .Cm arg .It Cm go[a-zA-Z0-9] open the uri marked as quickmark .Cm arg in the current tab .It Cm gn[a-zA-Z0-9] open the uri marked as quickmark .Cm arg in a new tab .It Cm [0-9]+t activate tab number .It Cm g0 go to first tab .It Cm g$ go to last tab .It Cm [0-9]*gt go to the .Cm arg next tab .It Cm [0-9]*gT go to the .Cm arg previous tab .Cm arg .It Cm ZZ quit .Nm .It Cm ZR restart .Nm .It Cm zi zoom in by 4% .It Cm zo zoom out by 4% .It Cm z0 set zoom level to 100% .It Cm [0-9]+Z set zoom level to .Cm arg % .El .Sh QUICKMARKS Quickmarks are like bookmarks, except they are refered to by a single character (a letter or a digit), instead of a longer name. See the .Cm M[a-zA-Z0-9] , .Cm go[a-zA-Z0-9] and .Cm gn[a-zA-Z0-9] buffer commands for usage. Quickmarks are stored in .Pa ~/.xxxterm/quickmarks and are saved automatically after each .Cm M[a-zA-Z0-9] buffer command. .Sh ABOUT SCREENS The about screens are internally generated web pages by .Nm for user interaction. These are entered in the address bar and the format is .Cm about:screen where screen is the desired screen to display. For example about:favorites. Any about screen can be used as the home page as specified by .Cm home in the configuration file. .Pp .Bl -tag -width "downloadsXXX" -offset indent -compact .It Cm about show the about screen .It Cm blank show a blank screen .It Cm cookiewl show the cookie whitelist screen .It Cm cookiejar show the cookiejar screen .It Cm downloads show the downloads screen .It Cm favorites show the favorites screen .It Cm help show the help web page .It Cm history show the history screen .It Cm jswl show the Java Script whitelist screen .It Cm set show the settings screen .It Cm stats show the statistics screen .El .Sh WHITELISTS This section describes advanced usage settings. Most users should use .Cm browser_mode instead to setup .Nm and skip over this section. .Pp .Nm has a number of whitelists to control blocking cookies and Java Script execution for FQDNs or domains. When properly enabled these whitelists require either the FQDN or top level domain to exist in the whitelists in order to allow cookies to be stored or Java Script to execute. Both Java Script and cookies have two whitelists associated with them. The whitelists are called session and persistent. Items in the session whitelists are only allowed for the lifetime of the .Nm instance. Items in the persistent whitelists are stored on disk and are restored upon restarting. .Pp Setting up the whitelists is a little tricky due to intricacies of WebKit. In fact the semantics are different for cookies and Java Script. .Pp Cookie whitelist requires the following configuration to be set: .Pp .Bl -tag -width "enable_cookie_whitelistXXX" -offset indent -compact .It Cm cookies_enabled This is a WebKit setting and must be set to .Pa 1 (ENABLED) in order to be able to use a cookie whitelist. .It Cm enable_cookie_whitelist This needs to be set to .Pa 1 to enable the cookie whitelist functionality. .It Cm cookie_wl These entries in the configuration file are the actual domains names in the cookie whitelist. .El .Pp Java Script whitelist requires the following configuration to be set: .Pp .Bl -tag -width "enable_js_whitelistXXX" -offset indent -compact .It Cm enable_scripts This is a WebKit setting and must be set to .Pa 0 (DISABLED) in order to be able to use a Java Script whitelist. .It Cm enable_js_whitelist This needs to be set to .Pa 1 to enable the Java Script whitelist functionality. .It Cm js_wl These entries in the configuration file are the actual domains names in the Java Script whitelist. .El .Pp Plugin whitelist requires the following configuration to be set: .Pp .Bl -tag -width "enable_plugin_whitelistXXX" -offset indent -compact .It Cm enable_plugins This is a WebKit setting and must be set to .Pa 1 (ENABLED) in order to be able to use a plugin whitelist. .It Cm enable_plugin_whitelist This needs to be set to .Pa 1 to enable the plugin whitelist functionality. .It Cm pl_wl These entries in the configuration file are the actual domains names in the plugin whitelist. .El .Pp See the .Pa FILES section for additional configuration file entries and details that alter runtime behavior. .Sh FILES .Bl -tag -width "/etc/xxxterm.confXXX" -compact .It Pa ~/.xxxterm.conf .Nm user specific settings. .It Pa ~/.xxxterm .Nm scratch directory. .El .Pp .Nm tries to open the user specific file, .Pa ~/.xxxterm.conf . If that file is unavailable, it then uses built-in defaults. .Pp The format of the file is \*(Ltkeyword\*(Gt = \*(Ltsetting\*(Gt. For example: .Pp .Dl http_proxy = http://127.0.0.1:8080 .Pp Enabling or disabling an option is done by using 1 or 0 respectively. .Pp The file supports the following keywords: .Pp .Bl -tag -width "enable_cookie_whitelistXXX" -offset indent -compact .It Cm alias Defines an alias for a given URL, so that the URL is loaded when the alias is entered in the address bar. If the aliased URL includes a %s format specifier, then any argument given after the alias on the address bar is substituted. For example, if g,http://www.google.com/search?q=%s is defined as an alias, then the URL http://www.google.com/search?q=foo is loaded when navigating to "g foo". .It Cm allow_volatile_cookies If set cookies are stored in the session cache but will be discarded once .Nm exits. Unfortunately enabling this does allow for some limited tracking on the web. .It Cm append_next When set a new tab is appended after the current tab instead of being appended as the last tab. .It Cm auto_load_images If disabled, images will not be loaded automatically. .It Cm autofocus_onload When set a tab that is loaded will attempt to autofocus the default input entry. This is only done for tabs that are currently visible. .It Cm browser_mode The .Nm browser has 3 default operating modes: .Pa normal (the default), .Pa whitelist and .Pa kiosk . In the .Pa normal mode the browser allows all cookies, plugins and Java Script as any other browser would. This means that all cookies are saved to persistent storage and that all Java Script and plugins run. .Pp On the other hand, using the .Pa whitelist mode enables whitelists. This requires the user to add all the required .Pa cookie_wl , .Pa js_wl and .Pa pl_wl items. If a domain does not appear in the whitelists .Nm disallows cookies, Java Script and plugin execution. .Pp In .Pa kiosk mode the browse works just like .Pa normal mode however the toolbar only has the backward, forward and home button. .Pp This setting must be the first entry in .Pa ~/.xxxterm.conf because it sets advanced settings that can be overridden later in the file. See the default config file for more details. .It Cm cmd_font Set the command prompt font. E.g. .Pa cmd_font = monospace normal 9 . .It Cm color_visited_uris When enabled (the default) .Nm will color visited links. This is done while the web page loads using JavaScript, rather than WebKit's (broken, see bug #51747) built-in facility for coloring visited links. The JavaScript approach is (probably) slower and is not consistent across tabs (unless the tabs are reloaded), but has the advantage of not leaking history data to web pages (see http://wtikay.com/docs/details.html). .It Cm cookie_policy This field delineates the cookie policy. Possible values are: no3rdparty, reject 3rd party cookies. accept, accept all cookies. reject, reject all cookies. .It Cm cookie_wl This is a cookie whitelist item. Use multiple times to add multiple entries. Valid entries are for example *.moo.com and the equivalent .moo.com. A fully qualified host is also valid and is for example www.moo.com. .It Cm cookies_enabled Enable cookies. .It Cm ctrl_click_focus Give focus in newly created tab instead of opening it in the background. .It Cm default_script Path to the script used as the default value for the run_script command. .It Cm default_zoom_level Set the default browsing zoom level. .It Cm download_dir Locations where files are downloaded to. This directory must exist and .Nm validates that during startup. .It Cm download_mode Controls how downloads are handled. Possible values are: .Bd -literal -offset indent start - automatically start download. ask - ask user for confirmation. add - add to downloadmanager, but do not start. .Ed The default is "start". .It Cm enable_autoscroll When enabled clicking MB3 will spawn the autoscroll ball, scrolling can then proceed by dragging the mouse away from the ball. .It Cm enable_cookie_whitelist When enabled all cookies must be in the whitelist or they are rejected. Additionally whitelisted cookies also enable HTML5 local storage for the domain. .It Cm enable_favicon_entry When enabled (the default) .Nm displays the favicon of the web page at the URI entry. This setting affects both .Cm normal and .Cm compact tabs. .It Cm enable_favicon_tabs When enabled (disabled by default) .Nm displays favicons at each tab. This setting only affects .Cm compact tabs. .It Cm enable_js_whitelist When enabled all domains must be in the js whitelist in order to run Java Script. NOTE: Make sure .Cm enable_scripts is set to 0. .It Cm enable_plugin_whitelist When enabled all domains must be in the plugin whitelist in order to run plugins. NOTE: Make sure .Cm enable_plugins is set to 0. .It Cm enable_plugins Enable external plugins such as Flash and Java. .It Cm enable_scripts Enable Java Script. .It Cm enable_socket When enabled the first instance of .Nm will create a socket in the .Pa ~/.xxxterm directory. Using the -n url option on subsequent .Nm invocations will cause the specified URL to be loaded in a new tab. Only a user with identical UID and GID can use this option. .It Cm enable_localstorage Enable html5 Local Storage. .It Cm enable_spell_checking Enables spell checking. Preferred languages can be set using .Cm spell_check_languages option. .It Cm encoding Set the default encoding. E.g. .Pa encoding = ISO-8859-1 . .It Cm external_editor Set which editor to use for external editing. the string <file> will be replaced by the current filename. E.g. .Pa external_editor = gvim -f <file> Note! .Cm xxxterm relies on the editor .Pa not forking into the background. .It Cm fancy_bar Enables a backward, forward, and stop button to the toolbar. Additionally if .Cm search_string is set it'll enable an entry box for searches. .It Cm guess_search When enabled .Nm will try to guess if the string you entered, in the URI entry widget or the command widget, is term you want to search for using search_string (see above). If the string does not contain a dot nor a slash, is not a path to a local file and does not resolves to an IP then it is assumed to be a search term. .It Cm gui_mode To simplify configuring .Nm allows you pick between two GUI modes: .Pa classic (the default) and .Pa minimal . In the .Pa classic mode the GUI looks similar to that of most mainstream browsers. While in .Pa minimal mode the GUI looks more vi-like. One can get a GUI between the two by tweaking the low-level GUI settings found under the advanced GUI setting section in the configuration file. .It Cm history_autosave When enabled .Nm will save all command and search history. Upon restarting .Nm the saved command and search history will be restored. .It Cm home Homepage in URL format. .It Cm http_proxy Proxy server in URL format. .Nm overrides .Cm http_proxy if it is specified as an environment variable. It must be noted that on older webkit versions one MUST use an IP address and not a FQDN. This works as expected with webkit 1.4.2. .Pp If one desires to use a socks proxy then an intermediary tool must be used. It has been reported that tsocks works with .Nm . .It Cm icon_size Permits icon sizes to be changed if .Cm fancy_bar is enabled. Size 1 is small; 2 is normal; 3 through 6 are progressively larger. .It Cm js_wl This is a Java Script whitelist item. See .Cm cookie_wl for semantics and more details. .It Cm max_connections The maximum number of connections that .Nm can open at once. .It Cm max_host_connections The maximum number of connections that .Nm can open at once to a given host. .It Cm mime_type Sets an action for a specific or default MIME type. For example, to download and view a pdf using kpdf set .Pa mime_type = application/pdf,kpdf . To set a default value use *, for example, .Pa mime_type = video/*,mplayer . Note that the action is only passed the URL and not all applications are capable of dealing with a URL and therefore one might have to create a wrapper script to download the content first. Alternatively one can add the .Pa @ in front of the MIME type to indicate "download first". For example, .Pa mime_type = @application/pdf,xpdf . When .Pa @ is use the file will be downloaded to the .Pa download_dir before the MIME handler is called. .It Cm oops_font Set the font used to display error messages. E.g. .Pa oops_font = monospace normal 9 . .It Cm pl_wl This is a plugin whitelist item. See .Cm cookie_wl for semantics and more details. .It Cm read_only_cookies Mark cookies file read-only and discard all cookies once the session is terminated. .It Cm refresh_interval Refresh interval while in the download manager. The default is 10. .It Cm referer Control how 'Referer' is handled in http-requests. .Bd -literal -offset indent always - always send referer never - never send referer same-domain - only send referer if it's for the same domain .Ed Any other value that is also a valid URL will use this custom value as referer. (E.g. you could set it to http://no-referer.com) The default value is "always" .It Cm resource_dir Directory that contains various .Nm resources such as icons. This is OS-specific and should be handled by the porter. .It Cm save_global_history If set the global history will be saved to .Pa ~/.xxxterm/history when quitting and restored at startup. See the .Sx KEY BINDINGS section above for how the global history is accessed. Global history is not saved to disk by default. .It Cm save_rejected_cookies Saves rejected cookies in cookie format in {work_dir}/rejected.txt. All cookies are saved and unlike a cookie jar they are never replaced. Make sure there is enough disk space to enable this feature. .It Cm search_string Default search engine string. See the .Pa xxxterm.conf file for details. .It Cm session_autosave Enable session auto-saving when changing state (e.g. adding or removing a tab). The session name is what is currently in use and is described in the .Cm session save and .Cm session open commands. .It Cm session_timeout This value is the time that is added in seconds to a session cookie. .It Cm show_tabs Enable or disable showing tabs. .It Cm show_url Enable or disable showing the url and toolbar. .It Cm show_statusbar Enable or disable showing the status bar. .It Cm single_instance If set and .Cm enable_socket is enabled only one .Nm will be permitted to run. If there is a URL specified it will be opened in a new tab in the already running .Nm session. .It Cm spell_check_languages The languages to be used for spell checking, separated by commas. For example, en_US. .It Cm ssl_ca_file If set to a valid PEM file all server certificates will be validated against it. The URL bar will be colored green (or blue when saved ) when the certificate is trusted and yellow when untrusted. .Pp If .Cm ssl_ca_file is not set then the URL bar will color all HTTPS connections red. .Pp WebKit only supports a single PEM file. Many OS' or distributions have many PEM files. One can simply concatenate all separate files into one large one. E.g. .Cm for i in `ls`; do cat $i >> cert.pem; done and use the resulting cert.pem file as the input to .Cm ssl_ca_file . It is advisable to periodically recreate the cert.pem file. .It Cm ssl_strict_certs If this value is set connections to untrusted sites will be aborted. This value is only used if .Cm ssl_ca_file is set. .It Cm statusbar_elems Define the components of the status bar. The possible components are: .Bd -literal -offset indent | - separator P - page progress percent B - buffer command Z - page zoom level .Ed The default is "BP". These components show nothing if there is nothing worth showing, like zoom amount 100%. .It Cm statusbar_font Set the status bar font. E.g. .Pa statusbar_font = monospace normal 9 . .It Cm tab_style Set the tab style to either .Cm normal - the default gtk notebook tabs, or .Cm compact for an alternative. You can switch the tab style with the .Pa tabnextstyle command. .It Cm tabbar_font Set the compact tab bar font. E.g. .Pa tabbar_font = monospace normal 9 . .It Cm url_regex This is the regular expression that is used to match what constitutes a valid URL when using .Pa guess_search . .It Cm user_agent Set to override the default .Nm user-agent string. May be specified several times for switching between user-agents. .It Cm window_height Set the default height of the browser window. .It Cm window_width Set the default width of the browser window. .It Cm window_maximize Maximize the browser window at startup. .It Cm work_dir Set the work directory where all .Nm scratch files are stored. Default is .Cm ~/.xxxterm . .It Cm xterm_workaround When enabled .Nm will look additionally at CUT_BUFFER0 if PRIMARY clipboard is empty. Additionally when the PRIMARY clipboard is cleared it will copy CUT_BUFFER0 into the PRIMARY clipboard. Default is 0. .El .Sh HISTORY .Nm was inspired by vimprobable2 and the bloat in other .Ux web browsers. .Sh AUTHORS .An -nosplit .Nm was written by .An Marco Peereboom Aq marco@peereboom.us , .An Stevan Andjelkovic Aq stevan@student.chalmers.se , .An Edd Barrett Aq vext01@gmail.com , .An Todd T. Fries Aq todd@fries.net , .An Raphael Graf Aq r@undefined.ch , and .An Michal Mazurek Aq akfaew@jasminek.net .