iptables – Route based on Source IP Address via 2 gateways on same NIC

In a Linux system, which acts as a gateway on my lan, I would like to route traffic based on source IP addresses.
I have 2 network cards and one of these cards has 2 different default gateways.

I know I can only have one default gateway on one system, and that route selection is based on the destination address.

I would like to make sure that the pc with ip 192.168.3.5 can access and be reachable through the gateway 172.16.62.254

The setting of the network interfaces is :

DEVICE=eth0
TYPE=Ethernet
IPADDR=172.16.61.2
PREFIX=24
IPADDR2=172.16.61.3
PREFIX2=24
GATEWAY=172.16.61.1

DEVICE=eth0:1
TYPE=Ethernet
DEFROUTE=no
IPADDR=172.16.62.100
PREFIX=24
#GATEWAY=172.16.62.254

DEVICE=eth1
TYPE=Ethernet
IPADDR=192.168.3.1
NETMASK=255.255.255.0

The routing table is:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1
172.16.62.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
172.16.61.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         172.16.61.1     0.0.0.0         UG    0      0        0 eth0

The ip addresses of the two gateways are:

172.16.61.1
172.16.62.254

The pc with IP address 192.168.3.2 must reach GW 172.16.61.1,
the pc with IP address 192.168.3.5 must reach GW 172.16.62.254

To allow access to the 2 gateways, I perform a translation of ip addresses via iptables :

iptables -t nat -A POSTROUTING -s 192.168.3.2 -p tcp -j SNAT --to-source 172.16.61.3  
iptables -t nat -A POSTROUTING -s 192.168.3.5 -p tcp -j SNAT --to-source 172.16.62.100

and viceversa

iptables -t nat -A PREROUTING -d 172.16.61.3 -p tcp -j DNAT --to-destination 192.168.3.2  
iptables -t nat -A PREROUTING -d 172.16.62.100 -p tcp -j DNAT --to-destination 192.168.3.5 

The idea to route packets through gateway 172.16.62.254 is to use iptables to mark packets whose source
ip address is 192.168.3.5 or 172.16.62.100 and then route them using iproute2 for which I performed the following steps:

  1. In /etc/iproute2/rt_tables I have added the line 200 route254

  2. I have marked the packets with:

    iptables -t mangle -A OUTPUT -s 192.168.3.5 -j MARK –set-mark 0x1
    iptables -t mangle -A OUTPUT -s 172.16.62.100 -j MARK –set-mark 0x1

  3. I have configured routing with:

    ip route add default via 172.16.62.254 dev eth0:1 table route254
    ip route add 172.16.62.0/24 dev eth0:1 src 172.16.62.100 table route254
    ip rule add from 172.16.62.100/32 table route254
    ip rule add to 172.16.62.100/32 table route254
    ip rule add prio 199 fwmark 0x1 lookup route254

What I got is that the reachability to the pc with address 192.168.3.2 works, the pc is reachable from the outside,
while the pc with address 192.168.3.5 is not.

The output of tcpdump in the case of the pc with address 192.168.3.2 is
18:38:31.317553 IP x.x.x.x.45053 > 172.16.61.3.ftp: S 3190836796:3190836796(0) win 5840 <mss 1380,sackOK,timestamp 2834368503 0,nop,wscale 7>
18:38:31.317832 IP x.x.x.x.45053 > 192.168.3.2.ftp: S 3190836796:3190836796(0) win 5840 <mss 1380,sackOK,timestamp 2834368503 0,nop,wscale 7>
18:38:31.317732 IP 192.168.3.2.ftp > x.x.x.x.45053: S 1998545683:1998545683(0) ack 3190836797 win 28960 <mss 1460,sackOK,timestamp 1123125 2834368503,nop,wscale 7>
18:38:31.317778 IP 172.16.61.3.ftp > x.x.x.x.45053: S 1998545683:1998545683(0) ack 3190836797 win 28960 <mss 1460,sackOK,timestamp 1123125 2834368503,nop,wscale 7>
18:38:31.368562 IP x.x.x.x.45053 > 172.16.61.3.ftp: . ack 1 win 46 <nop,nop,timestamp 2834368531 1123125>
18:38:31.368580 IP x.x.x.x.45053 > 192.168.3.2.ftp: . ack 1 win 46 <nop,nop,timestamp 2834368531 1123125>
18:38:33.257206 IP x.x.x.x.45053 > 172.16.61.3.ftp: P 1:3(2) ack 1 win 46 <nop,nop,timestamp 2834370444 1123125>

