Changeset 5 for trunk/UMainForm.pas
- Timestamp:
- Nov 27, 2008, 12:46:04 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:ignore
set to
*.dcu
KonfiguratorZdechovNET.exe
KonfiguratorZdechovNET.res
-
Property svn:ignore
set to
-
trunk/UMainForm.pas
r4 r5 6 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 7 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; 10 10 11 11 const … … 39 39 Button1: TButton; 40 40 Button2: TButton; 41 GroupBox1: TGroupBox;42 CheckBox1: TCheckBox;43 ComboBox1: TComboBox;44 Label1: TLabel;45 CheckBox2: TCheckBox;46 41 Bevel1: TBevel; 47 42 CheckBox4: TCheckBox; … … 55 50 XPManifest1: TXPManifest; 56 51 CheckBox6: TCheckBox; 57 CheckBox7: TCheckBox;58 CheckBox8: TCheckBox;59 52 Oprogramu1: TMenuItem; 60 53 CheckBox9: TCheckBox; 61 54 Zznamvyten1: TMenuItem; 62 Label2: TLabel;63 55 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;72 56 VPNpipojen1: TMenuItem; 73 CheckBox11: TCheckBox;74 57 Spustit1: TMenuItem; 75 58 Zasavit1: TMenuItem; 76 Label4: TLabel;77 Edit2: TEdit;78 59 procedure FormShow(Sender: TObject); 79 60 procedure Button2Click(Sender: TObject); … … 86 67 procedure Button3Click(Sender: TObject); 87 68 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);93 69 private 94 70 procedure LoadOptions; 95 71 procedure SaveOptions; 96 function GetLocalNetworkRouting: Boolean;97 procedure SetLocalNetworkRouting(const Value: Boolean);98 72 function GetCentralaHomepage: Boolean; 99 73 procedure SetCentralaHomepage(const Value: Boolean); … … 104 78 function GetShareUnblockFirewall: Boolean; 105 79 procedure SetShareUnblockFirewall(const Value: Boolean); 106 function GetZdechovNetConnection: Boolean;107 procedure SetZdechovNetConnection(const Value: Boolean);108 80 function GetNetSharedFolder: Boolean; 109 81 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);122 82 function GetNetworkDomain: string; 123 function GetConditionNetworkDomain: string;124 procedure SetConditionNetworkDomain(const Value: string);125 83 public 126 DefaultGateway: string;127 84 FirstStart: Boolean; 128 85 HostFilterIndex: Integer; 129 86 PingTimeout: Integer; 130 AutoDial: Boolean;131 AutoRedial: Boolean;132 87 NetworkTestLastUpdate: TDateTime; 133 property LocalNetworkRouting: Boolean read GetLocalNetworkRouting134 write SetLocalNetworkRouting;135 88 property CentralaHomepage: Boolean read GetCentralaHomepage 136 89 write SetCentralaHomepage; … … 141 94 property ShareUnblockFirewall: Boolean read GetShareUnblockFirewall 142 95 write SetShareUnblockFirewall; 143 property ZdechovNetConnection: Boolean read GetZdechovNetConnection144 write SetZdechovNetConnection;145 96 property NetSharedFolder: Boolean read GetNetSharedFolder 146 97 write SetNetSharedFolder; 147 property LogFileEnabled: Boolean read GetLogFileEnabled148 write SetLogFileEnabled;149 property LogFileName: string read GetLogFileName150 write SetLogFileName;151 property LogClearOnStart: Boolean read GetLogClearOnStart152 write SetLogClearOnStart;153 property ConnectionName: string read GetConnectionName154 write SetConnectionName;155 property VpnServiceEnabled: Boolean read GetVpnServiceEnabled156 write SetVpnServiceEnabled;157 property VpnServiceRunning: Boolean read GetVpnServiceRunning158 write SetVpnServiceRunning;159 98 property NetworkDomain: string read GetNetworkDomain; 160 property ConditionNetworkDomain: string read GetConditionNetworkDomain161 write SetConditionNetworkDomain;162 99 163 100 procedure Init; 164 procedure AddConnection;165 procedure DeleteConnection;166 101 end; 167 102 … … 178 113 179 114 uses UNetworkTest, UAboutWindow, ULogExceptions, DateUtils, Math, 180 UDialingLog,StrUtils, UServiceControl;115 StrUtils, UServiceControl; 181 116 182 117 {$R *.dfm} … … 260 195 end; 261 196 262 function TMainForm.GetLocalNetworkRouting: Boolean;263 var264 Command: TDosCommand;265 I: Integer;266 Lines2: TStringList;267 begin268 Lines2 := TStringList.Create;269 Result := False;270 Command := TDosCommand.Create(nil);271 with Command do try272 CommandLine := 'route print ' + LocalNetAddr + ' mask ' + LocalNetMask +273 ' ' + DefaultGateway + ' metric 30';274 OutputLines := Lines2;275 Execute2;276 for I := 0 to Lines2.Count - 1 do277 if Pos(LocalNetMask, Lines2[I]) > 0 then Result := True;278 finally279 Free;280 Lines2.Free;281 end;282 end;283 284 procedure TMainForm.SetLocalNetworkRouting(const Value: Boolean);285 var286 Command: TDosCommand;287 begin288 Command := TDosCommand.Create(nil);289 with Command do try290 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 finally294 Free;295 end;296 end;297 298 197 function TMainForm.GetCentralaHomepage: Boolean; 299 198 begin … … 327 226 LogExceptions.NazevAplikace := ApplicationName + ' ' + Version; 328 227 329 CheckBox1.Checked := AutoRedial;330 CheckBox2.Checked := LocalNetworkRouting;331 CheckBox3.Checked := LogClearOnStart;332 228 CheckBox4.Checked := CentralaHomepage; 333 229 CheckBox5.Checked := WorkgroupZdechov; 334 230 CheckBox6.Checked := ShareUnblockFirewall; 335 CheckBox7.Checked := AutoDial;336 CheckBox8.Checked := ZdechovNetConnection;337 231 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;351 232 end; 352 233 … … 358 239 procedure TMainForm.Button1Click(Sender: TObject); 359 240 begin 360 AutoRedial := CheckBox1.Checked;361 LocalNetworkRouting := CheckBox2.Checked;362 LogClearOnStart := CheckBox3.Checked;363 241 CentralaHomepage := CheckBox4.Checked; 364 242 WorkgroupZdechov := CheckBox5.Checked; 365 243 ShareUnblockFirewall := CheckBox6.Checked; 366 AutoDial := CheckBox7.Checked;367 ZdechovNetConnection := CheckBox8.Checked;368 244 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 375 246 CoolTrayIcon1.HideMainForm; 376 247 SaveOptions; … … 456 327 LoadOptions; 457 328 Application.ShowMainForm := not FirstStart; 458 VpnServiceRunning;459 329 end; 460 330 … … 506 376 end; 507 377 508 procedure TMainForm.AddConnection;509 var510 I: Integer;511 begin512 if MagRasCon1.ValidateName(DefaultConnectionName) = 0 then513 with MagRasEdt1 do begin514 PPPDefault;515 PhoneBookPath := ''; // 4.60516 // telephone numbers517 SetCanonical(ConnectionHost) ;518 519 // dial params520 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 stuff531 I := 0;532 MagRasCon1.GetDeviceList;533 while (I < MagRasCon1.DeviceNameList.Count) and534 (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 then538 PutDialProps (DefaultConnectionName);539 end;540 end;541 542 function TMainForm.GetZdechovNetConnection: Boolean;543 var544 I: Integer;545 begin546 MagRasGetEntryList('');547 I := 0;548 while (I < MagRasNumEntryRec) and549 (MagRasEntryRecs[I].EntryName <> DefaultConnectionName) do I := I + 1;550 Result := I < MagRasNumEntryRec;551 end;552 553 procedure TMainForm.SetZdechovNetConnection(const Value: Boolean);554 begin555 if Value then AddConnection else DeleteConnection;556 end;557 558 procedure TMainForm.DeleteConnection;559 begin560 with MagRasCon1 do begin561 EntryName := DefaultConnectionName;562 DeletePhonebook;563 end;564 end;565 566 378 procedure TMainForm.Button3Click(Sender: TObject); 567 379 begin 568 CheckBox1.Checked := True;569 CheckBox2.Checked := True;570 CheckBox3.Checked := True;571 380 CheckBox4.Checked := True; 572 381 CheckBox5.Checked := True; 573 382 CheckBox6.Checked := True; 574 CheckBox7.Checked := True;575 CheckBox8.Checked := True;576 383 CheckBox9.Checked := True; 577 CheckBox11.Checked := True;578 ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(DefaultConnectionName);579 384 end; 580 385 … … 618 423 end; 619 424 620 procedure TMainForm.Zznamvyten1Click(Sender: TObject);621 begin622 // if not DialingLog.Visible then DialingLog.ShowModal;623 ShellLaunch(LogFileName);624 end;625 626 425 procedure TMainForm.Init; 627 426 var 628 WSAErr: string;629 427 Hostname: string; 630 428 begin 631 429 HostName := 'default'; 632 GetIPFromHost(Hostname, DefaultGateway, WSAErr);633 DefaultGateway := ReverseString(DefaultGateway);634 DefaultGateway := '1'+Copy(DefaultGateway, Pos('.', DefaultGateway), 255);635 DefaultGateway := ReverseString(DefaultGateway);636 430 637 431 //DefaultGateway := GetDefaultGateway; … … 644 438 PName = ^Name; 645 439 var 646 HEnt: pHostEnt; 440 HEnt: pHostEnt; 647 441 HName: PName; 648 442 WSAData: TWSAData; 649 443 i: Integer; 650 444 begin 651 Result := False; 445 Result := False; 652 446 if WSAStartup($0101, WSAData) <> 0 then begin 653 447 WSAErr := 'Winsock is not responding."'; … … 678 472 end; 679 473 680 procedure TMainForm.Button4Click(Sender: TObject);681 begin682 OpenDialog1.FileName := Edit1.Text;683 if OpenDialog1.Execute then begin684 Edit1.Text := OpenDialog1.FileName;685 end;686 end;687 688 procedure TMainForm.CheckBox10Click(Sender: TObject);689 begin690 Edit1.Enabled := CheckBox10.Checked;691 Button4.Enabled := CheckBox10.Checked;692 end;693 694 function TMainForm.GetLogFileEnabled: Boolean;695 begin696 with TRegistry.Create do697 try698 RootKey := HKEY_LOCAL_MACHINE;699 OpenKey(RegistryPath, True);700 if ValueExists('LogFileEnabled') then Result := ReadBool('LogFileEnabled')701 else Result := False;702 finally703 Free;704 end;705 end;706 707 procedure TMainForm.SetLogFileEnabled(const Value: Boolean);708 begin709 with TRegistry.Create do710 try711 RootKey := HKEY_LOCAL_MACHINE;712 OpenKey(RegistryPath, True);713 WriteBool('LogFileEnabled', Value)714 finally715 Free;716 end;717 end;718 719 function TMainForm.GetLogFileName: string;720 begin721 with TRegistry.Create do722 try723 RootKey := HKEY_LOCAL_MACHINE;724 OpenKey(RegistryPath, True);725 if ValueExists('LogFileName') then Result := ReadString('LogFileName')726 else Result := ApplicationDataFolder + '\' + DefaultLogFileName;727 finally728 Free;729 end;730 end;731 732 procedure TMainForm.SetLogFileName(const Value: string);733 begin734 with TRegistry.Create do735 try736 RootKey := HKEY_LOCAL_MACHINE;737 OpenKey(RegistryPath, True);738 WriteString('LogFileName', Value)739 finally740 Free;741 end;742 end;743 744 474 procedure TMainForm.LoadOptions; 745 475 begin … … 750 480 if ValueExists('FirstStart') then FirstStart := ReadBool('FirstStart') 751 481 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');755 482 if ValueExists('NetworkTestLastUpdate') then NetworkTestLastUpdate := StrToDate(ReadString('NetworkTestLastUpdate')); 756 483 if ValueExists('PingTimeout') then PingTimeout := ReadInteger('PingTimeout') 757 484 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;762 485 finally 763 486 Free; … … 772 495 OpenKey(RegistryPath, True); 773 496 WriteBool('FirstStart', True); 774 WriteBool('AutoDial', AutoDial);775 WriteBool('AutoRedial', AutoRedial);776 WriteString('ConnectionName', ConnectionName);777 497 WriteString('NetworkTestLastUpdate', DateToStr(NetworkTestLastUpdate)); 778 498 WriteInteger('PingTimeout', PingTimeout); 779 WriteBool('LogFileEnabled', LogFileEnabled);780 WriteString('LogFileName', LogFileName);781 499 finally 782 500 Free; 783 501 end; 784 end;785 786 function TMainForm.GetConnectionName: string;787 begin788 with TRegistry.Create do789 try790 RootKey := HKEY_LOCAL_MACHINE;791 OpenKey(RegistryPath, True);792 if ValueExists('ConnectionName') then Result := ReadString('ConnectionName')793 else Result := '';794 finally795 Free;796 end;797 end;798 799 procedure TMainForm.SetConnectionName(const Value: string);800 begin801 with TRegistry.Create do802 try803 RootKey := HKEY_LOCAL_MACHINE;804 OpenKey(RegistryPath, True);805 WriteString('ConnectionName', Value)806 finally807 Free;808 end;809 end;810 811 function TMainForm.GetLogClearOnStart: Boolean;812 begin813 with TRegistry.Create do814 try815 RootKey := HKEY_LOCAL_MACHINE;816 OpenKey(RegistryPath, True);817 if ValueExists('LogClearOnStart') then Result := ReadBool('LogClearOnStart')818 else Result := False;819 finally820 Free;821 end;822 end;823 824 procedure TMainForm.SetLogClearOnStart(const Value: Boolean);825 begin826 with TRegistry.Create do827 try828 RootKey := HKEY_LOCAL_MACHINE;829 OpenKey(RegistryPath, True);830 WriteBool('LogClearOnStart', Value)831 finally832 Free;833 end;834 end;835 836 function TMainForm.GetVpnServiceEnabled: Boolean;837 var838 ServiceControl: TServiceControl;839 begin840 ServiceControl := TServiceControl.Create;841 with ServiceControl do begin842 ReadServicesList;843 try844 Result := True;845 IndexByName(DiallingServiceName);846 except847 Result := False;848 end;849 end;850 ServiceControl.Free;851 end;852 853 procedure TMainForm.SetVpnServiceEnabled(const Value: Boolean);854 var855 Command: TDosCommand;856 begin857 Command := TDosCommand.Create(nil);858 with Command do try859 if Value and not VpnServiceEnabled then begin860 CommandLine := ExtractFileDir(Application.ExeName)+'\DiallingService.exe /install /silent';861 Execute2;862 end;863 if not Value and VpnServiceEnabled then begin864 VpnServiceRunning := False;865 CommandLine := ExtractFileDir(Application.ExeName)+'\DiallingService.exe /uninstall /silent';866 Execute2;867 end;868 finally869 Free;870 end;871 GetVpnServiceRunning;872 end;873 874 function TMainForm.GetVpnServiceRunning: Boolean;875 var876 ServiceControl: TServiceControl;877 begin878 Result := False;879 Spustit1.Enabled := False;880 Zasavit1.Enabled := False;881 ServiceControl := TServiceControl.Create;882 with ServiceControl do begin883 ReadServicesList;884 try885 with Services[IndexByName(DiallingServiceName)] do begin886 Result := State = ssRunning;887 Spustit1.Enabled := (State = ssStopped) or (State = ssStopPending);888 Zasavit1.Enabled := (State = ssRunning) or (State = ssStartPending);889 end;890 except891 end;892 end;893 ServiceControl.Free;894 end;895 896 procedure TMainForm.SetVpnServiceRunning(const Value: Boolean);897 var898 ServiceControl: TServiceControl;899 begin900 ServiceControl := TServiceControl.Create;901 with ServiceControl do begin902 ReadServicesList;903 try904 if Value then Services[IndexByName(DiallingServiceName)].Start905 else Services[IndexByName(DiallingServiceName)].Stop;906 except907 end;908 end;909 ServiceControl.Free;910 GetVpnServiceRunning;911 end;912 913 procedure TMainForm.Spustit1Click(Sender: TObject);914 begin915 VpnServiceRunning := True;916 end;917 918 procedure TMainForm.Zasavit1Click(Sender: TObject);919 begin920 VpnServiceRunning := False;921 502 end; 922 503 … … 943 524 end; 944 525 945 function TMainForm.GetConditionNetworkDomain: string;946 begin947 with TRegistry.Create do948 try949 RootKey := HKEY_LOCAL_MACHINE;950 OpenKey(RegistryPath, True);951 if ValueExists('ConditionNetworkDomain') then Result := ReadString('ConditionNetworkDomain')952 else Result := 'zdechov.net';953 finally954 Free;955 end;956 end;957 958 procedure TMainForm.SetConditionNetworkDomain(const Value: string);959 begin960 with TRegistry.Create do961 try962 RootKey := HKEY_LOCAL_MACHINE;963 OpenKey(RegistryPath, True);964 WriteString('ConditionNetworkDomain', Value);965 finally966 Free;967 end;968 end;969 970 526 end.
Note:
See TracChangeset
for help on using the changeset viewer.