URI: 
       tmore code to integrate gui elements and script - tomb - the crypto undertaker
  HTML git clone git://parazyd.org/tomb.git
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit bd370c1ef5e23023cb4ce0177f507bc9daaa9963
   DIR parent 0bd8f4b4b6ce5dc270be35a59e4fc3c498e73b81
  HTML Author: Jaromil <jaromil@dyne.org>
       Date:   Wed, 12 Jan 2011 11:38:03 +0100
       
       more code to integrate gui elements and script
       
       Diffstat:
         A src/monmort.xpm                     |      47 +++++++++++++++++++++++++++++++
         M src/tomb                            |      67 ++++++++++++++++++++++++-------
         M src/tomb-gtk.cpp                    |     112 +++++++++++++------------------
         A src/tomb-notify.cpp                 |      70 +++++++++++++++++++++++++++++++
       
       4 files changed, 218 insertions(+), 78 deletions(-)
       ---
   DIR diff --git a/src/monmort.xpm b/src/monmort.xpm
       t@@ -0,0 +1,47 @@
       +/* XPM */
       +
       +/* The Tomb icon is an artwork by Jordi aka MonMort
       +   a nomadic graffiti artist from Barcelona */
       +
       +const char *monmort[] = {
       +/* columns rows colors chars-per-pixel */
       +"32 32 5 1",
       +"  c #000000",
       +". c #010101",
       +"X c #020202",
       +"o c #C1C1C1",
       +"O c None",
       +/* pixels */
       +"OO                            OO",
       +"O oooooooooooooooooooooooooooo O",
       +" oooooooooooooooooooooooooooooo ",
       +" oooooooooooooooooooooooooooooo ",
       +" oooooooo  X     oooooo     ooo ",
       +" oooooooo        oooooo     ooo ",
       +" oooooooo        oooooo     ooo ",
       +" oooooooo        oooooo     oooX",
       +" oooooooo    X   oooooo     ooo ",
       +" oooooooo        oooooo     ooo ",
       +" oooooooo       Xoooooo     ooo ",
       +" oooooooo        oooooo   X ooo ",
       +" oooooooo X      oooooo     ooo ",
       +" oooooooooooooooooooooooooooooo ",
       +" oooooooooooooooooooooo oooooooX",
       +" ooooooooooooooooooooooo oooooo ",
       +" oooooooooooooooo      X  ooooo ",
       +"O ooooooooooooooooooooooooooooo ",
       +"OO          oooooooooooooooooo O",
       +"OOOOOOOOOOOO oooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo oooXooo OO",
       +"OOOOOOOOOOOOO oooXooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooo ooo ooo oooXOO",
       +"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOOXooo ooo ooo ooo OO",
       +"OOOOOOOOOOOOO ooooooooooooooo OO",
       +"OOOOOOOOOOOOOO ooooooooooooo OOO",
       +"OOOOOOOOOOOOOOO             OOOO"
       +};
   DIR diff --git a/src/tomb b/src/tomb
       t@@ -1,4 +1,4 @@
       -#!/bin/bash
       +#!/bin/zsh
        #
        # Tomb
        #
       t@@ -30,7 +30,7 @@
        VERSION=0.9
        DATE=Jan/2011
        
       -PATH=/usr/bin:/usr/sbin:/bin:/sbin   
       +# PATH=/usr/bin:/usr/sbin:/bin:/sbin   
        
        # standard output message routines
        # it's always useful to wrap them, in case we change behaviour later
       t@@ -126,6 +126,11 @@ ask_password() {
                    
        }
        
       +# drop privileges
       +exec_as_user() {
       +    func "executing as user '$SUDO_USER': ${(f)@}"
       +    sudo -u $SUDO_USER ${@} &
       +}
        
        
        ############################
       t@@ -134,16 +139,15 @@ ask_password() {
        
        notice "Tomb  -  simple commandline tool for encrypted storage"
        act "version $VERSION ($DATE) by Jaromil @ dyne.org"
       -act ""
       -func "invoked with args \"$*\" "
       +func "invoked with args \"${(f)@}\" "
        func "running on `date`"
        
        
       -OPTS=`getopt -o hvs:k: -n 'tomb' -- "$@"`
       -
       +OPTS=`getopt -o hvs:k:S -n 'tomb' -- "$@"`
        while true; do
            case "$1" in
                -h)
       +            act ""
                    notice "Syntax: tomb [options] command [file] [mountpoint | size]"
                    act ""
                    notice "Options:"
       t@@ -151,6 +155,7 @@ while true; do
                    act "-v     print out the version information for this tool"
                    act "-s     size of the storage file when creating one (in MBytes)"
                    act "-k     path to the key to use for decryption"
       +            act "-S     acquire super user rights if possible"
                    act ""
                    notice "Commands:"
                    act "create     create a new encrypted storage FILE and keys"
       t@@ -159,6 +164,7 @@ while true; do
                    echo; exit 2 ;;
                -v)
                    # print out the GPL license in this file
       +            act ""
                    cat $0 | awk '
        BEGIN { license=0 }
        /^# This source/  { license=1 }
       t@@ -167,6 +173,37 @@ BEGIN { license=0 }
        '
                    act ""
                    exit 0 ;;
       +        -S) GETPRIV=true; shift 1 ;;
       +        *)  break ;;
       +    esac
       +done
       +
       +id | grep root > /dev/null
       +if [ $? != 0 ]; then
       +    error "This program must be run as root to produce results"
       +    if [ "$GETPRIV" = "true" ]; then
       +        which gksu > /dev/null
       +        if [ $? = 0 ]; then
       +            act "Using gksu for root execution of 'tomb ${(f)@}'"
       +            gksu "tomb ${(f)@}"
       +            exit $?
       +        fi
       +        which sudo > /dev/null
       +        if [ $? = 0 ]; then
       +            act "Using sudo for root execution of 'tomb ${(f)@}'"
       +            sudo "tomb ${(f)@}"
       +            exit $?
       +        fi
       +        exit 1
       +    else
       +        exit 1
       +    fi
       +fi
       +
       +# now process the real options
       +OPTS=`getopt -o hvs:k:S -n 'tomb' -- "$@"`
       +while true; do
       +    case "$1" in
                -s) SIZE=$2; shift 2 ;;
                -k) KEY=$2; shift 2 ;;
                --) shift; break ;;
       t@@ -180,11 +217,7 @@ if [ -z $CMD ]; then
            exit 0
        fi
        
       -id | grep root > /dev/null
       -if [ $? != 0 ]; then
       -    error "This program must be run as root to produce results"
       -    exit 1
       -fi
       +
        
        func "command: $CMD for file $FILE"
        
       t@@ -193,7 +226,7 @@ tombtab=${tombdir}/fstab
        if ! [ -r ${tombtab} ]; then
            act "creating tomb filesystem tab in your home"
            mkdir -p ${HOME}/.tomb
       -    echo "# entombed filesystem information, see man tomb" >          ${tombtab}
       +    echo "# entombed filesystem information, see man tomb (TODO)" >          ${tombtab}
            echo "# format here is similar to the system wide fstab" >>       ${tombtab}
            echo "# <file system> <mount point> <type> <options> <key>" >>    ${tombtab}
        fi
       t@@ -379,7 +412,9 @@ mount_tomb() {
            mount -t ext4 -o rw,noatime,nodev /dev/mapper/${mapper} ${MOUNT}
            
            notice "encrypted storage $FILE succesfully mounted on $MOUNT"
       -    
       +    if [ $DISPLAY ]; then 
       +        exec_as_user tomb-gtk ${FILE} ${MOUNT}
       +    fi
        }
        
        umount_tomb() {
       t@@ -388,7 +423,7 @@ umount_tomb() {
        
                how_many_tombs="`ls /dev/mapper/tomb* 2>/dev/null | wc -w`"
                if [ $how_many_tombs = 0 ]; then
       -            error "there is no tomb found to be mounted"
       +            error "there is no open tomb to be closed"
                    return
                elif [ $how_many_tombs = 1 ]; then
                    mapper=`ls /dev/mapper/tomb* 2>/dev/null`
       t@@ -450,6 +485,8 @@ umount_tomb() {
            # fi
        
            notice "crypt storage ${mapper} unmounted"
       +    exec_as_user tomb-notify "Tomb closed:" "${FILE}
       +Rest In Peace."
        }
                
        
       t@@ -457,8 +494,10 @@ case "$CMD" in
            create)   create_tomb ;;
            format)   format_tomb ;;
            mount)    mount_tomb  ;;
       +    open)     mount_tomb  ;;
            umount)   umount_tomb ;;
            unmount)  umount_tomb ;;
       +    close)    umount_tomb ;;
            *) error "command \"$CMD\" not recognized"
                act "try -h for help"
                ;;
   DIR diff --git a/src/tomb-gtk.cpp b/src/tomb-gtk.cpp
       t@@ -1,106 +1,90 @@
       +/*  Tomb - encrypted storage undertaker
       + *  
       + *  (c) Copyright 2007-2011 Denis Roio <jaromil@dyne.org>
       + *
       + * This source code is free software; you can redistribute it and/or
       + * modify it under the terms of the GNU Public License as published 
       + * by the Free Software Foundation; either version 3 of the License,
       + * or (at your option) any later version.
       + *
       + * This source code is distributed in the hope that it will be useful,
       + * but WITHOUT ANY WARRANTY; without even the implied warranty of
       + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       + * Please refer to the GNU Public License for more details.
       + *
       + * You should have received a copy of the GNU Public License along with
       + * this source code; if not, write to:
       + * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
       + */
       +
        #include <stdio.h>
        #include <stdlib.h>
        #include <unistd.h>
       +
        #include <gtk/gtk.h>
       +#include <libnotify/notify.h>
        
        /* The Tomb icon is an artwork by Jordi aka MonMort
           a nomadic graffiti artist from Barcelona */
       -const char *monmort[] = {
       -/* columns rows colors chars-per-pixel */
       -"32 32 5 1",
       -"  c #000000",
       -". c #010101",
       -"X c #020202",
       -"o c #C1C1C1",
       -"O c None",
       -/* pixels */
       -"OO                            OO",
       -"O oooooooooooooooooooooooooooo O",
       -" oooooooooooooooooooooooooooooo ",
       -" oooooooooooooooooooooooooooooo ",
       -" oooooooo  X     oooooo     ooo ",
       -" oooooooo        oooooo     ooo ",
       -" oooooooo        oooooo     ooo ",
       -" oooooooo        oooooo     oooX",
       -" oooooooo    X   oooooo     ooo ",
       -" oooooooo        oooooo     ooo ",
       -" oooooooo       Xoooooo     ooo ",
       -" oooooooo        oooooo   X ooo ",
       -" oooooooo X      oooooo     ooo ",
       -" oooooooooooooooooooooooooooooo ",
       -" oooooooooooooooooooooo oooooooX",
       -" ooooooooooooooooooooooo oooooo ",
       -" oooooooooooooooo      X  ooooo ",
       -"O ooooooooooooooooooooooooooooo ",
       -"OO          oooooooooooooooooo O",
       -"OOOOOOOOOOOO oooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo oooXooo OO",
       -"OOOOOOOOOOOOO oooXooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooo ooo ooo oooXOO",
       -"OOOOOOOOOOOOO ooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOOXooo ooo ooo ooo OO",
       -"OOOOOOOOOOOOO ooooooooooooooo OO",
       -"OOOOOOOOOOOOOO ooooooooooooo OOO",
       -"OOOOOOOOOOOOOOO             OOOO"
       -};
       -
       +#include <monmort.xpm>
        
        GtkStatusIcon *status_tomb;
        GtkMenu *menu_tomb;
        
       +NotifyNotification *notice;
       +GError *error;
       +
        // forward declaration of callbacks
        gboolean left_click(GtkWidget *w, GdkEvent *e);
       -gboolean cb_open(GtkWidget *w, GdkEvent *e);
       -gboolean cb_quit(GtkWidget *w, GdkEvent *e);
       -
       +gboolean cb_close(GtkWidget *w, GdkEvent *e);
        
        
        int main(int argc, char **argv) {
       -
          GObject *tray;
          GdkPixbuf *pb_monmort;
       -  GtkWidget *menu_open, *menu_close, *menu_quit;
       +  GtkWidget *menu_close;
          gint menu_x, menu_y;
          gboolean push_in = true;
        
       +  char tomb_file[512];
       +  
          gtk_set_locale();
          gtk_init(&argc, &argv);
        
       +  // libnotify
       +  notify_init(PACKAGE);
       +
          // set and show the status icon
          pb_monmort = gdk_pixbuf_new_from_xpm_data(monmort);
          status_tomb = gtk_status_icon_new_from_pixbuf(pb_monmort);
          //  gtk_status_icon_set_name(status_tomb, "tomb");
          gtk_status_icon_set_title(status_tomb, "Tomb");
       -  gtk_status_icon_set_tooltip_text (status_tomb, "Tomb - encrypted storage undertaker");
       +  gtk_status_icon_set_tooltip_text (status_tomb, "Tomb - crypto undertaker");
        
          //  gtk_status_icon_set_blinking(status_tomb, true);
          menu_tomb = (GtkMenu*) gtk_menu_new();
        
       -  menu_open = gtk_menu_item_new_with_label("Open");
       -  gtk_menu_attach(menu_tomb, menu_open, 0, 1, 0, 1);
       -  g_signal_connect_swapped(menu_open, "activate", G_CALLBACK(cb_open), NULL);
       -  gtk_widget_show(menu_open);
       -  
          menu_close = gtk_menu_item_new_with_label("Close");
       -  gtk_menu_attach(menu_tomb, menu_close, 0, 1, 1, 2);
       +  gtk_menu_attach(menu_tomb, menu_close, 0, 1, 0, 1);
       +  g_signal_connect_swapped(menu_close, "activate", G_CALLBACK(cb_close), NULL);
          gtk_widget_show(menu_close);
       +  
       +  g_signal_connect_swapped(status_tomb, "activate", G_CALLBACK(left_click), menu_tomb);
        
       -  menu_quit = gtk_menu_item_new_with_label("Quit");
       -  gtk_menu_attach(menu_tomb, menu_quit, 0, 1, 2, 3);
       -  g_signal_connect_swapped(menu_quit, "activate", G_CALLBACK(cb_quit), NULL);
       -  gtk_widget_show(menu_quit);
       +  notice = notify_notification_new_with_status_icon
       +    ("Tomb encrypted undertaker",
       +     "We started digging out bones",
       +     NULL, status_tomb);
       +  notify_notification_set_icon_from_pixbuf(notice, pb_monmort);
        
       -  g_signal_connect_swapped(status_tomb, "activate", G_CALLBACK(left_click), menu_tomb);
       +  notify_notification_show(notice, &error);
        
          gtk_main();
       +  
       +  notify_uninit();
        
          exit(0);
          
       -  
        }
        
        // callbacks
       t@@ -109,7 +93,7 @@ gboolean left_click(GtkWidget *w, GdkEvent *e) {
                         gtk_status_icon_position_menu, status_tomb,
                         1, gtk_get_current_event_time());
        } 
       -gboolean cb_open(GtkWidget *w, GdkEvent *e) { 
       -  execlp("tomb","tomb","mount","sarcofago","/mnt/etrom",NULL);
       +gboolean cb_close(GtkWidget *w, GdkEvent *e) { 
       +  execlp("tomb","tomb","-S","umount",NULL);
       +  gtk_main_quit();
        }
       -gboolean cb_quit(GtkWidget *w, GdkEvent *e) { gtk_main_quit(); }
   DIR diff --git a/src/tomb-notify.cpp b/src/tomb-notify.cpp
       t@@ -0,0 +1,70 @@
       +/*  Tomb - encrypted storage undertaker
       + *  
       + *  (c) Copyright 2007-2011 Denis Roio <jaromil@dyne.org>
       + *
       + * This source code is free software; you can redistribute it and/or
       + * modify it under the terms of the GNU Public License as published 
       + * by the Free Software Foundation; either version 3 of the License,
       + * or (at your option) any later version.
       + *
       + * This source code is distributed in the hope that it will be useful,
       + * but WITHOUT ANY WARRANTY; without even the implied warranty of
       + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       + * Please refer to the GNU Public License for more details.
       + *
       + * You should have received a copy of the GNU Public License along with
       + * this source code; if not, write to:
       + * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
       + */
       +
       +// this file is a notification tool to send messages on the screen
       +
       +#include <stdio.h>
       +#include <stdlib.h>
       +#include <unistd.h>
       +
       +#include <libnotify/notify.h>
       +
       +/* The Tomb icon is an artwork by Jordi aka MonMort
       +   a nomadic graffiti artist from Barcelona */
       +#include <monmort.xpm>
       +
       +int main(int argc, char **argv) {
       +  NotifyNotification *notice;
       +  GError *error;
       +  GdkPixbuf *pb_monmort;
       +
       +  char title[256];
       +  char body[512];
       +
       +  gtk_set_locale();
       +  gtk_init(&argc, &argv);
       +
       +  // libnotify
       +  notify_init(PACKAGE);
       +
       +  if(argc<3)
       +    snprintf(body,511, "I'm the crypto undertaker.\nLet's start digging out bones.");
       +  else
       +    snprintf(body,511, "%s", argv[2]);
       +
       +  if(argc<2)
       +    snprintf(title,255,"%s version %s",PACKAGE,VERSION);
       +  else
       +    snprintf(title,255, "%s", argv[1]);
       +    
       +  // set the icon
       +  pb_monmort = gdk_pixbuf_new_from_xpm_data(monmort);
       +
       +  notice = notify_notification_new(title, body, NULL, NULL);
       +  notify_notification_set_icon_from_pixbuf(notice, pb_monmort);
       +
       +  notify_notification_show(notice, &error);
       +
       +  notify_uninit();
       +
       +  usleep(.5);
       +
       +  exit(0);
       +  
       +}