uploads – How to change Route respond To A specific Path?

To increase site loading time and decrease the pressure on my website I have decided to host files(js,css,images) in other hosting, like google storage or amazon aws, problem is that I already published a lot of posts that includes images other files in the html, like:

<img src="https://wordpress.stackexchange.com/site.example/wp-content/uploads/images/image.png">

i can’t go all over the posts to change the src attribute, so I want to change my route code so every time a wp-content or wp-includes files is requested, it will redirect it to the host where my media files are, something like:

    if(str_contains(path, 'wp-content') || str_contains(path, 'wp-includes')){
      redirect("host.example".path);
    }

where on earth – What is the longest distance between two stops of a train route?

Given the vast distances and sparse population, you’d expect Australia to have some solid contenders, but somewhat surprisingly I can’t find any legs over 24h — partly because the trains cater to tourists and make stops at metropolises like Cook, WA (population 4) to break up the monotony a bit. Without this, Kalgoorlie to Adelaide on the Indian Pacific would clock in at 27.5 hours (dep 01:20 Mon, arr 07:20 Tue, -2.5 hrs time difference going from WA to SA).

But assuming we do count all stops, the longest distance between stops in Australia appears to be on the same line in the other direction: the weekly train departing Adelaide, SA on Thursdays at 21:40 arrives in Rawlinna, WA at 18:55 Fridays, for a non-stop travel time of 22 hrs 45 mins (including 2.5 hr time difference, now in the other direction). Schedules here: https://www.seat61.com/Australia.htm

Google Maps “directions” map maker function fails to utilize direct route due to road closure entry

Recently, when planning a trip to Yellowstone Natl Park, the Grand Loop Rd between Tower Junction and Canyon Village will not be included in any trip due to Google Maps inclusion of a road closure. Even one planning a route directly from Tower Junction to Canyon Village will be directed around the entire rest of the loop excluding the most direct route. Previously (approx. 2 yrs ago), this route was available, as I had planned an extensive trip including this route, and the map included this stretch of road. I am wondering if it has something to do with the “road closure” notice, or labels saying “(Closed winters)”, but other roads in the region (i.e., Norris Canyon Rd) are so labeled but allow planning to use these routes. How does one plan a future trip without consideration of present road closures?

india – Now that NGT has banned private vehicles from entering the Rohtang pass, what route should I take?

Is it clear for sure that tourists who are headed for Ladakh won’t be
blocked from entering the Rohtang pass? If so, how would the
authorities confirm that the tourist is headed for Ladakh?

There is no way to stop this from what I know. What about those who really plan to go to Ladakh but 100kms into the journey they get a phone call from home about some urgent situation that needs them to return immediately? Government cannot do much on that route except for charging every one and not just those who visit Rohtang pass alone.

If you suggest against taking this route, can you suggest the
alternative route, like Delhi-Srinagar-Leh route, and the current
situation thereof?

Have a look at the differences and see which one you like and decide Srinagar Leh route vs Manali Leh route.

Delhi Srinagar Leh roads are in a lot better condition as compared to Manali Leh road simply because Srinagar route is used by the armed forces on a daily basis and is used to transport defense equipment and other supplies every day where as Manali road is mainly used by tourists and locals. I have been to Leh both ways and find that Manali route is more scenic and I did not find much traffic on that route where as Srinagar route is normally busy.

nat – WireGuard: cannot delete iptables rule for default route

since I don’t want friends and colleagues in my VPN to use my VPN server as a proxy VPN for “anonymous” surfing, I want to disable the default route for the VPN. In a nutshell:

  • LAN (10.20.0.0/24) must be accessible
  • WAN (0.0.0.0/0) must be inaccessible

I was unable to find a WireGuard setting to do this except configuring the AllowedIPs directive in the client config. But what kind of security does that provide?? Anyone can easily edit his/her config, replace 10.20.0.0/24 with 0.0.0.0/0, and use my VPN as a proxy…

My next approach was to delete the iptables rule that permitts the forwarding from the VPN subnet to the WAN. But somehow I cannot delete the affected rule. If I create a similar rule (same subnet, same policy) I can delete it, but I am prevented from deleting the WireGuard rule somehow.

The rule in question has been marked with --> in the following output:

root@(...):~# iptables -L FORWARD

    Chain FORWARD (policy DROP)
    target     prot opt source               destination
    ...
    ACCEPT     all  --  anywhere             10.6.0.0/24          ctstate RELATED,ESTABLISHED /* wireguard-forward-rule */
