✨: put retrodojo in place, push wordpress database
This commit is contained in:
@@ -8,6 +8,7 @@ web_hostname:
|
||||
- host: forum.nintendojo.fr
|
||||
- host: nintendojofr.com
|
||||
- host: www.nintendojofr.com
|
||||
type: retrodojo
|
||||
- host: forum.nintendojofr.com
|
||||
|
||||
mariadb_root_pass: !vault |
|
||||
@@ -18,6 +19,26 @@ mariadb_root_pass: !vault |
|
||||
3437653064323138310a663363373736623931336432376466316666616234356133383263373136
|
||||
31343534663063663134306464306234366430323762656165653930333134326231
|
||||
|
||||
wordpress_maria_database: "dojo_wp"
|
||||
wordpress_maria_user: "adm_wp"
|
||||
wordpress_maria_password: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
38313239383663383462323538363935613137373662633662616136623936386436383464363037
|
||||
3939316130376137663534633336653764346436636135620a376238636561303031323735643131
|
||||
65623362303866323463393331333666633038323530616662316533326136343738626566656233
|
||||
3736633934323465620a306132356536386230653936653864653232366231636237346561316238
|
||||
3764
|
||||
|
||||
retrodojo_maria_database: "{{ wordpress_maria_database }}"
|
||||
retrodojo_maria_user: "usr_wp"
|
||||
retrodojo_maria_password: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
65643533356337353931626366643865373538303836373331373335653938636161356463313330
|
||||
6265333735333835333161303135316638656330356264320a636536316330663730323766353639
|
||||
65386530353032336161353330313863623231646632643861666562353764373066663337353063
|
||||
6364633734323732390a363539333537396164633965346637313532666366336362346663326661
|
||||
6663
|
||||
|
||||
webapps_htpasswd_editeurs: !vault |
|
||||
$ANSIBLE_VAULT;1.1;AES256
|
||||
63663638356139373663646639633762393761333536393331363066353039393266306638326336
|
||||
|
@@ -20,3 +20,4 @@
|
||||
diff: true
|
||||
roles:
|
||||
- wordpress
|
||||
- retrodojo
|
||||
|
10
roles/retrodojo/tasks/db.yml
Normal file
10
roles/retrodojo/tasks/db.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
|
||||
- name: Create retrodojo db user
|
||||
community.mysql.mysql_user:
|
||||
login_unix_socket: "/var/run/mysqld/mysqld.sock"
|
||||
login_user: root
|
||||
login_password: "{{ mariadb_root_pass }}"
|
||||
name: "{{ retrodojo_maria_user }}"
|
||||
password: "{{ retrodojo_maria_password }}"
|
||||
priv: "{{ retrodojo_maria_database }}.wp_dojohistoricalid:SELECT/{{ retrodojo_maria_database }}.wp_posts:SELECT/{{ retrodojo_maria_database }}.wp_terms:SELECT/{{ retrodojo_maria_database }}.wp_term_relationships:SELECT"
|
12
roles/retrodojo/tasks/main.yml
Normal file
12
roles/retrodojo/tasks/main.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
|
||||
- name: Init db
|
||||
ansible.builtin.include_tasks: db.yml
|
||||
|
||||
- name: Put program file in place
|
||||
ansible.builtin.template:
|
||||
src: "index.php.j2"
|
||||
dest: "{{ retrodojo_home }}/index.php"
|
||||
owner: root
|
||||
group: www-data
|
||||
mode: "0o640"
|
110
roles/retrodojo/templates/index.php.j2
Normal file
110
roles/retrodojo/templates/index.php.j2
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
// conversion from the letter ID to the datetime+rank ID
|
||||
define("CODE", "aQwZsXeDcRfVtGbYhNuJiKoLpMAqWzSxEdCrFvTgByHnUjIkOlPm");
|
||||
define("MYSQL_USER", "{{ retrodojo_maria_user }}");
|
||||
define("MYSQL_PASSWORD", "{{ retrodojo_maria_password }}");
|
||||
define("MYSQL_DATABASE", "{{ retrodojo_maria_database }}");
|
||||
|
||||
function decode_article($code) {
|
||||
$id = 0;
|
||||
foreach(str_split($code) as $key => $value) {
|
||||
$transposed = strrpos(CODE, $value);
|
||||
$id += 10 ** (3 - $key) * ($transposed % 10);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
function get_current_guid_from_historical_id_for($conn, $article_type, $hist_id) {
|
||||
$guid = "";
|
||||
$query = <<<QUERY
|
||||
SELECT guid
|
||||
FROM wp_dojohistoricalid
|
||||
INNER JOIN wp_posts ON wp_dojohistoricalid.current_id = wp_posts.ID
|
||||
INNER JOIN wp_terms ON wp_dojohistoricalid.term_id = wp_terms.term_id
|
||||
WHERE slug = "$article_type"
|
||||
AND historical_id = $hist_id;
|
||||
QUERY;
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
if (mysqli_num_rows($result) == 1) {
|
||||
$row = mysqli_fetch_row($result);
|
||||
$guid = $row[0];
|
||||
}
|
||||
|
||||
return $guid;
|
||||
}
|
||||
|
||||
// get the article ID no matter what
|
||||
if (isset($_GET["id"])) {
|
||||
$article_id = substr($_GET["id"], 0, 4);
|
||||
}
|
||||
|
||||
if (preg_match("/\/index\.php\/(.+)\/(.+)\/([A-Za-z]{4})-/", $_SERVER["DOCUMENT_URI"], $matches)) {
|
||||
$article_id = $matches[3];
|
||||
}
|
||||
|
||||
// connect to MySQL via WP login
|
||||
$conn = mysqli_connect("localhost", MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
|
||||
|
||||
if (isset($article_id)) {
|
||||
if (preg_match("/\/nouvelles\//", $_SERVER["DOCUMENT_URI"])) {
|
||||
/*
|
||||
This part of the script decodes the Nouvelles ID and search the current DB for the right article
|
||||
*/
|
||||
$decoded_day = strrpos(CODE, $article_id[0]);
|
||||
$decoded_month = strrpos(CODE, $article_id[1]);
|
||||
$decoded_year = strrpos(CODE, $article_id[2]) + 2000;
|
||||
$decoded_rank = strrpos(CODE, $article_id[3]);
|
||||
|
||||
$query = <<<QUERY
|
||||
SELECT guid
|
||||
FROM wp_posts INNER JOIN wp_term_relationships ON wp_posts.ID = wp_term_relationships.object_id
|
||||
WHERE term_taxonomy_id = 3
|
||||
AND YEAR(post_date) = $decoded_year
|
||||
AND MONTH(post_date) = $decoded_month
|
||||
AND DAY(post_date) = $decoded_day
|
||||
ORDER BY post_date;
|
||||
QUERY;
|
||||
$result = mysqli_query($conn, $query);
|
||||
mysqli_data_seek($result, $decoded_rank - 1);
|
||||
$row = mysqli_fetch_row($result);
|
||||
|
||||
header("Location: " . str_replace("http:", "https:", $row[0]), true, 301);
|
||||
} elseif(preg_match("/\/nezvroses\//", $_SERVER["DOCUMENT_URI"])) {
|
||||
$current_guid = get_current_guid_from_historical_id_for($conn, "nezvroses", decode_article($article_id));
|
||||
if (!empty($current_guid)) {
|
||||
header("Location: " . str_replace("http:", "https:", $current_guid), true, 301);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
}
|
||||
} elseif(preg_match("/\/analyses\//", $_SERVER["DOCUMENT_URI"])) {
|
||||
$current_guid = get_current_guid_from_historical_id_for($conn, "analyses", decode_article($article_id));
|
||||
if (!empty($current_guid)) {
|
||||
header("Location: " . str_replace("http:", "https:", $current_guid), true, 301);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
}
|
||||
} elseif(preg_match("/\/editoriaux\//", $_SERVER["DOCUMENT_URI"])) {
|
||||
$current_guid = get_current_guid_from_historical_id_for($conn, "editos", decode_article($article_id));
|
||||
if (!empty($current_guid)) {
|
||||
header("Location: " . str_replace("http:", "https:", $current_guid), true, 301);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
}
|
||||
} elseif(preg_match("/\/apercus\//", $_SERVER["DOCUMENT_URI"])) {
|
||||
$current_guid = get_current_guid_from_historical_id_for($conn, "apercus", decode_article($article_id));
|
||||
if (!empty($current_guid)) {
|
||||
header("Location: " . str_replace("http:", "https:", $current_guid), true, 301);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
}
|
||||
} else {
|
||||
// any other matches (apercus, etc…) will be sent a 404 for now
|
||||
http_response_code(404);
|
||||
}
|
||||
} else {
|
||||
header("Location: https://www.nintendojo.fr", true, 307);
|
||||
}
|
||||
|
||||
mysqli_close($conn);
|
4
roles/retrodojo/vars/main.yml
Normal file
4
roles/retrodojo/vars/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
retrodojo_access_url: "{{ web_hostname | selectattr('type', 'defined') | selectattr('type', '==', 'retrodojo') | map(attribute='host') | first }}"
|
||||
retrodojo_home: "/srv/http/{{ retrodojo_access_url }}"
|
20
roles/wordpress/tasks/db.yml
Normal file
20
roles/wordpress/tasks/db.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
|
||||
- name: Create wordpress db
|
||||
community.mysql.mysql_db:
|
||||
login_unix_socket: "/var/run/mysqld/mysqld.sock"
|
||||
login_user: root
|
||||
login_password: "{{ mariadb_root_pass }}"
|
||||
name: "{{ wordpress_maria_database }}"
|
||||
state: present
|
||||
encoding: utf8mb4
|
||||
collation: utf8mb4_general_ci
|
||||
|
||||
- name: Create wordpress db read/write user
|
||||
community.mysql.mysql_user:
|
||||
login_unix_socket: "/var/run/mysqld/mysqld.sock"
|
||||
login_user: root
|
||||
login_password: "{{ mariadb_root_pass }}"
|
||||
name: "{{ wordpress_maria_user }}"
|
||||
password: "{{ wordpress_maria_password }}"
|
||||
priv: "{{ wordpress_maria_database }}.*:ALL"
|
@@ -1,5 +1,7 @@
|
||||
---
|
||||
|
||||
- name: Init DB
|
||||
ansible.builtin.include_tasks: db.yml
|
||||
- name: WP for NintendojoFR
|
||||
ansible.builtin.include_tasks: wp_dojo.yml
|
||||
- name: WP dev for NintendojoFR
|
||||
|
Reference in New Issue
Block a user