Warning: The magic method Restrict_Widgets::__wakeup() must have public visibility in /var/www/storepeter.dk/public_html/wp-content/plugins/restrict-widgets/restrict-widgets.php on line 72

Warning: Cannot modify header information - headers already sent by (output started at /var/www/storepeter.dk/public_html/wp-settings.php:597) in /var/www/storepeter.dk/public_html/wp-content/plugins/google-language-translator/google-language-translator.php on line 464
Web – StorePeter https://storepeter.dk The world need chaos - I am here to help Wed, 25 May 2022 15:02:23 +0000 en-US hourly 1 https://wordpress.org/?v=7.1.2 Using Simply.com as mailserver from Gmail https://storepeter.dk/web/using-simply-com-as-mailserver-from-gmail Tue, 17 May 2022 18:02:21 +0000 http://storepeter.dk/?p=5664 Continue reading →]]> We have been very happy Google users for many many years.

In 2008 we started using Google Apps for Your Domain, handling storepeter.dk and lorenzen.us

In  2016 Google Apps was renamed to G-Suite, but it was the same thing, maybe some more apps, our primary use was: Gmail, Calendar, and Grand-Central/Voice.

Now in 2022 G-Suite is being renamed Google Workspace and it will no longer be a free service.  We are very grateful for our 14 years together.  We have had a free mail and calendar and home-phone service, while Google has been able to grow this into a business. It is just natural that Google tries to cash in, after all, its mission is to make money for its shareholders.

Google Workspace costs $6/user/month, which is too steep for our little family (we do have more e-mail addresses than most families). Of course, Google does this to get some income from the many small businesses that have set up a service like ours and want to brag about having their own domain name.

G Suite legacy free edition

6 days  before the June 1st 2022 deadline Google send out an E-mail:

  • [Action Required] Upgrade your G Suite legacy free edition subscriptions to Google Workspace by June 27, 2022

With this happy message deep inside the e-mail:

If you’re an individual or family using your account for
non-commercial purposes, you can continue using
the G Suite legacy free edition and opt out of the transition

to Workspace in the Google Admin console before June 27, 2022.

It seems that Google have done the right thing and found a solution for us and other early adapters who have used G-suite since before 2012. G Suite legacy free edition Thank You Google.

So this whole exercise is no longer necessary for us.

Had Google introduced a service with a more modest price tag ($10/family/month) I am sure we would have accepted it. Now we will end up sending our money to Simply.com which offers something like that in that price range. We could migrate to their webmail service too, but we are used to Gmail so let’s see if we can set up a system where we can keep both using Gmail and using our domain names.

Before 2008 I was running my own mail server, and I have been running my own WEB-servers for more than 25 years, I still do, although this is probably going to change too.

Basically what Google says is that you can continue having a free Gmail service if you give up your own domain, in my case, this would mean that peter@lorenzen.us would be replaced by something like peter.lorenzen.us@gmail.com. Kind of fair you get free e-mail and advertise a little for Gmail each time you use it.

BUT – let us see if we can keep @lorenzen.us addresses and still be able to use the familiar Gmail.

The plan here is to have Gmail.com handle our E-mail much as before but with new @gmail .com addresses.  As  Mail and WEB-servers we will use Simply.com which is a Danish company.  Hence the Lorenzen’s will use Gmail, while Simply.com will work as an E-mail Gateway/Relay, and that is what the rest of the world will see.

  • Simply.com receives all mail to storepeter.dk and  lorenzen.us and forwards it immediately to Gmail.com
  • The Lorenzen’s use Gmail.com and when they send an E-mail it is forwarded through Simply.com mail server.

Simply.com as mail server

When you order a WEB-hotel with Simply.com you also get a e-mail-service. We setup an  E-mail account for all the users on our domains. These E-mail accounts are not used by our users, they are only used to forward mail to the gmail.com mailserver and to send-out e-mail in the name of @lorenzen.us or @storepeter.dk on behalf of the gmail server.  For each Webmail a forward of mail has to be setup, see the above screen-shot.

  • webmail -> Settings -> Filters -> redirect message to username@gmail.com
  • webmail -> Settings -> Identities -> Full Name <username@storepeter.dk>
  • webmail -> Settings -> Identities -> Full Name <username@lorenzen.us>

