Changeset 5 for trunk/UMainForm.pas


Ignore:
Timestamp:
Nov 27, 2008, 12:46:04 PM (15 years ago)
Author:
george
Message:
  • Odstraněno: Funkce a ovládací prvky související s vytáčením VPN.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      *.dcu
      KonfiguratorZdechovNET.exe
      KonfiguratorZdechovNET.res
  • trunk/UMainForm.pas

    r4 r5  
    66  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    77  Dialogs, StdCtrls, ComCtrls, ShellApi, DosCommand, Registry, Menus,
    8   CoolTrayIcon, ExtCtrls, XPMan, magrascon, magrasedt, magrasent, SHFolder,
    9   ShlObj, magrasapi, Winsock, UTextFileStream;
     8  CoolTrayIcon, ExtCtrls, XPMan, SHFolder,
     9  ShlObj, Winsock, UTextFileStream;
    1010
    1111const
     
    3939    Button1: TButton;
    4040    Button2: TButton;
    41     GroupBox1: TGroupBox;
    42     CheckBox1: TCheckBox;
    43     ComboBox1: TComboBox;
    44     Label1: TLabel;
    45     CheckBox2: TCheckBox;
    4641    Bevel1: TBevel;
    4742    CheckBox4: TCheckBox;
     
    5550    XPManifest1: TXPManifest;
    5651    CheckBox6: TCheckBox;
    57     CheckBox7: TCheckBox;
    58     CheckBox8: TCheckBox;
    5952    Oprogramu1: TMenuItem;
    6053    CheckBox9: TCheckBox;
    6154    Zznamvyten1: TMenuItem;
    62     Label2: TLabel;
    6355    OpenDialog1: TOpenDialog;
    64     GroupBox2: TGroupBox;
    65     CheckBox10: TCheckBox;
    66     Label3: TLabel;
    67     Edit1: TEdit;
    68     Button4: TButton;
    69     MagRasCon1: TMagRasCon;
    70     MagRasEdt1: TMagRasEdt;
    71     CheckBox3: TCheckBox;
    7256    VPNpipojen1: TMenuItem;
    73     CheckBox11: TCheckBox;
    7457    Spustit1: TMenuItem;
    7558    Zasavit1: TMenuItem;
    76     Label4: TLabel;
    77     Edit2: TEdit;
    7859    procedure FormShow(Sender: TObject);
    7960    procedure Button2Click(Sender: TObject);
     
    8667    procedure Button3Click(Sender: TObject);
    8768    procedure Oprogramu1Click(Sender: TObject);
    88     procedure Zznamvyten1Click(Sender: TObject);
    89     procedure Button4Click(Sender: TObject);
    90     procedure CheckBox10Click(Sender: TObject);
    91     procedure Spustit1Click(Sender: TObject);
    92     procedure Zasavit1Click(Sender: TObject);
    9369  private
    9470    procedure LoadOptions;
    9571    procedure SaveOptions;
    96     function GetLocalNetworkRouting: Boolean;
    97     procedure SetLocalNetworkRouting(const Value: Boolean);
    9872    function GetCentralaHomepage: Boolean;
    9973    procedure SetCentralaHomepage(const Value: Boolean);
     
    10478    function GetShareUnblockFirewall: Boolean;
    10579    procedure SetShareUnblockFirewall(const Value: Boolean);
    106     function GetZdechovNetConnection: Boolean;
    107     procedure SetZdechovNetConnection(const Value: Boolean);
    10880    function GetNetSharedFolder: Boolean;
    10981    procedure SetNetSharedFolder(const Value: Boolean);
    110     function GetLogFileEnabled: Boolean;
    111     procedure SetLogFileEnabled(const Value: Boolean);
    112     function GetLogFileName: string;
    113     procedure SetLogFileName(const Value: string);
    114     function GetConnectionName: string;
    115     procedure SetConnectionName(const Value: string);
    116     function GetLogClearOnStart: Boolean;
    117     procedure SetLogClearOnStart(const Value: Boolean);
    118     function GetVpnServiceEnabled: Boolean;
    119     procedure SetVpnServiceEnabled(const Value: Boolean);
    120     function GetVpnServiceRunning: Boolean;
    121     procedure SetVpnServiceRunning(const Value: Boolean);
    12282    function GetNetworkDomain: string;
    123     function GetConditionNetworkDomain: string;
    124     procedure SetConditionNetworkDomain(const Value: string);
    12583  public
    126     DefaultGateway: string;
    12784    FirstStart: Boolean;
    12885    HostFilterIndex: Integer;
    12986    PingTimeout: Integer;
    130     AutoDial: Boolean;
    131     AutoRedial: Boolean;
    13287    NetworkTestLastUpdate: TDateTime;
    133     property LocalNetworkRouting: Boolean read GetLocalNetworkRouting
    134       write SetLocalNetworkRouting;
    13588    property CentralaHomepage: Boolean read GetCentralaHomepage
    13689      write SetCentralaHomepage;
     
    14194    property ShareUnblockFirewall: Boolean read GetShareUnblockFirewall
    14295      write SetShareUnblockFirewall;
    143     property ZdechovNetConnection: Boolean read GetZdechovNetConnection
    144       write SetZdechovNetConnection;
    14596    property NetSharedFolder: Boolean read GetNetSharedFolder
    14697      write SetNetSharedFolder;
    147     property LogFileEnabled: Boolean read GetLogFileEnabled
    148       write SetLogFileEnabled;
    149     property LogFileName: string read GetLogFileName
    150       write SetLogFileName;
    151     property LogClearOnStart: Boolean read GetLogClearOnStart
    152       write SetLogClearOnStart;
    153     property ConnectionName: string read GetConnectionName
    154       write SetConnectionName;
    155     property VpnServiceEnabled: Boolean read GetVpnServiceEnabled
    156       write SetVpnServiceEnabled;
    157     property VpnServiceRunning: Boolean read GetVpnServiceRunning
    158       write SetVpnServiceRunning;
    15998    property NetworkDomain: string read GetNetworkDomain;
    160     property ConditionNetworkDomain: string read GetConditionNetworkDomain
    161       write SetConditionNetworkDomain;
    16299
    163100    procedure Init;
    164     procedure AddConnection;
    165     procedure DeleteConnection;
    166101  end;
    167102
     
    178113
    179114uses UNetworkTest, UAboutWindow, ULogExceptions, DateUtils, Math,
    180   UDialingLog, StrUtils, UServiceControl;
     115  StrUtils, UServiceControl;
    181116
    182117{$R *.dfm}
     
    260195end;
    261196
    262 function TMainForm.GetLocalNetworkRouting: Boolean;
    263 var
    264   Command: TDosCommand;
    265   I: Integer;
    266   Lines2: TStringList;
    267 begin
    268   Lines2 := TStringList.Create;
    269   Result := False;
    270   Command := TDosCommand.Create(nil);
    271   with Command do try
    272     CommandLine := 'route print ' + LocalNetAddr + ' mask ' + LocalNetMask +
    273       ' ' + DefaultGateway + ' metric 30';
    274     OutputLines := Lines2;
    275     Execute2;
    276     for I := 0 to Lines2.Count - 1 do
    277       if Pos(LocalNetMask, Lines2[I]) > 0 then Result := True;
    278   finally
    279     Free;
    280     Lines2.Free;
    281   end;
    282 end;
    283 
    284 procedure TMainForm.SetLocalNetworkRouting(const Value: Boolean);
    285 var
    286   Command: TDosCommand;
    287 begin
    288   Command := TDosCommand.Create(nil);
    289   with Command do try
    290     if Value then CommandLine := 'route -p add '+LocalNetAddr+' mask '+LocalNetMask+' '+DefaultGateway+' metric 30'
    291       else CommandLine := 'route delete '+LocalNetAddr+' mask '+LocalNetMask+' '+DefaultGateway+' metric 30';
    292     Execute2;
    293   finally
    294     Free;
    295   end;
    296 end;
    297 
    298197function TMainForm.GetCentralaHomepage: Boolean;
    299198begin
     
    327226  LogExceptions.NazevAplikace := ApplicationName + ' ' + Version;
    328227
    329   CheckBox1.Checked := AutoRedial;
    330   CheckBox2.Checked := LocalNetworkRouting;
    331   CheckBox3.Checked := LogClearOnStart;
    332228  CheckBox4.Checked := CentralaHomepage;
    333229  CheckBox5.Checked := WorkgroupZdechov;
    334230  CheckBox6.Checked := ShareUnblockFirewall;
    335   CheckBox7.Checked := AutoDial;
    336   CheckBox8.Checked := ZdechovNetConnection;
    337231  CheckBox9.Checked := NetSharedFolder;
    338 
    339         MagRasCon1.GetPhoneBookEntries;
    340   ComboBox1.Items.Assign(MagRasCon1.PhoneBookEntries);
    341   ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(ConnectionName);
    342   Edit2.Text := ConditionNetworkDomain;
    343 
    344   CheckBox10.Checked := LogFileEnabled;
    345   CheckBox11.Checked := VpnServiceEnabled;
    346   Edit1.Text := LogFileName;
    347   Edit1.Enabled := LogFileEnabled;
    348   Button4.Enabled := LogFileEnabled;
    349 
    350   Label2.Caption := 'Brána: ' + DefaultGateway;
    351232end;
    352233
     
    358239procedure TMainForm.Button1Click(Sender: TObject);
    359240begin
    360   AutoRedial := CheckBox1.Checked;
    361   LocalNetworkRouting := CheckBox2.Checked;
    362   LogClearOnStart := CheckBox3.Checked;
    363241  CentralaHomepage := CheckBox4.Checked;
    364242  WorkgroupZdechov := CheckBox5.Checked;
    365243  ShareUnblockFirewall := CheckBox6.Checked;
    366   AutoDial := CheckBox7.Checked;
    367   ZdechovNetConnection := CheckBox8.Checked;
    368244  NetSharedFolder := CheckBox9.Checked;
    369   LogFileEnabled := CheckBox10.Checked;
    370   LogFileName := Edit1.Text;
    371   VpnServiceEnabled := CheckBox11.Checked;
    372 
    373   ConditionNetworkDomain := Edit2.Text;
    374   ConnectionName := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
     245
    375246  CoolTrayIcon1.HideMainForm;
    376247  SaveOptions;
     
    456327  LoadOptions;
    457328  Application.ShowMainForm := not FirstStart;
    458   VpnServiceRunning;
    459329end;
    460330
     
    506376end;
    507377
    508 procedure TMainForm.AddConnection;
    509 var
    510   I: Integer;
    511 begin
    512   if MagRasCon1.ValidateName(DefaultConnectionName) = 0 then
    513   with MagRasEdt1 do begin
    514     PPPDefault;
    515     PhoneBookPath := '';  // 4.60
    516     // telephone numbers
    517     SetCanonical(ConnectionHost) ;
    518 
    519     // dial params
    520     UserName := LowerCase(GetComputerNetName);
    521     Password := '';
    522 
    523     bPreviewUserPw := True;
    524     bShowDialingProgress := True;
    525     bRequireCHAP := False;
    526     bRequireMSEncryptedPassword := False;
    527     bSoftwareCompression := True;
    528     bCustom := True;
    529 
    530     // device stuff
    531     I := 0;
    532     MagRasCon1.GetDeviceList;
    533     while (I < MagRasCon1.DeviceNameList.Count) and
    534       (Pos('PPTP', MagRasCon1.DeviceNameList[I]) = 0) do I := I + 1;
    535     DeviceName := MagRasCon1.DeviceNameList[I];
    536     DeviceType := MagRasCon1.DeviceTypeList[I] ;
    537     if PutAllEntryProps(DefaultConnectionName) = 0 then
    538       PutDialProps (DefaultConnectionName);
    539   end;
    540 end;
    541 
    542 function TMainForm.GetZdechovNetConnection: Boolean;
    543 var
    544   I: Integer;
    545 begin
    546   MagRasGetEntryList('');
    547   I := 0;
    548   while (I < MagRasNumEntryRec) and
    549     (MagRasEntryRecs[I].EntryName <> DefaultConnectionName) do I := I + 1;
    550   Result := I < MagRasNumEntryRec;
    551 end;
    552 
    553 procedure TMainForm.SetZdechovNetConnection(const Value: Boolean);
    554 begin
    555   if Value then AddConnection else DeleteConnection;
    556 end;
    557 
    558 procedure TMainForm.DeleteConnection;
    559 begin
    560   with MagRasCon1 do begin
    561     EntryName := DefaultConnectionName;
    562     DeletePhonebook;
    563   end;
    564 end;
    565 
    566378procedure TMainForm.Button3Click(Sender: TObject);
    567379begin
    568   CheckBox1.Checked := True;
    569   CheckBox2.Checked := True;
    570   CheckBox3.Checked := True;
    571380  CheckBox4.Checked := True;
    572381  CheckBox5.Checked := True;
    573382  CheckBox6.Checked := True;
    574   CheckBox7.Checked := True;
    575   CheckBox8.Checked := True;
    576383  CheckBox9.Checked := True;
    577   CheckBox11.Checked := True;
    578   ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(DefaultConnectionName);
    579384end;
    580385
     
    618423end;
    619424
    620 procedure TMainForm.Zznamvyten1Click(Sender: TObject);
    621 begin
    622 //  if not DialingLog.Visible then DialingLog.ShowModal;
    623   ShellLaunch(LogFileName);
    624 end;
    625 
    626425procedure TMainForm.Init;
    627426var
    628   WSAErr: string;
    629427  Hostname: string;
    630428begin
    631429  HostName := 'default';
    632   GetIPFromHost(Hostname, DefaultGateway, WSAErr);
    633   DefaultGateway := ReverseString(DefaultGateway);
    634   DefaultGateway := '1'+Copy(DefaultGateway, Pos('.', DefaultGateway), 255);
    635   DefaultGateway := ReverseString(DefaultGateway);
    636430
    637431  //DefaultGateway := GetDefaultGateway;
     
    644438  PName = ^Name;
    645439var
    646   HEnt: pHostEnt; 
     440  HEnt: pHostEnt;
    647441  HName: PName;
    648442  WSAData: TWSAData;
    649443  i: Integer;
    650444begin
    651   Result := False;     
     445  Result := False;
    652446  if WSAStartup($0101, WSAData) <> 0 then begin
    653447    WSAErr := 'Winsock is not responding."';
     
    678472end;
    679473
    680 procedure TMainForm.Button4Click(Sender: TObject);
    681 begin
    682   OpenDialog1.FileName := Edit1.Text;
    683   if OpenDialog1.Execute then begin
    684     Edit1.Text := OpenDialog1.FileName;
    685   end;
    686 end;
    687 
    688 procedure TMainForm.CheckBox10Click(Sender: TObject);
    689 begin
    690   Edit1.Enabled := CheckBox10.Checked;
    691   Button4.Enabled := CheckBox10.Checked;
    692 end;
    693 
    694 function TMainForm.GetLogFileEnabled: Boolean;
    695 begin
    696   with TRegistry.Create do
    697   try
    698     RootKey := HKEY_LOCAL_MACHINE;
    699     OpenKey(RegistryPath, True);
    700     if ValueExists('LogFileEnabled') then Result := ReadBool('LogFileEnabled')
    701       else Result := False;
    702   finally
    703     Free;
    704   end;
    705 end;
    706 
    707 procedure TMainForm.SetLogFileEnabled(const Value: Boolean);
    708 begin
    709   with TRegistry.Create do
    710   try
    711     RootKey := HKEY_LOCAL_MACHINE;
    712     OpenKey(RegistryPath, True);
    713     WriteBool('LogFileEnabled', Value)
    714   finally
    715     Free;
    716   end;
    717 end;
    718 
    719 function TMainForm.GetLogFileName: string;
    720 begin
    721   with TRegistry.Create do
    722   try
    723     RootKey := HKEY_LOCAL_MACHINE;
    724     OpenKey(RegistryPath, True);
    725     if ValueExists('LogFileName') then Result := ReadString('LogFileName')
    726       else Result := ApplicationDataFolder + '\' + DefaultLogFileName;
    727   finally
    728     Free;
    729   end;
    730 end;
    731 
    732 procedure TMainForm.SetLogFileName(const Value: string);
    733 begin
    734   with TRegistry.Create do
    735   try
    736     RootKey := HKEY_LOCAL_MACHINE;
    737     OpenKey(RegistryPath, True);
    738     WriteString('LogFileName', Value)
    739   finally
    740     Free;
    741   end;
    742 end;
    743 
    744474procedure TMainForm.LoadOptions;
    745475begin
     
    750480      if ValueExists('FirstStart') then FirstStart := ReadBool('FirstStart')
    751481        else FirstStart := False;
    752       if ValueExists('AutoDial') then AutoDial := ReadBool('AutoDial');
    753       if ValueExists('AutoRedial') then AutoRedial := ReadBool('AutoRedial');
    754       if ValueExists('ConnectionName') then ConnectionName := ReadString('ConnectionName');
    755482      if ValueExists('NetworkTestLastUpdate') then NetworkTestLastUpdate := StrToDate(ReadString('NetworkTestLastUpdate'));
    756483      if ValueExists('PingTimeout') then PingTimeout := ReadInteger('PingTimeout')
    757484        else PingTimeout := 200;
    758       if ValueExists('LogFileEnabled') then LogFileEnabled := ReadBool('LogFileEnabled')
    759         else LogFileEnabled := False;
    760       if ValueExists('LogFileName') then LogFileName := ReadString('LogFileName')
    761         else LogFileName := ApplicationDataFolder + '\' + DefaultLogFileName;
    762485    finally
    763486      Free;
     
    772495      OpenKey(RegistryPath, True);
    773496      WriteBool('FirstStart', True);
    774       WriteBool('AutoDial', AutoDial);
    775       WriteBool('AutoRedial', AutoRedial);
    776       WriteString('ConnectionName', ConnectionName);
    777497      WriteString('NetworkTestLastUpdate', DateToStr(NetworkTestLastUpdate));
    778498      WriteInteger('PingTimeout', PingTimeout);
    779       WriteBool('LogFileEnabled', LogFileEnabled);
    780       WriteString('LogFileName', LogFileName);
    781499    finally
    782500      Free;
    783501    end;
    784 end;
    785 
    786 function TMainForm.GetConnectionName: string;
    787 begin
    788   with TRegistry.Create do
    789   try
    790     RootKey := HKEY_LOCAL_MACHINE;
    791     OpenKey(RegistryPath, True);
    792     if ValueExists('ConnectionName') then Result := ReadString('ConnectionName')
    793       else Result := '';
    794   finally
    795     Free;
    796   end;
    797 end;
    798 
    799 procedure TMainForm.SetConnectionName(const Value: string);
    800 begin
    801   with TRegistry.Create do
    802   try
    803     RootKey := HKEY_LOCAL_MACHINE;
    804     OpenKey(RegistryPath, True);
    805     WriteString('ConnectionName', Value)
    806   finally
    807     Free;
    808   end;
    809 end;
    810 
    811 function TMainForm.GetLogClearOnStart: Boolean;
    812 begin
    813   with TRegistry.Create do
    814   try
    815     RootKey := HKEY_LOCAL_MACHINE;
    816     OpenKey(RegistryPath, True);
    817     if ValueExists('LogClearOnStart') then Result := ReadBool('LogClearOnStart')
    818       else Result := False;
    819   finally
    820     Free;
    821   end;
    822 end;
    823 
    824 procedure TMainForm.SetLogClearOnStart(const Value: Boolean);
    825 begin
    826   with TRegistry.Create do
    827   try
    828     RootKey := HKEY_LOCAL_MACHINE;
    829     OpenKey(RegistryPath, True);
    830     WriteBool('LogClearOnStart', Value)
    831   finally
    832     Free;
    833   end;
    834 end;
    835 
    836 function TMainForm.GetVpnServiceEnabled: Boolean;
    837 var
    838   ServiceControl: TServiceControl;
    839 begin
    840   ServiceControl := TServiceControl.Create;
    841   with ServiceControl do begin
    842     ReadServicesList;
    843     try
    844       Result := True;
    845       IndexByName(DiallingServiceName);
    846     except
    847       Result := False;
    848     end;
    849   end;
    850   ServiceControl.Free;
    851 end;
    852 
    853 procedure TMainForm.SetVpnServiceEnabled(const Value: Boolean);
    854 var
    855   Command: TDosCommand;
    856 begin
    857   Command := TDosCommand.Create(nil);
    858   with Command do try
    859     if Value and not VpnServiceEnabled then begin
    860       CommandLine := ExtractFileDir(Application.ExeName)+'\DiallingService.exe /install /silent';
    861       Execute2;
    862     end;
    863     if not Value and VpnServiceEnabled then begin
    864         VpnServiceRunning := False;
    865         CommandLine := ExtractFileDir(Application.ExeName)+'\DiallingService.exe /uninstall /silent';
    866         Execute2;
    867       end;
    868   finally
    869     Free;
    870   end;
    871   GetVpnServiceRunning;
    872 end;
    873 
    874 function TMainForm.GetVpnServiceRunning: Boolean;
    875 var
    876   ServiceControl: TServiceControl;
    877 begin
    878   Result := False;
    879   Spustit1.Enabled := False;
    880   Zasavit1.Enabled := False;
    881   ServiceControl := TServiceControl.Create;
    882   with ServiceControl do begin
    883     ReadServicesList;
    884     try
    885       with Services[IndexByName(DiallingServiceName)] do begin
    886         Result := State = ssRunning;
    887         Spustit1.Enabled := (State = ssStopped) or (State = ssStopPending);
    888         Zasavit1.Enabled := (State = ssRunning) or (State = ssStartPending);
    889       end;
    890     except
    891     end;
    892   end;
    893   ServiceControl.Free;
    894 end;
    895 
    896 procedure TMainForm.SetVpnServiceRunning(const Value: Boolean);
    897 var
    898   ServiceControl: TServiceControl;
    899 begin
    900   ServiceControl := TServiceControl.Create;
    901   with ServiceControl do begin
    902     ReadServicesList;
    903     try
    904       if Value then Services[IndexByName(DiallingServiceName)].Start
    905         else Services[IndexByName(DiallingServiceName)].Stop;
    906     except
    907     end;
    908   end;
    909   ServiceControl.Free;
    910   GetVpnServiceRunning;
    911 end;
    912 
    913 procedure TMainForm.Spustit1Click(Sender: TObject);
    914 begin
    915   VpnServiceRunning := True;
    916 end;
    917 
    918 procedure TMainForm.Zasavit1Click(Sender: TObject);
    919 begin
    920   VpnServiceRunning := False;
    921502end;
    922503
     
    943524end;
    944525
    945 function TMainForm.GetConditionNetworkDomain: string;
    946 begin
    947   with TRegistry.Create do
    948   try
    949     RootKey := HKEY_LOCAL_MACHINE;
    950     OpenKey(RegistryPath, True);
    951     if ValueExists('ConditionNetworkDomain') then Result := ReadString('ConditionNetworkDomain')
    952       else Result := 'zdechov.net';
    953   finally
    954     Free;
    955   end;
    956 end;
    957 
    958 procedure TMainForm.SetConditionNetworkDomain(const Value: string);
    959 begin
    960   with TRegistry.Create do
    961   try
    962     RootKey := HKEY_LOCAL_MACHINE;
    963     OpenKey(RegistryPath, True);
    964     WriteString('ConditionNetworkDomain', Value);
    965   finally
    966     Free;
    967   end;
    968 end;
    969 
    970526end.
Note: See TracChangeset for help on using the changeset viewer.