141 lines
3.7 KiB
Plaintext
141 lines
3.7 KiB
Plaintext
unit DUrlPrvMain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Tocsg.Controls;
|
|
|
|
type
|
|
TDlgUrlPrvMain = class(TForm)
|
|
miUrlPrevent: TButton;
|
|
mmUrls: TMemo;
|
|
mmResult: TMemo;
|
|
Label1: TLabel;
|
|
Label2: TLabel;
|
|
procedure miUrlPreventClick(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
MgCtrls_: TManagerInputControlsData;
|
|
public
|
|
{ Public declarations }
|
|
Constructor Create(aOwner: TComponent); override;
|
|
Destructor Destroy; override;
|
|
end;
|
|
|
|
var
|
|
DlgUrlPrvMain: TDlgUrlPrvMain;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Tocsg.Firewall, Tocsg.Process, Tocsg.Safe, Tocsg.Strings, Tocsg.Network,
|
|
Winapi.ActiveX, NetFwTypeLib_TLB, Tocsg.Path, Tocsg.Url;
|
|
|
|
{$R *.dfm}
|
|
|
|
const
|
|
FW_Head = '$Test_';
|
|
|
|
Constructor TDlgUrlPrvMain.Create(aOwner: TComponent);
|
|
begin
|
|
Inherited Create(aOwner);
|
|
MgCtrls_ := TManagerInputControlsData.Create(CutFileExt(GetRunExePath) + '.ini');
|
|
MgCtrls_.RegInputCtrl(mmUrls);
|
|
MgCtrls_.Load;
|
|
end;
|
|
|
|
Destructor TDlgUrlPrvMain.Destroy;
|
|
begin
|
|
FreeAndNil(MgCtrls_);
|
|
ClearCrmFwPolicy(nil, false, FW_Head);
|
|
Inherited;
|
|
end;
|
|
|
|
procedure TDlgUrlPrvMain.miUrlPreventClick(Sender: TObject);
|
|
var
|
|
UrlList,
|
|
PreventIpList: TStringList;
|
|
i, c, nPos, nProfile: Integer;
|
|
ss: TStringStream;
|
|
sData,
|
|
sUrlName: String;
|
|
FwRule: TFwRule;
|
|
FwPolicy: INetFwPolicy2;
|
|
begin
|
|
// mmResult.Text := GetHostIPsFromDomain('jp.cdn.hub-services.vmwservices.com', #13#10);
|
|
//mmResult.Text := GetHostIPsFromDomain('google.com', #13#10);
|
|
//exit;
|
|
if mmUrls.Enabled then
|
|
begin
|
|
mmUrls.Text := Trim(mmUrls.Text);
|
|
if mmUrls.Text = '' then
|
|
begin
|
|
MessageBox(Handle, PChar('차단 할 URL을 등록해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK);
|
|
exit;
|
|
end;
|
|
MgCtrls_.Save;
|
|
|
|
Guard(UrlList, TStringList.Create);
|
|
SplitString(mmUrls.Text, ';', UrlList);
|
|
Guard(PreventIpList, TStringList.Create);
|
|
|
|
ZeroMemory(@FwRule, SizeOf(FwRule));
|
|
FwRule.sGroup := 'Tocsg Group';
|
|
FwRule.sDesc := 'Url Prevent Test';
|
|
// FwRule.nProfiles := FW_PROFILE_ANY;
|
|
// FwRule.nProtocol := NET_FW_IP_PROTOCOL_ANY;
|
|
// FwRule.sRemotePorts := '443,80,8080,8443,135,445,902,912,1025,1026,1027,1028,1688,3838,5357,23401';
|
|
FwRule.bEnabled := true;
|
|
|
|
mmResult.Clear;
|
|
|
|
CoInitialize(nil);
|
|
try
|
|
FwPolicy := CoNetFwPolicy2.Create;
|
|
|
|
Guard(ss, TStringStream.Create('', TEncoding.UTF8));
|
|
for i := 0 to UrlList.Count - 1 do
|
|
begin
|
|
if UrlList[i] = '' then
|
|
continue;
|
|
|
|
mmResult.Lines.Add(UrlList[i]);
|
|
SplitString(ExtractIPsFromUrl(UrlList[i], false, ';'), ';', PreventIpList);
|
|
if PreventIpList.Count > 0 then
|
|
begin
|
|
for c := 0 to PreventIpList.Count - 1 do
|
|
mmResult.Lines.Add(PreventIpList[c]);
|
|
|
|
sUrlName := StringReplace(UrlList[i], '.', '', [rfReplaceAll]);
|
|
FwRule.sName := FW_Head + 'eCrmHE-' + sUrlName;// + IntToStr(c + 1);
|
|
FwRule.sRemoteAddresses := PreventIpList.CommaText;
|
|
FwRule.nDirection := NET_FW_RULE_DIR_OUT;
|
|
AddFwRule(FwPolicy, FwRule);
|
|
|
|
FwRule.nDirection := NET_FW_RULE_DIR_IN;
|
|
AddFwRule(FwPolicy, FwRule);
|
|
end;
|
|
mmResult.Lines.Add('');
|
|
end;
|
|
|
|
SendMessage(mmResult.Handle, WM_VSCROLL, SB_TOP, 0);
|
|
finally
|
|
CoUninitialize;
|
|
end;
|
|
end else begin
|
|
if MessageBox(Handle, PChar('중지하시겠습니까?'),
|
|
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
|
|
|
|
ClearCrmFwPolicy(nil, false, FW_Head);
|
|
end;
|
|
|
|
mmUrls.Enabled := not mmUrls.Enabled;
|
|
if mmUrls.Enabled then
|
|
miUrlPrevent.Caption := 'URL 차단'
|
|
else
|
|
miUrlPrevent.Caption := 'URL 차단 중지';
|
|
end;
|
|
|
|
end.
|