Need help dealing with subdomains and regions - subdomain

Well, i'm about creating a new set of subdomains, by countries [germany, poland..] something like
germany.example.com
the thing is , i have a database with set of data containing a country field:
Item1 -- PL
item2 -- PL
item3 -- XX
item4 -- XX
i want that subdomain to pull the data from this specific country only, so poland.example.com will only filter data from that country.
i have my script working from the main domain example.com with a dropdown box where you can select the country and it adds cookies or /preferences to the user.
the main question is : how can i deal with the subdomain the right way?

When a browser sends a request to a server, it includes a Host: header which tells the server which subdomain the user wants. Use this in your script to select the correct database.

Done!
Solution
From the hosting : create a subdomain with root directory so subdomain XX.example.com should not have a folder /xx in your root directory, its directory must remain null
get the subdomain using php (explode $_SERVER Host if you want... or any other method you prefer)
process the subdomain variable from your main web script, since now you have the subdomain value (XX) you can process it using your script.
... do whatever you want with that subdomain value, like
if ( $subdomain == "xx" ) ... do something here
else .. do something else

Related

Semantic Wiki: Check form input if value already exists

we have a formular to create host names with some additional information.
Inside the formular we include a template, which gets the values via input fields:
{{{for template|IP|multiple|add button text=Add IP}}}
'''IP:''' {{{field|IP|mandatory|property=Host IP}}}
'''MAC:''' {{{field|MAC}}}
{{{end template}}}
We want to have a check if the given IP adress is already used by another host.
I already tried creating an array and iterating through the values and compare it with a given value: this works.
{{#arraydefine: myArray1 | {{ #ask: [[IP::+]] | mainlabel=- |headers=hide | ?IP }} }}
{{#arrayprint: myArray1||####| {{#ifeq: #### | {{{IP}}} | Duplicate #### <br>| No duplicate #### <br>}} }}
However, if I include this in the form itself, the IP input box doesn't assign the value to an actual variable {{{IP}}} - therefor I cannot access it with the method above.
I then tried to use it on the template "IP" directly. That works, but now it checks with every existing site which uses this template and of course, finds duplicates (because it checks it's own value against the array which also contains the value since it's already existing).
I spent almost 2 work days on this little issue now and I reach the limits of my understanding of semantic wiki. Any ideas would be appreciated.
Thank you in advance!
Since your page name is the host name, and host pages store the IP, you can do the following:
Ask for pages with the same IP as the current page :
{{#ask:[[IP::{{{IP}}}]] |mainlabel=-|?#-=}}
Store the result into an array, lets call it "hosts". The array now contains host names that have the same IP as the current page (with html link removed) and the current page itself.
Create a new array containing a single value, the current page name (using {{FULLPAGENAME}} magic word), lets call it "current"
Substract the two arrays :
{{#arraydiff:duplicate|hosts|current}}
Then check the length of the resulting array "duplicate".
if arraysize > 0, a host page different from current page exists with the same IP.

How do I get all strings that do not contain another string in MySQL?

I have a table called "Domains" with field "Name" (unique, always lowercase) which contains a list of domains and subdomains on my server like:
blah.example.com
www.example.com
www.blah.example.com
example.com
example.nl
example.org
Looking at this list, names 1, 2 and 3 are subdomains of item 4. And I'm looking to just find all domains in this table without these subdomains. Or, to be more precise, any name that does not have part of it in the name from another record. Thus only item 4, 5 and 6.
If record 4 was missing then this query would also have item 1 and 2 as result, but not item 3. After all, item 3 has item 1 as part of it.
Just trying to find the query that can provide me this result... Something with select d.name from domains where d.name not in... Well, there my mind goes blank.
Why?
This list of domains is generated by my web server which registers every new domain that gets requested on it. I'm working on a reporting page where I would display the top domain names to see if there are any weird domains in it. For some reason, I sometimes see unknown domain names in these requests and this might give some additional insight in it all.
I am going to change my code so it will include references to parent domains in the same table in the future but for now I'll have to deal with this and a simple SQL solution.
Use a self-join that matches on suffixes using LIKE
SELECT d1.name
FROM domains AS d1
LEFT JOIN domains AS d2 ON d1.name LIKE CONCAT('%.', d2.name)
WHERE d2.name IS NULL
DEMO

How can my front-end access files from the file storage of my back-end if they're separated? Should my database table contains file name or file path?

Lets say I am creating a Node.js API and one of my database models/tables looks like this:
Table: servers
Columns: id, name, image
So the image column of that table should contain some sort of reference to the image file of that server.
Inside the function which creates a server entry to the database, I set the value of that column to the name of the image file. For example a record might look like this:
{
id: 1,
name: 'Server1',
image: 'server1.png'
}
When my front-end makes a GET request to the /servers endpoint, the back-end returns all servers. I then would like to loop over them and render the name and image of the server. My problem is that on the front-end I only know the name of the image, without the actual path to that image.
I just can't wrap my head around this. I was thinking that maybe I have to set the value of the image column to an actual URL which will be the path + file name instead of the file name but I'm not sure.

ESP8266 and mySQL

To begin with, I set up my database which includes (an id (which is auto increment), username, email, and 2 more which are place0 and place1 (those two are boolean type)). Now my question is how can I connect an esp8266 directly to the database and update the booleans from 0 to 1 and back using a button for each one? Also, how can I read the boolean on the esp and turn an led for example? I need to make it update the values for a selected user not all of them....for example, I have users with id 1, 2, 3...i need to make the updates only on 1 if that one is selected...
Note that both the database and the esp8266 are in my house (on a local network)
Thanks very much
Nikolaos Konstantinou
NcCon
The best way I can think of is ESP8266 to Web Server(PHP/Python/NodeJS etc) to MySQL
Send the boolean values in the form of the HTTP Post method and handle the post method in Webserver then update the MYSQL table.
check out this link
For some reason, if you want to avoid webserver you can try micro python upymysql module which helps to directly communicate the database from ESP board uPyMySQL

How to create Delegation Signer (DS) record for a subdomain with PowerDNS?

I have a domain mydomain.com. The DNS servers for this domain are under my control and I'm running PowerDNS there. I've set up DNSSEC for my main domain mydomain.com and I've registered the keys at registrar. Everything works fine for the main domain. However when I create subdomains (zones) with PowerAdmin GUI then I get the following error for my subdomains from DNSSEC analysis tool at http://dnssec-debugger.verisignlabs.com/:
No DS records found for subdomain.mydomain.com in the mydomain.com zone
Question: how to add that DS record to mydomain.com zone with powerdns?
Note: I haven't used PowerAdmin, so this is a PowerDNS answer.
Assuming you have also signed these subdomains/zones, you would use pdnssec show-zone to see the DS records for them. Then, insert these DS records into the parent zone (mydomain.com), with fields set like this:
domain_id = id of domain.com
name = sub.mydomain.com
type = DS
content = copy/paste from pdnssec show-zone
You also need to insert NS records (as above, but with type=NS and content=name of your server), to get a valid delegation, even if it is local!
If you don't actually care about DNSSEC for the subdomains, just insert the NS records and leave out the DS. This will tell validators that the subdomain is deliberately insecure.