Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


Correspondent

John Duarte

Host Image
Host ID: 277

email: john.nospam@nospam.duarte-dailey.us
episodes: 4

hpr2067 :: Haste - the pastebin alternative

Released on 2016-07-05 under a CC-BY-SA license.

Haste

A walk through of installing haste as an open source federated pastebin.com alternative.

See the project at hastebin.com

I ran into project this while following John Kulp’s notes on his blather intro.

Installing node.js

Installing via a package manager. See nodejs website for most up-to-date information. Commands given below are just for reference.

RedHat based systems

curl --silent --location https://rpm.nodesource.com/setup | sudo bash -
sudo yum install -y nodejs

Debian based systems

curl --silent --location https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs

Upgrade npm

npm install npm -g

haste-server

Take a look at the haste-server project on github

Clone haste-server git repository

git clone https://github.com/seejohnrun/haste-server.git
cd haste-server

Choose storage method

Choices

  • file system
  • redis
  • memcached

If you will be using the file system storage method, delete storage section in config.js using your favorite text editor.

Install

npm install
npm start &

Use server

You can now browse to your new haste-server at the server name or ip at port 7777. Follow the icon links on the page for usage.

http://<servername>:7777

Using shell to add content

Create a bash alias to pipe files to the haste file server.

Add the following to your .bashrc file:

HASTE_SERVER='http://myserver:7777'
haste() { a=$(cat); curl -X POST -s -d "$a" $HASTE_SERVER/documents | awk -v server="$HASTE_SERVER" -F '"' '{print server"/"$4}'; }

References


hpr2048 :: The Hubot chat-bot

Released on 2016-06-08 under a CC-BY-SA license.

Hubot

Intro

Hubot is a chat-bot written by the folks at GitHub. It is a node.js application written in CoffeeScript.

Hubot has a variety of adapters that allow it to connect to a variety of chat platforms. These range from IRC to Slack. So, the platform you are interested in probably already has an adapter available for it.

Hubot uses individual CoffeeScript scripts to provide chat-bot functionality. There are a slew of existing scripts available in the npm. Just search for hubot-scripts.

You can also write your own in order to make sure that Hubot provides the functionality that you need.

Install

Hubot is available as an npm package. So, you will need to install node.js and npm on your system. I will leave this as an exercise for the listener.

I will however, throw out a tip for those of you using a Raspberry Pi for this. The node.js platform should be deployed on an ARM system using the armhf (ARM hard float) architecture. The nod e.js stack needed to run Hubot will not properly install if you are using the armel (ARM soft float) architecture.

Once you have node.js and npm installed, you can install hubot and its dependencies with the following command.

npm install -g hubot yo generator-hubot coffee-script

You create your own instance of hubot by using yeoman generator. You need to do this as a non-root user. When you create your bot, you will give it a name and specify the adapter to use. These can be specified as command line flags, or the generator will prompt you for this information.

  • Owner
  • Name
  • Description
  • Adapter

Interactive

yo hubot

Providing the answers

yo hubot --name mybot --description "My Helpful Robot" --adapter shell --defaults

Running

Once hubot is installed, you can run it with the following. I will use the shell adapter, which provides an interactive shell from which to trigger hubot scripts.

./bin/hubot --adapter shell

Our Hubot instance is now active and ready to receive commands. We will start with a simple ping command.

mybot> mybot ping
mybot> PONG

We can see the available commands by asking Hubot for help

mybot> mybot help
mybot adapter - Reply with the adapter
mybot animate me <query> - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
mybot echo <text> - Reply back with <text>
mybot help - Displays all of the help commands that Hubot knows about.
mybot help <query> - Displays all help commands that match <query>.
mybot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.
mybot map me <query> - Returns a map view of the area returned by `query`.
mybot mustache me <url|query> - Adds a mustache to the specified URL or query result.
mybot ping - Reply with pong
mybot pug bomb N - get N pugs
mybot pug me - Receive a pug
mybot the rules - Make sure hubot still knows the rules.
mybot time - Reply with current time
mybot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.
mybot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <source> and <target> are optional
ship it - Display a motivation squirrel

We will try a couple more.