On Simply.com storepeter.dk is the main domain, while lorenzen.us is just an alias for storepeter.dk hence E-mail to peter@lorenzen.us will end up at peter@storepeter.dk which then again is forwarded to my gmail-account.  Also the lorenzen.us WEB-pages are just aliases for the storepeter.dk WEB-pages, but people passing by our WEB-sites should not notice any of this.

Let Gmail send mail as @storepeter.dk or @lorenzen.us

  • Login as as user@gmail.com
  • Settings -> See all settings
  • Settings -> Accounts and import
  • – see above left screenshot
  • Settings -> Accounts and import -> Send mail as – Add another email address
  • – see above middle screenshot
  • Add another email address -> Name: User-Name
  • Add another email address ->Email-address: user@lorenzen.us
  • Add another email address -> Next Step
  • – see above right screenshot
  • Add another email address -> SMTP Server: smtp.simply.com
  • Add another email address ->Username: user@storepeter.dk
  • Add another email address ->Password: very-secret-user-email-password
  • Add another email address -> Add Account

Let Gmail poll simply.com every 30 minutes

In theory, this step should not be necessary since we forward all mail to simply.com on arrival, but it seems the forward functionality on the simply.com mail-server does not really work, I do not why, are the forward rejected by the gmail.com account or is never sent by simply.com. 

 

But it seems to be necessary, just follow this recipe Simply.com: Setting up mail through Gmail

That  should be it:

 

]]>
Migrating WordPress BLOG to docker https://storepeter.dk/linux/migrating-this-blog-to-docker Fri, 14 May 2021 03:28:42 +0000 http://peter.storepeter.dk/?p=4922 Continue reading →]]>  This blog is powered by WordPress and has been running natively using LAMP on my Ubuntu-server since 2014, it has served me well with a few caveat, mainly related the fact that the MySQL database and the WEB-server is shared with other uses on this system.

During these 7 years Ubuntu has gone from version 12.04 to 20.4, the hardware has been upgraded once, from a desktop-grade PC to a server, while a ZFS mirror has made disk-crashes a non-issue.

So it is time to migrate to a container based setup.

Install Docker and docker-compose

Read https://docs.docker.com/engine/install/ubuntu/ or get and execute https://gist.github.com/wdullaer/f1af16bd7e970389bad3 which is a shell-script that installs the latest version of docker and docker-compose, here is the script I executed

https://gist.github.com/wdullaer/f1af16bd7e970389bad3

This should result in a working Docker environment, For convenience let us add ourselves to the docker group, so we can execute docker commands without sudo

sudo usermod -aG docker $USER

Install WordPress in Docker

For the installation of WordPress, WEB-server and SQL-server I followed: https://nickvanhoof.com/docker-compose-wordpress/

This should gives us a virgin WordPress installation. I have tweaked docker-compose.yml to my needs, I replaced mysql with mariadb, put in some very secret passwords, and made it start automagically. Since I plan on running more instances, I have exposed the ports for this blog at 13306,10080,10081, for the next instance I add 10000 to the port number.

version: '3.7'

volumes:
  wp-data:
networks:
  wp-back:

services:

  db:
    restart: always
    image: mariadb
    volumes:
      - ./db_data:/var/lib/mysql
    environment:
       MYSQL_ROOT_PASSWORD: rootPassword
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wp-user
       MYSQL_PASSWORD: wp-pass
    ports:
      - 13306:3306
    networks:
      - wp-back

  phpmyadmin:
    restart: always
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
      MYSQL_USER: wp-user
      MYSQL_PASSWORD: wp-pass
      MYSQL_ROOT_PASSWORD: rootPassword
    ports:
      - 10081:80
    networks:
      - wp-back

  wordpress:
    restart: always
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 10080:80
      - 10443:443
    environment:
       WORDPRESS_DB_HOST: db
       WORDPRESS_DB_USER: wp-user
       WORDPRESS_DB_PASSWORD: wp-pass
    volumes:
      - ./wp_data:/var/www/html
    container_name: wordpress-site
    networks:
      - wp-back

