- page 2

  • Redirect


    One way to redirect inside the rails router based on the client’s Accept-Language header.

    Previously i thought i had to do this inside the proxy webserver nginx, only really possible with the lua-enhanced fork of openresty, or the selfcompiled nginx version.

    Or to go into the rack middleware world and figure out how to do it there - it’s probably still the fastest, cleanest to do it there.

    There are more ways above that: routes file, and of course application controller.

    I went for the routes file and added this directive:

    root to: redirect { |params, request|
    
    "/#{best_locale_from_request!(request)}"
    
    }, status: 302, as: :redirected_root
    

    The curly braces syntax is obligatory, do/end block does not work.

    The actual work is being done with the help of teh accept_language gem and these two methods, split up for easier reading i presume:

    def best_locale_from_request(request)
    	return I18n.default_locale unless request.headers.key?("HTTP_ACCEPT_LANGUAGE")
    	string = request.headers.fetch("HTTP_ACCEPT_LANGUAGE")
    	locale = AcceptLanguage.parse(string).match(*I18n.available_locales)
    
    	# If the server cannot serve any matching language,
    	# it can theoretically send back a 406 (Not Acceptable) error code.
    	# But, for a better user experience, this is rarely done and more
    	# common way is to ignore the Accept-Language header in this case.
    
    	return I18n.default_locale if locale.nil?
    	locale
    end
    

    I’ve put them both into the routes file, but there might be a better place for that.

    The available locales array grew a bit, in order to prevent edge cases:

    # config/application.rb
    
    config.i18n.available_locales = [:en, :"en-150", :"en-001", :"en-DE", :de, :"de-AT", :"de-CH", :"de-DE", :"de-BE", :"de-IT", :"de-LI", :"de-LU", :et, :"et-EE"]
    

    turns out the gem always forwards the geography part as well, so in order to make sure nobody is left out, i’ve added this for now. this might become tricky later on as paths are created based on that, and the language switcher might be a bit more tricky. maybe it makes sense to cut the second part off somehow.

    Resources:

    Accept-Language gem: https://github.com/cyril/accept_language.rb

    A rack app i did not get to work, but apparently does the i18n settings as well: https://github.com/blindsidenetworks/i18n-language-mapping

    This was very helpful for the redirect syntax: https://www.paweldabrowski.com/articles/rails-routes-less-known-features

  • I shared a link

    PERMALINK

    Isabel Jezierska: 'Maybe it's time to speak out?'

    Demonstrations by students and university staff in Estonia have, until now, been slow and infrequent. However, demonstrations are a natural part of a democratic society and a legitimate way to influence leaders to change their policies, writes Isabel Jezierska, MA student at the University of Tartu.

    https://news.err.ee/1608698500/isabel-jezierska-maybe-it-s-time-to-speak-out

  • I shared a link

    PERMALINK

    Liberal entrepreneurs ditching 'no-state-help' dogma, lawmakers are not

    Every economic downturn brings changes to the market and Estonia is no different. The 2008 loan market collapse made Estonian companies think about financial reserves. The pandemic has changed e-Estonia's often individualistic business approach, as business leaders are calling for more state help. But the government doesn't seem to listen.

    and as always: privatise profits, socialise risks

  • I shared a link

    PERMALINK

    Augenzeugen berichten von Exekutionen und Vergewaltigungen

    Nach Aussagen von ukrainischen Geflüchteten haben russische Soldaten in Vororten von Kiew wehrlose Zivilisten getötet und Frauen vergewaltigt. RBB24 Recherche liegen entsprechende Augenzeugenberichte vor.

    “Der angeschossene Juri S. bricht zusammen. Er blutet stark. Die Soldaten schieben einen Deckel auf den Schacht und gehen ins Haus. Tatjana S. erinnert sich, wie sie hrten, dass sie das Haus durchsuchten. Mehrere Stunden sitzen Mutter und Tochter eingesperrt in dem Pumpenschacht. Der Atem von Juri S. wird von Stunde zu Stunde schwcher. Gegen 02.30 Uhr in der Nacht stirbt er.”

    “Sie berichtet, dass Soldaten ihren Mann ermordet haben, nachdem sie eine Camouflage-Jacke in seinem Auto gefunden hatten. Der Mrder soll gesagt haben: “Ich habe ihn erschossen, weil er ein Nazi war.” Natalya* selbst sei von den Ttern mehrfach vergewaltigt worden, whrend ihr vierjhriger Sohn nebenan im Heizungsraum weinte.”

    1. Alle Sanktionen jetzt.
    2. Alle Waffenlieferungen jetzt.
    3. Ukraine in die EU jetzt.
    4. Russland raus aus allen internationalen Vertrgen und Organisation jetzt.
  • I shared a link

    PERMALINK

    Attention Required! | Cloudflare

    This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
  • Moving lvm-thin volumes on proxmox between vm-s or ct-s


    Following this official howto

    lvs shows you all volumes in their volume group (in my case ‘ssd’)

    LV               VG  Attr       LSize    Pool        Data%  Meta%
    data             pve twi-a-tz-- 32.12g               0.00   1.58
    root             pve -wi-ao---- 16.75g
    swap             pve -wi-ao---- 8.00g
    guests           ssd twi-aotz-- <2.33t               74.93  45.51
    vm-100-disk-0    ssd Vwi-a-tz-- 12.00g guests        72.69
    vm-101-disk-0    ssd Vwi-a-tz-- 12.00g guests        85.22
    vm-101-disk-1    ssd Vwi-a-tz-- 50.00g guests        99.95
    vm-102-disk-0    ssd Vwi-a-tz-- 12.00g guests        97.57
    vm-102-disk-1    ssd Vwi-a-tz-- 50.00g guests        64.54
    vm-103-disk-0    ssd Vwi-a-tz-- 12.00g guests        74.37
    vm-103-disk-1    ssd Vwi-a-tz-- 150.00g guests        52.42
    vm-104-disk-0    ssd Vwi-a-tz-- 12.00g guests        90.74
    vm-104-disk-1    ssd Vwi-a-tz-- 10.00g guests        95.27
    vm-105-disk-0    ssd Vwi-a-tz-- 12.00g guests        55.79
    vm-105-disk-1    ssd Vwi-a-tz-- 10.00g guests        32.89
    vm-106-disk-0    ssd Vwi-a-tz-- 12.00g guests        77.78
    vm-106-disk-1    ssd Vwi-a-tz-- 10.00g guests        99.82
    vm-107-disk-0    ssd Vwi-a-tz-- 32.00g guests        0.00
    vm-107-disk-1    ssd Vwi-a-tz-- 500.00g guests        95.41
    vm-108-disk-0    ssd Vwi-aotz-- 8.00g guests        43.73
    vm-109-disk-0    ssd Vwi-a-tz-- 12.00g guests        52.41
    vm-109-disk-1    ssd Vwi-a-tz-- 50.00g guests        2.22
    vm-110-disk-0    ssd Vwi-a-tz-- 12.00g guests        51.14
    vm-110-disk-1    ssd Vwi-a-tz-- 50.00g guests        2.22
    vm-111-disk-0    ssd Vwi-a-tz-- 12.00g guests        84.85
    vm-111-disk-1    ssd Vwi-a-tz-- 100.00g guests        16.97
    vm-112-disk-0    ssd Vwi-a-tz-- 8.00g guests        13.53
    vm-113-disk-0    ssd Vwi-a-tz-- 8.00g guests        11.55
    vm-114-disk-0    ssd Vwi-a-tz-- 16.00g guests        84.31
    vm-115-disk-0    ssd Vwi-a-tz-- 16.00g guests        97.12
    vm-116-disk-0    ssd Vwi-a-tz-- 8.00g guests        31.49
    vm-117-cloudinit ssd Vwi-aotz-- 4.00m guests        50.00
    vm-117-disk-0    ssd Vwi-aotz-- 10.00g guests        39.71
    vm-117-disk-1    ssd Vwi-aotz-- 1000.00g guests        97.47
    

    If the id of the new ct or vm is not equal to the id of the volume’s previous attachment, rename them, i.e.

    lvrename ssd/vm-101-disk-1 ssd/vm-117-disk-2
    

    This will make vm-101-disk-1 available as vm-117-disk-2, you have to increase the count in the end of the name.

    Then edit the config of the actual vm.

    Take the line from /etc/pve/qemu-server/<vm id>.conf that describes the volume to the new <vm id>.conf

    The tricky thing was to run qm rescan afterwards which fixed syntax and made the volume appear in the web gui where i could finally attache it to the new vm.