liquid_feedback_frontend

annotate app/main/_prefork/10_init.lua @ 1525:628e1b9126c0

Handle no valid session in session filter correctly
author bsw
date Thu Aug 20 15:55:04 2020 +0200 (2020-08-20)
parents f1258993d993
children 45fd259aa1ad
rev   line source
bsw/jbe@1309 1 config.app_version = "4.0.0-pre"
bsw@1222 2
bsw@1222 3 -- TODO abstraction
bsw@1222 4 -- get record by id
bsw@1222 5 function mondelefant.class_prototype:by_id(id)
bsw@1222 6 local selector = self:new_selector()
bsw@1222 7 selector:add_where{ 'id = ?', id }
bsw@1222 8 selector:optional_object_mode()
bsw@1222 9 return selector:exec()
bsw@1222 10 end
bsw@1222 11
bsw@1222 12 if not config.password_hash_algorithm then
bsw@1222 13 config.password_hash_algorithm = "crypt_sha512"
bsw@1222 14 end
bsw@1222 15
bsw@1222 16 if not config.password_hash_min_rounds then
bsw@1222 17 config.password_hash_min_rounds = 10000
bsw@1222 18 end
bsw@1222 19
bsw@1222 20 if not config.password_hash_max_rounds then
bsw@1222 21 config.password_hash_max_rounds = 20000
bsw@1222 22 end
bsw@1222 23
bsw@1253 24 if config.use_terms_checkboxes == nil then
bsw@1253 25 config.use_terms_checkboxes = {}
bsw@1253 26 end
bsw@1253 27
bsw@1222 28 if config.enabled_languages == nil then
bsw@1222 29 config.enabled_languages = { 'en', 'de', 'ka' } --, 'eo', 'el', 'hu', 'it', 'nl', 'zh-Hans', 'zh-TW' }
bsw@1222 30 end
bsw@1222 31
bsw@1222 32 if config.default_lang == nil then
bsw@1222 33 config.default_lang = "en"
bsw@1222 34 end
bsw@1222 35
bsw@1222 36 if config.mail_subject_prefix == nil then
bsw@1222 37 config.mail_subject_prefix = "[LiquidFeedback] "
bsw@1222 38 end
bsw@1222 39
bsw@1250 40 if config.notification_digest_template == nil then
bsw@1250 41 config.notification_digest_template = "Hello #{name},\n\nthis is your personal digest.\n\n#{digest}\n"
bsw@1250 42 end
bsw@1250 43
bsw@1222 44 if config.member_image_content_type == nil then
bsw@1222 45 config.member_image_content_type = "image/jpeg"
bsw@1222 46 end
bsw@1222 47
bsw@1222 48 if config.member_image_convert_func == nil then
bsw@1222 49 config.member_image_convert_func = {
bsw@1222 50 avatar = function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail", "48x48", "jpeg:-") end,
bsw@1222 51 photo = function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail", "240x240", "jpeg:-") end
bsw@1222 52 }
bsw@1222 53 end
bsw@1222 54
bsw@1222 55 if config.locked_profile_fields == nil then
bsw@1222 56 config.locked_profile_fields = {}
bsw@1222 57 end
bsw@1222 58
bsw@1222 59 if config.check_delegations_default == nil then
bsw@1222 60 config.check_delegations_default = "confirm"
bsw@1222 61 end
bsw@1222 62
bsw@1511 63 if config.cookie_name == nil then
bsw@1511 64 config.cookie_name = "liquid_feedback_session"
bsw@1511 65 end
bsw@1511 66
bsw@1511 67 if config.cookie_name_samesite == nil then
bsw@1511 68 config.cookie_name_samesite = config.cookie_name .. "_samesite"
bsw@1511 69 end
bsw@1511 70
bsw@1222 71 if config.ldap == nil then
bsw@1222 72 config.ldap = {}
bsw@1222 73 end
bsw@1222 74
bsw/jbe@1309 75 if config.oauth2 then
bsw/jbe@1309 76 local scopes = {
bsw/jbe@1309 77 { scope = "authentication", name = { de = "Identität feststellen (nur Screen-Name)", en = "Determine identity (screen name only)" } },
bsw/jbe@1309 78 { scope = "identification", name = { de = "Identität feststellen", en = "Determine identity" } },
bsw/jbe@1309 79 { scope = "notify_email", name = { de = "E-Mail-Adresse für Benachrichtigungen verwenden", en = "Use email address for notifications" } },
bsw/jbe@1309 80 { scope = "read_contents", name = { de = "Inhalte lesen", en = "Read content" } },
bsw/jbe@1309 81 { scope = "read_authors", name = { de = "Autorennamen lesen", en = "Read author names" } },
bsw/jbe@1309 82 { scope = "read_ratings", name = { de = "Bewertungen lesen", en = "Read ratings" } },
bsw/jbe@1309 83 { scope = "read_identities", name = { de = "Identitäten lesen", en = "Read identities" } },
bsw/jbe@1309 84 { scope = "read_profiles", name = { de = "Profile lesen", en = "Read profiles" } },
bsw/jbe@1309 85 { scope = "post", name = { de = "Neue Inhalte veröffentlichen", en = "Post new content" } },
bsw/jbe@1309 86 { scope = "rate", name = { de = "Bewertungen vornehmen", en = "Do ratings" } },
bsw/jbe@1309 87 { scope = "vote", name = { de = "Abstimmen", en = "Vote" } },
bsw/jbe@1309 88 { scope = "delegate", name = { de = "Delegieren", en = "Delegate" } },
bsw/jbe@1309 89 { scope = "profile", name = { de = "Eigenes Profil lesen", en = "Read your profile" } },
bsw/jbe@1309 90 { scope = "settings", name = { de = "Einstellungen einsehen", en = "Read your settings" } },
bsw/jbe@1309 91 { scope = "update_name", name = { de = "Screen-Namen ändern", en = "Update screen name" } },
bsw/jbe@1309 92 { scope = "update_notify_email", name = { de = "E-Mail-Adresse für Benachrichtigungen ändern", en = "Update notify email address" } },
bsw/jbe@1309 93 { scope = "update_profile", name = { de = "Profil bearbeiten", en = "Update your profile" } },
bsw/jbe@1309 94 { scope = "update_settings", name = { de = "Benutzereinstellungen ändern", en = "Update your settings" } }
bsw/jbe@1309 95 }
bsw/jbe@1309 96 local s = config.oauth2.available_scopes or {}
bsw/jbe@1309 97 for i, scope in ipairs(scopes) do
bsw/jbe@1309 98 s[#s+1] = scope
bsw/jbe@1309 99 end
bsw/jbe@1309 100 config.oauth2.available_scopes = s
bsw/jbe@1309 101 if not config.oauth2.endpoint_magic then
bsw/jbe@1309 102 config.oauth2.endpoint_magic = "liquidfeedback_client/redirection_endpoint"
bsw/jbe@1309 103 end
bsw/jbe@1309 104 if not config.oauth2.manifest_magic then
bsw/jbe@1309 105 config.oauth2.manifest_magic = "liquidfeedback_client/manifest"
bsw/jbe@1309 106 end
bsw/jbe@1309 107 if not config.oauth2.host_func then
bsw/jbe@1309 108 config.oauth2.host_func = function(domain) return extos.pfilter(nil, "host", "-t", "TXT", domain) end
bsw/jbe@1309 109 end
bsw/jbe@1309 110 if not config.oauth2.authorization_code_lifetime then
bsw/jbe@1309 111 config.oauth2.authorization_code_lifetime = 5 * 60
bsw/jbe@1309 112 end
bsw/jbe@1309 113 if not config.oauth2.refresh_token_lifetime then
bsw/jbe@1309 114 config.oauth2.refresh_token_lifetime = 60 * 60 * 24 * 30 * 3
bsw/jbe@1309 115 end
bsw/jbe@1309 116 if not config.oauth2.refresh_pause then
bsw/jbe@1309 117 config.oauth2.refresh_pause = 60
bsw/jbe@1309 118 end
bsw/jbe@1309 119 if not config.oauth2.refresh_grace_period then
bsw/jbe@1309 120 config.oauth2.refresh_grace_period = 60
bsw/jbe@1309 121 end
bsw/jbe@1309 122 if not config.oauth2.access_token_lifetime then
bsw/jbe@1309 123 config.oauth2.access_token_lifetime = 60 * 60
bsw/jbe@1309 124 end
bsw/jbe@1309 125 if not config.oauth2.dynamic_registration_lifetime then
bsw/jbe@1309 126 config.oauth2.dynamic_registration_lifetime = 60 * 60 * 24
bsw/jbe@1309 127 end
bsw/jbe@1309 128 end
bsw/jbe@1309 129
bsw@1222 130 if not config.database then
bsw@1222 131 config.database = { engine='postgresql', dbname='liquid_feedback' }
bsw@1222 132 end
bsw@1222 133
jbe@1167 134 if config.fork == nil then
bsw@1158 135 config.fork = {}
bsw@1158 136 end
bsw@1158 137
jbe@1167 138 if config.fork.pre == nil then
jbe@1167 139 config.fork.pre = 2
bsw@1158 140 end
bsw@1158 141
jbe@1167 142 if config.fork.min == nil then
jbe@1167 143 config.fork.min = 4
jbe@1167 144 end
jbe@1167 145
jbe@1167 146 if config.fork.max == nil then
bsw@1169 147 config.fork.max = 128
bsw@1158 148 end
bsw@1158 149
jbe@1167 150 if config.fork.delay == nil then
jbe@1167 151 config.fork.delay = 0.125
jbe@1167 152 end
jbe@1167 153
jbe@1167 154 if config.fork.error_delay == nil then
jbe@1167 155 config.fork.error_delay = 2
bsw@1158 156 end
bsw@1158 157
jbe@1167 158 if config.fork.exit_delay == nil then
jbe@1167 159 config.fork.exit_delay = 2
jbe@1167 160 end
jbe@1167 161
jbe@1167 162 if config.fork.idle_timeout == nil then
jbe@1167 163 config.fork.idle_timeout = 900
jbe@1167 164 end
jbe@1167 165
jbe@1167 166 if config.port == nil then
bsw@1158 167 config.port = 8080
bsw@1158 168 end
bsw@1158 169
bsw@1158 170 if config.localhost == nil then
bsw@1158 171 config.localhost = true
bsw@1158 172 end
bsw@1158 173
jbe@1167 174 local listen_options = {
jbe@1167 175 pre_fork = config.fork.pre,
jbe@1167 176 min_fork = config.fork.min,
jbe@1167 177 max_fork = config.fork.max,
jbe@1167 178 fork_delay = config.fork.delay,
jbe@1167 179 fork_error_delay = config.fork.error_delay,
jbe@1167 180 exit_delay = config.fork.exit_delay,
jbe@1167 181 idle_timeout = config.fork.idle_timeout,
bsw@1169 182 memory_limit = config.fork.memory_limit,
jbe@1167 183 min_requests_per_fork = config.fork.min_requests,
jbe@1167 184 max_requests_per_fork = config.fork.max_requests,
jbe@1167 185 http_options = config.http_options
jbe@1167 186 }
jbe@1167 187
jbe@1167 188 if config.ipv6 then
bsw@1199 189 local host = config.localhost and "::1" or "::"
bsw@1199 190 listen_options[#listen_options+1] = { proto = "tcp", host = host, port = config.port }
jbe@1167 191 end
jbe@1167 192 if config.ipv6 ~= "only" then
bsw@1202 193 local host = config.localhost and "127.0.0.1" or "0.0.0.0"
bsw@1199 194 listen_options[#listen_options+1] = { proto = "tcp", host = host, port = config.port }
jbe@1167 195 end
jbe@1167 196
bsw@1222 197 request.set_404_route{ module = 'index', view = '404' }
bsw@1222 198
bsw@1222 199 request.set_absolute_baseurl(config.absolute_base_url)
bsw@1222 200
bsw/jbe@1309 201 -- TODO remove style cache
bsw/jbe@1309 202
jbe@1167 203 listen(listen_options)
jbe@1167 204
bsw@1158 205 listen{
jbe@1167 206 {
bsw/jbe@1309 207 proto = "main",
bsw/jbe@1309 208 name = "process_event_stream",
bsw/jbe@1309 209 handler = function(poll)
bsw/jbe@1309 210 Event:process_stream(poll)
bsw/jbe@1309 211 end
bsw/jbe@1309 212 }
bsw/jbe@1309 213 }
bsw/jbe@1309 214
bsw/jbe@1309 215 listen{
bsw/jbe@1309 216 {
jbe@1167 217 proto = "interval",
jbe@1167 218 name = "send_pending_notifications",
jbe@1167 219 delay = 5,
bsw@1248 220 handler = function()
bsw@1248 221 while true do
bsw@1250 222 if not Newsletter:send_next_newsletter() then
bsw@1250 223 break
bsw@1250 224 end
bsw@1414 225 moonbridge_io.poll(nil, nil, 1)
bsw@1250 226 end
bsw@1250 227 while true do
bsw@1250 228 if not InitiativeForNotification:notify_next_member() then
bsw@1248 229 break
bsw@1248 230 end
bsw@1414 231 moonbridge_io.poll(nil, nil, 1)
bsw@1248 232 end
jbe@1167 233 end
jbe@1167 234 },
jbe@1167 235 min_fork = 1,
jbe@1167 236 max_fork = 1
bsw@1158 237 }
bsw@1158 238
bsw@1158 239 execute.inner()
bsw@1158 240

Impressum / About Us