Migrate the current WordPress site to the docker based WordPress

Now we just need to migrate the  current WordPress blog for http://storepeter.dk to the new docker based WordPress . A WordPress blog is made up of two parts, a file-system-tree and a sql-tree,.  Again we are lucky someone has made a plugin which can import and export a complete blog.

But there is a slight problem, the free version only handles up to 512Mb, and my WordPress blog fills more than 1Gb,  you can buy an unlimited version,  Or you could get an older version of this tool, where the limit can be modified, check Removing the 512MB size limit on All-in-One WP Migration Plugin. Of course you could copy it manually using rsync an mysqldump.

Running more than a single BLOG

In my original LAMP setup i used VirtualHost in the Apache configuration-file to serve multiple blogs, here is an excerpt of /etc/apache2/sites-enabled/wordpress.conf 

<VirtualHost *:80>
    ServerName peter.lorenzen.us
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/peter.lorenzen.us
    CustomLog /var/log/apache2/peter-access.log combined
    Options All
    <Directory /var/www/peter.lorenzen.us>
        AllowOverride All
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName deborah.lorenzen.us
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/deborah.lorenzen.us
    CustomLog /var/log/apache2/deborah-access.log combined
    Options All
    <Directory /var/www/deborah.lorenzen.us>
        AllowOverride All
    </Directory>
</VirtualHost>

Now I would like to have seperate containers per blog, hence a demultiplexer of some kind is needed to send the request to the relevant WordPress-Docker instance.

The simplest way to achieve this is just to change the Apache configuration to use mod_proxy, and the VirtualHost definition would look like this

<VirtualHost *:80>
    ServerName peter.lorenzen.us
    ServerAdmin peter@lorenzen.us
    ProxyRequests off
    ProxyPreserveHost On
    LogLevel error
    # debug, info, notice, warn, error, crit, alert, emerg.
    <Location />
        ProxyPass http://localhost:10080/
        ProxyPassReverse http://localhost:10080/
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

Thats it  – the BLOG should now be running inside a Docker container.

Was the containerization worth it 

It took me a few days to get this working, having never used docker before,  The real challenge  will be when things do not work,  Docker has introduced new layers so it might be hard to figure out what is wrong.  The old system just had one Web-server and one SQL-server which handled all the blogs on my system, and  they also handled other workload irrelevant to the blogs.

Performance wise I am not too worried: a http request will first be served by Apache (reverse proxy) which will send the request to the relevant WEB- server running inside Docker,  That Web-server will run some PHP code  from the file system which will aquire some information from the Database server in another Docker-container. Compared to the original LAMP based system, there will be a WEB/SQL-server per BLOG and there will be an extra delay going through the reverse proxy.

A great advantage is that all the files and the database are now in one spot, and I can just clone the directory /y/DOCKER/peter.lorenzen.us to a different host, and start a new instance there using “docker-compose up -d” hence trying out new stuff away from the production server is a breeze.

Another great advantage is that: if the system administrator (that’s me) is fooling around with f,ex.  the database-server and makes a mistake, the BLOG-servers will not be affected.

Let us see how I like this in another 7 year, that is how long the previous LAMP system worked without any flaws, and very little downtime.

]]>
Cloning your WordPress to another server and another name https://storepeter.dk/linux/cloning-your-wordpress-to-another-server-and-another-name Thu, 18 Dec 2014 11:44:15 +0000 http://peter.storepeter.dk/?p=649 Continue reading →]]> Da er jeg er ved at flytte rundt på et af mine data-centre, vil jeg gerne have en live backup af mine blogs, således at denne blog kunne findes under både http://storepeter.dk og http://storepeter.dk, så jeg kan teste den inden den tages i permanent drift.