--> ACCEPT     all  --  10.6.0.0/24          anywhere             /* wireguard-forward-rule */

Commands that I have tried to get rid of this rule:

root@(...):~# iptables -D FORWARD -s 10.6.0.0/24 -j ACCEPT
iptables: Bad rule (does a matching rule exist in that chain?).

If I add the same rule again (without the comment):

root@(...):~# iptables -L FORWARD

    Chain FORWARD (policy DROP)
    target     prot opt source               destination
    ...
    ACCEPT     all  --  anywhere             10.6.0.0/24          ctstate RELATED,ESTABLISHED /* wireguard-forward-rule */
--> ACCEPT     all  --  10.6.0.0/24          anywhere             /* wireguard-forward-rule */
--> ACCEPT     all  --  10.6.0.0/24          anywhere

root@(...):~# iptables -D FORWARD -s 10.6.0.0/24 -j ACCEPT
root@(...):~#

No problem… 😐

Note: If you need further logs/output, please let me know. Thanks in advance!


FINAL ANSWER:
WireGuard also specifies interfaces and a comment. These have to be an exact match when deleting rules. You can see the full list of arguments using iptables with the -v option.

The command that finally removed the rule was:

iptables -D FORWARD -i wg0 -o wlan0 -s 10.6.0.0/24 -m comment --comment "wireguard-forward-rule" -j ACCEPT

8 – Creating a route that returns an AJAX Response that opens a modal

​I have this route that is suppose to render a block and two view blocks and then display them in a modal.

Originally, I had this route created in the Pages section of Structure, but then decided to create it in my module using this tutorial

However, when I construct it in my module, now it won’t open in a modal. It attempts to, but then just fails with no errors in the console or in Drupal, so I can’t debug the issue because I can’t even find out what the issue is… If I go to the route directly in the browser instead of through a link, it just prints out an array of command objects

Here’s my code:

my_module.routing.yml

my_module.my.results:
  path: "/user/results"
  defaults:
    _title: "My Results"
    _controller: 'Drupalmy_moduleControllerme3Controller::myResults'
  requirements:
    _user_is_logged_in: "TRUE"
    _is_ajax_request: 'TRUE'

myController.php

class myController extends ControllerBase {
  function myResults() {
    $renderer = Drupal::service('renderer');

    $top_careers_view = views_embed_view('top_careers', 'block_top_careers');
    $top_careers = $renderer->render($top_careers_view);
    $matched_degrees_view = views_embed_view('matched_degrees', 'block_matched_degrees');
    $matched_degrees = $renderer->render($matched_degrees_view);

    $content = $top_careers . $matched_degrees;

    $title = "Title";
    $options = (
      'dialogClass' => 'my_modal'
    );
    $response = new AjaxResponse();
    $response->addCommand(new OpenModalDialogCommand($title, $content, $options));

    return $response;
  }
}

my-template.html.twig

<a 
  class="use-ajax"
  data-dialog-type="modal" 
  data-dialog-options='{
    "dialogClass": "my-modal"
  }'
  href="/{{ language }}/my/results">{{ 'Match More Careers'|t }}
</a>

At one point I had /my/results_test created in Pages that I would open up in a modal via the html link:

<a 
  class="ytp-magenta-button use-ajax"
  data-dialog-type="modal" 
  data-dialog-options='{
    "dialogClass": "ytp-dashboard-me3-modal"
  }'
  href="/{{ language }}/my/results_test">{{ 'Match More Careers'|t }}
</a>

I also had the /my/results route still created in my module and if I created a modal-link (defined above) to it from one of the blocks in /my/result_test, then the /my/results route would open in a modal as expected.

So essentially, with what I have, I can open my modal route from another modal, but I can’t open it directly from a regular page…

domain name system – GoDaddy DNS vs Route 53 DNS

I want to connect my GoDaddy’s domain to Cloudfront CDN.
I have 2 options to do that:

  1. Use GoDaddy’s DNS and add a CNAME record that points to the Cloudfront distribution xxx.cloudfront.net. I tried to implement this option and it works well.
  2. Use Route 53 DNS to get the page from Cloudfront. This option is written in the Getting started guide

I checked dnsperf.com and GoDaddy’s DNS has better performance than Route 53.

What are the advantages of using Route 53 DNS, without moving the domain?

What option is more fast and what is the expected time difference?

What option has 1 DNS call and what option has 2 DNS calls?

