24
Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique X-Window, développé au MIT dans le cadre du projet Athena Développement par Sun du système NeWS (Network Windowing System) NeWS étant un système propriétaire de Sun basé sur PostScript d'Adobe alors que X était entièrement libre, c'est ce dernier qui s'est imposé en se propageant rapidement dans le monde Unix, et en particulier dans les universités.

Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique X-Window, développé au MIT dans le cadre du projet Athena Développement

Embed Size (px)

Citation preview

Page 1: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

11

X WindowX WindowSystème graphique

X-Window, développé au MIT dans le cadre du projet Athena

Développement par Sun du système NeWS (Network Windowing System)

NeWS étant un système propriétaire de Sun basé sur PostScript d'Adobe alors que X était entièrement libre, c'est ce dernier qui s'est imposé en se propageant rapidement dans le monde Unix, et en particulier dans les universités.

X-Window, développé au MIT dans le cadre du projet Athena

Développement par Sun du système NeWS (Network Windowing System)

NeWS étant un système propriétaire de Sun basé sur PostScript d'Adobe alors que X était entièrement libre, c'est ce dernier qui s'est imposé en se propageant rapidement dans le monde Unix, et en particulier dans les universités.

Page 2: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

22

X WindowX WindowSystème graphique

X-Window du MIT (notez l'absence de "s" à Window, au contraire des produits propriétaires, comme Windows 95, OpenWindows, DECWindows), c'est: avant tout, un protocole d'affichage graphique de très bas niveau, c'est-à-

dire avec des primitives simples une plateforme software (serveur) permettant cet affichage interactif sur

un ensemble restreint de plateformes hardware (en principe, écran, clavier et souris à 3 boutons)

Xlib, l'ensemble de fonctions de base à disposition des clients le toolkit "Xt Intrinsics", ensemble de fonctions de gestion de widgets les widgets Athena standards (Xaw) un "window manager" (twm), tout aussi standard, mais offrant un "look"

un peu simple un ensemble d'applications clientes: xterm, xedit, xman, xclock… un ensemble de fichiers de configuration par défaut (.Xresources...) à

l'usage de twm et des applications.

X-Window du MIT (notez l'absence de "s" à Window, au contraire des produits propriétaires, comme Windows 95, OpenWindows, DECWindows), c'est: avant tout, un protocole d'affichage graphique de très bas niveau, c'est-à-

dire avec des primitives simples une plateforme software (serveur) permettant cet affichage interactif sur

un ensemble restreint de plateformes hardware (en principe, écran, clavier et souris à 3 boutons)

Xlib, l'ensemble de fonctions de base à disposition des clients le toolkit "Xt Intrinsics", ensemble de fonctions de gestion de widgets les widgets Athena standards (Xaw) un "window manager" (twm), tout aussi standard, mais offrant un "look"

un peu simple un ensemble d'applications clientes: xterm, xedit, xman, xclock… un ensemble de fichiers de configuration par défaut (.Xresources...) à

l'usage de twm et des applications.

Page 3: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

33

X WindowX WindowQu’est-ce que X?

Environnement graphique basé sur un modèle client-serveur Le service affiche l’écran et gère les entrées utilisateur

(souris, clavier, etc…) Le client est un programme qui utilise l’affichage

graphique

X possède son propre protocole réseau# grep X /etc/services | grep 6000

x11 6000/tcp X # the X Window System

La version utilisée est X11R6

Environnement graphique basé sur un modèle client-serveur Le service affiche l’écran et gère les entrées utilisateur

(souris, clavier, etc…) Le client est un programme qui utilise l’affichage

graphique

X possède son propre protocole réseau# grep X /etc/services | grep 6000

x11 6000/tcp X # the X Window System

La version utilisée est X11R6

Page 4: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

44

X WindowX WindowBibliothèques

Bibliothèques qui gèrent l’affichage Xlib accès de base Boîtes à outils (widgets)

Xaw AthenaOpenLook SunMotifQt K Desktop Environment (KDE)Gtk GIMP ToolKit de GNU Network Object Model

Environment (GNOME)

Bibliothèques qui gèrent l’affichage Xlib accès de base Boîtes à outils (widgets)

Xaw AthenaOpenLook SunMotifQt K Desktop Environment (KDE)Gtk GIMP ToolKit de GNU Network Object Model

Environment (GNOME)

Page 5: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

55

X WindowX WindowBibliothèques

Implémentations du standard X dans les distributions Linux XFree86 Ancien standard Xorg Nouveau standard

Les deux implémentations offrent les mêmes services.

Implémentations du standard X dans les distributions Linux XFree86 Ancien standard Xorg Nouveau standard

Les deux implémentations offrent les mêmes services.

Page 6: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

66

X WindowX WindowConfiguration

xorgcfg outil de configuration

Dans les distributions Red Hat, xorgcfg est remplacé par system-config-display

xorgcfg outil de configuration

Dans les distributions Red Hat, xorgcfg est remplacé par system-config-display

Page 7: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

77

X WindowX WindowFichier de configuration Le fichier /etc/X11/xorg.conf

Attention! Faire une sauvegarde de ce fichier avant toute modification

Le fichier /etc/X11/xorg.conf

Attention! Faire une sauvegarde de ce fichier avant toute modification

Page 8: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

88

X WindowX WindowServeur de polices de caractères

X Window propose un processus serveur de polices de caractères

# service xfs status

xfs (pid 2182) en cours d'exécution... GNOME

Configuration # more /etc/X11/fs/config

#

# Default font server configuration file for Red Hat Linux

#

# allow a max of 10 clients to connect to this font server

client-limit = 10

# when a font server reaches its limit, start up a new one

clone-self = on

# where to look for fonts

#

catalogue = /usr/X11R6/lib/X11/fonts/korean,

/usr/X11R6/lib/X11/fonts/misc:unscaled,

/usr/X11R6/lib/X11/fonts/75dpi:unscaled,

X Window propose un processus serveur de polices de caractères

# service xfs status

xfs (pid 2182) en cours d'exécution... GNOME

Configuration # more /etc/X11/fs/config

#

# Default font server configuration file for Red Hat Linux

#

# allow a max of 10 clients to connect to this font server

client-limit = 10

# when a font server reaches its limit, start up a new one

clone-self = on

# where to look for fonts

#

catalogue = /usr/X11R6/lib/X11/fonts/korean,

/usr/X11R6/lib/X11/fonts/misc:unscaled,

/usr/X11R6/lib/X11/fonts/75dpi:unscaled,

Page 9: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

99

X WindowX WindowServeur de polices de caractères

Des polices peuvent être ajoutées Par exemple Xorg, FreeType et TrueType

Vérifier si les chemins dans le fichier de configuration

xfontsel

Des polices peuvent être ajoutées Par exemple Xorg, FreeType et TrueType

Vérifier si les chemins dans le fichier de configuration

xfontsel

Page 10: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1010

X WindowX WindowEnvironnements graphiques

Les gestionnaires d’affichage (Display Manager) sont des clients X qui affichent un cartouche de connexion gdmGNOME kdmKDE xdm

Le gestionnaire d’affichage distributions Red Hat, xorgcfg a été remplacé par system-config-display

# grep initdefault /etc/inittab

# 0 - halt (Do NOT set initdefault to this)

# 6 - reboot (Do NOT set initdefault to this)

id:5:initdefault:

Les gestionnaires d’affichage (Display Manager) sont des clients X qui affichent un cartouche de connexion gdmGNOME kdmKDE xdm

Le gestionnaire d’affichage distributions Red Hat, xorgcfg a été remplacé par system-config-display

# grep initdefault /etc/inittab

# 0 - halt (Do NOT set initdefault to this)

# 6 - reboot (Do NOT set initdefault to this)

id:5:initdefault:

Page 11: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1111

X WindowX WindowEnvironnements graphiques

Avec le niveau d’init 5 /etc/X11/prefdm est exécuté

# grep prefdm /etc/inittab

x:5:respawn:/etc/X11/prefdm -nodaemon

Le script /etc/X11/prefdm lit le fichier /etc/sysconfig/desktop

# more /etc/sysconfig/desktop

DESKTOP="GNOME"

Avec le niveau d’init 5 /etc/X11/prefdm est exécuté

# grep prefdm /etc/inittab

x:5:respawn:/etc/X11/prefdm -nodaemon

Le script /etc/X11/prefdm lit le fichier /etc/sysconfig/desktop

# more /etc/sysconfig/desktop

DESKTOP="GNOME"

Page 12: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1212

X WindowX WindowConfiguration du gestionnaire d’affichage

GNOME/etc/X11/gdm/gdm.confKDE /usr/share/config/kdm/kdmrcXDM /usr/X11R6/lib/X11/xdm/xdm-config

Le répertoire peut être différent en fonction de la distribution

GNOME/etc/X11/gdm/gdm.confKDE /usr/share/config/kdm/kdmrcXDM /usr/X11R6/lib/X11/xdm/xdm-config

Le répertoire peut être différent en fonction de la distribution

Page 13: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1313

X WindowX WindowContrôle de plusieurs écrans

X Window peut contrôler plusieurs écrans

Les écrans se nomment <nom-de-machine>:0.0 <nom-de-machine>:0.1

X Window peut contrôler plusieurs écrans

Les écrans se nomment <nom-de-machine>:0.0 <nom-de-machine>:0.1

Page 14: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1414

X WindowX WindowPrise de contrôle à distance

rsh remote shell

rlogin

telnet

ssh ssh <nom-de-machine> ssh –X <nom-de-machine>

rsh remote shell

rlogin

telnet

ssh ssh <nom-de-machine> ssh –X <nom-de-machine>

Page 15: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1515

X WindowX WindowScripts d’administration

Tcl/TkTcl Tool Command LanguageTKTool Kit

Tcl/TkTcl Tool Command LanguageTKTool Kit

Page 16: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1616

X WindowX WindowExemple Tcl/Tk

Page 17: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1717

X WindowX WindowExemple Tcl/Tk#!/usr/bin/wish

# nagios-ws.sh GUI (Graphic User Interface).

# Creation date: jeu jan 25 09:32:17 CET 2007

#

# Set window title

wm title . "Ajouter et supprimer une machine"

# Default values

set realdir /root/nagios/bin

set machinename poste12

set parentname switch1

set backupdir /data/backup

# Recherche du site

set fqdn [exec hostname -a]

set host [exec hostname]

set domaine [string trimleft $fqdn $host]

# First frame : parameter fields

frame .first -borderwidth 10

pack .first -side top -fill x

label .first.machinelabel -text "Nom de la machine:" -padx 0

entry .first.srvname -width 12 -relief sunken -justify right -textvariable machinename

label .first.domainlabel -text "$domaine" -padx 0

label .first.plabel -text " Nom du parent:" -padx 0

entry .first.pname -width 12 -relief sunken -justify right -textvariable parentname

label .first.domainlabel2 -text "$domaine" -padx 0

pack .first.machinelabel .first.srvname .first.domainlabel -side left

pack .first.plabel .first.pname .first.domainlabel2 -side left

#!/usr/bin/wish

# nagios-ws.sh GUI (Graphic User Interface).

# Creation date: jeu jan 25 09:32:17 CET 2007

#

# Set window title

wm title . "Ajouter et supprimer une machine"

# Default values

set realdir /root/nagios/bin

set machinename poste12

set parentname switch1

set backupdir /data/backup

# Recherche du site

set fqdn [exec hostname -a]

set host [exec hostname]

set domaine [string trimleft $fqdn $host]

# First frame : parameter fields

frame .first -borderwidth 10

pack .first -side top -fill x

label .first.machinelabel -text "Nom de la machine:" -padx 0

entry .first.srvname -width 12 -relief sunken -justify right -textvariable machinename

label .first.domainlabel -text "$domaine" -padx 0

label .first.plabel -text " Nom du parent:" -padx 0

entry .first.pname -width 12 -relief sunken -justify right -textvariable parentname

label .first.domainlabel2 -text "$domaine" -padx 0

pack .first.machinelabel .first.srvname .first.domainlabel -side left

pack .first.plabel .first.pname .first.domainlabel2 -side left

Page 18: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1818

X WindowX WindowExemple Tcl/Tk

# Create a frame for buttons and entry.

frame .second -borderwidth 10

pack .second -side top -fill x

# Create the command buttons.

label .second.commandlabel -text "Commandes:" -padx 0

button .second.add -text "Ajouter" -command Add

button .second.remove -text "Supprimer" -command Remove

button .second.check -text "Vérifier" -command Check

button .second.restart -text "Redémarrer" -command Restart

pack .second.commandlabel .second.add .second.remove .second.check .second.restart -side left

button .second.help -text "Aide" -command Help

button .second.quit -text "Quitter" -command exit

pack .second.quit .second.help -side right

# Create a text widget to log the output

frame .t

set log [text .t.log -width 80 -height 40 \

-borderwidth 2 -relief raised -setgrid true \

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

# Create a frame for buttons and entry.

frame .second -borderwidth 10

pack .second -side top -fill x

# Create the command buttons.

label .second.commandlabel -text "Commandes:" -padx 0

button .second.add -text "Ajouter" -command Add

button .second.remove -text "Supprimer" -command Remove

button .second.check -text "Vérifier" -command Check

button .second.restart -text "Redémarrer" -command Restart

pack .second.commandlabel .second.add .second.remove .second.check .second.restart -side left

button .second.help -text "Aide" -command Help

button .second.quit -text "Quitter" -command exit

pack .second.quit .second.help -side right

# Create a text widget to log the output

frame .t

set log [text .t.log -width 80 -height 40 \

-borderwidth 2 -relief raised -setgrid true \

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

Page 19: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

1919

X WindowX WindowExemple Tcl/Tk

# Run the program and arrange to read its input

proc Run {} {

global command input log machinename parentname

if [catch {open "|$command |& cat"} input] {

$log insert end $input\n

} else {

fileevent $input readable Log

$log insert end $command\n

}

}

# Read and log ouput from the program

proc Log {} {

global input log

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

}

# Stop the program and fix up the button

proc Stop {} {

global input

catch {close $input}

}

# Run the program and arrange to read its input

proc Run {} {

global command input log machinename parentname

if [catch {open "|$command |& cat"} input] {

$log insert end $input\n

} else {

fileevent $input readable Log

$log insert end $command\n

}

}

# Read and log ouput from the program

proc Log {} {

global input log

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

}

# Stop the program and fix up the button

proc Stop {} {

global input

catch {close $input}

}

# Add workstation

proc Add {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname add"

Run

}

# Remove workstation

proc Remove {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname remove"

Run

}

# Check configuration

proc Check {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname check"

Run

}

# Service Restart

proc Restart {} {

global command

set command "service nagios restart"

Run

}

# Help

proc Help {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -h"

Run

#set command "echo nagios-ws.sh -ws $machinename -p $parentname"

}

# Add workstation

proc Add {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname add"

Run

}

# Remove workstation

proc Remove {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname remove"

Run

}

# Check configuration

proc Check {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -ws $machinename -p $parentname check"

Run

}

# Service Restart

proc Restart {} {

global command

set command "service nagios restart"

Run

}

# Help

proc Help {} {

global realdir command machinename parentname

set command "$realdir/nagios-ws.sh -h"

Run

#set command "echo nagios-ws.sh -ws $machinename -p $parentname"

}

Page 20: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

2020

X WindowX WindowAutre Exemple Tcl/Tk

Page 21: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

2121

X WindowX WindowAutre Exemple Tcl/Tk

#!/usr/bin/wish

# db.sh GUI (Graphic User Interface).

# $Id$

# Set window title

wm title . "Save & Restore Database"

# Default values

set servername localhost

set databasename NomBase

set username NomUtilisateur

set backupdir /data/backup

# First frame : parameter fields

frame .first -borderwidth 10

pack .first -side top -fill x

label .first.srvlabel -text "Server Name:" -padx 0

entry .first.srvname -width 17 -relief sunken -textvariable servername

label .first.dblabel -text " Database Name:" -padx 0

entry .first.dbname -width 17 -relief sunken -textvariable databasename

label .first.usrlabel -text " User Name:" -padx 0

entry .first.usrname -width 17 -relief sunken -textvariable username

pack .first.srvlabel .first.srvname -side left

pack .first.dblabel .first.dbname -side left

pack .first.usrlabel .first.usrname -side left

#!/usr/bin/wish

# db.sh GUI (Graphic User Interface).

# $Id$

# Set window title

wm title . "Save & Restore Database"

# Default values

set servername localhost

set databasename NomBase

set username NomUtilisateur

set backupdir /data/backup

# First frame : parameter fields

frame .first -borderwidth 10

pack .first -side top -fill x

label .first.srvlabel -text "Server Name:" -padx 0

entry .first.srvname -width 17 -relief sunken -textvariable servername

label .first.dblabel -text " Database Name:" -padx 0

entry .first.dbname -width 17 -relief sunken -textvariable databasename

label .first.usrlabel -text " User Name:" -padx 0

entry .first.usrname -width 17 -relief sunken -textvariable username

pack .first.srvlabel .first.srvname -side left

pack .first.dblabel .first.dbname -side left

pack .first.usrlabel .first.usrname -side left

# Create a frame for chosing backup file.

frame .second -borderwidth 10

pack .second -side top -fill x

label .second.filenamelabel -text "File name:" -padx 0

pack .second.filenamelabel -side left

button .second.choosefile -text "Choose file" -command Choose

pack .second.choosefile -side right

entry .second.cmd -width 20 -relief sunken -textvariable filename

pack .second.cmd -side left -fill x -expand true

# Create a frame for buttons and entry.

frame .third -borderwidth 10

pack .third -side top -fill x

# Create the command buttons.

label .third.databaselabel -text "Database commands:" -padx 0

button .third.save -text "Save" -command Save

button .third.restore -text "Restore" -command Restore

button .third.stop -text "Stop" -command StopDatabase

pack .third.databaselabel .third.save .third.restore -side left

button .third.help -text Help -command Help

button .third.quit -text Quit -command exit

pack .third.quit .third.help -side right

# Create a text widget to log the output

frame .t

set log [text .t.log -width 80 -height 40 \

-borderwidth 2 -relief raised -setgrid true \

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

# Create a frame for chosing backup file.

frame .second -borderwidth 10

pack .second -side top -fill x

label .second.filenamelabel -text "File name:" -padx 0

pack .second.filenamelabel -side left

button .second.choosefile -text "Choose file" -command Choose

pack .second.choosefile -side right

entry .second.cmd -width 20 -relief sunken -textvariable filename

pack .second.cmd -side left -fill x -expand true

# Create a frame for buttons and entry.

frame .third -borderwidth 10

pack .third -side top -fill x

# Create the command buttons.

label .third.databaselabel -text "Database commands:" -padx 0

button .third.save -text "Save" -command Save

button .third.restore -text "Restore" -command Restore

button .third.stop -text "Stop" -command StopDatabase

pack .third.databaselabel .third.save .third.restore -side left

button .third.help -text Help -command Help

button .third.quit -text Quit -command exit

pack .third.quit .third.help -side right

# Create a text widget to log the output

frame .t

set log [text .t.log -width 80 -height 40 \

-borderwidth 2 -relief raised -setgrid true \

-yscrollcommand {.t.scroll set}]

scrollbar .t.scroll -command {.t.log yview}

pack .t.scroll -side right -fill y

pack .t.log -side left -fill both -expand true

pack .t -side top -fill both -expand true

Page 22: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

2222

X WindowX WindowAutre Exemple Tcl/Tk

# Run the program and arrange to read its input

proc Run {} {

global command input log servername databasename username

if [catch {open "|$command |& cat"} input] {

$log insert end $input\n

} else {

fileevent $input readable Log

$log insert end $command\n

}

}

# Read and log ouput from the program

proc Log {} {

global input log

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

}

# Stop the program and fix up the button

proc Stop {} {

global input

catch {close $input}

}

# Run the program and arrange to read its input

proc Run {} {

global command input log servername databasename username

if [catch {open "|$command |& cat"} input] {

$log insert end $input\n

} else {

fileevent $input readable Log

$log insert end $command\n

}

}

# Read and log ouput from the program

proc Log {} {

global input log

if [eof $input] {

Stop

} else {

gets $input line

$log insert end $line\n

$log see end

}

}

# Stop the program and fix up the button

proc Stop {} {

global input

catch {close $input}

}

# Choose file

proc Choose {} {

global filename backupdir

set directory "/data/backup"

set types {

{{Backup Files} {.backup} }

{{All Files} * }

}

set filename [tk_getOpenFile -initialdir $backupdir -filetypes $types]

}

# Save database

proc Save {} {

global command servername databasename username

set command "db.sh -srv $servername -db $databasename -usr $username save"

Run

}

# Restore database

proc Restore {} {

global command servername databasename username filename

if {$filename != ""} {

set command "db.sh -srv $servername -db $databasename -usr $username -file $filename restore"

Run

}

}

# Stop database

proc StopDatabase {} {

global command servername

set command "ssh root@$servername service postgresql status"

Run

}

# Help

proc Help {} {

global command

set command "db.sh -help"

Run

}

#

# Choose file

proc Choose {} {

global filename backupdir

set directory "/data/backup"

set types {

{{Backup Files} {.backup} }

{{All Files} * }

}

set filename [tk_getOpenFile -initialdir $backupdir -filetypes $types]

}

# Save database

proc Save {} {

global command servername databasename username

set command "db.sh -srv $servername -db $databasename -usr $username save"

Run

}

# Restore database

proc Restore {} {

global command servername databasename username filename

if {$filename != ""} {

set command "db.sh -srv $servername -db $databasename -usr $username -file $filename restore"

Run

}

}

# Stop database

proc StopDatabase {} {

global command servername

set command "ssh root@$servername service postgresql status"

Run

}

# Help

proc Help {} {

global command

set command "db.sh -help"

Run

}

#

Page 23: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

2323

Exemple shell

#!/bin/sh

#

# Save databases

#

PROGNAME=`basename $0`

SYNTAXE="Usage : $PROGNAME [-srv <server name>] [-db <database name>] [-file <backup file>] [-usr <username>] save | restore"

EXAMPLE1="db.sh -db jabberd2 -srv srv54 -usr jabberd2 -file 20060216-15:01:42.backup restore"

EXAMPLE2="db.sh -db jabberd2 -srv srv54 -usr jabberd2 save"

# Initialisation

DBSRV=database1

DBNAME=NomDeLaBase

DBUSER=NomUtilisateur

HEURE=`date +%Y%m%d-%T`

BACKUPDIR=/data/backup

PGBINDIR=/exe/pgsql/bin

restore()

{

if [ ! -f $BACKUPFILE ]; then

echo "$BACKUPFILE file doesn't exist!..."

fi

#!/bin/sh

#

# Save databases

#

PROGNAME=`basename $0`

SYNTAXE="Usage : $PROGNAME [-srv <server name>] [-db <database name>] [-file <backup file>] [-usr <username>] save | restore"

EXAMPLE1="db.sh -db jabberd2 -srv srv54 -usr jabberd2 -file 20060216-15:01:42.backup restore"

EXAMPLE2="db.sh -db jabberd2 -srv srv54 -usr jabberd2 save"

# Initialisation

DBSRV=database1

DBNAME=NomDeLaBase

DBUSER=NomUtilisateur

HEURE=`date +%Y%m%d-%T`

BACKUPDIR=/data/backup

PGBINDIR=/exe/pgsql/bin

restore()

{

if [ ! -f $BACKUPFILE ]; then

echo "$BACKUPFILE file doesn't exist!..."

fi

echo "Deleting database..."

$PGBINDIR/dropdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database deleted"

else

echo "ERROR CODE: $STATUS"

echo "The database is not restored"

exit $STATUS

fi

echo "Creating new database..."

$PGBINDIR/createdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Empty database created"

else

echo "ERROR CODE: $STATUS"

echo "The new empty database is not created"

exit $STATUS

fi

echo "Restoring $BACKUPFILE file in new database..."

$PGBINDIR/pg_restore -i -h $DBSRV -p 5432 -U $DBUSER -d $DBNAME -v "$BACKUPFILE"

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database restored"

else

echo "The database is not restored"

fi

exit $STATUS

}

echo "Deleting database..."

$PGBINDIR/dropdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database deleted"

else

echo "ERROR CODE: $STATUS"

echo "The database is not restored"

exit $STATUS

fi

echo "Creating new database..."

$PGBINDIR/createdb -h $DBSRV -p 5432 -U $DBUSER $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Empty database created"

else

echo "ERROR CODE: $STATUS"

echo "The new empty database is not created"

exit $STATUS

fi

echo "Restoring $BACKUPFILE file in new database..."

$PGBINDIR/pg_restore -i -h $DBSRV -p 5432 -U $DBUSER -d $DBNAME -v "$BACKUPFILE"

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database restored"

else

echo "The database is not restored"

fi

exit $STATUS

}

Page 24: Master 1 ère année Sécurité des Systèmes Informatique 1 X Window Système graphique  X-Window, développé au MIT dans le cadre du projet Athena  Développement

Master 1 ère année Sécurité des Systèmes

Informatique

Master 1 ère année Sécurité des Systèmes

Informatique

2424

Exemple shellsave()

{

BACKUPFILE=${BACKUPFILE:=$BACKUPDIR/$HEURE-$DBSRV-$DBNAME.backup}

echo "Saving database..."

if [ ! -d "$BACKUPDIR" ]; then

mkdir -p $BACKUPDIR

fi

$PGBINDIR/pg_dump -i -h $DBSRV -p 5432 -U $DBUSER -F c -b -v -f "$BACKUPFILE" $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database saved"

else

echo "The database is not saved"

fi

exit $STATUS

}

while [ $# -gt 0 ]

do

case "$1" in

-h | -help )

echo $SYNTAXE

echo $EXAMPLE1

echo $EXAMPLE2

exit 0

;;

save()

{

BACKUPFILE=${BACKUPFILE:=$BACKUPDIR/$HEURE-$DBSRV-$DBNAME.backup}

echo "Saving database..."

if [ ! -d "$BACKUPDIR" ]; then

mkdir -p $BACKUPDIR

fi

$PGBINDIR/pg_dump -i -h $DBSRV -p 5432 -U $DBUSER -F c -b -v -f "$BACKUPFILE" $DBNAME

STATUS=$?

if [ $STATUS = 0 ]; then

echo "Database saved"

else

echo "The database is not saved"

fi

exit $STATUS

}

while [ $# -gt 0 ]

do

case "$1" in

-h | -help )

echo $SYNTAXE

echo $EXAMPLE1

echo $EXAMPLE2

exit 0

;;

-db )

shift

DBNAME=$1

shift

;;

-file )

shift

BACKUPFILE=$1

shift

;;

-srv )

shift

DBSRV=$1

shift

;;

-usr )

shift

DBUSER=$1

shift

;;

* )

# Fonctions

case "$1" in

save | restore)

FUNCTION=$1

$FUNCTION

;;

*)

echo $SYNTAXE

echo $EXAMPLE

exit 1

esac

echo $SYNTAXE

exit 1

;;

esac

done

-db )

shift

DBNAME=$1

shift

;;

-file )

shift

BACKUPFILE=$1

shift

;;

-srv )

shift

DBSRV=$1

shift

;;

-usr )

shift

DBUSER=$1

shift

;;

* )

# Fonctions

case "$1" in

save | restore)

FUNCTION=$1

$FUNCTION

;;

*)

echo $SYNTAXE

echo $EXAMPLE

exit 1

esac

echo $SYNTAXE

exit 1

;;

esac

done