Jeg kunne selvfølgelig klone min virtuel-maskine, men da internettet til mit datacenter i Danmark ikke er så god ville det tage lang tid, og det ville heller ikke ændre navnet til peter.storepeter.dk i stedet for peter.lorenzen.us.

Min måde at gøre det på er at oprette en splinter ny maskine (måske virtuel) som beskrevet tidligere i denne blog, og så overføre filerne og mysql-databasen og rette den til med de nye site-navn hvis CLONE er sat. Der laves først en exact klone, så klonen kunne tage over fra den originale ved simpelthen at lade peter.lorenzen.us pege på den (NOTE databasen skal ikke fixes), Hvis CLONE er sat laves der en klone med et andet navn, ved at pille lidt i mysql-databasen.

Skriptet kan også senere holde kopien og klonenen up-to-date

#!/bin/bash
#
# generate script to
# transfer /var/www and mysql to backupserver

CLONE=1

BLOGS="peter deborah"
RHOST="blogdk"
FROM=lorenzen.us
TO=storepeter.dk

OPTIONS=" -u root -pmit-hemmelige-password"
DUMP_OPTIONS=$OPTIONS
DUMP_OPTIONS="$DUMP_OPTIONS --all-databases"
DUMP_OPTIONS="$DUMP_OPTIONS --flush-privileges"

sudo rsync -av --delete /var/www/wordpress $RHOST:/var/www/.
mysqldump $DUMP_OPTIONS >/tmp/blog_mysqldump
for i in $BLOGS;do
        sudo rsync -av --delete /var/www/$i.$FROM $RHOST:/var/www/.
        if [ $CLONE = 1 ]; then
                sudo ssh $RHOSTS rsync -av --delete /var/www/$i.$FROM/. /var/www/$i.$TO
                (
                        echo "define('WP_HOME','http://$i.$TO');"
                        echo "define('WP_SITEURL','http://$i.$TO');"
                ) | sudo ssh $RHOST "cat >> /var/www/$i.$TO/wp-config.php"
                echo "UPDATE wp_options SET option_value = replace(option_value, 'http://$i.$FROM', 'http://$i.$TO') WHERE option_name = 'home' OR option_name = 'siteurl';" >>/tmp/blog_mysqldump
                echo "UPDATE wp_posts SET guid = replace(guid, 'http://$i.$FROM', 'http://$i.$TO');" >>/tmp/blog_mysqldump
                echo "UPDATE wp_posts SET post_content = replace(post_content, 'http://$i.$FROM', 'http://$i.$TO');" >>/tmp/blog_mysqldump
        fi
done

ssh $RHOST mysql $OPTIONS 

Med den rette sudo-opsætning og ssh-nøgler kan dette gøres uden at jeg skal taste passwords

PS: hvis du ligesom jeg har pillet i .htaccess for at undgå brute-force login-attacks, skal man lige rette lidt i den også.

PPS: eftersom wordpress gemmer parametre herunder URL for blog-en i mysql-databasen kan den samme host ikke umiddelbart servicere både peter.lorenzen.us og peter.storepeter.dk, men scriptet ovenfor er en god template for at lave et lille script der kan skifte frem og tilbage, mellem to domæner. Havde man nu haft studenter, var det en god øvelse, at sætte dem til.

]]> De gamle Websider pakket ind i WordPress https://storepeter.dk/web/de-gamle-websider-pakket-ind-i-wordpress Wed, 08 Oct 2014 12:21:57 +0000 http://peter.storepeter.dk/?p=340 Continue reading →]]> Jeg har tidligere beskrevet hvordan jeg ved hjælp af mod_rewrite og et par linier i .htaccess kunne få adgang til mine gamle WEB-sider, idet de meget belejligt startede med stort, se Access til sider uden for WordPress.

Men det kunne jo se godt ud hvis de gamle sider blev pakket ind i det samme tema som denne blog bruger – dvs der er en header, en side-kolone og en footer.

WordPress generer siderne dynamisk. Selve indholdet er gemt i en mysql-database. I stedet vil jeg have hovedsiden til at komme direkte fra den gamle fil der indeholder en fuld html-side med header og body.