mybot> mybot echo "Hello world"
"Hello world"
mybot> mybot the rules
0. A robot may not harm humanity, or, by inaction, allow humanity to come to harm.
1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.
3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.

Adding Scripts

npm scripts

npm install hubot-simpsons

Add hubot-simpsons to the array in the external-scripts.json file.

mybot> mybot simpsons quote
mybot> Disco Stu⦠likes disco.

Writing scripts

https://github.com/github/hubot/blob/master/docs/scripting.md

You can add your own custom scripts by adding them to the scripts directory. An examples.coffee script was included when Hubot was installed. It includes a variety of examples of things Hubot can do. I will illustrate by paring this down to a simple single script that responds to requests to open doors. Our simple script will open most doors, but will politely refuse to open the 'pod bay' doors.

The script uses the respond method on the robot module. This method takes a regex patten to respond to. It returns a result that contains a match array when the pattern has been detected. In our script we capture the group between 'onen the' and 'doors'. We then use this to determine which response to provide. The response is triggered with the robots reply method.

module.exports = (robot) ->

 robot.respond /open the (.*) doors/i, (res) ->
   doorType = res.match[1]
   if doorType is "pod bay"
     res.reply "I'm afraid I can't let you do that."
   else
     res.reply "Opening #{doorType} doors"

Restart Hubot by...

Now we can use our new, useful Hubot script.

mybot> mybot open the french doors
mybot> Shell: Opening french doors
mybot> mybot open the pod bay doors
mybot> Shell: I'm afraid I can't let you do that.

Aliases

A rose by any other name... If you would like your Hubot to respond to another name, you can assign your Hubot aliases to respond to. I really like this feature and I assign the '!' as my Hubot alias. This allows me to invoke Hubot with a single character.

mybot> ! open the pod bay doors
mybot> Shell: I'm afraid I can't let you do that.

Adapters

Obviously the shell adapter is not very useful aside from allowing us to play with or develop Hubot scripts. Hubot comes with several adapters that allow it to integrate with existing chat systems. These include: * IRC * XMPP * Campfire * HipChat * Slack * IRC * IRC

Conclusion

I hope this gives you a sense of what Hubot can do and how you can utilize it. Personally, I use Hubot in a variety of ways ranging from silly entertainment to useful communication tool. Using the eight-ball script, I can see if I will have a good day.

mybot> mybot eight-ball Will I have a good day?
mybot> Shell: Most certainly!
mybot> :-)

Using a modified version of of the sms script, I can send text messages to my family members who are not available online.

mybot> mybot sms trinity   See you on the other side!
mybot> Shell: Sent sms to 3125550690
mybot> :-)

hpr1888 :: Diceware Passphrase

Released on 2015-10-28 under a CC-BY-SA license.