The output of tcpdump in the case of the pc with address 192.168.3.5 is
12:49:04.047809 IP x.x.x.x.60804 > 172.16.62.100.ftp: S 790746700:790746700(0) win 5840 <mss 1380,sackOK,timestamp 2986198269 0,nop,wscale 7>
12:49:04.048069 IP x.x.x.x.60804 > 192.168.3.5.ftp: S 790746700:790746700(0) win 5840 <mss 1380,sackOK,timestamp 2986198269 0,nop,wscale 7>
12:49:04.047884 IP 192.168.3.5.ftp > x.x.x.x.60804: S 3787612501:3787612501(0) ack 790746701 win 28960 <mss 1460,sackOK,timestamp 922143 2986198269,nop,wscale 7>
12:49:04.047909 IP 172.16.62.100.ftp > x.x.x.x.60804: S 3787612501:3787612501(0) ack 790746701 win 28960 <mss 1460,sackOK,timestamp 922143 2986198269,nop,wscale 7>
12:49:05.448336 IP 192.168.3.5.ftp > x.x.x.x.60804: S 3787612501:3787612501(0) ack 790746701 win 28960 <mss 1460,sackOK,timestamp 923544 2986198269,nop,wscale 7>
12:49:05.448351 IP 172.16.62.100.ftp > x.x.x.x.60804: S 3787612501:3787612501(0) ack 790746701 win 28960 <mss 1460,sackOK,timestamp 923544 2986198269,nop,wscale 7>
12:49:07.048100 IP x.x.x.x.60804 > 172.16.62.100.ftp: S 790746700:790746700(0) win 5840 <mss 1380,sackOK,timestamp 2986201269 0,nop,wscale 7>
12:49:07.048128 IP x.x.x.x.60804 > 192.168.3.5.ftp: S 790746700:790746700(0) win 5840 <mss 1380,sackOK,timestamp 2986201269 0,nop,wscale 7>

In order to check if the packages were actually marked I used :

iptables -A INPUT -m mark ! --mark 0 -m limit --limit 8/min --limit-burst 12 -j LOG --log-prefix "IPTables-Marks: "  

but I have no entry in the log file

How can i allow the pc with ip address 192.168.3.5 to access and be reachable through the gateway 172.16.62.254 ?

seo – How to show same company’s different office address in google based on the user’s country?

our company has five offices in five countries , once the user search in google, I need to show the office address based on the user’s country, for example if the user search from US , I need google to show US office address automatically, also if the user search a specific office address then the search result will show that country office address, for example, the user search “ABC UK or ABC UK office address ” then the search result shows the UK office address. How can I do that?

woocommerce offtopic – adding surcharge based on subcategory and category

    // Add percentage based additional fee or surcharge

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
  global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $percentage = 0.3; // Add your percentage here
    $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;    
    $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );

}

this is all good but I want to add a surcharge based on the product category and subcategory too. is there any option to that ?

wp : 5.8
php 8.0.7

python – pandas.DaraFrame resample OHLC based on a non-time value

I have a csv file that looks like this:

    time, price
0   2021-07-23T20:00:00.000221421Z  368.06
1   2021-07-23T20:00:00.001131397Z  368.06
2   2021-07-23T20:00:00.008030544Z  368.06
3   2021-07-23T20:00:00.00807574Z   368.06
4   2021-07-23T20:00:00.008084129Z  368.06
... ... ...
32435   2021-07-23T23:59:46.272261376Z  367.84
32436   2021-07-23T23:59:53.782418944Z  367.84
32437   2021-07-23T23:59:56.24058112Z   367.84
32438   2021-07-23T23:59:58.981374464Z  367.84
32439   2021-07-23T23:59:58.981374464Z  367.84
32440 rows × 2 columns