Et minimal wordpress tema kunne se således ud:




Jeg har jo allerede et php-script kørende som henter filer og billeder fra “oldweb” så dette script skal blot udvides en smule. Alle filer der hentes som ender på .html skal sendes igennem handle_html() Det gør jeg ved lige at indskyde nedenstående, før jeg leverer $file til browseren.

# MAIN
#....
is_file($file) || not_found($_SERVER['REQUEST_URI']);
# We are now ready to return $file to the Browser
if (preg_match('/.html$/', $file)) {
handle_html($file);
}

handle_html() sætter header, side-kolone, og footer på, og tager indholdet fra den gamle WEB-side, vi skal kun bruge det mellem

...

handle_html() set således ud:

function handle_html($file)
{
get_header();
?>

/',$line))) {
$body = false;
}
if ($body) {
print $line;
}
if (preg_match('/


Hvis du vil se nogen af disse gamle WEB-sider kræver det blot at du er logged ind her, enten med dit facebook/linkedin/google ID eller du har oprettet dig på gammeldags maner.

]]>
Stilen skal selvfølgelig laves om https://storepeter.dk/web/stilen-skal-selvfolgelig-laves-om Tue, 30 Sep 2014 17:23:33 +0000 http://peter.storepeter.dk/?p=319 Continue reading →]]> Det tager ikke lang tid inden man synes at layout på WEB-sitet skal laves om. Der er godt nok 2678 “themes” at vælge imellem, men man kan jo ligeså godt lave sin egen, og det er ikke så svært.

Jeg har baseret mit paa “Twenty Ten” hvor jeg har

  • Lidt mere plads til “The World needs….”
  • Fjernet det skarpe sorte look – det er nu lysegråt
  • Forsiden indeholder nu kun excerpts
  • Login/Logout i menu barren, højre-stillet

Disse ændringer illusterer ganske godt de forskellige måder man kan gribe det an på
Det hele foregår i et nyt directory der er oprettet til det

/var/www/peter.lorenzen.us/wp-content/themes/twentyten-child

I style.css beskriver man at dette er et “child theme” og vi arver de fleste af de originale opsætninger, her er hvordan min ser ud nu.

/*
Theme Name: Twenty Ten Child
Theme URI: http://storepeter.dk/themes/twentyten-child
Description: Twenty Ten Child Theme
Author: Peter Lorenzen
Author URI: http://storepeter.dk
Template: twentyten
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentyten-child
*/

@import url("../twentyten/style.css");

#site-info {
	float: left;
	font-size: 18px;
	font-weight: bold;
	width: 700px;
}
#site-title {
	float: left;
	font-size: 30px;
	line-height: 36px;
	margin: 0 0 18px 0;
	width: 570px;
}
#site-description {
	clear: right;
	float: right;
	font-style: italic;
	font-size: 18px;
	margin: 15px 0 18px 0;
	width: 350px;
}
/* This is the custom header image */
#branding img {
        border-top: 0px;
        border-bottom: 0px;
        display: block;
        float: left;
}

.header-img {
   display: none;
}
.home .header-img {
   display: block;
}
#access {
	background: #eee;
	display: block;
	float: left;
	margin: 0 auto;
	width: 940px;
}
#access .menu-header,
div.menu {
	font-size: 20px;
	margin-left: 12px;
	width: 928px;
}
#access ul ul a {
	background: #ddd;
	line-height: 1em;
	padding: 10px;
	width: 160px;
	height: auto;
}
#access ul ul :hover > a {
	background: #ddd;
	color: #333;
}
#access ul li.current_page_item > a,
#access ul li.current_page_ancestor > a,
#access ul li.current-menu-ancestor > a,
#access ul li.current-menu-item > a,
#access ul li.current-menu-parent > a {
	font-weight: bold;
	color: #000;

}
* html #access ul li.current_page_item a,
* html #access ul li.current_page_ancestor a,
* html #access ul li.current-menu-ancestor a,
* html #access ul li.current-menu-item a,
* html #access ul li.current-menu-parent a,
* html #access ul li a:hover {
	color: #888;
	background: #ccc;
}
#menu-login-logout {
	float: right;
}

