Mercurial Hosting > luan
annotate src/luan/host/Init.luan @ 1238:3d29033de2bf
changes for https
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 Jun 2018 22:03:09 -0600 |
parents | 22228c12b6dd |
children | 2612e4307987 |
rev | line source |
---|---|
1135 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
1238 | 3 local do_file = Luan.do_file or error() |
1135 | 4 local String = require "luan:String.luan" |
5 local gsub = String.gsub or error() | |
6 | |
7 | |
8 local Init = {} | |
9 | |
10 local dir, domain = ... | |
11 | |
12 | |
13 -- logging | |
14 | |
15 java() | |
16 local Logger = require "java:org.apache.log4j.Logger" | |
1199 | 17 local Level = require "java:org.apache.log4j.Level" |
18 local EnhancedPatternLayout = require "java:org.apache.log4j.EnhancedPatternLayout" | |
19 local RollingFileAppender = require "java:org.apache.log4j.RollingFileAppender" | |
1135 | 20 |
21 local root = gsub(domain,"\.",":") | |
22 | |
1199 | 23 local logger = Logger.getLogger(root) |
24 local has_appenders = logger.getAllAppenders().hasMoreElements() | |
25 if not has_appenders then | |
26 logger.setAdditivity(false) | |
27 local layout = EnhancedPatternLayout.new("%d %-5p %c{-1} - %m%n") | |
28 local log_dir = dir.."/site/private/local/logs/" | |
1135 | 29 |
1199 | 30 local function add_appender(file,level) |
31 local appender = RollingFileAppender.new(layout, log_dir..file) | |
32 appender.setMaxFileSize("1MB") | |
33 logger.addAppender(appender) | |
34 if level ~= logger.getEffectiveLevel() then | |
35 appender.setThreshold(level) | |
36 end | |
37 end | |
1135 | 38 |
1199 | 39 add_appender("error.log",Level.ERROR) |
40 add_appender("warn.log",Level.WARN) | |
41 add_appender("info.log",Level.INFO) | |
1135 | 42 end |
43 | |
1199 | 44 local Logging = require "luan:logging/Logging.luan" |
1135 | 45 |
46 local old_logger = Logging.logger | |
47 | |
48 function Logging.root_logger() | |
49 return old_logger(root) | |
50 end | |
51 | |
52 function Logging.logger(name) | |
53 return old_logger( root .. "." .. name ) | |
54 end | |
55 | |
56 Init.logger_root = root.."." | |
57 | |
58 | |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
59 -- set vars |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
60 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
61 local Io = require "luan:Io.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
62 local Http = require "luan:http/Http.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
63 local Hosting = require "luan:host/Hosting.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
64 local Mail = require "luan:mail/Mail.luan" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
65 |
1238 | 66 Init.password = do_file(dir.."/info.luan").password or error() |
1235
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
67 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
68 Http.dir = "file:"..dir.."/site" |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
69 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
70 function Io.schemes.site(path,loading) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
71 return Io.uri( Http.dir..path, loading ) |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
72 end |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
73 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
74 Hosting.domain = domain |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
75 Io.password = Init.password |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
76 |
22228c12b6dd
fix luanhost thread logging
Franklin Schmidt <fschmidt@gmail.com>
parents:
1199
diff
changeset
|
77 |
1135 | 78 -- mail - fix later |
79 | |
80 Hosting.send_mail = Mail.Sender{ | |
81 host = "smtpcorp.com"; | |
82 username = "smtp@luanhost.com"; -- ? | |
83 password = "luanhost"; | |
84 port = 2525; | |
85 }.send | |
86 | |
87 | |
1238 | 88 -- callback to luanhost code |
89 do_file "file:init.luan" | |
90 | |
91 | |
1135 | 92 return Init |