I’m trying to merge the rows into 0.10 OHLC price range intervals, so that the end result looks like this:

time, open, high, low, close
0   2021-07-23T20:00:00.000221421Z  368.06  368.06  367.96  367.96
1   2021-07-23T20:00:00.337192Z 367.95  368.04  367.94  368.04
2   2021-07-23T20:00:11.632994Z 368.05  368.06  367.96  368.06
3   2021-07-23T20:00:39.91849344Z   368.07  368.08  367.98  367.98
4   2021-07-23T20:01:04.188584192Z  367.97  368.04  367.94  367.94

Here’s my attempt, which works but it seems quite slow:

import pandas

print('time, open, high, low, close', file = open(file = 'range.csv', mode = 'a'))

dataframe = pandas.read_csv(filepath_or_buffer = 'quotes.csv')

bar = ({'time': dataframe.iloc(0, 0), 'open': dataframe.iloc(0, 1), 'high': dataframe.iloc(0, 1), 'low': dataframe.iloc(0, 1), 'close': dataframe.iloc(0, 1)})

cycle = (0)

while cycle(-1) < len(dataframe.index):
  high = float(bar(-1)('high'))
  low = float(bar(-1)('low'))
  price = float(dataframe.iloc(cycle(-1), 1))
  time = dataframe.iloc(cycle(-1), 0)

  if price < high - 0.1 or price > low + 0.1:
    bar.append({'time': time, 'open': price, 'high': price, 'low': price})
    bar(-2)('close') = dataframe.iloc(cycle(-2), 1)
    print(bar(-2)('time'), ',', bar(-2)('open'), ',', bar(-2)('high'), ',', bar(-2)('low'), ',', bar(-2)('close'), file = open(file = 'range.csv', mode ='a'))

  if price > high:
    bar(-1)('high') = price

  if price < low:
    bar(-1)('low') = price

  cycle.append(cycle(-1) + 1)

I’m a novice coder at best, and so my question is this the correct/”pythonic” way of achieving this result, or is there a better way? I haven’t found a way of implementing pandas.DataFrame.resample to achieve this result. Thanks in advance for your time!

database – How to implement notification system based on time that runs in regular intervals

I have a MySQL database with nodeJS server. I want to implement a notification functionality which is as follows. Once a user registers, I want to (inform) send some particular information to the user that runs in fixed time interval. Something like a task management and tracking.
If user A registers at 10am local time, notification must be sent 24 hours after A registers ie (notifications depends upon time that user registers however with a fixed interval). How do I implement this solution. I have looked at jobs in sql and cron jobs in NodeJs however I’m not sure of the approach, any guidance would be appreciated.

P.S. What would be the approach for same problem with mongoDB?

Microsoft Teams-SharePoint: Acces to uploaded file and revisions based on its ID

Problem Description

I uploaded a file on my private channel on teams as illustrated in the first figure.
enter image description here. This file is automatically uploaded now on SharePoint as illustrated in the following picture.

enter image description here

I also modified the file once so now I have two revisions of the file as illustrated in:
enter image description here


Questions

By using the Graph API: Is there a way to acces this file based on its unique ID, which I can’t find. And also based on its unique Is it possible to retrieve the file description, history of modifications.

https://graph.microsoft.com/v1.0/me/test.sharepoint.com/sites/test-TeamsSPO/root/children?$select=id,name

actions – Subscription Box philosophy: users choose from 6 products that rotate weekly. How should I go about updating a renewal order based on usermeta prefs?

This is a meal subscription service. 6 different meals are available each week for a 10 week rotation. Customers can purchase individual meal(s) or a meal bundle (5, 10, 20 meals) for delivery the following week. The cutoff time is Friday and the menu changes. Meals are set up as individual Woo Products.