For kun at have billede på forsiden er det nødvendigt at lave lidt om på header.php.
Den er kopiereret over fra den originale, jeg har lave følgende ændringer:

peter@blog:/var/www/peter.lorenzen.us/wp-content/themes/twentyten-child$ diff -Naur  ../twentyten/header.php header.php 
--- ../twentyten/header.php	2014-09-27 20:56:15.600408218 -0400
+++ header.php	2014-09-28 17:39:55.125767502 -0400
@@ -51,6 +51,10 @@
 	 * as styles, scripts, and meta tags.
 	 */
 	wp_head();
+	if ( function_exists( 'my_head' ) ) {
+		echo "\n";
+		my_head();
+	}
 ?>
 
 
@@ -96,7 +100,9 @@
 							$header_image_height = HEADER_IMAGE_HEIGHT;
 						}
 					?>
-						
+						
+							
+						
 					
 			
 
peter@blog:/var/www/peter.lorenzen.us/wp-content/themes/twentyten-child$ 

den øverste ændring har ikke noget med dette at gøre, måske kommer jeg ind på hvad den gør en anden god gang.

For kun at få uddrag af mine blog-posts på forsiden, har jeg lavet denne ændring til loop.c

peter@blog:/var/www/peter.lorenzen.us/wp-content/themes/twentyten-child$ diff -Naur  ../twentyten/loop.php loop.php
--- ../twentyten/loop.php	2014-09-14 14:20:00.991113408 -0400
+++ loop.php	2014-09-30 11:59:24.292652640 -0400
@@ -135,7 +135,7 @@
 				
 			
 
-	
+	
 			
peter@blog:/var/www/peter.lorenzen.us/wp-content/themes/twentyten-child$

Login /Logout er lidt mere tricky specielt da jeg gerne vil have knappen til højre. det klares med et par linier i style.css filen ovenfor og denne funtions.php

functions.php skal ikke kopieres over fra den originale, man skal alene tilføje de extra funtioninalitet man ønsker.

Det var alt, der er masser af hjælp at hente på WEB-en, så det er bare med at gå igang

Start måske med den her http://www.hongkiat.com/blog/wordpress-child-themes-dev/

]]>
Billeder fra den gamle WEB https://storepeter.dk/web/billeder-fra-den-gamle-web Mon, 22 Sep 2014 17:27:08 +0000 http://peter.storepeter.dk/?p=252 Continue reading →]]> Sidst skrev jeg lidt om hvordan jeg har gjort vore gamle WEB-sider tilgængelig for registrede brugere på min BLOG, men billed håndteringen var ikke helt på plads.

Før Facebook bruge vi jo vores WEB til at dele vores billeder, jeg havde efterhånden fået strikket et php-script sammen til at håndtere det, og hver gang jeg pillede i det blev det endnu mere kompliceret tilsidst var det opp paa 1134 linier kode, og tæt på lige så mange bugs. Så jeg turde ikke røre ved det.

Nu er jeg så startet forfra, og har implementeret de mest brugte hjørner af scriptet. Det gamle script havde mange (all for mange) muligheder, men de tre vigtigste var:

http://storepeter.dk/pics?Peter – Viste et galleri af billederne under Peter

http://storepeter.dk/thumb?Peter/020129-213456.jpg – Viste en thumbnail

http://storepeter.dk/pics?Peter/020129-213456.jpg – Viste selve billedet

Jeg har genskabt denne funktionalitet ved at udvide det script jeg præsenterede for et par dag siden – kun 70 linier er der kommet til siden sidst, og jeg er godt tilfreds med resultatet – farvel til det gamle pics-script paa 1134 liner.
Og takket være lightbox ser det meget bedre ud end før. Nedenfor er er hvad der skal tilføjes til http://storepeter.dk/web/access-til-sider-uden-for-wordpress posten fra forleden:


