⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isafer_option.~pas

📁 一款防火墙源码
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
+Read rule set from Registry and Display it
Feb 12, 2004
LuuTruongHuy
}
procedure TForm_Option.FormShow(Sender: TObject);
var
     fwRule:TPSMFWRule;
     ruleList:TStringList;


     ListItem: TListItem;
     i: Integer;
     //for IP rules
     fromIP: string;
     toIP: string;
     fromPort: Integer;
     toPort: Integer;
     //for Path rules
     Path: string;
     Permit: Integer;

     bCheck: boolean;

     imIndex:Integer;
begin

  //Start FireWall Log here--huynote

     bCheck:= CreateIpcQueue('PSMFirewall', PSMFW_Callback);
     if(not bCheck)then
        Showmessage('Error when starting logging Firewall!')
     else
         isLogStarted:=True;

  ruleList:=TStringList.Create;
  fwRule.GetIPRuleList(ruleList);
  //For IP Rule
  for i:=0 to ruleList.Count-1 do
  begin
      fwRule.ExtractIPRule(ruleList[i],fromIP,toIP,fromPort,toPort,Permit);
      ListItem:= ListView_FWRule.Items.Add;
      ListItem.ImageIndex:=5;
      ListItem.Caption:= fromIp+' ~'+toIP;
      ListItem.SubItems.Add(Format('%d ~%d',[fromPort,toPort])) ;
      ListItem.SubItems.Add('TCP/UDP');
      if( permit=1) then
          ListItem.SubItems.Add('ALLOW')
      else
          ListItem.SubItems.Add('DENY');
  end;
  //For Path Rule
  ruleList.Clear;
  ImageListForAppPath.Clear;

  fwRule.GetPathRuleList(ruleList);
  for i:=0 to ruleList.Count-1 do
  begin
      fwRule.ExtractPathRule(ruleList[i],path, Permit);
      imIndex:=ImageListForAppPath.AddIcon(Form_FWRule.GetICON(path));

      ListItem:= Path_List.Items.Add;
      ListItem.Caption:= path;
      ListItem.ImageIndex:=  imIndex;
      if permit=1 then
          ListItem.SubItems.Add('ALLOW')
          //ListItem.SubItems.i
      else
          ListItem.SubItems.Add('DENY');
  end;
  ruleList.Free;

  //For security level.
   TrackBar_Level.Position:=2-fwRule.GetSecurityLevel;

   TrackBar_LevelChange(nil);
end;

{close form options}
procedure TForm_Option.FormDestroy(Sender: TObject);
begin
     // 肺弊沤祸 辆丰
     if isLogStarted then begin
          DestroyIpcQueue('PSMFirewall');
          isLogStarted:=False;
     end;

     while bPortScanning do begin
          Sleep(100);
          Application.ProcessMessages;
     end;

     logImages.Free;
     logPaths.Free;
end;

procedure TForm_Option.FormClose(Sender: TObject;
          var Action: TCloseAction);
var
    HMapMutex:THandle;
begin
     //Hide form
     Action:=caHide;   //TRR

     if isLogStarted then begin
          //Stop Logging function.
          DestroyIpcQueue('PSMFirewall');
          isLogStarted:=False;
     end;

     ListView_FWRule.Clear;

     HMapMutex := CreateMutex(nil, false, pchar('PSMFirewallApplication'));
     if HMapMutex <> 0 then begin
          if WaitForSingleObject(HMapMutex,100) = WAIT_OBJECT_0 then
          begin
                ListView_FWLog.Clear;
          end;
     end;
     ReleaseMutex(HMapMutex);
     CloseHandle(HMapMutex);

     Path_List.Clear;

     while bPortScanning do begin
          Sleep(100);
          Application.ProcessMessages;
     end;

end;


{
Show Shared Folder List View
}
procedure TForm_Option.TabSheet_FolderShow(Sender: TObject);
begin
     UpdateFolderInfo(self);
end;
{
Show tab-page of choosing security level.
}
procedure TForm_Option.TabSheet_LevelShow(Sender: TObject);
begin
;
end;

procedure TForm_Option.TrackBar_LevelChange(Sender: TObject);
var
     nLevel: Integer;
