summaryrefslogtreecommitdiff
path: root/tex/context
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-03-07 13:03:14 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-03-07 13:03:14 +0100
commit62185974cd9c16ad11788dbeebb30f466a2fb38c (patch)
tree74c188aedb7fa2d08b28a8e86084f70aa6c93da4 /tex/context
parent4ec0856ccdbd5bf6e110467d4623b52566b0e37d (diff)
downloadcontext-62185974cd9c16ad11788dbeebb30f466a2fb38c.tar.gz
2018-03-07 12:26:00
Diffstat (limited to 'tex/context')
-rw-r--r--tex/context/base/mkii/cont-new.mkii2
-rw-r--r--tex/context/base/mkii/context.mkii2
-rw-r--r--tex/context/base/mkii/mult-de.mkii2
-rw-r--r--tex/context/base/mkiv/cont-new.mkiv2
-rw-r--r--tex/context/base/mkiv/context.mkiv2
-rw-r--r--tex/context/base/mkiv/status-files.pdfbin25857 -> 25855 bytes
-rw-r--r--tex/context/base/mkiv/status-lua.pdfbin253048 -> 253055 bytes
-rw-r--r--tex/context/base/mkiv/util-sql-imp-ffi.lua6
-rw-r--r--tex/context/base/mkiv/util-sql-logins.lua306
-rw-r--r--tex/context/interface/mkii/keys-de.xml2
-rw-r--r--tex/context/interface/mkiv/i-context.pdfbin848101 -> 848098 bytes
-rw-r--r--tex/context/interface/mkiv/i-readme.pdfbin60775 -> 60776 bytes
12 files changed, 318 insertions, 6 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii
index 64f238b14..55741083b 100644
--- a/tex/context/base/mkii/cont-new.mkii
+++ b/tex/context/base/mkii/cont-new.mkii
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\newcontextversion{2018.03.06 14:59}
+\newcontextversion{2018.03.07 12:18}
%D This file is loaded at runtime, thereby providing an
%D excellent place for hacks, patches, extensions and new
diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii
index 59c766e6d..f2fce340e 100644
--- a/tex/context/base/mkii/context.mkii
+++ b/tex/context/base/mkii/context.mkii
@@ -20,7 +20,7 @@
%D your styles an modules.
\edef\contextformat {\jobname}
-\edef\contextversion{2018.03.06 14:59}
+\edef\contextversion{2018.03.07 12:18}
%D For those who want to use this:
diff --git a/tex/context/base/mkii/mult-de.mkii b/tex/context/base/mkii/mult-de.mkii
index 8e79e3856..a5269ff3f 100644
--- a/tex/context/base/mkii/mult-de.mkii
+++ b/tex/context/base/mkii/mult-de.mkii
@@ -1077,6 +1077,7 @@
\setinterfaceconstant{preview}{vorschau}
\setinterfaceconstant{previous}{vorige}
\setinterfaceconstant{previousnumber}{vorigenummer}
+\setinterfaceconstant{print}{print}
\setinterfaceconstant{printable}{druckbar}
\setinterfaceconstant{process}{process}
\setinterfaceconstant{profile}{profile}
@@ -1162,6 +1163,7 @@
\setinterfaceconstant{sidemethod}{sidemethod}
\setinterfaceconstant{sidespaceafter}{nebennachspatium}
\setinterfaceconstant{sidespacebefore}{nebenvorspatium}
+\setinterfaceconstant{sidespaceinbetween}{sidespaceinbetween}
\setinterfaceconstant{sidethreshold}{sidethreshold}
\setinterfaceconstant{sign}{zeichen}
\setinterfaceconstant{simplecommand}{simplecommand}
diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv
index 185b10341..ae8748f0f 100644
--- a/tex/context/base/mkiv/cont-new.mkiv
+++ b/tex/context/base/mkiv/cont-new.mkiv
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\newcontextversion{2018.03.06 14:59}
+\newcontextversion{2018.03.07 12:18}
%D This file is loaded at runtime, thereby providing an excellent place for
%D hacks, patches, extensions and new features.
diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv
index 2fc4222bb..8cf5eff00 100644
--- a/tex/context/base/mkiv/context.mkiv
+++ b/tex/context/base/mkiv/context.mkiv
@@ -42,7 +42,7 @@
%D has to match \type {YYYY.MM.DD HH:MM} format.
\edef\contextformat {\jobname}
-\edef\contextversion{2018.03.06 14:59}
+\edef\contextversion{2018.03.07 12:18}
\edef\contextkind {beta}
%D For those who want to use this:
diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf
index 1693e5e85..b5094c116 100644
--- a/tex/context/base/mkiv/status-files.pdf
+++ b/tex/context/base/mkiv/status-files.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf
index f63b33d65..5ee29c774 100644
--- a/tex/context/base/mkiv/status-lua.pdf
+++ b/tex/context/base/mkiv/status-lua.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/util-sql-imp-ffi.lua b/tex/context/base/mkiv/util-sql-imp-ffi.lua
index adda02107..07c4752cd 100644
--- a/tex/context/base/mkiv/util-sql-imp-ffi.lua
+++ b/tex/context/base/mkiv/util-sql-imp-ffi.lua
@@ -144,7 +144,8 @@ ffi.cdef [[
local sql = utilities.sql
----- mysql = ffi.load(os.name == "windows" and "libmysql" or "libmysqlclient")
-local mysql = ffilib(os.name == "windows" and "libmysql" or "libmysqlclient")
+----- mysql = ffilib(os.name == "windows" and "libmysql" or "libmysqlclient")
+local mysql = ffilib(os.name == "windows" and "libmysql" or "libmysql")
if not mysql then
report_state("unable to load library")
@@ -508,7 +509,8 @@ local function execute(specification)
end
local wraptemplate = [[
-local mysql = ffi.load(os.name == "windows" and "libmysql" or "libmysqlclient")
+----- mysql = ffi.load(os.name == "windows" and "libmysql" or "libmysqlclient")
+local mysql = ffi.load(os.name == "windows" and "libmysql" or "libmysql")
local mysql_fetch_row = mysql.mysql_fetch_row
local ffi_tostring = ffi.string
diff --git a/tex/context/base/mkiv/util-sql-logins.lua b/tex/context/base/mkiv/util-sql-logins.lua
new file mode 100644
index 000000000..e4329ecc2
--- /dev/null
+++ b/tex/context/base/mkiv/util-sql-logins.lua
@@ -0,0 +1,306 @@
+if not modules then modules = { } end modules ['util-sql-logins'] = {
+ version = 1.001,
+ comment = "companion to lmx-*",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+if not utilities.sql then require("util-sql") end
+
+local sql = utilities.sql
+local sqlexecute = sql.execute
+local sqlmakeconverter = sql.makeconverter
+
+local format = string.format
+local ostime = os.time
+local formatter = string.formatter
+
+local trace_logins = true
+local report_logins = logs.reporter("sql","logins")
+
+local logins = sql.logins or { }
+sql.logins = logins
+
+logins.maxnoflogins = logins.maxnoflogins or 10
+logins.cooldowntime = logins.cooldowntime or 10 * 60
+logins.purgetime = logins.purgetime or 1 * 60 * 60
+logins.autopurge = true
+
+local template_create = [[
+CREATE TABLE
+ `logins`
+ (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) COLLATE utf8_bin NOT NULL,
+ `time` int(11) DEFAULT '0',
+ `n` int(11) DEFAULT '0',
+ `state` int(11) DEFAULT '0',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `id_UNIQUE` (`id`),
+ UNIQUE KEY `name_UNIQUE` (`name`)
+ )
+ ENGINE=InnoDB
+ DEFAULT CHARSET=utf8
+ COLLATE=utf8_bin
+ COMMENT='state: 0=unset 1=known 2=unknown'
+]]
+
+local states = {
+ [0] = "unset",
+ [1] = "known",
+ [2] = "unknown",
+}
+
+local converter_fetch, fields_fetch = sqlmakeconverter {
+ { name = "id", type = "number" },
+ { name = "name", type = "string" },
+ { name = "time", type = "number" },
+ { name = "n", type = "number" },
+ { name = "state", type = "number" }, -- faster than mapping
+}
+
+local template_fetch = format( [[
+ SELECT
+ %s
+ FROM
+ `logins`
+ WHERE
+ `name` = '%%[name]%%'
+]], fields_fetch )
+
+local template_insert = [[
+ INSERT INTO `logins`
+ ( `name`, `state`, `time`, `n`)
+ VALUES
+ ('%[name]%', %state%, %time%, %n%)
+]]
+
+local template_update = [[
+ UPDATE
+ `logins`
+ SET
+ `state` = %state%,
+ `time` = %time%,
+ `n` = %n%
+ WHERE
+ `name` = '%[name]%'
+]]
+
+local template_delete = [[
+ DELETE FROM
+ `logins`
+ WHERE
+ `name` = '%[name]%'
+]]
+
+local template_purge = [[
+ DELETE FROM
+ `logins`
+ WHERE
+ `time` < '%time%'
+]]
+
+-- todo: auto cleanup (when new attempt)
+
+local cache = { } setmetatable(cache, { __mode = 'v' })
+
+local function usercreate(presets)
+ sqlexecute {
+ template = template_create,
+ presets = presets,
+ }
+end
+
+local function userunknown(presets,name)
+ local d = {
+ name = name,
+ state = 2,
+ time = ostime(),
+ n = 0,
+ }
+ sqlexecute {
+ template = template_update,
+ presets = presets,
+ variables = d,
+ }
+ cache[name] = d
+ report_logins("user %a is registered as unknown",name)
+end
+
+local function userknown(presets,name)
+ local d = {
+ name = name,
+ state = 1,
+ time = ostime(),
+ n = 0,
+ }
+ sqlexecute {
+ template = template_update,
+ presets = presets,
+ variables = d,
+ }
+ cache[name] = d
+ report_logins("user %a is registered as known",name)
+end
+
+local function userreset(presets,name)
+ sqlexecute {
+ template = template_delete,
+ presets = presets,
+ }
+ cache[name] = nil
+ report_logins("user %a is reset",name)
+end
+
+local function userpurge(presets,delay)
+ sqlexecute {
+ template = template_purge,
+ presets = presets,
+ variables = {
+ time = ostime() - (delay or logins.purgetime),
+ }
+ }
+ cache = { }
+ report_logins("users are purged")
+end
+
+local function verdict(okay,...)
+ if not trace_logins then
+ -- no tracing
+ elseif okay then
+ report_logins("%s, granted",formatter(...))
+ else
+ report_logins("%s, blocked",formatter(...))
+ end
+ return okay
+end
+
+local lasttime = 0
+
+local function userpermitted(presets,name)
+ local currenttime = ostime()
+ if logins.autopurge and (lasttime == 0 or (currenttime - lasttime > logins.purgetime)) then
+ report_logins("automatic purge triggered")
+ userpurge(presets)
+ lasttime = currenttime
+ end
+ local data = cache[name]
+ if data then
+ report_logins("user %a is cached",name)
+ else
+ report_logins("user %a is fetched",name)
+ data = sqlexecute {
+ template = template_fetch,
+ presets = presets,
+ converter = converter_fetch,
+ variables = {
+ name = name,
+ }
+ }
+ end
+ if not data or not data.name then
+ local d = {
+ name = name,
+ state = 0,
+ time = currenttime,
+ n = 1,
+ }
+ sqlexecute {
+ template = template_insert,
+ presets = presets,
+ variables = d,
+ }
+ cache[name] = d
+ return verdict(true,"creating new entry for %a",name)
+ end
+ cache[name] = data[1]
+ local state = data.state
+ if state == 2 then -- unknown
+ return verdict(false,"user %a has state %a",name,states[state])
+ end
+ local n = data.n
+ local m = logins.maxnoflogins
+ if n > m then
+ local deltatime = currenttime - data.time
+ local cooldowntime = logins.cooldowntime
+ if deltatime < cooldowntime then
+ return verdict(false,"user %a is blocked for %s seconds out of %s",name,cooldowntime-deltatime,cooldowntime)
+ else
+ n = 0
+ end
+ end
+ if n == 0 then
+ local d = {
+ name = name,
+ state = 0,
+ time = currenttime,
+ n = 1,
+ }
+ sqlexecute {
+ template = template_update,
+ presets = presets,
+ variables = d,
+ }
+ cache[name] = d
+ return verdict(true,"user %a gets a first chance",name)
+ else
+ local d = {
+ name = name,
+ state = 0,
+ time = currenttime,
+ n = n + 1,
+ }
+ sqlexecute {
+ template = template_update,
+ presets = presets,
+ variables = d,
+ }
+ cache[name] = d
+ return verdict(true,"user %a gets a new chance, %s attempts out of %s done",name,n,m)
+ end
+end
+
+logins.create = usercreate
+logins.known = userknown
+logins.unknown = userunknown
+logins.reset = userreset
+logins.purge = userpurge
+logins.permitted = userpermitted
+
+return logins
+
+-- --
+
+-- sql.setmethod("client")
+
+-- local presets = {
+-- database = "test",
+-- username = "root",
+-- password = "something",
+-- }
+
+-- logins.cooldowntime = 2*60
+-- logins.maxnoflogins = 3
+
+-- sql.logins.purge(presets,0)
+
+-- for i=1,6 do
+-- print("")
+-- sql.logins.permitted(presets,"hans")
+-- sql.logins.permitted(presets,"kees")
+-- sql.logins.permitted(presets,"ton")
+-- if i == 1 then
+-- -- sql.logins.unknown(presets,"hans")
+-- -- sql.logins.known(presets,"kees")
+-- end
+-- end
+
+-- if loginpermitted(presets,username) then
+-- if validlogin(username,...) then
+-- -- sql.logins.known(presets,username)
+-- elseif unknownuser(username) then
+-- sql.logins.unknown(presets,username)
+-- end
+-- end
+
diff --git a/tex/context/interface/mkii/keys-de.xml b/tex/context/interface/mkii/keys-de.xml
index 449d46fa6..f399f128a 100644
--- a/tex/context/interface/mkii/keys-de.xml
+++ b/tex/context/interface/mkii/keys-de.xml
@@ -1083,6 +1083,7 @@
<cd:constant name='preview' value='vorschau'/>
<cd:constant name='previous' value='vorige'/>
<cd:constant name='previousnumber' value='vorigenummer'/>
+ <cd:constant name='print' value='print'/>
<cd:constant name='printable' value='druckbar'/>
<cd:constant name='process' value='process'/>
<cd:constant name='profile' value='profile'/>
@@ -1168,6 +1169,7 @@
<cd:constant name='sidemethod' value='sidemethod'/>
<cd:constant name='sidespaceafter' value='nebennachspatium'/>
<cd:constant name='sidespacebefore' value='nebenvorspatium'/>
+ <cd:constant name='sidespaceinbetween' value='sidespaceinbetween'/>
<cd:constant name='sidethreshold' value='sidethreshold'/>
<cd:constant name='sign' value='zeichen'/>
<cd:constant name='simplecommand' value='simplecommand'/>
diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf
index 1a29d501f..ac301f450 100644
--- a/tex/context/interface/mkiv/i-context.pdf
+++ b/tex/context/interface/mkiv/i-context.pdf
Binary files differ
diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf
index 47eb69524..d7c363731 100644
--- a/tex/context/interface/mkiv/i-readme.pdf
+++ b/tex/context/interface/mkiv/i-readme.pdf
Binary files differ