/*
* required addition to .htaccess
* RewriteRule ^[A-Z] if_logged_in.php [L]
* RewriteRule ^pics if_logged_in.php [L]
* RewriteRule ^thumb if_logged_in.php [L]
*/

require_once('wp-load.php');
$oldweb = ABSPATH.'oldweb/';
is_user_logged_in() || auth_redirect();

function not_found($what)
{
status_header(404);
die('404 http://'.$_SERVER['HTTP_HOST']." $what not found");
}
function setup_file($pattern,$subdir)
{
global $url;
global $oldweb;
global $file;
if (!preg_match($pattern,$url['path']))
return false;
if (!isset($url['query']))
return false;
$opath = $url['query'];
$dir = dirname($opath);
$file = basename($opath);
$file = $oldweb.$dir.$subdir.$file;
return true;
}
function gallery($galid)
{
global $oldweb;
$files = array_diff(scandir($oldweb.$galid.'/00_THUMB'), array('..', '.'));
if (!count($files))
not_found("empty");
header('Content-Type: text/html; charset=utf-8');
echo "\n\n\n";
echo " Gallery $galid\n";
echo "\n";
echo "\n";
echo "\n";
echo "\n\n";
foreach ($files as $file) {
if (is_file($oldweb.$galid.'/00_CAPTION/'.$file.'.cmt')) {
$caption = file_get_contents($oldweb.$galid.'/00_CAPTION/'.$file.'.cmt')." ".$file;
} else {
$caption = $file;
}
echo "";
echo "
";
}
die();
}

# MAIN
$url = parse_url($_SERVER['REQUEST_URI']);
if (setup_file('/^\/pics/','/00_BIG/')) {
if (is_dir($oldweb.$url['query'].'/00_THUMB'))
gallery($url['query']);
} elseif (setup_file('/^\/thumb/','/00_THUMB/')) {
} else {
$file = $oldweb.$url['path'];
if (is_dir($file)) { // redirect dir to dir/
if (preg_match('/\/$/', $file)) {
$file = $file.'index.html';
} else {
header("Location: http://".$_SERVER['HTTP_HOST'].$url['path'].'/');
die();
}
}
}

/*
* end of changes by peter@lorenzen.us
* The rest was taken from https://gist.github.com/hakre/1552239
*/

]]>
Access til sider uden for WordPress https://storepeter.dk/web/access-til-sider-uden-for-wordpress https://storepeter.dk/web/access-til-sider-uden-for-wordpress#comments Sat, 20 Sep 2014 14:23:14 +0000 http://peter.storepeter.dk/?p=193 Continue reading →]]> WordPress har masser af muligheder for justere hvem der kan se posts/pages, men sider uden for WordPress er tilgængelig for alle.

Jeg vil gerne give access til mine gamle WEB-sider, men ikke offentligt, i første omgang er adgang for registrerede brugere nok (Der er ikke så mange).

En diskussion på  http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in overbeviste mig om at det kunne lade sig gøre, så jeg gik igang.

På min gamle WEB-site havde jeg i min vished startet alle directories med stort, noget jeg siden har fortrudt, men det viste sig smart lige her.  Derudover var alle billeder pakket ind i et php-script /pics/index.php som engang i tidernes morgen, hvor der var plads problemer på min WEB-server, kunne hente billeder fra en anden server.  Under WordPress bruger jeg Permalink til at identificere posts/pages så alle URL-er er med småt.

En simple måde til at se forskel på sider i og uden for WordPress, er at se om stedet starter med småt eller stort. Adgang til WEB-træet kontrolleres af .htaccess, tilføjer vi et par liner til den kan vi sende de gamle sider gennem et php-script.
RewriteRule ^[A-Z] if_logged_in.php [L]
RewriteRule ^pics if_logged_in.php [L]
Selve php-scriptet ser således ud:

* @license GPL-3.0+
* @registry SPDX
* modified by peter@lorenzen.us
*
* required addition to .htaccess
* RewriteRule ^[A-Z] if_logged_in.php [L]
* RewriteRule ^pics if_logged_in.php [L]
*/

