📄 isafer_option.~pas
字号:
if((nIndex >= 0) and (ChosenRuleType=IP_RULE_TYPE)) then begin
if Application.MessageBox('Delete the selected IP/Port rule?', 'PSM Firewall', MB_YESNO) = IDYES then begin
{Remove from Registry}
RuleIdentify:= ListView_FWRule.Items.Item[nIndex].Caption;
Delim:=Pos('~',RuleIdentify);
FromIP:=Trim(LeftStr(RuleIdentify,Delim-1));
ToIP:=Trim(RightStr(RuleIdentify,Length(RuleIdentify)-Delim));
//AnsiReplaceStr(RuleIdentify,'~','|');
FWRule.RemoveIPRule(PChar(FromIP),PChar(ToIP));
{Remore from Displaying List}
ListView_FWRule.Items.Delete(nIndex);
if(Form_Main.bFWStart)then
ApplyFWStatus(1);
end;
end else begin //No rule is selected in IP Rule list, then try with Path List
nIndex:= Path_List.ItemIndex;
if(( nIndex>=0) and (ChosenRuleType=PATH_RULE_TYPE)) then
begin
if Application.MessageBox('Delete the selected application rule?', 'PSM Firewall', MB_YESNO) = IDYES then begin
//delete from registry
RuleIdentify:= Path_List.Items.Item[nIndex].Caption;
FWRule.RemovePathRule(Pchar(RuleIdentify));
//delre from List
Path_List.Items.Delete(nIndex);
if(Form_Main.bFWStart)then
ApplyFWStatus(1);
end;
end
else
Application.MessageBox('Select the rule first!', 'iSafer', MB_OK);
end;
end;
{
Apply sercurity level
}
procedure TForm_Option.BmBtnApplySecurityClick(Sender: TObject);
var
nLevel: Integer;
fwRuler:TPSMFWRule;
begin
nLevel:= 2 - TrackBar_Level.Position;
fwRuler.SetSecurityLevel(nLevel);
BmBtnApplySecurity.Enabled:= False;
if(Form_Main.bFWStart)then
ApplyFWStatus(1);
end;
{
Cancel apply sercurity level
}
procedure TForm_Option.BmBtnCancelSecuiryClick(Sender: TObject);
var
nLevel: Integer;
fwRule:TPSMFWRule;
begin
nLevel:=fwRule.GetSecurityLevel;
TrackBar_Level.Position:= 2 - nLevel;
BmBtnApplySecurity.Enabled:= False;
end;
procedure TForm_Option.BmBtnFolderViewClick(Sender: TObject);
var
nIndex: Integer;
strPath: String;
begin
nIndex:= ListView_Folder.ItemIndex;
if nIndex >= 0 then begin
strPath:= ListView_Folder.Items.Item[nIndex].SubItems.Strings[0];
ShellExecute(Handle,'open','explorer',PChar(strPath),'',SW_SHOWNORMAL);
end;
end;
procedure TForm_Option.BmBtnFolderInfoClick(Sender: TObject);
var
nIndex: Integer;
strItem: String;
ExecInfo: TShellExecuteInfo;
begin
nIndex:= ListView_Folder.ItemIndex;
if nIndex >= 0 then begin
strItem:= ListView_Folder.Items.Item[nIndex].SubItems.Strings[0];
FillChar(ExecInfo, SizeOf(ExecInfo), 0);
ExecInfo.cbSize := SizeOf(TShellExecuteInfo);
ExecInfo.fMask := SEE_MASK_INVOKEIDLIST or SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
ExecInfo.lpFile := PChar(strItem);
ExecInfo.lpVerb := 'Properties';
ExecInfo.nShow := SW_SHOWDEFAULT;
ShellExecuteEx(@ExecInfo);
end;
end;
procedure TForm_Option.BmBtnFolderStopClick(Sender: TObject);
type
tFuncNT = function(ServerName, NetName: LPWSTR; Reserved: DWORD): DWord; stdcall;
tFunc95 = function(ServerName, NetName: PChar; Reserved: DWORD): Integer; stdcall;
var
nIndex: Integer;
strNameNT: WideString;
strName95: String;
strPath, strTemp: String;
DLLHandle: THandle;
MyFuncNT: TFuncNT;
MyFunc95: TFunc95;
begin
nIndex:= ListView_Folder.ItemIndex;
if nIndex >= 0 then begin
strNameNT:= ListView_Folder.Items.Item[nIndex].Caption;
strName95:= ListView_Folder.Items.Item[nIndex].Caption;
strPath:= ListView_Folder.Items.Item[nIndex].SubItems.Strings[0];
strTemp:= strName95 + 'Unshare the selected folder?';
if Application.MessageBox(PChar(strTemp), 'iSafer', MB_YESNO) = IDYES then begin
if OS.dwPlatformId = VER_PLATFORM_WIN32_NT then begin
// Windows NT/2000 拌凯
DLLHandle:= LoadLibrary('netapi32.dll');
if DLLHandle < 32 then exit;
@MyFuncNT:= GetProcAddress(DLLHandle, 'NetShareDel');
if not (@MyFuncNT = nil) then begin
MyFuncNT('', PWideChar(strNameNT), 0);
end;
FreeLibrary(DLLHandle);
end else begin
// Windows 95/98 拌凯
DLLHandle:= LoadLibrary('svrapi.dll');
if DLLHandle < 32 then exit;
@MyFunc95:= GetProcAddress(DLLHandle, 'NetShareDel');
if not (@MyFunc95 = nil) then begin
MyFunc95('', PChar(strName95), 0);
end;
FreeLibrary(DLLHandle);
end;
UpdateFolderInfo(self); // 傍蜡 弃歹 沥焊 舅酒郴扁
end;
end;
end;
procedure TForm_Option.BmBtnReloadClick(Sender: TObject);
begin
UpdateFolderInfo(self);
end;
procedure TForm_Option.BmBtnPortDefaultClick(Sender: TObject);
var
i, nPortCount: Integer;
PortNumber:Integer;
currTh:Integer;
ListItem: TListItem;
begin
nPortCount:=0;
ListView_PortTemp.Width:= 0;
ListView_PortTemp.Height:= 0;
ListView_PortTemp.Visible:= True;
for i:=0 to ListView_PortTemp.Items.Count-1 do
if ListView_PortTemp.Items.Item[i].SubItems.Strings[1] = 'Default' then begin
inc(nPortCount);
end;
ProgressBar.Min:=0;
ProgressBar.Max:=100;
ProgressBar.Position:=0;
bPortScanning:= True;
ListView_Port.Items.BeginUpdate;
ListView_Port.Items.Clear;
currTh:=0;
for i:=0 to ListView_PortTemp.Items.Count-1 do begin
if ListView_PortTemp.Items.Item[i].SubItems.Strings[1] = 'Default' then
begin
ProgressBar.Position := Round(100*currTh/nPortCount);
PortNumber:= StrToInt(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
try
// Trying to open serversocket
ServerSocket.Port := PortNumber;
ServerSocket.Open();
ServerSocket.Close();
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add('Close');
except
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add(' Open ');
end; // try/except
inc(currTh);
end;
end;
bPortScanning:= False;
ListView_Port.Items.EndUpdate;
ListView_PortTemp.Visible:= False;
ProgressBar.Position :=0;
end;
procedure TForm_Option.BmBtnPortBackDoorClick(Sender: TObject);
var
i, nPortCount: Integer;
PortNumber:Integer;
currTh:Integer;
ListItem: TListItem;
begin
//Count the number of backdoor port
nPortCount:=0;
ListView_PortTemp.Width:= 0;
ListView_PortTemp.Height:= 0;
ListView_PortTemp.Visible:= True;
for i:=0 to ListView_PortTemp.Items.Count-1 do
if ListView_PortTemp.Items.Item[i].SubItems.Strings[1] = 'Backdoor' then begin
inc(nPortCount);
end;
ProgressBar.Min:=0;
ProgressBar.Max:=100;
ProgressBar.Position:=0;
bPortScanning:= True;
ListView_Port.Items.BeginUpdate;
ListView_Port.Items.Clear;
currTh:=0;
for i:=0 to ListView_PortTemp.Items.Count-1 do begin
if ListView_PortTemp.Items.Item[i].SubItems.Strings[1] = 'Backdoor' then
begin
ProgressBar.Position := Round(100*currTh/nPortCount);
PortNumber:= StrToInt(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
try
// Trying to open serversocket
ServerSocket.Port := PortNumber;
ServerSocket.Open();
ServerSocket.Close();
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add('Close');
except
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add(' Open ');
end; // try/except
inc(currTh);
end;
end;
bPortScanning:= False;
ListView_Port.Items.EndUpdate;
ListView_PortTemp.Visible:= False;
ProgressBar.Position :=0;
end;
procedure TForm_Option.BmBtnPortAllClick(Sender: TObject);
var
i, nPortCount: Integer;
PortNumber:Integer;
currTh:Integer;
ListItem: TListItem;
begin
nPortCount:=0;
ListView_PortTemp.Width:= 0;
ListView_PortTemp.Height:= 0;
ListView_PortTemp.Visible:= True;
for i:=0 to ListView_PortTemp.Items.Count-1 do
inc(nPortCount);
ProgressBar.Min:=0;
ProgressBar.Max:=100;
ProgressBar.Position:=0;
bPortScanning:= True;
ListView_Port.Items.BeginUpdate;
ListView_Port.Items.Clear;
currTh:=0;
for i:=0 to ListView_PortTemp.Items.Count-1 do begin
//if ListView_PortTemp.Items.Item[i].SubItems.Strings[1] = 'Backdoor' then
ProgressBar.Position := Round(100*currTh/nPortCount);
PortNumber:= StrToInt(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
// Trying to open serversocket
try
ServerSocket.Port := PortNumber;
ServerSocket.Open();
ServerSocket.Close();
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add('Close');
except
ListItem:= ListView_Port.Items.Add;
ListItem.ImageIndex:=7;
ListItem.Caption:= ListView_PortTemp.Items.Item[i].Caption;
ListItem.SubItems.Add(ListView_PortTemp.Items.Item[i].SubItems.Strings[0]);
ListItem.SubItems.Add(' Open ');
end;//Try
inc(currTh);
//end;
end;
bPortScanning:= False;
ListView_Port.Items.EndUpdate;
ListView_PortTemp.Visible:= False;
ProgressBar.Position :=0;
end;
procedure TForm_Option.mnuRuleAddnewClick(Sender: TObject);
begin
if(ChosenRuleType=IP_RULE_TYPE) then
begin
Form_FWRule.FWRule.ActivePage:=Form_FWRule.IpRulePage;
Form_FWRule.ShowModal;
end
else if (ChosenRuleType=PATH_RULE_TYPE) then
begin
Form_FWRule.FWRule.ActivePage:=Form_FWRule.PathRulePage;
Form_FWRule.ShowModal;
end;
end;
procedure TForm_Option.DeleteClick(Sender: TObject);
begin
BmtBtnDeleteClick(nil);
end;
procedure TForm_Option.mnuRuleChangePermisionClick(Sender: TObject);
var
FWRule :TPSMFWRule;
RuleIdentify:string;
nIndex:Integer;
Delim:Integer;
FromIP:string;
ToIP:string;
FromPort:string;
ToPort:string;
PortRange:string;
SlectedItem:TListItem;
Permision:String;
PermissionValue:Integer;
strmsg:string;
begin
if(ChosenRuleType=IP_RULE_TYPE) then
begin
nIndex:= ListView_FWRule.ItemIndex;
if(nIndex>=0) then
begin
SlectedItem:= ListView_FWRule.Items.Item[nIndex];
RuleIdentify:= SlectedItem.Caption;
Delim:=Pos('~',RuleIdentify);
FromIP:=Trim(LeftStr(RuleIdentify,Delim-1));
ToIP:=Trim(RightStr(RuleIdentify,Length(RuleIdentify)-Delim));
PortRange:= SlectedItem.SubItems[0];
Permision:= SlectedItem.SubItems[2];
Delim:=Pos('~',PortRange);
FromPort:=Trim(LeftStr(PortRange,Delim-1));
ToPort:=Trim(RightStr(PortRange,Length(PortRange)-Delim));
if(Permision='DENY') then PermissionValue:=0
else PermissionValue:=1;
strmsg:='IP Rule : '#13#10'IP range: [From '+ FromIP+' , To '+ ToIP+']'#13#10;
strmsg:=strmsg+'Port range: ['+FromPort+', '+ ToPort+']'#13#10;
strmsg:=strmsg+'Permission: '+ Permision+''#13#10;
strmsg:=strmsg+'**********************'#13#10;
if(Permision='DENY') then
strmsg:=strmsg+'Change permission to (Allow)?'
else strmsg:=strmsg+'Change permission to (Deny)?';
if Application.MessageBox(PChar(strmsg),'PSM Firewall', MB_YESNO) = IDYES then
begin
if(Permision='DENY') then
begin
FWRule.ModifyIPrule(Pchar(fromIP),PChar(toIP),StrToInt(fromPort),strtoint(toPort),StrToInt(fromPort),strtoint(toPort),1);
SlectedItem.SubItems[2]:='ALLOW';
end
else
begin
FWRule.ModifyIPrule(Pchar(fromIP),PChar(toIP),StrToInt(fromPort),strtoint(toPort),strtoint(fromPort),strtoint(toPort),0) ;
SlectedItem.SubItems[2]:='DENY' ;
end;
if(Form_Main.bFWStart) then
ApplyFWStatus(1);
end
// Application.MessageBox('No rule is selected', 'PSM Firewall', MB_OK);
end;
end
else if(ChosenRuleType=PATH_RULE_TYPE) then
begin
nIndex:= Path_List.ItemIndex;
if(nIndex>=0) then
begin
SlectedItem:=Path_List.Items.Item[nIndex];
RuleIdentify:= SlectedItem.Caption;
Permision:= SlectedItem.SubItems[0];
strmsg:='Application rule : '#13#10'program path = '+RuleIdentify+' '#13#10;
strmsg:=strmsg+'Permission: '+ Permision+''#13#10;
strmsg:=strmsg+'**********************'#13#10;
if(Permision='DENY') then
strmsg:=strmsg+'Change permission to (Allow)?'
else strmsg:=strmsg+'Change permission to (Deny)?';
if Application.MessageBox(PChar(strmsg),'PSM Firewall', MB_YESNO) = IDYES then
begin
if(Permision='DENY') then
begin
FWRule.ModifyPathrule(Pchar(RuleIdentify),1) ;
SlectedItem.SubItems[0]:='ALLOW';
end
else
begin
FWRule.ModifyPathrule(Pchar(RuleIdentify),0) ;
SlectedItem.SubItems[0]:='DENY' ;
end;
if(Form_Main.bFWStart) then
ApplyFWStatus(1);
end;
end
else
begin
Application.MessageBox('No rule is selected', 'PSM Firewall', MB_OK);
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -