📄 isafer_fwrule.pas
字号:
if Assigned(PrevWndProc) then PrevWndproc(Message);
end;
procedure TForm_FWRule.FormShow(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_IP_SingleClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_IP_RangeClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_IP_AllClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_Port_SingleClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_Port_RangeClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
procedure TForm_FWRule.Radio_Port_AllClick(Sender: TObject);
begin
InputStatusCheck(self);
end;
{process when users choose editing path-rule page}
procedure TForm_FWRule.ChooseEditPathRule();
var
fwPathRule:TPSMFWRule;
ispermitted: integer;
ListItem: TListItem;
imIndex:Integer;
tmpPath:String;
begin
if Permission.ItemIndex =0 then
ispermitted:=1
else
ispermitted:=0;
{Add to Registry}
tmpPath:=LowerCase(PathEdit.Text);
if(fwPathRule.PathRuleExisted(PChar(tmpPath),ispermitted)=False) then
begin
fwPathRule.AddPathRule(PChar(tmpPath),ispermitted);
{Add to PathRule List}
//if(Form_Option.Path_List.FindCaption(0,tmpPath,FALSE,TRUE,FALSE)= nil)then
imIndex:=Form_Option.ImageListForAppPath.AddIcon(GetICON(PathEdit.Text));
ListItem:=Form_Option.Path_List.Items.Add;
//ListItem.ImageIndex:=5;
ListItem.Caption:=tmpPath;// PathEdit.Text;
if(ispermitted=1) then
ListItem.SubItems.Add('ALLOW')
else
ListItem.SubItems.Add('DENY');
//Add Application icon here.
ListItem.ImageIndex:=imIndex;
end
else
MessageBox(Self.Handle,'This Application Rule is existed','PSM FireWall',MB_OK or MB_ICONEXCLAMATION);
end;
{
Get IP Address from IP control
Creat on 19th Feb, 2004
LuuTruongHuy<lhuy@psmkorea.co.kr>
}
function TForm_FWRule.GetIPAddress(handle:HWND):string;
var
wIP: longword;
b1,b2,b3,b4: Byte;
begin
SendMessage(handle,IPM_GETADDRESS,0,LPARAM(@wIP));
b1:=FIRST_IPADDRESS(wIP);
b2:=SECOND_IPADDRESS(wIP);
b3:=THIRD_IPADDRESS(wIP);
b4:=FOURTH_IPADDRESS(wIP);
Result:=Format('%d.%d.%d.%d',[b1,b2,b3,b4]);
end;
procedure TForm_FWRule.SetIPFrom(sIp:string);
var
ipItems: TStringList;
b1,b2,b3,b4: Byte;
ipNum:Integer;
begin
ipItems:=TStringList.Create;
ExtractStrings(['.'],[' '],PChar(sIp),ipItems);
b1:=strtoint(ipItems[0]);
b2:=strtoint(ipItems[1]);
b3:=strtoint(ipItems[2]);
b4:=strtoint(ipItems[3]);
ipItems.Free;
ipNum:= MAKEIPADDRESS(b1,b2,b3,b4);
SendMessage(HIPAddressFrom,IPM_SETADDRESS,0,lParam(DWORD(ipNum)));
end;
procedure TForm_FWRule.BmBtnEditOKClick(Sender: TObject);
var
i: Integer;
strIP, strPort, strProtocol, strType: String;
strMessage: String;
strFileName: String;
bSuccess: Boolean;
ListItem: TListItem;
TempFile: TextFile;
//Huy
psmFWRule:TPSMFWRule;
FromIP,ToIP: Pchar;
FromPort,ToPort: Integer;
IsPermitted: Integer;
begin
//Check which page is currently active
//Huy
strMessage:= '';
{Editing Path Rule page is active}
if FWRule.ActivePageIndex=1 then
begin
if not FileExists(PathEdit.Text) then
begin
MessageBox(Self.Handle,'Chosen file doesn''t exist', 'Please choose another.',MB_OK or MB_ICONERROR );
exit;
end;
ChooseEditPathRule;
if(Form_Main.bFWStart)then
ApplyFWStatus(1);//Apply a new rule
Form_FWRule.Close;
exit;
end;
{Editing IP Rule page is active}
// IP林家 汲沥 眉农
if Radio_IP_Single.Checked then begin
FromIP:= PChar(GetIPAddress(HIPAddressFrom));
ToIP:= PChar(GetIPAddress(HIPAddressFrom));
end;
if Radio_IP_Range.Checked then begin
FromIP:= PChar(GetIPAddress(HIPAddressFrom));
ToIP:= Pchar(GetIPAddress(HIPAddressTo));
end;
if Radio_IP_All.Checked then begin
FromIP:= '000.000.000.001';
ToIP:= '255.255.255.255';
end;
FromIP:= Pchar(psmFWRule.IPStd(FromIP));
ToIP:= PChar(psmFWRule.IPStd(ToIP));
//Check IP range validity
if StrComp(FromIP,ToIP)>0 then
begin
MessageBox(Form_FWRule.Handle,'IP range is invalid','Rule Edit Error',MB_OK or MB_ICONERROR);
exit;
end;
strIP:= FromIP + ' ~ ' + ToIP;
strMessage:= strMessage + 'IP Address : ' + FromIP + ' ~ ' + ToIP;
strMessage:= strMessage + #13;
// 器飘锅龋 汲沥 眉农
{for editing port}
try
if Radio_Port_Single.Checked then begin
FromPort:=StrToInt(Trim(MaskEdit_sPort.Text));
ToPort:= StrToInt(Trim(MaskEdit_sPort.Text));
end;
if Radio_Port_Range.Checked then begin
FromPort:=StrToInt(Trim(MaskEdit_sPort.Text));
ToPort:= StrToInt(Trim(MaskEdit_ePort.Text));
end;
except
MessageBox(Form_FWRule.Handle,'Invalid Port Number','Rule Edit Error',MB_OK or MB_ICONERROR);
exit;
end;
if Radio_Port_All.Checked then begin
FromPort:=0;
ToPort:= 65535;
end;
//Check of port range is valid or not
if(FromPort>ToPort) then
begin
MessageBox(Form_FWRule.Handle,'Port range is invalid','Rule Edit Error',MB_OK or MB_ICONERROR);
exit;
end;
if(ToPort<0) then ToPort:=0;
if(ToPort>65535) then ToPort:=65535;
if(FromPort<0) then FromPort:=0;
if(FromPort>65535) then FromPort:=65535;
strPort:= inttostr(FromPort) + ' ~ ' + inttostr(ToPort);
strMessage:= strMessage + 'Port number : ' + inttostr(FromPort) + ' ~ ' + inttostr(ToPort);
strMessage:= strMessage + #13;
// 器飘鸥涝 汲沥 眉农
{
if Radio_TCP.Checked then begin
strProtocol:= 'TCP';
strMessage:= strMessage + '器飘鸥涝 : TCP';
end;
if Radio_UDP.Checked then begin
strProtocol:= 'UDP';
strMessage:= strMessage + '器飘鸥涝 : UDP';
end;
}
strProtocol:= 'TCP/UDP';
strMessage:= strMessage + 'Protocol : TCP/UDP';
strMessage:= strMessage + #13;
// 倾侩咯何 汲沥 眉农
if Radio_Access_Allow.Checked then begin
strType:= 'Allow';
strMessage:= strMessage + 'Permission : Allow';
IsPermitted:=1;
end;
if Radio_Access_Deny.Checked then begin
strType:= 'Deny';
strMessage:= strMessage + 'Permission : Deny';
IsPermitted:=0;
end;
strMessage:= strMessage + #13;
strMessage:= strMessage + #13 + 'add this rule?';
if Application.MessageBox(PChar(strMessage), PChar(Form_FWRule.Caption), MB_YESNO) = IDYES then begin
// 规拳寒 逢 利侩窍扁
if Form_Main.bFWStart then begin
{In the case the service was started}
//bSuccess:= Form_Option.iShieldRuleControl(1, strIP, strPort, strProtocol, strType);
end else begin
{In the case the service wasnot started}
bSuccess:= True;
end;
{Add and modify by Huy in Feb 04}
bSuccess:= True;
if bSuccess then begin
// 规拳寒 逢 府胶飘俊 眠啊窍扁
//if(Form_Option.ListView_FWRule.FindCaption())
if(psmFWRule.IPRuleExisted(FromIp,ToIp,FromPort,ToPort,IsPermitted)=False)then
begin
ListItem:= Form_Option.ListView_FWRule.Items.Add;
ListItem.ImageIndex:=5;
ListItem.Caption:= strIP;
ListItem.SubItems.Add(strPort);
ListItem.SubItems.Add(strProtocol);
//ListItem.SubItems.Add(strType);
if(ispermitted=1) then
ListItem.SubItems.Add('ALLOW')
else
ListItem.SubItems.Add('DENY');
//Add rule to Registry-Huy
psmFWRule.AddIPRule(FromIp,ToIp,FromPort,ToPort,IsPermitted);
if(Form_Main.bFWStart) then
ApplyFWStatus(1);
end
else
MessageBox(Self.Handle,'This IP Rule is existed','PSM FireWall',MB_OK or MB_ICONEXCLAMATION);
end;
Form_FWRule.Close;
end;
end;
procedure TForm_FWRule.BmBtnEditCancelClick(Sender: TObject);
begin
Close;
end;
procedure TForm_FWRule.BmBtnPathClick(Sender: TObject);
begin
OpenDialog1.Filter := 'Execute File (*.exe,*.com)|*.EXE;*.COM;*.DLL|All File (*.*)|*.* ';
OpenDialog1.Execute;
PathEdit.Text:=OpenDialog1.FileName;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -