unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,shellapi, StdCtrls, Menus,
  ComCtrls, ImgList,inifiles, FileCtrl,strutils, ExtCtrls, JclSysInfo,
  JvComponent, SMLang, SMTray, ExtActns, jpeg,registry, JvCreateProcess,uciaservicetools,
  JvComponentBase;

type
  TMain = class(TForm)
    ImageList1: TImageList;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Esci1: TMenuItem;
    tunnell1: TMenuItem;
    Aggiungi1: TMenuItem;
    Modifica1: TMenuItem;
    Elimina1: TMenuItem;
    Nascondi1: TMenuItem;
    N1: TMenuItem;
    PopupMenu1: TPopupMenu;
    Modifica2: TMenuItem;
    AttivaTunnell1: TMenuItem;
    Elimina2: TMenuItem;
    DisattivaTunnell1: TMenuItem;
    Processi1: TMenuItem;
    Lista1: TMenuItem;
    checkprocessi: TTimer;
    ListView1: TListView;
    files: TFileListBox;
    ListBox1: TListBox;
    Button1: TButton;
    ools1: TMenuItem;
    Opzioni1: TMenuItem;
    N2: TMenuItem;
    Visitasitoweb1: TMenuItem;
    Autore1: TMenuItem;
    language: TSMLanguage;
    TrayBar: TSMTrayIcon;
    PopupMenu2: TPopupMenu;
    Visualizza1: TMenuItem;
    Esci2: TMenuItem;
    StatusBar: TStatusBar;
    RASManager1: TMenuItem;
    Button2: TButton;
    Panel1: TPanel;
    Image1: TImage;
    Memo1: TMemo;
    JvCreateProcess1: TJvCreateProcess;
    elprocessH: TListBox;
    chkprocess: TButton;
    elprocessID: TListBox;
    Image2: TImage;
    Image3: TImage;
    Modificascript1: TMenuItem;
    Visualizzalog1: TMenuItem;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure AttivaTunnell1Click(Sender: TObject);
    procedure Info1Click(Sender: TObject);
    procedure Esci1Click(Sender: TObject);
    procedure Lista1Click(Sender: TObject);
    procedure Aggiungi1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure checkprocessiTimer(Sender: TObject);
    procedure DisattivaTunnell1Click(Sender: TObject);
    procedure Elimina2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure LicenzaPutty1Click(Sender: TObject);
    procedure LicenzaSSHTM1Click(Sender: TObject);
    procedure Autore1Click(Sender: TObject);
    procedure GeneratoredichiaviPutty1Click(Sender: TObject);
    procedure Visitasitoweb1Click(Sender: TObject);
    procedure Visualizza1Click(Sender: TObject);
    procedure Nascondi1Click(Sender: TObject);
    procedure Esci2Click(Sender: TObject);
    procedure TrayBarDblClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure RASManager1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    Function ExecuteAndWait(sExecutableFile : String; wWindowState : Word = SW_SHOWNORMAL) : Cardinal;
    procedure chkprocessClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Modificascript1Click(Sender: TObject);
    procedure Visualizzalog1Click(Sender: TObject);
    procedure Modifica2Click(Sender: TObject);
    procedure Elimina1Click(Sender: TObject);

   
  private
    { Private declarations }
  public
    { Public declarations }
    codhandle0:longword;
    pathopenvpnexe,pathopenvpnconfig,pathopenvpnlog: string;
  end;

var
  Main: TMain;
  path,Programma,Parametri,Directory: string;
  CaricaSoloINI: boolean;
  Connessi,Disconnessi: integer;
  ProcH,ProcID:cardinal;


implementation

uses ShowTunnell, about, listprocess,ricercafileedirectory,messaggi,licenza,exdials0;

{$R *.dfm}

Function tmain.ExecuteAndWait(sExecutableFile : String; wWindowState : Word = SW_SHOWNORMAL) : Cardinal;
var
         siInfo  : TStartUpInfo;
         piInfo  : TProcessInformation;
