Showing posts with label network. Show all posts
Showing posts with label network. Show all posts

Friday, March 23, 2012

PPTP from Command Line

Although this blog is supposed to be about StumpWM, there are things unrelated to the window manager that one needs to do in order to make the transition easier. Since the network manager applet is not available in StumpWM (unless you use a systray program like trayer), you need to know how to do certain tasks without it.

I'm comfortable configuring my network from command line. There was one thing though that I had always done using Network Manager applet; setting up pptp. I googled for it and quickly found this which explains how I can use pptp from the command line.

First you create a file in /etc/ppp/peers. Name the file whatever you want, like myvpn. Put this inside that file:

remotename myvpn
linkname myvpn
ipparam myvpn
pty "pptp <host> --nolaunchpppd "
name <username>
usepeerdns
require-mppe
refuse-eap
noauth

# adopt defaults from the pptp-linux package
file /etc/ppp/options.pptp
Fix the host name and the user name accordingly. Then add a line like this to /etc/ppp/chap-secrets:

<username> myvpn <password> *

Again obviously you need to put your own username and password plus the correct connection name.

I have also created two scripts in /etc/ppp/ip-up.d/ and /etc/ppp/ip-down.d/ to set up the default gateway properly. These scripts are tailored for my own system and you might need to adapt them. the one in ip-up.d/ removes the current default gateway and adds a new one. The other one reverses this.

/etc/ppp/ip-up.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route del default gw 192.168.1.1
    route add default gw 192.168.2.100
fi
/etc/ppp/ip-down.d/myvpn:
#!/bin/bash

if [[ $PPP_LOCAL = 192.168.2.* ]]; then
    route add default gw 192.168.1.1
    route del default gw 192.168.2.100
fi
Don't forget to make the scripts executable. Also notice that ip-up.d/ and ip-down.d/ are only available in Debian and its derivatives (to learn more about the arguments passed to them and the available environment variables, see the Debian /etc/ppp/ip-up and /etc/ppp/ip-down scripts). Other distros use slightly different paths.

Saturday, March 10, 2012

Beginning StumpWM configuration

StumWM stores its configuration in a .stumpwmrc file in the home directory. The number one thing I need in this file is Swank. Here's the code I used.
(load "/home/mostafa/slime/swank-loader.lisp")
(swank-loader:init)
(defcommand swank () ()
  (setf stumpwm:*top-level-error-action* :break)
  (swank:create-server :port 4005
                       :style swank:*communication-style*
                       :dont-close t)
  (echo-string
   (current-screen)
   "Starting swank. M-x slime-connect RET RET, then (in-package stumpwm)."))
(swank)
For some reason, this does not always start swank though. When that happens, I just hit C-t ; and run "swank." I can then connect to the Lisp image by invoking slime-connect in emacs.

I've been using this sample as the base for my own .stumpwmrc. What I've learned? First, I learned how I can declare a command that can be run interactively run through StumpWM's semi-colon prompt. The macro is defcommand. It's similar to defun, only with an additional set of "interactive" parameters which will be prompted for at run time.

I also learned that I can define my own key-bindings using define-key. Here's an example:
(define-key *root-map* (kbd "x") "firefox")
This tells StumpWM to run the command "firefox" previously declared by defcommand when I hit C-t x. C-t is StumpWM's prefix key (can be changed of course). Any key-binding added to *root-map* is should be used after pressing this prefix. If wan't to make a key-binding without the prefix key, I can add it to *top-map*. This is how the "firefox" command is defined:
;; launch web browser
(defcommand firefox () ()
  "start firefox or switch to it if already running."
  (run-or-raise "firefox" '(:class "Firefox")))
Remember that the value after :class should be Firefox with a capital F. If it's not written like that, rerunning the command will not raise the current window, but will open a new one. On Debian, :class should be Iceweasel instead of Firefox. (For a short explanation of class and other window attributes in X see here. In short, class name is, by convention, the instance name with the first letter capitalized.)

One of the most frequent things I do throughout my day is jumping to Wikipedia to look up something, or to search for it in Google. These two commands help me do that easier:
;; ask the user for a search string and search for it in Wikipedia
(defcommand wikipedia (search)
  ((:string "Search in Wikipedia for: "))
  "prompt the user for a search term and look it up in the English Wikipedia"
  (check-type search string)
  (let ((uri (format nil "http://en.wikipedia.org/wiki/Special:Search?search=~a" search)))
    (run-shell-command
     (cat "firefox \"" uri "\""))))

;; ask the user for a search string and search for it in Google
(defcommand google (search)
  ((:string "Search in Google for: "))
  "prompt the user for a search term and look it up in Google "
  (check-type search string)
  (let ((uri (format nil "http://www.google.com/search?q=~a" search)))
    (run-shell-command
     (cat "firefox \"" uri "\""))))
Finally, I need to more things. First, Network Manager seems essential. I'm going to use it's Tray icon at the moment, so since StumpWM doesn't have a tray, I'll use trayer which launches a tray in a floating window. In Debian, trayer can be installed by running apt-get install trayer. This launches trayer properly and then runs the Network Manager applet.
;; system tray
(run-shell-command
 "/usr/bin/trayer --SetDockType false --transparent true --expand false")

;; start network manager applet
(run-shell-command "nm-applet --sm-disable")
And then I need to load my own customized keymap (I swap the ctrl and alt keys and make Caps Lock an additional alt).
;; load keyboard map
(run-shell-command "xmodmap ~/.xmodmap")
That's it for now.

Better Console Font (in Arch)

In order to use Terminus as my console (tty) font, I simply installed the package terminus-font with pacman (includes both console and X11 ...