require_once('wp-load.php');

is_user_logged_in() || auth_redirect();

$oldweb = dirname(__FILE__).'/oldweb/';
$url=parse_url($_SERVER['REQUEST_URI']);
$path = $url['path'];
if (preg_match('/^\/pics/',$path)) {
$opath = $url['query'];
$dir = dirname($opath);
$file = basename($opath);
$file = $oldweb.$dir.'/00_BIG/'.$file;
}
else {
$file = $oldweb.$path;
if (is_dir($file)) {
if (preg_match('/\/$/', $file)) {
$file = $file.'index.html';
}
else {
header("Location: http://".$_SERVER['HTTP_HOST'].$path.'/');
die();
}
}
}

/*
* end of changes by peter@lorenzen.us
* The rest was taken from https://gist.github.com/hakre/1552239
*/

if (!is_file($file)) {
status_header(404);
print "base==$base, file=$file, path=$path";
die('404 — File not found.');
}

$mime = wp_check_filetype($file);
if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) )
$mime[ 'type' ] = mime_content_type( $file );

if( $mime[ 'type' ] )
$mimetype = $mime[ 'type' ];
else
$mimetype = 'image/' . substr( $file, strrpos( $file, '.' ) + 1 );

header( 'Content-Type: ' . $mimetype ); // always send this
if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) )
header( 'Content-Length: ' . filesize( $file ) );

$last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) );
$etag = '"' . md5( $last_modified ) . '"';
header( "Last-Modified: $last_modified GMT" );
header( 'ETag: ' . $etag );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' );

// Support for Conditional GET
$client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false;

if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = false;

$client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
// If string is empty, return 0. If not, attempt to parse into a timestamp
$client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;

// Make a timestamp for our most recent modification...
$modified_timestamp = strtotime($last_modified);

if ( ( $client_last_modified && $client_etag )
? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) )
: ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) )
) {
status_header( 304 );
exit;
}

// If we made it this far, just serve the file
readfile( $file );


Husk også en .htaccess som forbyder adgang i oldweb

]]>
https://storepeter.dk/web/access-til-sider-uden-for-wordpress/feed 1
Hvorfor https://storepeter.dk/web/hvorfor Wed, 17 Sep 2014 13:21:01 +0000 http://peter.storepeter.dk/?p=66 Continue reading →]]> Jeg har fået et stykke kontrakt-arbejde, nemlig at lave en BLOG.   Det har jeg aldrig prøvet før, faktisk hader jeg “Portaler” som gerne vil have alt til at foregå gennem dem, og man skal have endnu en login, og endnu et password (eller værre  – endnu et sted som kender mit password).

For at få lidt erfaring med det, har jeg lavet en til mig selv.   Jeg har faktisk tænkt mig at bruge den, ikke som erstatning for facebook, men som et sted hvor jeg selv kan finde tilbage til hvordan jeg lavede noget, eller noget musik jeg kunne lide.

Hvorfor:

  • For at lære det
  • Måske fordi jeg gerne vil “eje” det selv
  • Et spinkelt håb om at det bliver lettere at finde noget
  • Jeg er jo en kontrol-freak – så nu er det mig der bestemmer om/hvis der kommer en ny tidslinie eller…

Jeg kommer i første omgang nok kun til at bruge min blog til ting jeg gerne vil kunne finde igen f.ex. elektronik/computere/musik relaterede ting

Jeg har intet behov for at eje andres kommentarer, jeg glæder mig hver gang der kommer nogen, men I er velkomne til at give dem på (til) facebook.

Jeg har forsøgt at integrere det med facebook – så man ikke behøver en ny login/password du kan bruge sin facebook/google/linkedin (FGL)  men du kan også lave din egen login hvis du ikke vil give sine FGL-data væk

BLOG-en er offentlig, i modsætning til hvordan jeg personligt bruger facebook, hvor kun mine facebook venner kan se mit facebook indhold.

Og hvordan laver man så sådan en blog? Det beskrev jeg i peter.lorenzen.us er online

]]>