begin
     nLevel:= 2 - TrackBar_Level.Position;
     if (nLevel = 0) then begin
          Label_Level0.Caption:= 'Low';
          Label_Level2.Caption:= '- All IP/Ports are allow except:';
          Label_Level3.Caption:= '- All dened IP/Ports in the rule set are blocked';
     end else if (nLevel = 1) then begin
          Label_Level0.Caption:= 'Medium';
          Label_Level2.Caption:= '- Allow only Well - Known Ports';
          Label_Level3.Caption:= '- All dened IP/Ports in the rule set are blocked'
     end else if (nLevel = 2) then begin
          Label_Level0.Caption:= 'High';
          Label_Level2.Caption:= '- Block all IP/Ports except:';
          Label_Level3.Caption:= '- All allowed IP/Ports in the rule set are allowed'
     end;
     //Btn_Level_OK.Enabled:= True;

     BmBtnApplySecurity.Enabled:=True;
end;

{
Select Shared foler in list view
}
procedure TForm_Option.ListView_FolderSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
     if ListView_Folder.ItemIndex < 0 then begin
          BmBtnFolderView.Enabled:= False;
          BmBtnFolderInfo.Enabled:= False;
          BmBtnFolderStop.Enabled:= False;
     end else begin
          BmBtnFolderView.Enabled:= True;
          BmBtnFolderInfo.Enabled:= True;
          BmBtnFolderStop.Enabled:= True;

     end;
