'=====================================================================================================
' Cryptmd5.bas + pass.php joint dans le zip à uploader sur son serveur.
' 
' Créateur :         N.FIX (Mine2rien)
' http://www.rapidq-france.org
'
' Version       :    1.01
' Date          :    25/12/2005
'
'-----------------------------------------------------------------------------------------------------
' Interactions entre un programme RapidQ et un script php.
'
' ----------------------------------------------------------------------------------------------------
DECLARE SUB cryptage

DECLARE SUB DIALOGPHP
DIM site AS STRING 'c'est le nom de l'hebergeur
site ="rapidq-france.org"

DIM adresse AS STRING  'qui permettra de mettre le lien du script php



	 DIM Sock AS INTEGER 	 				'numero du Sock
	 DIM Sockethttp AS QSocket			'Socket pour la lecture des fichiers php
'une constante de 2secondes pourle temps de réponse du site
 	CONST TimeOut = 2         			' 2 seconds

create Form1 as qform
center
  Caption="Test de Cryptage MD5 via RQ et php"
create bouton2 as qbutton
  left=10
  top=100
  width=80
  height=30
  Caption="Cryptage"
  onclick=cryptage
End create
Create editretour as qedit
top=60
left=10
width=200
height=100
End create

create editdepart as qedit
top=10
left=10
width=200
height=100
text="icimonmotdepassacrypterenMD5"
end create

End create



SUB cryptage
	 '	 le lien
	 '##################################################################
	 '####ATTENTION LIEN VALIDE POUR TESTS JUSQU'AU 1er JANVIER 2006####
	 '##################################################################

adresse ="http://www.rapidq-france.org/tests/pass.php?pass=" + editdepart.text 'lien vers le script + l'edit contenant le mot a crypter.
	 dialogphp

END SUB


SUB dialogphp

	 DIM text AS STRING

	 
	 Sock = Sockethttp.Connect(site, 80)   'connection en http port 80
	 'si sock=-1 c'est que la connection est impossible
	 'soit 
 	 IF sock=-1 THEN
	 	 MESSAGEBOX "Vous n'etes pas connecté ou Erreur sur le serveur","Erreur connection serveur",0
 	 EXIT SUB
	  END IF


	 '-- demande
     	 	 Sockethttp.WriteLine(Sock, "GET " & adresse & " ")
	 '-- optionnel...
   		 Sockethttp.WriteLine(Sock, "HOST "+Server+":"+STR$(80))
	 'fin de demande
   		 Sockethttp.WriteLine(Sock, "")    '-- End request

'atttente suivant le serveur
'pas necessaire en local
'a voir avec l'adsl
'bah 2 secs ça tue personne
 	  T# = TIMER
	 DO
	 	 DOEVENTS
 	 LOOP UNTIL  TIMER - T# >= TimeOut 

	 Text=""
	  'tant que le serveur répond
	 DO 
 	 	 IF Sockethttp.IsServerReady(Sock) THEN
        		 	 Text = Text + Sockethttp.Read(Sock, 32000)     '' 32000 bytes... whatever they give us
	 		 Bytes = Bytes + Sockethttp.Transferred 'nombre d'octet recu
'text =$msg
	 	 END IF
	 DOEVENTS

	 LOOP UNTIL Sockethttp.Transferred = 0 
'affiche le retour

	 editretour.text = text

	 Sockethttp.close(sock) 

END SUB

Form1.showmodal
