View source with raw comments or as raw
    1/*  Part of SWISH
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2014-2018, VU University Amsterdam
    7			      CWI, Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(swish_app,
   37	  [
   38	  ]).   39:- use_module(library(pldoc), []).   40:- use_module(library(pengines)).   41:- use_module(library(http/http_dispatch)).   42:- use_module(library(option)).   43:- use_module(library(apply)).   44:- use_module(library(settings)).   45
   46:- use_module(lib/messages).   47:- use_module(lib/paths).   48:- use_module(lib/config, []).   49:- use_module(lib/page, []).   50:- use_module(lib/storage).   51:- use_module(lib/include).   52:- use_module(lib/swish_csv).   53:- use_module(lib/examples).   54:- use_module(lib/profiles).   55:- use_module(lib/highlight).   56:- use_module(lib/markdown).   57:- use_module(lib/chat, []).   58:- use_module(lib/template_hint, []).   59:- if(exists_source(library(http/http_dyn_workers))).   60:- use_module(library(http/http_dyn_workers)).   61:- else.   62:- use_module(lib/plugin/http_dyn_workers, []).   63:- endif.   64:- use_module(lib/web).   65:- use_module(lib/version).   66
   67
   68		 /*******************************
   69		 *	      VERSION		*
   70		 *******************************/
   71
   72setup_versions :-
   73	prolog_load_context(directory, Dir),
   74	register_git_module(swish,
   75			    [ directory(Dir),
   76			      home_url('https://github.com/SWI-Prolog/swish')
   77			    ]),
   78	check_prolog_version(070717).
   79
   80:- initialization setup_versions.   81
   82
   83		 /*******************************
   84		 *	       CORS		*
   85		 *******************************/
   86
   87% By default, enable CORS
   88
   89:- set_setting_default(http:cors, [*]).   90
   91
   92		 /*******************************
   93		 *         LOCAL CONFIG		*
   94		 *******************************/
   95
   96% create the application first, so we can modify it inside the
   97% configuration files.
   98:- pengine_application(swish).
 load_config
Load files from config-enabled if present. Currently loads from a single config-enabled directory, either found locally or from the swish directory.
  106load_config :-
  107	absolute_file_name(config_enabled(.), Path,
  108			   [ file_type(directory),
  109			     access(read),
  110			     file_errors(fail)
  111			   ]), !,
  112	atom_concat(Path, '/*.pl', Pattern),
  113	expand_file_name(Pattern, Files),
  114	maplist(user:ensure_loaded, Files).
  115load_config.
  116
  117:- initialization(load_config, now).  118
  119
  120		 /*******************************
  121		 *	      CONFIG		*
  122		 *******************************/
  123
  124:- multifile
  125	swish_config:config/2,
  126	swish_config:source_alias/2.
 swish_config:config(?Config, ?Value) is nondet
All solutions of this predicate are available in the JavaScript object config.swish.config. Config must be an atom that is also a valid JavaScript identifier. Value must be a value that is valid for json_write_dict/2. Defined config parameters:
show_beware
If true, show the Beware modal dialog on startup
tabled_results
If true, check the table results checkbox by default.
application
Name of the Pengine application.
csv_formats
CSV output formats offered. For example, ClioPatria defines this as [rdf,prolog]. The first element is default.
community_examples
Allow marking saved programs as example. If marked, the programs are added to the Examples menu.
public_access
If lib/authenticate.pl is loaded and this flag is true, all access to SWISH demands authentication. If false, only running queries and saving files is restricted. Note that this flag has no effect if no authentication module is loaded.
include_alias
Alias for searching files for `:- include(Alias(Name)).`
ping
Ping pengine status every N seconds. Updates sparkline chart with stack usage.
notebook
Dict holding options for notebooks:
eval_script
Whether or not to evaluate JavaScript in cells
fullscreen
Whether or not to start in fullscreen mode by default
fullscreen
Dict holding options for fullscreen mode:
  • hide_navbar: hide the navigation bar when in fullscreen mode.
chat
Activate the chat interface
chat_spam_protection
Perform protection against spamming on chat messages.
default_query
Initial query for the source search in an empty tab

These config options are commonly overruled using one of the configuration files. See config-available and config-enabled directories.

The defaults below are for small installations. See config-available/dim_large.pl for a default config for large communities.

  183% Allow other code to overrule the defaults from this file.
  184term_expansion(swish_config:config(Config, _Value), []) :-
  185	clause(swish_config:config(Config, _), _).
  186
  187swish_config:config(show_beware,        false).
  188swish_config:config(tabled_results,     false).
  189swish_config:config(application,        swish).
  190swish_config:config(csv_formats,        [prolog]).
  191swish_config:config(community_examples, true).
  192swish_config:config(public_access,      false).
  193swish_config:config(include_alias,	example).
  194swish_config:config(ping,		2).
  195swish_config:config(notebook,		_{ eval_script: true,
  196					   fullscreen: false
  197					 }).
  198swish_config:config(fullscreen,		_{ hide_navbar: true
  199					 }).
  200swish_config:config(chat,		true).
  201swish_config:config(chat_spam_protection, true).
  202swish_config:config(default_query,	'').
 swish_config:source_alias(Alias, Options) is nondet
Specify access for files below a given alias. Options define
access(Access)
One of read or both. Default is read.
if(Condition)
Provide additional conditions. Defined conditions are:
loaded
Only provide access to the file if it is loaded.
  216% setup HTTP session management
  217:- use_module(lib/session).  218
  219
  220                 /*******************************
  221                 *   CREATE SWISH APPLICATION   *
  222                 *******************************/
  223
  224:- multifile
  225	pengines:prepare_module/3.  226
  227:- use_module(swish:lib/render).  228:- use_module(swish:lib/trace).  229:- use_module(swish:lib/projection).  230:- use_module(swish:lib/attvar).  231:- use_module(swish:lib/jquery).  232:- use_module(swish:lib/dashboard).  233:- use_module(swish:lib/md_eval).  234:- use_module(swish:lib/html_output).  235:- use_module(swish:lib/swish_diagnostics).  236:- use_module(swish:lib/swish_debug).  237:- use_module(swish:library(pengines_io)).  238:- use_module(swish:library(solution_sequences)).  239:- use_module(swish:library(aggregate)).  240
  241pengines:prepare_module(Module, swish, _Options) :-
  242	pengines_io:pengine_bind_io_to_html(Module).
  243
  244% Additional sandboxing rules.
  245:- use_module(lib/flags).  246
  247% Libraries that are nice to have in SWISH, but cannot be loaded
  248% because they use directives that are considered unsafe.  We load
  249% them here, so they only need to be imported, which is just fine.
  250
  251:- use_module(library(clpfd), []).  252:- use_module(library(clpb), []).  253:- if(exists_source(library(dcg/high_order))).  254:- use_module(library(dcg/high_order), []).  255:- endif.  256:- use_module(lib/swish_chr, []).  257
  258% load rendering modules
  259
  260:- use_module(swish(lib/render/sudoku),	  []).  261:- use_module(swish(lib/render/chess),	  []).  262:- use_module(swish(lib/render/table),	  []).  263:- use_module(swish(lib/render/codes),	  []).  264:- use_module(swish(lib/render/svgtree),  []).  265:- use_module(swish(lib/render/graphviz), []).  266:- use_module(swish(lib/render/c3),	  []).  267:- use_module(swish(lib/render/url),	  []).  268:- use_module(swish(lib/render/bdd),	  []).  269:- use_module(swish(lib/render/mathjax),  []).  270:- use_module(swish(lib/render/gvterm),   []).