A walk through of how to use diceware (http://world.std.com/~reinhold/diceware.html) to create a passphrase and update your GPG key to use it.


hpr1498 :: Personal OpenVPN

Released on 2014-04-30 under a CC-BY-SA license.

Personal OpenVPN

This guide will walk you through setting up an OpenVPN server as well as a client.

OpenVPN Server Setup

Here is how to install OpenVPN on Centos6. Other RedHat derivatives should be similar.

    wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
    rpm -Uvh epel-release-6-8.noarch.rpm
    yum install openvpn -y

Here is how to install OpenVPN on a Debian server. Other Debian derivatives should be similar.

    apt-get install openvpn

After the server is installed, the server certificate authority and keys must be generated. This will be followed by the client keys, and then the server configuration file.

Copy the easy-rsa scripts into /etc/openvpn

    cp -rf /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa  # on Debian
    cp -rf /usr/share/openvpn/easy-rsa/2.0/* /etc/openvpn/easy-rsa  # on Centos6

Set Environmental variables

    cd /etc/openvpn/easy-rsa
    vim vars

Change the following variables to meet your needs. These are used for your convenience. They will be used as the defaults during the interactive key generation session to set the keys attributes.

    export KEY_COUNTRY="US"
    export KEY_PROVINCE="CA"
    export KEY_CITY="SanFrancisco"
    export KEY_ORG="Fort-Funston"
    export KEY_EMAIL="me@myhost.mydomain"

Source the variables to the current shell

. ./vars

Create certificate authority

    ./clean-all
    ./build-ca
    ./build-dh

Create keys for the server and clients

    ./build-key-server server
    ./build-key client1
    ./build-key client2

Setup the server configuration file

  cd /etc/openvpn
  gunzip /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz  # on Debian
  vim /etc/openvpn/server.conf

Server settings

    port 1194
    proto udp
    dev tun
    ca     /etc/openvpn/easy-rsa/keys/ca.crt
    cert   /etc/openvpn/easy-rsa/keys/server.crt
    key    /etc/openvpn/easy-rsa/keys/server.key
    dh     /etc/openvpn/easy-rsa/keys/dh2048.pem
    server 10.10.42.0 255.255.255.0
    ifconfig-pool-persist ipp.txt
    client-config-dir ccd
    route 10.10.42.0 255.255.255.0
    client-to-client
    keepalive 10 120
    cipher AES-256-CBC   # AES
    comp-lzo
    user nobody
    group nogroup
    persist-key
    persist-tun
    status openvpn-status.log
    verb 3

Restart VPN Service

    service openvpn restart

If the service fails to start, try starting openVPN manually. The resulting errors will allow you to see what item in the configuration file is incorrect.

    openvpen server.conf

Once you are able to get openVPN to start without error, kill it and restart it using the service command above. You can verify that the vpn is successfully running by looking at the configured interfaces using the following command.

    ifconfig

You should now see an entry like the following:

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.10.42.1  P-t-P:10.10.42.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:622255 errors:0 dropped:0 overruns:0 frame:0
          TX packets:986993 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:40649523 (38.7 MiB)  TX bytes:1344026670 (1.2 GiB)

OpenVPN Client Setup

The installation of OpenVPN for linux is the same as described above for the server. For Windows, Download and run the OpenVPN installer from the OpenVPN Community Downloads.

NOTE: On Windows, User Account Control (UAC) must be turned off in order to allow OpenVPN to execute the necessary network commands to bring up the VPN. Open Start > Control Panel > User Accounts and Family Safety > User Accounts > Change User Account Control Settings. Set to Never Notify, click OK, and reboot the machine.

Client Configuration file

For linux, the client config file would go in `/etc/openvpn` just like the server config. We will name it `client.conf` to clarify that the device is being configured as an OpenVPN client. On Windows, the keys and client config files go in the `C:\Program Files (x86)\OpenVPN\config`. The config file has to have an `.ovpn` suffix.

    client
    dev tun
    proto udp
    remote myvpn.example.org 1194
    resolv-retry infinite
    nobind
    user nobody
    group nogroup
    persist-key
    persist-tun
    ca     /etc/openvpn/keys/ca.crt
    # on Windows, the format is:
    # ca "C:\\Program Files (x86)\\OpenVPN\\config\\ca.crt"
    # Windows may also change the file suffix on the crt files to cer.
    # So, If Windows complains that it cannot find the file,
    # examine its properties to verify the suffix.
    # The logs are stored at C:\\Program Files (x86)\\OpenVPN\\log
    cert   /etc/openvpn/keys/client1.crt
    key    /etc/openvpn/keys/client1.key
    ns-cert-type server
    cipher AES-256-CBC
    comp-lzo
    verb 3

Copy client key and server ca files onto client

    scp  ca.crt  user@client1:.openvpn/
    scp  client1.crt  user@client1:.openvpn/
    scp  client1.key  user@client1:.openvpn/

On the server create the ccd directory to assign static addresses to clients.

    mkdir /etc/openvpn/ccd

For each device, add a file with the CN name of the key. In that file, you will indicate the static address to be used and the server IP For linux, the server IP will be the VPN address of your VPN server. On Windows, the VPN client will set up a local TAP interface that must be used as the server IP. See the OpenVPN docs for available client and TAP server IP pairs.

Examples:

    cat /etc/openvpn/ccd/linux-client
    ifconfig-push 10.10.42.10 10.10.42.1
    cat /etc/openvpn/ccd/windows-client
    ifconfig-push 10.10.42.13 10.10.42.14

References:


Become a Correspondent