liquid_feedback_frontend
view app/main/_prefork/10_init.lua @ 1816:baa87c3780ad
Delete after updating member data
| author | bsw | 
|---|---|
| date | Fri Dec 03 10:31:51 2021 +0100 (2021-12-03) | 
| parents | 7b16ddc69a2f | 
| children | 138a1508cdf3 | 
 line source
     1 config.app_version = "4.0.0"
     3 -- TODO abstraction
     4 -- get record by id
     5 function mondelefant.class_prototype:by_id(id)
     6   local selector = self:new_selector()
     7   selector:add_where{ 'id = ?', id }
     8   selector:optional_object_mode()
     9   return selector:exec()
    10 end
    12 if not config.password_hash_algorithm then
    13   config.password_hash_algorithm = "crypt_sha512"
    14 end
    16 if not config.password_hash_min_rounds then
    17  config.password_hash_min_rounds = 10000
    18 end
    20 if not config.password_hash_max_rounds then
    21   config.password_hash_max_rounds = 20000
    22 end
    24 if config.use_terms_checkboxes == nil then
    25   config.use_terms_checkboxes = {}
    26 end
    28 if config.enabled_languages == nil then
    29   config.enabled_languages = { 'en', 'de', 'ka' } --, 'eo', 'el', 'hu', 'it', 'nl', 'zh-Hans', 'zh-TW' }
    30 end
    32 if config.default_lang == nil then
    33   config.default_lang = "en"
    34 end
    36 if config.mail_subject_prefix == nil then
    37   config.mail_subject_prefix = "[LiquidFeedback] "
    38 end
    40 if config.notification_digest_template == nil then
    41   config.notification_digest_template = _"Hello #{name},\n\nthis is your personal digest.\n\n#{digest}\n"
    42 end
    44 if config.member_image_content_type == nil then
    45   config.member_image_content_type = "image/jpeg"
    46 end
    48 if config.member_image_convert_func == nil then
    49   config.member_image_convert_func = {
    50     avatar = function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail",   "48x48", "jpeg:-") end,
    51     photo =  function(data) return extos.pfilter(data, "convert", "jpeg:-", "-thumbnail", "240x240", "jpeg:-") end
    52   }
    53 end
    55 if config.locked_profile_fields == nil then
    56   config.locked_profile_fields = {}
    57 end
    59 if config.check_delegations_default == nil then
    60   config.check_delegations_default = "confirm"
    61 end
    63 if config.cookie_name == nil then
    64   config.cookie_name = "liquid_feedback_session"
    65 end
    67 if config.cookie_name_samesite == nil then
    68   config.cookie_name_samesite = config.cookie_name .. "_samesite"
    69 end
    71 if config.ldap == nil then
    72   config.ldap = {}
    73 end
    75 if config.oauth2 then
    76   local scopes = {
    77     { scope = "authentication", name = { de = "Identität feststellen (nur Screen-Name)", en = "Determine identity (screen name only)" } },
    78     { scope = "identification", name = { de = "Identität feststellen", en = "Determine identity" } },
    79     { scope = "notify_email", name = { de = "E-Mail-Adresse für Benachrichtigungen verwenden", en = "Use email address for notifications" } },
    80     { scope = "read_contents", name = { de = "Inhalte lesen", en = "Read content" } },
    81     { scope = "read_authors", name = { de = "Autorennamen lesen", en = "Read author names" } },
    82     { scope = "read_ratings", name = { de = "Bewertungen lesen", en = "Read ratings" } },
    83     { scope = "read_identities", name = { de = "Identitäten lesen", en = "Read identities" } },
    84     { scope = "read_profiles", name = { de = "Profile lesen", en = "Read profiles" } },
    85     { scope = "post", name = { de = "Neue Inhalte veröffentlichen", en = "Post new content" } },
    86     { scope = "rate", name = { de = "Bewertungen vornehmen", en = "Do ratings" } },
    87     { scope = "vote", name = { de = "Abstimmen", en = "Vote" } },
    88     { scope = "delegate", name = { de = "Delegieren", en = "Delegate" } },
    89     { scope = "profile", name = { de = "Eigenes Profil lesen", en = "Read your profile" } },
    90     { scope = "settings", name = { de = "Einstellungen einsehen", en = "Read your settings" } },
    91     { scope = "update_name", name = { de = "Screen-Namen ändern", en = "Update screen name" } },
    92     { scope = "update_notify_email", name = { de = "E-Mail-Adresse für Benachrichtigungen ändern", en = "Update notify email address" } },
    93     { scope = "update_profile", name = { de = "Profil bearbeiten", en = "Update your profile" } },
    94     { scope = "update_settings", name = { de = "Benutzereinstellungen ändern", en = "Update your settings" } },
    95     { scope = "login", name = { de = "Login", en = "Login" } }
    96   }
    97   local s = config.oauth2.available_scopes or {}
    98   for i, scope in ipairs(scopes) do
    99     s[#s+1] = scope
   100   end
   101   config.oauth2.available_scopes = s
   102   if not config.oauth2.endpoint_magic then
   103     config.oauth2.endpoint_magic = "liquidfeedback_client/redirection_endpoint"
   104   end
   105   if not config.oauth2.manifest_magic then
   106     config.oauth2.manifest_magic = "liquidfeedback_client/manifest"
   107   end
   108   if not config.oauth2.host_func then
   109     config.oauth2.host_func = function(domain) return extos.pfilter(nil, "host", "-t", "TXT", domain) end
   110   end
   111   if not config.oauth2.authorization_code_lifetime then
   112     config.oauth2.authorization_code_lifetime = 5 * 60
   113   end
   114   if not config.oauth2.refresh_token_lifetime then
   115     config.oauth2.refresh_token_lifetime = 60 * 60 * 24 * 30 * 3
   116   end
   117   if not config.oauth2.refresh_pause then
   118     config.oauth2.refresh_pause = 60
   119   end
   120   if not config.oauth2.refresh_grace_period then
   121     config.oauth2.refresh_grace_period = 60
   122   end
   123   if not config.oauth2.access_token_lifetime then
   124     config.oauth2.access_token_lifetime = 60 * 60
   125   end
   126   if not config.oauth2.dynamic_registration_lifetime then
   127     config.oauth2.dynamic_registration_lifetime = 60 * 60 * 24
   128   end
   129   if config.oauth2.refresh_pause < config.oauth2.refresh_grace_period then
   130     print("ERROR: config.auth2.refresh_pause is smaller than config.oauth2.refresh_grace_period")
   131     os.exit()
   132   end
   133 end
   135 if not config.database then
   136   config.database = { engine='postgresql', dbname='liquid_feedback' }
   137 end
   139 if not config.formatting_engines then
   140   config.enforce_formatting_engine = "html"
   141   config.formatting_engines = {
   142     { id = "html",
   143       name = "html",
   144       executable = "cat"
   145     }
   146   }
   147 end
   149 if not config.style then
   150   config.style = {
   151     color_md = {
   152       primary = "green",
   153       primary_contrast = "dark",
   154       accent = "blue",
   155       accent_contrast = "dark"
   156     }
   157   }
   158 end
   160 if not config.member_profile_fields then
   161   config.member_profile_fields = {}
   162 end
   165 if config.fork == nil then
   166   config.fork = {}
   167 end
   169 if config.fork.pre == nil then
   170   config.fork.pre = 2
   171 end
   173 if config.fork.min == nil then
   174   config.fork.min = 4
   175 end
   177 if config.fork.max == nil then
   178   config.fork.max = 128
   179 end
   181 if config.fork.delay == nil then
   182   config.fork.delay = 0.125
   183 end
   185 if config.fork.error_delay == nil then
   186   config.fork.error_delay = 2
   187 end
   189 if config.fork.exit_delay == nil then
   190   config.fork.exit_delay = 2
   191 end
   193 if config.fork.idle_timeout == nil then
   194   config.fork.idle_timeout = 900
   195 end
   197 if config.port == nil then
   198   config.port = 8080
   199 end
   201 if config.localhost == nil then
   202   config.localhost = true
   203 end
   205 local listen_options = {
   206   pre_fork              = config.fork.pre,
   207   min_fork              = config.fork.min,
   208   max_fork              = config.fork.max,
   209   fork_delay            = config.fork.delay,
   210   fork_error_delay      = config.fork.error_delay,
   211   exit_delay            = config.fork.exit_delay,
   212   idle_timeout          = config.fork.idle_timeout,
   213   memory_limit          = config.fork.memory_limit,
   214   min_requests_per_fork = config.fork.min_requests,
   215   max_requests_per_fork = config.fork.max_requests,
   216   http_options          = config.http_options
   217 }
   219 if config.ipv6 then
   220   local host = config.localhost and "::1" or "::"
   221   listen_options[#listen_options+1] = { proto = "tcp", host = host, port = config.port }
   222 end
   223 if config.ipv6 ~= "only" then
   224   local host = config.localhost and "127.0.0.1" or "0.0.0.0"
   225   listen_options[#listen_options+1] = { proto = "tcp", host = host, port = config.port }
   226 end
   228 request.set_404_route{ module = 'index', view = '404' }
   230 request.set_absolute_baseurl(config.absolute_base_url)
   232 -- TODO remove style cache
   234 listen(listen_options)
   236 listen{
   237   {
   238     proto = "main",
   239     name = "process_event_stream",
   240     handler = function(poll)
   241       Event:process_stream(poll)
   242     end    
   243   }
   244 }
   246 listen{
   247   {
   248     proto = "interval",
   249     name  = "send_pending_notifications",
   250     delay = 5,
   251     handler = function()
   252       while true do
   253         if not Newsletter:send_next_newsletter() then
   254           break
   255         end
   256         moonbridge_io.poll(nil, nil, 1)
   257       end
   258       while true do
   259         if not InitiativeForNotification:notify_next_member() then
   260           break
   261         end
   262         moonbridge_io.poll(nil, nil, 1)
   263       end
   264     end
   265   },
   266   min_fork = 1,
   267   max_fork = 1
   268 }
   270 if config.firstlife_groups then
   271   assert(loadcached(encode.file_path(WEBMCP_BASE_PATH, "lib", "firstlife", "groups.lua")))()
   272   listen{
   273     {
   274       proto = "interval",
   275       name  = "mirror_firstlife_groups",
   276       delay = 5,
   277       handler = function()
   278         firstlife_mirror_groups()
   279       end
   280     },
   281     min_fork = 1,
   282     max_fork = 1
   283   }
   284 end
   286 execute.inner()