Subscribing to bundles that change weekly is not a typical scenario handled by “Subscriptions”, “Product Bundles”, and “Composite Products” plugins so I need another method. I’ll explain why these don’t work at the bottom.

Here’s my philosophy, please let me know if this is how I should go about this:

  1. Customers would purchase a simple subscription to become
    subscribers of weekly bundles.
  2. Subscribers would have access to a preferences page with the active meals for the week and can choose their quantities before the Friday cutoff (or get the default choices). This data could be stored as usermeta. Non-scubscribers just choose to order a bundle or individual meals and checkout as normal.
  3. The subscriptions are synchronized to renew on Friday. Users can update their preferences anytime before the Friday cutoff. Whatever the user’s preferences are at the time of renewal, are applied to the order.

The preferences could be stored as simple usermeta similar to “persistent cart”. Is it possible to use the meta preferences to apply the actual products and quantities as line items at the time the order renews such as woocommerce_scheduled_subscription_payment? The subscription price will not change.

Is there any better solution?

The reason the current subscription plugins won’t work is that any time a user updates their subscription, it’s processed as a subscription switch, then processes as a new order by requiring the users to go through the cart again. If multiple customers want to change multiple times before the cutoff it creates too many orders.

I tried setting up Composite products with each week being a component so the user can select their meals for each week but this weekly renewal order would contain all 10 weeks instead of the current week.

sharepoint online – Filter array of objects based on multiple properties/conditions

I’m pretty sure you are not getting any results from your filter because when you build your counter object in the reducer, you build it with complex property names that are combining many of your SharePoint field values into one long string, and then when you try to access the properties of the counter object in the filter, you are only specifying one of the SharePoint fields to try to find the property.

There are no properties on that object that have only the value of one of the SharePoint fields.

If you were to console.log(lookup) right after you build it using the reduce() function, you will see an object that looks something like this:

{
    "3001317_0001_Wood_FOO": 0,
    "3001317_0001_Metal_BAR": 1,
    "3001316_0002_Wood_FOO": 0,
    "3001316_0002_Metal_FOO": 2,
    "3001316_0001_Wood_BAR": 0
}

Now, the way that reducer works is that it adds a new property with that complex property name for each unique combination of those four field values. When it first adds it, it gives it a value of 0. 0 in this case means there is one item that has that unique combination of four field values. Then, if it finds another item with the same combination, it increments the counter. So a counter value of 1 means there are actually two duplicate items, and 2 means there are actually three items that are identical.

The reason the filter then works to pull out the duplicates is because you are checking against the counter object, and if there was only one unique item, then the counter value for that combination will be 0, which is a falsy value, so the filter won’t pull it, whereas if there were duplicates, the counter value will be 1 (or more), which is a truthy value, so the filter will pull it.

But, in your filter, you are only using the one field to try to access the counter properties, like this:

var askingForValue = lookup("3001317")

BUT – remember all the properties on the counter are much more than just that, there is no property on the counter object that is as simple as "3001317".

So what you have to do is re-create the complex property names / keys you created in the reducer:

FltrInv = getResp.filter(e => lookup(`${e.PCF_x0020_No}_${e.Item_x0020_No}_${e.Material}_${e.YourReference}`));

Also keep in mind, that filter will pull all the items that have duplicates, even if there are multiple sets of duplicates.

For example, if you look back at my fictitious counter object, if you ran that filter over the SharePoint results, you would end up with an array of 5 items:

  • 2 items would have field values 3001317 / 0001 / Metal / BAR
  • 3 items would have field values 3001316 / 0002 / Metal / FOO

How to create a custom module for checking availability of shipping and COD based on zip codes available in database

I just want to create a custom module which is able to check availability of shipping and COD based on zip codes(stored in database).Admin will be able to add zip codes and availability from admin panel or through csv files and want to display message accordingly.

How to add custom fee on checkout based on Dropdown Selection?

I want to add custom fee on checkout based on Drop-down value.

enter image description here

enter image description here

Like this based on selection i want to change custom fee value based on drop-down selection.