begin
         FillChar(siInfo, SizeOf(siInfo), #0);

         with siInfo do begin
              cb          := SizeOf(siInfo);
              dwFlags     := STARTF_USESHOWWINDOW;
              wShowWindow := wWindowState;
         end;
         CreateProcess(NIL,pChar(sExecutableFile) , NIL, NIL, FALSE, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL, pchar(pathopenvpnconfig),siInfo, piInfo);
//         if Result then
//            WaitForSingleObject(piInfo.hprocess,INFINITE);

//           sleep(500);
//showmessage('provo');

//            terminateprocess(piInfo.hprocess,0);
//            result:=piInfo.dwProcessId;
//            result:=piInfo.hprocess;
//              result:=piInfo.dwThreadId;

ProcH:=piInfo.hprocess;
ProcID:=piInfo.dwProcessId;

end;


procedure TMain.Button2Click(Sender: TObject);
var conn: tinifile;
begin
conn:=tinifile.Create('FASTLink.ini');
conn.WriteString('Path','FASTLink Directory','Path to FASTLink working directory');
conn.Free;


end;

procedure TMain.Button3Click(Sender: TObject);
var
  proc_info: TProcessInformation;
  startinfo: TStartupInfo;
  ExitCode: longword;

begin
// Initialize the structures
  FillChar(proc_info, sizeof(TProcessInformation), 0);
  FillChar(startinfo, sizeof(TStartupInfo), 0);
  startinfo.cb := sizeof(TStartupInfo);
  startinfo.wShowWindow:=SW_HIDE;
  // Attempts to create the process
  if CreateProcess('plink.exe', '-ssh -batch -l ad -pw 11032001 -L 5901:127.0.0.1:5900 127.0.0.1', nil,
      nil, false, NORMAL_PRIORITY_CLASS, nil, nil,
       startinfo, proc_info) <> False then begin
    // The process has been successfully created
    // No let's wait till it ends...
    WaitForSingleObject(proc_info.hProcess, INFINITE);
    // Process has finished. Now we should close it.
    GetExitCodeProcess(proc_info.hProcess, ExitCode);  // Optional
    CloseHandle(proc_info.hThread);
    CloseHandle(proc_info.hProcess);
    Application.MessageBox(
      PChar(Format('Notepad finished! (Exit code=%d)', [ExitCode])),
      'Info', MB_ICONINFORMATION);
  end else begin
    // Failure creating the process
    Application.MessageBox('Couldn''t execute the '
      + 'application', 'Error', MB_ICONEXCLAMATION);
  end;//if

end;

procedure TMain.FormShow(Sender: TObject);
var a,b:integer;
    cartelle: TExpandedFolder;
    var conn: tinifile;
begin
(*
conn:=tinifile.Create(path+'\Default.lng');
//      conn.ReadString('LanguageFile','Language','Italiano');
//      conn.ReadString('LanguageFile','Version','1.0');
//      conn.ReadString('LanguageFile','Date','08-31-2004');
file1.Caption:=conn.ReadString('Translation','File','&File');
//showmessage(file1.Caption);
nascondi1.Caption:=conn.ReadString('Translation','Hide','&Nascondi');
esci1.Caption:=      conn.ReadString('Translation','Exit','&Esci');
tunnell1.Caption:=      conn.ReadString('Translation','Tunnells','&Tunnell');
aggiungi1.Caption:=      conn.ReadString('Translation','Add','&Aggiungi');
modifica1.Caption:=      conn.ReadString('Translation','Edit','&Modifica');
elimina1.Caption:=      conn.ReadString('Translation','Delete','E&limina');
autore1.Caption:=      conn.ReadString('Translation','About','&Info');
Form_ShowTunn.serversshtitle.Caption:=      conn.ReadString('Translation','SSHServer','Server SSH');
Form_ShowTunn.ipaddress.Caption:=      conn.ReadString('Translation','IpAddress','Indirizzo IP');
Form_ShowTunn.port.Caption:=      conn.ReadString('Translation','Port','Porta');
Form_ShowTunn.authserverssshtitle.caption:=      conn.ReadString('Translation','AuthServerSSH','Autenticazione Server SSH');
Form_ShowTunn.useraccount.Caption:=      conn.ReadString('Translation','UserAccount','Account utente');
Form_ShowTunn.tunnellsshtitle.Caption:=      conn.ReadString('Translation','TunnellSSHDetail','Dati Tunnell SSH');
Form_ShowTunn.Localport.Caption:=      conn.ReadString('Translation','LocalPort','Porta locale');
Form_ShowTunn.ipservice.Caption:=      conn.ReadString('Translation','IpService','Indirizzo IP servizio');
Form_ShowTunn.portservice.Caption:=      conn.ReadString('Translation','PortService','Porta servizio');
Form_ShowTunn.autoconnecttitle.Caption:=      conn.ReadString('Translation','AutoconnTitle','Autoconnessione');
Form_ShowTunn.autoconnect.Caption:=      conn.ReadString('Translation','Autoconnect','Connetti automaticamente durante avvio');
Form_ShowTunn.Button2.Caption:=      conn.ReadString('Translation','Cancel','&Annulla');
Form_ShowTunn.debug.Caption:= conn.ReadString('Translation','Debug','SSH Debug');
Form_ShowTunn.debug.Checked:=conn.ReadBool('Translation','DebugChecked',False);
conn.Free;

//mainmenu1.Items.RethinkHotkeys;
*)





(*
cartelle:=TExpandedFolder.Create;
cartelle.Path:=path+'\tunnells\';
cartelle.MaxDepth:=0;

listbox1.Items:=cartelle.DirNames;
*)





(*
// Avvia le connessioni in auto avvio
for b:=0 to ListView1.items.count-1 do begin
  listview1.itemindex:=b;
  CaricaSoloIni:=True;
  ListView1DblClick(Sender);
  StatusBar.Panels[0].Text:='Tunnell: '+Listview1.Items[b].Caption;
  if showtunn.autoconnect.Checked then AttivaTunnell1Click(Sender);
end;
*)


language.LoadResources(path+'\default.lng');


end;

procedure TMain.AttivaTunnell1Click(Sender: TObject);
var Tunnell,FileBat:string;
    codhandle:hwnd;
    FileRun: TFileRun;
    codice: cardinal;
    conn: tinifile;
begin
//CaricaSoloIni:=True;
//ListView1DblClick(Sender);


if listview1.itemindex = -1 then exit;

//showmessage('ciao dal tunnell');

(*
Tunnell:=path+'tunnells\'+listview1.Items[listview1.itemindex].Caption+
'\'+listview1.Items[listview1.itemindex].Caption+'SSH.exe';
//showmessage(tunnell);

Programma:=Tunnell;

FileBat:=path+'tunnells\'+listview1.Items[listview1.itemindex].Caption+
'\'+listview1.Items[listview1.itemindex].Caption+'SSH.bat';

//Parametri:='-ssh -batch -l '+
Parametri:='-ssh -l '+
           ShowTunn.mxflatedit1.text+
           ' -pw '+ ShowTunn.mxflatedit2.Text + ' -L '+
           ShowTunn.mxflatmaskedit5.Text+':'+
           ShowTunn.mxflatmaskedit3.Text+':'+
           ShowTunn.mxflatmaskedit4.Text+
           ' '+ShowTunn.mxflatmaskedit1.Text;

Directory:=ExtractFileDir(Programma);

//showmessage(programma);
showmessage(parametri);

//codhandle:=ShellExecute(form1.Handle, 'open', pchar(Tunnell), '-ssh -batch -l ad -pw 11032001 -L 5901:127.0.0.1:5900 127.0.0.1', nil, SW_SHOW);
//codhandle:=ShellExecute(Handle, 'open', pchar(Tunnell), pchar(parametri), nil, SW_SHOW);
*)


// "C:\Programmi\OpenVPN\bin\openvpn.exe" --pause-exit --config "%1"

conn:=tinifile.Create(extractfilepath(application.exename)+'tunnells\'+Listview1.Items[listview1.itemindex].Caption+'\tunnel.tun');
if conn.ReadBool('Tunnell','Debug',false) then
codice:=ExecuteAndWait(pathopenvpnexe+' --pause-exit --config '+listview1.Items[listview1.itemindex].Caption+'.ovpn '+' --log '+pathopenvpnlog+'\\'+listview1.Items[listview1.itemindex].Caption+'.log',SW_SHOW)
else
codice:=ExecuteAndWait(pathopenvpnexe+' --pause-exit --config '+listview1.Items[listview1.itemindex].Caption+'.ovpn '+' --log '+pathopenvpnlog+'\\'+listview1.Items[listview1.itemindex].Caption+'.log',SW_HIDE);
conn.Free;

//showmessage(floattostr(codice));

//elprocessid.Items[listview1.itemindex]:=floattostr(codice);

elprocessID.Items[listview1.itemindex]:=floattostr(ProcID);
elprocessH.Items[listview1.itemindex]:=floattostr(ProcH);


(*

FileRun:=Tfilerun.Create(self);
filerun.FileName:=pathopenvpnexe;
//filerun.Directory:=pathopenvpnDirectory;
filerun.Parameters:='--pause-exit --config '+listview1.Items[listview1.itemindex].Caption+'.ovpn';
//if ShowTunn.debug.Checked then
filerun.ShowCmd:=scshow;
*)

//else
//filerun.ParentControl:=memo1;
//filerun.ShowCmd:=schide;
//filerun.Browse:=true;
//showmessage('browse');

//filerun.Execute;


(*
jvcreateprocess1.ApplicationName:=pathopenvpnexe;
jvcreateprocess1.CommandLine:='--pause-exit --config '+listview1.Items[listview1.itemindex].Caption+'.ovpn';
//jvcreateprocess1.Environment.Add('--pause-exit --config '+listview1.Items[listview1.itemindex].Caption+'.ovpn');
memo1.lines:=jvcreateprocess1.ConsoleOutput;
jvcreateprocess1.Run;
*)
(*
if ShowTunn.debug.Checked then
codhandle:=ShellExecute(main.Handle, 'open', pchar(Programma), pchar(Parametri), pchar(Directory), SW_SHOW)
else
codhandle:=ShellExecute(main.Handle, 'open', pchar(Programma), pchar(Parametri), pchar(Directory), SW_HIDE);
*)

//showmessage(floattostr(codhandle));

//codhandle:=ShellExecute(form1.Handle, 'open', 'c:\windows\notepad.exe', nil, nil, SW_SHOW);
//showmessage(floattostr(codhandle0));

checkprocessiTimer(Sender);

CaricaSoloIni:=False;

end;

procedure TMain.Info1Click(Sender: TObject);
begin
aboutbox.showmodal;
end;

procedure TMain.Esci1Click(Sender: TObject);
var b:integer;
begin

for b:=0 to elprocessh.items.count-1 do begin
    terminateprocess(strtoint(elprocessh.Items[b]),0);
end;

if CiaIsService then
      PostThreadMessage(CiaService.ServiceThread.ThreadID, WM_QUIT, 0, 0)
   else
      Application.Terminate;
//close;
end;

procedure TMain.Lista1Click(Sender: TObject);
begin
form2.show;
end;



procedure TMain.Aggiungi1Click(Sender: TObject);
var nomeconn:string;
    dirname,sourcefile,destfile: string;
    conn: tinifile;

begin   
nomeconn:= InputBox(fmessage.CreazTunnell.Text, fmessage.nomedaassegnare.text, '');
if nomeconn='' then begin
showmessage(fmessage.NomeNonValido.Text);
exit;
end;

listview1.items.Add;
listview1.Items[listview1.Items.Count-1].Caption:=nomeconn;

dirname:=path+'\Tunnells\'+nomeconn;
//showmessage(dirname);

//sourcefile:=path+'\plink.exe';
//destfile:=dirname+'\'+nomeconn+'SSH.exe';


If Not DirectoryExists(DirName)Then
      CreateDirectory(pchar(DirName), nil);
//      copyfile(pchar(sourcefile),pchar(destfile),false);

      conn:=tinifile.Create(dirname+'\tunnel.tun');
      conn.WriteBool('Tunnell','AutoConnessione',false);
      conn.Free;


memo1.lines.SaveToFile(pathopenvpnconfig+'\'+nomeconn+'.ovpn');

showmessage('connessione ok');
end;



procedure TMain.FormCreate(Sender: TObject);
var a:integer;
    conn: tinifile;
    sd:string;
    Reg: tregistry;
begin


//Rintraccia installazione siinca

      Reg:=TRegistry.Create;
//      Reg.RootKey:=HKEY_CURRENT_USER;
      Reg.RootKey:=HKEY_LOCAL_MACHINE;
      if Reg.OpenKey('Software\OpenVPN',false) then
      begin
        pathopenvpnexe:=Reg.ReadString('exe_path');
        pathopenvpnconfig:=Reg.ReadString('config_dir');
        pathopenvpnlog:=Reg.ReadString('log_dir');
      end;

//getdir(0,sd);
//showmessage(sd);

(*
fileini:=tinifile.Create('FASTLink.ini');
path:=fileini.ReadString('Path','FASTLink Directory','');
fileini.Free;
*)
//showmessage(path);

//getdir(0,path);
CaricaSoloIni:=True;
//Application.ShowMainForm:=False;
//Nascondi1Click(Sender);

path:=extractfilepath(application.ExeName);

//********************************************************



files.Directory:=pathopenvpnconfig;
files.Update;


listview1.Items.Clear;
for a:=0 to files.items.count-1 do begin
listview1.Items.Add;
listview1.Items[a].Caption:=copy(files.Items[a],0,length(files.Items[a])-5);
end;
//showmessage('qui');
elprocessID.Items.Clear;
for a:=0 to listview1.Items.count-1 do begin
elprocessID.Items.Add('0');
end;

elprocessH.Items.Clear;
for a:=0 to listview1.Items.count-1 do begin
elprocessH.Items.Add('0');
end;

CaricaSoloIni:=False;
//StatusBar.Panels[0].Text:=fmessage.Pronto.Text;

traybar.Icon:=image2.Picture.Icon;


//listview1.ItemIndex:=2;
//AttivaTunnell1Click(Sender);

// Avvia le connessioni in auto avvio
for a:=0 to ListView1.items.count-1 do begin
  listview1.itemindex:=a;
  StatusBar.Panels[0].Text:='Tunnell: '+Listview1.Items[a].Caption;
      conn:=tinifile.Create(extractfilepath(application.exename)+'tunnells\'+Listview1.Items[a].Caption+'\tunnel.tun');


  if conn.ReadBool('Tunnell','AutoConnessione',false) then AttivaTunnell1Click(Sender);
    conn.Free;
end;


//********************************************************


end;

procedure TMain.checkprocessiTimer(Sender: TObject);
var a,b:integer;
    pid:integer;
    trovato: boolean;
begin
(*
Form2.Button1Click(Sender);
for b:=0 to listview1.items.count-1 do begin
trovato:=false;
for a:=0 to form2.listbox1.items.count-1 do begin
    if lowercase(form2.listbox1.Items[a])=lowercase(listview1.items[b].Caption+'SSH.exe') then begin
    trovato:=true;
    pid:=GetPidFromProcessName(listview1.items[b].Caption+'SSH.exe');
    if trovato then begin
    //showmessage('Trovato con PID: '+ floattostr(pid));
    listview1.items[b].ImageIndex:=1;
    break;
    end;
    end;
    if not trovato then listview1.items[b].ImageIndex:=0;
end;
end;
*)

trovato:=false;
traybar.Icon:=image2.Picture.Icon;

if listview1.items.count >0 then
for b:=0 to listview1.items.count-1 do begin
    if openprocess(PROCESS_QUERY_INFORMATION,true,strtoint(elprocessid.Items[b]))>0 then begin
    listview1.items[b].ImageIndex:=1;
    trovato:=true;
    break;
    end
    else listview1.items[b].ImageIndex:=0;


end;

if trovato then traybar.Icon:=image3.Picture.Icon;


end;

procedure TMain.DisattivaTunnell1Click(Sender: TObject);
begin
if listview1.itemindex = -1 then exit;
//TerminateApp(GetPidFromProcessName(listview1.items[listview1.itemindex].Caption+'SSH.exe'),5);


terminateprocess(strtoint(elprocessh.Items[listview1.itemindex]),0);

//SendMessage(strtoint(elprocessid.Items[listview1.itemindex]), WM_CLOSE, 0, 0);


elprocessid.Items[listview1.itemindex]:='0';
elprocessh.Items[listview1.itemindex]:='0';


end;

procedure TMain.Elimina1Click(Sender: TObject);
begin
removedirectory(pchar(path+'\Tunnells\'+listview1.items[listview1.itemindex].Caption));
deletefile(pathopenvpnconfig+'\'+listview1.items[listview1.itemindex].Caption);
end;

procedure TMain.Elimina2Click(Sender: TObject);
var a:integer;
begin
if listview1.itemindex = -1 then exit;
DisattivaTunnell1Click(Sender);

If DirectoryExists(path+'\Tunnells\'+listview1.items[listview1.itemindex].Caption)Then begin
//showmessage('esiste');
files.Directory:=path+'\Tunnells\'+listview1.items[listview1.itemindex].Caption;
files.Update;
for a:=0 to files.items.count-1 do begin
    deletefile(files.Items[a]);
end;
    files.Directory:='..\';
    files.Update;

    if RemoveDir(path+'\Tunnells\'+listview1.items[listview1.itemindex].Caption) then
    listview1.items[listview1.itemindex].Delete else
    showmessage(fmessage.ProbRimozCartella.Text);
end;


end;

procedure TMain.Button1Click(Sender: TObject);
var conn: tinifile;
begin
(*conn:=tinifile.Create(path+'\Default.lng');
      conn.WriteString('LanguageFile','Language','Italiano');
      conn.WriteString('LanguageFile','Version','1.0');
      conn.WriteString('LanguageFile','Date','08-31-2004');
      conn.WriteString('Translation','File','&File');
      conn.WriteString('Translation','Hide','&Nascondi');
      conn.WriteString('Translation','Exit','&Esci');
      conn.WriteString('Translation','Tunnells','&Tunnell');
      conn.WriteString('Translation','Add','&Aggiungi');
      conn.WriteString('Translation','Edit','&Modifica');
      conn.WriteString('Translation','Delete','E&limina');
      conn.WriteString('Translation','About','&Info');
      conn.WriteString('Translation','SSHServer','Server SSH');
      conn.WriteString('Translation','IpAddress','Indirizzo IP');
      conn.WriteString('Translation','Port','Porta');
      conn.WriteString('Translation','AuthServerSSH','Autenticazione Server SSH');
      conn.WriteString('Translation','UserAccount','Account utente');
      conn.WriteString('Translation','TunnellSSHDetail','Dati Tunnell SSH');
      conn.WriteString('Translation','LocalPort','Porta locale');
      conn.WriteString('Translation','IpService','Indirizzo IP servizio');
      conn.WriteString('Translation','PortService','Porta servizio');
      conn.WriteString('Translation','AutoconnTitle','Autoconnessione');
      conn.WriteString('Translation','Autoconnect','Connetti automaticamente durante avvio');
      conn.WriteString('Translation','Cancel','&Annulla');
      conn.WriteString('Translation','Debug','SSH Debug');
      conn.Free;
*)

language.SaveResources(main,extractfilepath(application.ExeName)+'template1.lng');

language.SaveResources(showtunn,path+'\template2.lng');
language.SaveResources(aboutbox,path+'\template3.lng');
language.SaveResources(fmessage,path+'\template4.lng');
end;

procedure TMain.LicenzaPutty1Click(Sender: TObject);
begin
licence.caption:='Putty Licence';
licence.Memo1.Lines.Clear;
licence.Memo1.Lines.LoadFromFile(path+'\puttylicense.txt');
licence.ShowModal;
end;

procedure TMain.LicenzaSSHTM1Click(Sender: TObject);
begin
licence.Caption:='FASTLink Licence';
licence.Memo1.Lines.Clear;
licence.Memo1.Lines.LoadFromFile(path+'\license.txt');
licence.ShowModal;
end;

procedure TMain.Autore1Click(Sender: TObject);
begin
aboutbox.Showmodal;
end;

procedure TMain.GeneratoredichiaviPutty1Click(Sender: TObject);
begin
ShellExecute(main.Handle, 'open', pchar(path+'\puttygen.exe'), nil, nil, SW_SHOW);
end;

procedure TMain.Visitasitoweb1Click(Sender: TObject);
begin
ShellExecute(main.Handle, 'open', pchar('http://www.rinorusso.it'), nil, nil, SW_SHOW);
end;

procedure TMain.Visualizza1Click(Sender: TObject);
begin
Traybar.Hide;
main.show;
end;

procedure TMain.Nascondi1Click(Sender: TObject);
begin
TrayBar.Show;

main.Hide;
end;

procedure TMain.Esci2Click(Sender: TObject);
begin
Esci1Click(Sender);
end;

procedure TMain.TrayBarDblClick(Sender: TObject);
begin
Visualizza1Click(Sender);
end;

procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Nascondi1Click(Sender);
end;



procedure TMain.RASManager1Click(Sender: TObject);
begin
formras.show;
end;

procedure TMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Nascondi1Click(Sender);
canclose:=false;
end;

procedure TMain.chkprocessClick(Sender: TObject);
var cod: cardinal;
begin
cod:=openprocess(PROCESS_QUERY_INFORMATION,true,strtoint(elprocessid.Items[listview1.itemindex]));
//showmessage(floattostr(cod));
end;
procedure TMain.FormDestroy(Sender: TObject);
begin
Esci1Click(Sender);
end;

procedure TMain.Modificascript1Click(Sender: TObject);
begin
licence.caption:='FASTOpenVPN-Gui script reader - '+pathopenvpnconfig+'\'+listview1.Items[listview1.itemindex].Caption+'.ovpn';
licence.Memo1.Lines.Clear;
licence.Memo1.Lines.LoadFromFile(pathopenvpnconfig+'\'+listview1.Items[listview1.itemindex].Caption+'.ovpn');
licence.ShowModal;
end;

procedure TMain.Visualizzalog1Click(Sender: TObject);
begin
licence.caption:='FASTOpenVPN-Gui log reader - '+pathopenvpnlog+'\'+listview1.Items[listview1.itemindex].Caption+'.ovpn';
licence.Memo1.Lines.Clear;
licence.Memo1.Lines.LoadFromFile(pathopenvpnlog+'\'+listview1.Items[listview1.itemindex].Caption+'.log');
licence.ShowModal;
end;

procedure TMain.Modifica2Click(Sender: TObject);
var conn: tinifile;
begin


   conn:=tinifile.Create(extractfilepath(application.exename)+'tunnells\'+Listview1.Items[listview1.itemindex].Caption+'\tunnel.tun');
   with showtunn do begin
   caption:='FASTOpenVPN-Gui - Impostazioni '+ Listview1.Items[listview1.itemindex].Caption;
   autoconnect.checked:=conn.ReadBool('Tunnell','AutoConnessione',false);
   debug.checked:=conn.readBool('Tunnell','Debug',false); 
   end;
   conn.Free;

if caricasoloini=false then showtunn.Show;
end;

end.