end;
{
For shared folder
}
{
procedure TForm_Option.Btn_FolderViewClick(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;
}

{
For shared folder
}

{
For shared folder
}
procedure TForm_Option.Btn_FolderReloadClick(Sender: TObject);   // 货肺 绊魔
begin
     UpdateFolderInfo(self);
end;







procedure TForm_Option.ListView_FWRuleEnter(Sender: TObject);
begin
    ChosenRuleType:=IP_RULE_TYPE;
end;

procedure TForm_Option.Path_ListEnter(Sender: TObject);
begin
     ChosenRuleType:=PATH_RULE_TYPE;
end;


procedure TForm_Option.ListView_FWRuleSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
end;

{Add IP Rule from Log list by selecting add IP rule on popup menu}
procedure TForm_Option.mnuAddIPRuleClick(Sender: TObject);
var
    //selectedIndex: Integer;
    //Rule Items
    //time:string;
    ip: string;
    //port: integer;
    sPort:String;
    permission: integer;

    //SelItem:TListItem;
    //strTmp:String;
    fwRule:TPSMFWRule;
begin
     if  ListView_FWLog.Selected= nil then
          MessageBox(Self.Handle,'Select one item in log list first','PSM Firewall',MB_OK or MB_ICONEXCLAMATION)

     else
          begin
                ip:= ListView_FWLog.Selected.SubItems[2];    //IP column
                sPort:= ListView_FWLog.Selected.SubItems[4]; //Port column

                if CompareText('DENY',ListView_FWLog.Selected.SubItems[1])=0 then
                    Permission:=0
                else Permission:=1;
                //ShowMessage(ip);

                //Form_FWRule.MaskEdit_sIP.Text:=fwRule.IPStd(PChar(ip));
                Form_FWRule.SetIPFrom(fwRule.IPStd(PChar(ip)));
                Form_FWRule.MaskEdit_sPort.Text:=Format('%5s',[sPort]);
                Form_FWRule.Radio_IP_Single.Checked:=TRUE;
                Form_FWRule.Radio_Port_Single.Checked:=TRUE;
                if Permission=1 then
                    Form_FWRule.Radio_Access_Allow.Checked:=True
                else
                    Form_FWRule.Radio_Access_Deny.Checked:=True;
                Form_FWRule.FWRule.ActivePage:=Form_FWRule.IpRulePage;
                Form_FWRule.Show;

          end;
end;
{Add Path Rule From Log List}
procedure TForm_Option.mnuAddPathRuleClick(Sender: TObject);
var
     path: string;
     permission: integer;
begin
     if  ListView_FWLog.Selected= nil then
          MessageBox(Self.Handle,'Select one item in log list first','PSM Firewall',MB_OK or MB_ICONEXCLAMATION)

     else
          begin
                path:= ListView_FWLog.Selected.SubItems[5]; //Path column

                if CompareText('DENY',ListView_FWLog.Selected.SubItems[1])=0 then
                    Permission:=0
                else Permission:=1;
                //ShowMessage(path);

                Form_FWRule.PathEdit.Text:=LowerCase(path);


                if Permission=1 then
                    Form_FWRule.Permission.ItemIndex:=0
                else
                    Form_FWRule.Permission.ItemIndex:=1;

                Form_FWRule.FWRule.ActivePage:=Form_FWRule.PathRulePage;
                Form_FWRule.Show;

          end;
end;
{display or hide direction column}
procedure TForm_Option.mnuDirectionClick(Sender: TObject);
begin
    if mnuDirection.Checked then
    begin
         mnuDirection.Checked:= False;
         ListView_FWLog.Columns[1].Width:=0;
    end
    else
    begin
         mnuDirection.Checked:= TRue;
         ListView_FWLog.Columns[1].Width:=70;
    end;
end;
{display application path or not}
procedure TForm_Option.mnuApplicationPathClick(Sender: TObject);
begin
    if mnuApplicationpath.Checked then
    begin
         mnuApplicationpath.Checked:= False;
         ListView_FWLog.Columns[6].Width:=0;
    end
    else
    begin
         mnuApplicationpath.Checked:= True;
         ListView_FWLog.Columns[6].Width:=250;
    end;
end;
{display or hide bytes received}
procedure TForm_Option.mnuBytesReceivedClick(Sender: TObject);
begin
    if mnuBytesReceived.Checked then
    begin
         mnuBytesReceived.Checked:= False;
         ListView_FWLog.Columns[7].Width:=0;
    end
    else
    begin
         mnuBytesReceived.Checked:= True;
         ListView_FWLog.Columns[7].Width:=70;
    end;
end;

procedure TForm_Option.mnuBytesSentClick(Sender: TObject);
begin
    if mnuBytesSent.Checked then
    begin
         mnuBytesSent.Checked:= False;
         ListView_FWLog.Columns[8].Width:=0;
    end
    else
    begin
         mnuBytesSent.Checked:= True;
         ListView_FWLog.Columns[8].Width:=70;
    end;
end;

procedure TForm_Option.mnuSocketNumberClick(Sender: TObject);
begin
    if mnuSocketNumber.Checked then
    begin
         mnuSocketNumber.Checked:= False;
         ListView_FWLog.Columns[10].Width:=0;
         //ListView_FWLog.Columns[10].//
    end
    else
    begin
         mnuSocketNumber.Checked:= True;
         ListView_FWLog.Columns[10].Width:=50;
    end;
end;

procedure TForm_Option.mnuPermissionClick(Sender: TObject);
begin
     if mnuPermission.Checked then
    begin
         mnuPermission.Checked:= False;
         ListView_FWLog.Columns[2].Width:=0;
    end
    else
    begin
         mnuPermission.Checked:= True;
         ListView_FWLog.Columns[2].Width:=70;
    end;
end;

procedure TForm_Option.ListView_FWLogEnter(Sender: TObject);
begin
     if(ListView_FWLog.Selected<>Nil) then
          ListView_FWLog.Selected.MakeVisible(False);

end;

procedure TForm_Option.mnuClearLogClick(Sender: TObject);
//var
//HMapMutex: THandle;
begin
     //HMapMutex := CreateMutex(nil, false, pchar('PSMFirewallApplication'));
     //if HMapMutex <> 0 then begin
     //     if WaitForSingleObject(HMapMutex,100) = WAIT_OBJECT_0 then
      //    begin
               ListView_FWLog.Visible:=False;
               ListView_FWLog.Items.BeginUpdate;
               ListView_FWLog.Items.Clear;
               ListView_FWLog.Items.EndUpdate;
               ListView_FWLog.Visible:=True;
        //  end;
     //end;
     //ReleaseMutex(HMapMutex);
     //CloseHandle(HMapMutex);
end;

procedure TForm_Option.mnuHostNameClick(Sender: TObject);
begin
     if mnuHostName.Checked then
    begin
         mnuHostName.Checked:= False;
         ListView_FWLog.Columns[4].Width:=0;
    end
    else
    begin
         mnuHostName.Checked:= True;
         ListView_FWLog.Columns[4].Width:=150;
    end;
end;

{
Add new Rule, This function displays rule editor dialog
}

procedure TForm_Option.BmBtnAddNewClick(Sender: TObject);
begin
      Form_FWRule.ShowModal;
end;

{
remove Rules from display list
Huy marked.
}

procedure TForm_Option.BmtBtnDeleteClick(Sender: TObject);
var
     nIndex: Integer;
     //strFileName: String;
     //bSuccess: Boolean;
     //TempFile: TextFile;
     //Huy
     RuleIdentify: String;
     //StrTmp:String;
     FromIP,ToIP:string;
     FWRule: TPSMFWRule;
     Delim: Integer;

     //h:String;
begin
        nIndex:= ListView_FWRule.ItemIndex;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -