Actions

Etherbox : Différence entre versions

De erg

Ligne 1 : Ligne 1 :
 
(Based on a setup used for working sessions at [http://constantvzw.org constant]. MM)
 
(Based on a setup used for working sessions at [http://constantvzw.org constant]. MM)
  
= Copy the starting image =
+
== Copy the starting image ==
  
 
Downloaded from https://www.raspberrypi.org/downloads/raspbian/
 
Downloaded from https://www.raspberrypi.org/downloads/raspbian/
Ligne 15 : Ligne 15 :
 
You could use [https://etcher.io/ Etcher.io] as well
 
You could use [https://etcher.io/ Etcher.io] as well
  
= Enable SSH =
+
== Enable SSH ==
  
 
SSH is no longer on by default!
 
SSH is no longer on by default!
Ligne 32 : Ligne 32 :
 
Then enable ssh under connectivity.
 
Then enable ssh under connectivity.
  
= How to find the IP address of the pi =
+
== Find the IP address of the pi ==
  
Simplest way is to connect on a wired network (plug the pi and your laptop into a router with ethernet cables), then type:
+
Simplest way is to connect on a wired network that has DHCP and plug both the pi and your laptop into a router with ethernet cables, then type:
  
 
     ping raspberrypi.local
 
     ping raspberrypi.local
Ligne 40 : Ligne 40 :
 
And you should be able to see the IP address.
 
And you should be able to see the IP address.
  
Then you can conenct with ssh with:
+
Then you can connect with ssh with either:
  
 
     ssh pi@raspberrypi.local
 
     ssh pi@raspberrypi.local
Ligne 46 : Ligne 46 :
 
or with the IP address in place of "raspberrypi.local" if you are on the wifi.
 
or with the IP address in place of "raspberrypi.local" if you are on the wifi.
  
with the default password "raspberry"
+
Login with the default password "raspberry"
  
= Bring the rest of the software up to date =  
+
== Make it easier to login, with an ssh key ==
 +
 
 +
Starting from your laptop (open a new Terminal session if you are connected to the pi):
 +
 
 +
    ssh-keygen
 +
 
 +
Choose the defaults. This generates an "ssh key" pair.
 +
 
 +
Use the ssh-copy-id utility to send it to the pi.
 +
 
 +
    ssh-copy-id pi@raspberrypi.local
 +
 
 +
== Bring the rest of the software up to date ==
  
 
<pre>sudo apt-get update
 
<pre>sudo apt-get update
Ligne 79 : Ligne 91 :
 
<pre>sudo reboot</pre>
 
<pre>sudo reboot</pre>
  
== Make it easier to login, with an ssh key ==
+
== Setup apache to serve the root with custom header + readme's ==
 
 
Starting from your laptop (open a new Terminal session if you are connected to the pi):
 
 
 
    ssh-keygen
 
 
 
Choose the defaults. This generates an "ssh key" pair.
 
 
 
Use the ssh-copy-id utility to send it to the pi.
 
 
 
    ssh-copy-id pi@raspberrypi.local
 
 
 
= Setup apache to serve the root with custom header + readme's =
 
  
 
<pre>sudo apt-get install apache2
 
<pre>sudo apt-get install apache2
Ligne 111 : Ligne 111 :
  
 
<pre>sudo service apache2 reload</pre>
 
<pre>sudo service apache2 reload</pre>
 +
 
=== droptoupload.cgi ===
 
=== droptoupload.cgi ===
  
Ligne 124 : Ligne 125 :
 
   sudo chmod +x droptoupload.cgi
 
   sudo chmod +x droptoupload.cgi
  
= HEADER.shtml =
+
=== HEADER.shtml ===
 
Sample Header that adds javascript to:
 
Sample Header that adds javascript to:
 
* Move the README.html to the TOP of the page
 
* Move the README.html to the TOP of the page
Ligne 166 : Ligne 167 :
 
&lt;/script&gt;</pre>
 
&lt;/script&gt;</pre>
  
= Better permissions with facl =
+
== Better permissions with facl ==
  
 
[http://www.linuxcommand.org/man_pages/setfacl1.html setfacl]
 
[http://www.linuxcommand.org/man_pages/setfacl1.html setfacl]
Ligne 177 : Ligne 178 :
  
 
<pre>sudo chmod g-w /home/pi</pre>
 
<pre>sudo chmod g-w /home/pi</pre>
= Install etherpad =
+
 
 +
== Install etherpad ==
  
 
And the version of &quot;nodejs&quot; is now 0.10.29~dfsg-2. So let's try it with etherpad...
 
And the version of &quot;nodejs&quot; is now 0.10.29~dfsg-2. So let's try it with etherpad...
Ligne 223 : Ligne 225 :
 
</pre>
 
</pre>
  
== Set up Mysql ==
+
=== Set up Mysql ===
  
 
First thing to do is to install MySQL :
 
First thing to do is to install MySQL :
Ligne 248 : Ligne 250 :
  
  
==Run etherpad for the first time as the etherpad user...==
+
=== Run etherpad for the first time as the etherpad user...===
  
 
<pre>cd /opt/etherpad
 
<pre>cd /opt/etherpad
Ligne 254 : Ligne 256 :
 
Following the first recipe on this page about [https://github.com/ether/etherpad-lite/wiki/How-to-deploy-Etherpad-Lite-as-a-service deploying etherpad as a systemd service]
 
Following the first recipe on this page about [https://github.com/ether/etherpad-lite/wiki/How-to-deploy-Etherpad-Lite-as-a-service deploying etherpad as a systemd service]
  
== Setup etherpad to start as a service ==
+
=== Setup etherpad to start as a service ===
  
 
<pre>sudo nano /etc/systemd/system/etherpad.service</pre>
 
<pre>sudo nano /etc/systemd/system/etherpad.service</pre>
Ligne 280 : Ligne 282 :
 
<pre>sudo systemctl enable etherpad</pre>
 
<pre>sudo systemctl enable etherpad</pre>
  
= etherdump =
+
== etherdump ==
 
Etherdump is a script that dumps all pads to different format text files. It's run periodically by a cron job to create a running archive of the etherpads.
 
Etherdump is a script that dumps all pads to different format text files. It's run periodically by a cron job to create a running archive of the etherpads.
  
Ligne 294 : Ligne 296 :
 
sudo python3 setup.py install</pre>
 
sudo python3 setup.py install</pre>
  
== Setup the folder ==
+
=== Setup the folder ===
  
 
<pre>cd /home/pi
 
<pre>cd /home/pi
Ligne 333 : Ligne 335 :
 
     sudo apt-get install pandoc texlive-latex-recommended texlive-fonts-recommended
 
     sudo apt-get install pandoc texlive-latex-recommended texlive-fonts-recommended
  
= Access point =
+
== Access point ==
  
 
Taken from [https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide#Access_Point_with_Captive_Portal this &quot;ultimate&quot; guide]
 
Taken from [https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide#Access_Point_with_Captive_Portal this &quot;ultimate&quot; guide]

Version du 30 janvier 2018 à 18:05

(Based on a setup used for working sessions at constant. MM)

Copy the starting image

Downloaded from https://www.raspberrypi.org/downloads/raspbian/

Based on the "lite" image (zip or torrent). As of 20 Jan 2018, this is Raspian "Stretch" lite.

The **lite** image has no desktop / windows session.

Based on 2017-04-10-raspian-jessie-lite.zip

unzip -p 2017-04-10-raspbian-jessie-lite.zip | pv | sudo dd of=/dev/sdc bs=4M

You could use Etcher.io as well

Enable SSH

SSH is no longer on by default!

Before putting the SD card in the pi, you can enable ssh. Just create a empty file named "ssh" and save it in the /boot partition of the SD Card.

So mount the SD card and

 cd /media/USERNAME/boot
 touch ssh

Otherwise, you can connect with a screen and run:

sudo raspi-config

Then enable ssh under connectivity.

Find the IP address of the pi

Simplest way is to connect on a wired network that has DHCP and plug both the pi and your laptop into a router with ethernet cables, then type:

   ping raspberrypi.local

And you should be able to see the IP address.

Then you can connect with ssh with either:

   ssh pi@raspberrypi.local

or with the IP address in place of "raspberrypi.local" if you are on the wifi.

Login with the default password "raspberry"

Make it easier to login, with an ssh key

Starting from your laptop (open a new Terminal session if you are connected to the pi):

   ssh-keygen

Choose the defaults. This generates an "ssh key" pair.

Use the ssh-copy-id utility to send it to the pi.

   ssh-copy-id pi@raspberrypi.local

Bring the rest of the software up to date

sudo apt-get update
sudo apt-get upgrade

Assign Static Ip Adress to the Pi

For that, you need to modify a file named 'dhcpcd.conf'. But first, you need to backup this file :

cd /etc/
sudo cp dhcpcd.conf ddhcpcd.conf.original

Then modify the 'dhcpcd.conf' :

 sudo nano dhcpcd.conf

Then find this and replace (with your value) :

# Example static IP configuration:
interface eth0
static ip_address=192.168.1.5/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

Where 192.168.1.5/24 is the new Ip address of your Pi.

At last, reboot your Pi :

sudo reboot

Setup apache to serve the root with custom header + readme's

sudo apt-get install apache2
cd /etc/apache2/sites-available
sudo nano 000-default.conf
    ServerAdmin webmaster@localhost
    # DocumentRoot /var/www/html
    DocumentRoot /home/pi
    <Directory /home/pi>
           Options Indexes FollowSymLinks
           AllowOverride none
           Require all granted
    </Directory>

    HeaderName /include/HEADER.shtml
    ReadmeName README.html

NB: Sets the HeaderName and ReadmeName directives (part of mod_autoindex).

sudo service apache2 reload

droptoupload.cgi

sudo a2enmod cgi
sudo service apache2 restart

Placed 'droptoupload.cgi' in /usr/lib/cgi-bin and tried running it with:

./droptoupload.cgi

Like this is just outputs an HTML form. Looking at http://etherbox.local/cgi-bin/droptoupload.cgi should also display an upload form.

The HEADER.shtml includes a link to this cgi.

  sudo chmod +x droptoupload.cgi

HEADER.shtml

Sample Header that adds javascript to:

<script src="/cgi-bin/droptoupload.cgi"></script>
<style>
body {
background: #38b8e9;
color: black;
}
a {
color: white;
}
#logo {
white-space: pre;
font-family: monospace;
}
</style>
<div class="links" style="margin-bottom: 1em">LOCAL:
<a href="/">&nbsp;/&nbsp;</a>
<a href="/home/pi/">home</a>
<a href="/home/pi/etherdump/">etherdump</a>
PUBLIC:
<a href="http://constantvzw.org/site/-The-Technogalactic-Software-Observatory-.html">constant</a>
<a href="https://gitlab.constantvzw.org/observatory">gitlab</a>
</div>
<style>
.links {
font-family: monospace;
text-transform: uppercase;
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
  var p = document.querySelectorAll(".top"),
      t = document.getElementsByTagName("table")[0];
  for (var i=0, l=p.length; i<l; i++) {
    document.body.insertBefore(p[i], t);
  }
});
</script>

Better permissions with facl

setfacl

sudo addgroup pi www-data

sudo setfacl -Rm g:www-data:rwX /home/pi
sudo setfacl -d -Rm g:www-data:rwX /home/pi

Unfortunately, I had problems then with permissions on the .ssh folder (preventing keys to be used). To remove the fact on just this folder:

sudo chmod g-w /home/pi

Install etherpad

And the version of "nodejs" is now 0.10.29~dfsg-2. So let's try it with etherpad...

sudo apt-get install npm git

sudo ln -s /usr/bin/nodejs /usr/bin/node

cd /opt
sudo git clone https://github.com/ether/etherpad-lite.git
sudo mv etherpad-lite etherpad

# TODO: don't create home folder! ... find option
sudo adduser --system --home=/opt/etherpad --group etherpad
sudo chown -R etherpad:etherpad etherpad

Les fichiers se trouvent dans opt/etherpad/var sous forme d'un seul fichier "dirtyDB" - > You should use a dedicated database such as "mysql", if you are planning on using etherpad-in a production environment.

sudo apt-get install mysql-server

Create your setting file.

sudo cp settings.json.template settings.json

then, desactivate the dirty.db file and configure the mysql database

sudo nano settings.json

Find and change this part :

  //The Type of the database. You can choose between dirty, postgres, sqlite and mysql
  //You shouldn't use "dirty" for for anything else than testing or development
 /* "dbType" : "dirty",
  //the database specific settings
  "dbSettings" : {
                   "filename" : "var/dirty.db"
                 },
*/
  //An Example of MySQL Configuration
   "dbType" : "mysql",
   "dbSettings" : {
                    "user"    : "etherpaduser",
                    "host"    : "localhost",
                    "password": "etherpadpass",
                    "database": "etherpad",
                    "charset" : "utf8mb4"
                  },

Set up Mysql

First thing to do is to install MySQL :

sudo apt-get install mysql-server

Then create the database, for this we need to login with the Root user (super-user) :

sudo su

Run mysql  :

mysql

Then create the database and the user 'etherpaduser' with the password 'etherpadpass' :

create database etherpad;
grant all on etherpad.* to 'etherpaduser'@'localhost' identified by 'etherpadpass';

Just to test if it works :

mysql -u etherpaduser -p etherpad


Run etherpad for the first time as the etherpad user...

cd /opt/etherpad
sudo --user etherpad bin/run.sh

Following the first recipe on this page about deploying etherpad as a systemd service

Setup etherpad to start as a service

sudo nano /etc/systemd/system/etherpad.service
[Unit]
Description=Etherpad-lite, the collaborative editor.
After=syslog.target network.target

[Service]
Type=simple
User=etherpad
Group=etherpad
WorkingDirectory=/opt/etherpad
ExecStart=/usr/bin/nodejs /opt/etherpad/node_modules/ep_etherpad-lite/node/server.js
Restart=always

[Install]
WantedBy=multi-user.target

After this, to start once...

sudo systemctl start etherpad

And to automatically start on boot:

sudo systemctl enable etherpad

etherdump

Etherdump is a script that dumps all pads to different format text files. It's run periodically by a cron job to create a running archive of the etherpads.

Install deps:

sudo apt install python3-pip
sudo pip3 install python-dateutil jinja2 html5lib

Install from repo:

git clone http://murtaugh@gitlab.constantvzw.org/aa/etherdump.git
cd etherdump
sudo python3 setup.py install

Setup the folder

cd /home/pi
mkdir etherdump
cd etherdump
etherdump init

Type in:

http://etherbox.local:9001/

And paste the API key. (Look at: /opt/etherpad/APIKEY.txt)

styles.css + versions.js

scp styles.css versions.js pi@etherbox.local:etherdump/lib

The URLs of these files are options to the etherdump pull command and should match.

etherdump.sh + cron

Make the script that runs automatically.

nano etherdump.sh
#!/bin/bash
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
cd /home/pi/etherdump
etherdump pull --all --pub /home/pi/etherdump --css lib/styles.css --script lib/versions.js
etherdump index *.meta.json > index.html

And set it to run every 5 minutes

crontab -e
PATH=/home/pi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# m h  dom mon dow   command
*/5 * * * * /home/pi/etherdump.sh > /home/pi/cron.log.txt 2>&1

The PATH is important. It can also be in the etherdump.sh but basically should match what you see when you "echo $PATH" (for the script to run in the same way as for the pi user).

Install Pandoc (+ tex -- for PDF generation ... takes a long time)

   sudo apt-get install pandoc texlive-latex-recommended texlive-fonts-recommended

Access point

Taken from this "ultimate" guide

apt-get install dnsmasq wireless-tools hostapd

# the next wasn't necessary for jessie, but for completeness..
RPI3 broadcom chip 
apt-get install firmware-brcm80211
rmmod brcmfmac
modprobe brcmfmac

Give fixed IP to wlan0 interface, edit /etc/network/interfaces switch off the built in stuff and add (section 2):

auto eth0
allow-hotplug eth0
iface etho inet dhcp

#################################
# 1. ORIGINAL settings... use wpa_supplicant for client mode
#allow-hotplug wlan0
#iface wlan0 inet manual
#    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
#
#################################
# 2. Fixed IP address (for hotspot / hostapd)
auto wlan0
iface wlan0 inet static
address 10.9.8.7
netmask 255.255.255.0
#################################

Replace /etc/dnsmasq.conf with:

interface=wlan0
dhcp-range=10.9.8.10,50.9.8.254,12h
address=/#/10.9.8.7
no-resolv

Edit /etc/hostapd/hostapd.conf file (adjust depending on driver/hardware)

interface=wlan0
driver=nl80211
ssid=WiFeels
hw_mode=g
channel=6

Edit /etc/default/hostapd and add

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Make hostapd start at boot

update-rc.d hostapd defaults

Reboot.

Extra

Changed dnsmasq.conf

interface=wlan0
dhcp-range=10.9.10.50,10.9.10.254,12h
#address=/#/10.9.10.7                                                                                                           # no-resolv

AND added to /etc/hosts

10.9.10.7 etherbox.local

and this seems to then work over the direct hotspot connection.

Tunnel

Configure ssh to use the tunnel

TODO: THESE INSTRUCTIONS ARE FOR THE WEBSITE BOT/X .. NOT THE ETHERBOX

BASED ON: http://activearchives.org/wiki/Making_a_local_server_public_with_pagekite.py

~/.ssh/config

   Host erg.activearchives.org
   CheckHostIP no
   ProxyCommand /usr/bin/corkscrew %h 10107 %h %p

cron.sh

<source lang="bash">

  1. Dump the etherpad to files

cd etherdump etherdump pull --meta --text --dhtml --pub . --no-raw-ext etherdump index \

 *.meta.json \
 --templatepath /home/pi/include \
 --template etherdump.template.html \
 --title "Erg etherdump" > index2.html
  1. Run the makefile

cd /home/pi make </source>


makefile

The makefile defines the "recipe" that turns the pads (when they are named something.md) into HTML. The "%.html: %.md" is an "implicit rule" that defines how any ".md" file (right hand side, or pre-requesite, can be turned into a ".html" file (left hand side, or "target" in the language of the makefile. For this kind of rule the special variables can be really useful (like $< and $@).

This makefile uses the pandoc program to convert markdown to html. This program has LOTS of options is quite powerful. Good documenation on the markdown format, and how pandoc supports it is: http://pandoc.org/MANUAL.html#pandocs-markdown

<source lang="bash"> mdsrc=$(shell ls etherdump/*.md) htmldest=$(mdsrc:%.md=%.html)

all: $(htmldest)

  1. $< is the right part input prereq $@ is the target

%.html: %.md pandoc --from markdown \ --standalone \ --section-divs \ --smart \ --css styles.css \ --to html5 \ $< -o $@ </source>

include/etherdump.template.html

<source lang="html"> <!DOCTYPE html> <html lang="Modèle:Language"> <head> <meta charset="utf-8" /> <meta name="google-site-verification" content="Ro8-A1t6QCIzTm_O49iqKED8YbvVnMELgdKDjy1bnqc" /> <title>Modèle:Title</title> <link rel="stylesheet" type="text/css" href="{%block css %}styles.css{%endblock%}"> <link rel="alternate" type="application/rss+xml" href="recentchanges.rss"> {% block scripts %} <script src="jquery-latest.js"></script> <script src="jquery.tablesorter.min.js"></script> {% endblock scripts %} </head> <body>

Modèle:Title

To hide a pad from this listing, use the __NOPUBLISH__ tag.

Last updated Modèle:Timestamp.

<script src="index.js"></script>

<thead> </thead> <tbody> {% for pad in pads %} {% endfor %} </tbody>
name versions last edited revisions authors

<a href="Modèle:Pad.link">Modèle:Pad.padid</a>

{% for v in pad.versions %}<a href="Modèle:V.url">Modèle:V.type</a> {% endfor %} {% if pad.padid.endswith(".md") %}<a href="{{pad.padid.split(".", 1)[0]}}.html">html</a>{% endif %}

Modèle:Pad.lastedited iso Modèle:Pad.revisions Modèle:Pad.author ids

</body> </html>

</source>