There is an Old answer, but it is not very clear to me.

Alter existing ‘Log In’ route so URL includes request_uri as query string

I am trying to alter the existing ‘Log In’ URL so that it points to a certain location and also includes the REQUEST_URI as a query string that is not encoded. How do I do this?

Based on this article, Altering existing routes and adding new routes based on dynamic ones and this SE answer I can change the ‘Log In’ URL so it points to a different location (/login). What I can’t seem to figure out is how to add a query string that isn’t encoded.

This code:

$route->setPath('/login?destination=' . Drupal::request()->server->get('REQUEST_URI'));

Gives me:

/login%3Fdestination%3Dpage2

What I want is:

/login?destination=page2

I have looked into RequestContext::setQueryString and Route::addOptions but can’t seem to get anything to work.

Full code:

<?php
namespace DrupalmyModuleRouting;

use DrupalCoreRoutingRouteSubscriberBase;
use SymfonyComponentRoutingRouteCollection;

/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {

    /**
    * {@inheritdoc}
    */

    protected function alterRoutes(RouteCollection $collection) {
        // Change path '/user/login' to '/login'.
        if ($route = $collection->get('user.login')) {
            //$route->setPath('/login');
            $route->setPath('/login?destination=' . Drupal::request()->server->get('REQUEST_URI'));

        }
        
        // Always deny access to '/user/logout'.
        // Note that the second parameter of setRequirement() is a string.
        if ($route = $collection->get('user.logout')) {
            $route->setRequirement('_access', 'FALSE');
        }
    }
}

Idiomatic Ruby if/else in a Sinatra route

Apologies if this question doesn’t fit the format here, seemed more appropriate here than SO due to the more nebulous nature of the question.

Think mini tinyURL clone: POST to service to save the url + hash, then look up the mapping when visiting /anything. It’s been a while since I’ve touched Ruby, and the resulting code snippet is not easy on the eyes:

require 'sinatra'
require 'mongoid'
require 'digest'

class MinifiedUrl
  include Mongoid::Document

  field :code, type: String
  field :original_url, type: String
end

# Redirect to the actual url, like tinyurl.com/abcdefg
get '/:code' do
  link = MinifiedUrl.where(:code => params(:code)).first # .first is falsy if there is no mapping
  if link
    puts "Found minified link"
    redirect link(:original_url), 302
  else
    puts "No minified link"
    redirect '/404', 404
  end
end

# Create a mapping from a POST request like { url: 'https://google.com/ '}
post '/' do
  incoming_url = params(:url)

  link = MinifiedUrl.where(:code => params(:code)).first 
  # Reassign link if link is falsy
  link = MinifiedUrl.create(:target_url => incoming_url, :code => Digest::MD5.hexdigest(incoming_url)(0..5)) unless link

  link(:slug)
end

Is there an obvious way to make the code more idiomatic? My concern is multiple calls to MinifiedUrl model / reassigning value of link. I can’t put my finger on it, but it doesn’t feel ruby-like.

Idiomatic Ruby if/else in a Sinatra route

Apologies if this question doesn’t fit the format here, seemed more appropriate here than SO due to the more nebulous nature of the question.

Think mini tinyURL clone: POST to service to save the url + hash, then look up the mapping when visiting /anything. It’s been a while since I’ve touched Ruby, and the resulting code snippet is not easy on the eyes:

require 'sinatra'
require 'mongoid'
require 'digest'

class MinifiedUrl
  include Mongoid::Document

  field :code, type: String
  field :original_url, type: String
end

# Redirect to the actual url, like tinyurl.com/abcdefg
get '/:code' do
  link = MinifiedUrl.where(:code => params(:code)).first # .first is falsy if there is no mapping
  if link
    puts "Found minified link"
    redirect link(:original_url), 302
  else
    puts "No minified link"
    redirect '/404', 404
  end
end

# Create a mapping from a POST request like { url: 'https://google.com/ '}
post '/' do
  incoming_url = params(:url)

  link = MinifiedUrl.where(:code => params(:code)).first 
  # Reassign link if link is falsy
  link = MinifiedUrl.create(:target_url => incoming_url, :code => Digest::MD5.hexdigest(incoming_url)(0..5)) unless link

  link(:slug)
end

Is there an obvious way to make the code more idiomatic? My concern is multiple calls to MinifiedUrl model / reassigning value of link. I can’t put my finger on it, but it doesn’t feel ruby-like.