This shows you the differences between two versions of the page.
userspace:block_websites_from_hosts-file [2020/01/23 09:53] bobzbobz created |
userspace:block_websites_from_hosts-file [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Block websites from hosts-file ====== | ||
- | //Scripts and guide by Soren Birk// | ||
- | I created this package to block users from accessing certain " | ||
- | |||
- | The package contains 2 productproperties, | ||
- | |||
- | |||
- | **Tested with**: | ||
- | * OPSI 4.1.1.83 | ||
- | * Winst 4.12.1.5 | ||
- | * Windows 10, 64-Bit | ||
- | |||
- | **Instructions: | ||
- | * Creating the blocklists: | ||
- | * Add the website you want to block like this: 127.0.0.1 < | ||
- | |||
- | **Tree:** | ||
- | < | ||
- | CLIENT_DATA | ||
- | ├ setup.ins | ||
- | ├ uninstall.ins | ||
- | ├ delsub.ins | ||
- | ├ blockwebsitelogo.png | ||
- | └ sitelists | ||
- | ├ blocklist1.txt | ||
- | ├ blocklist2.txt | ||
- | ├ blocklist3.txt | ||
- | . | ||
- | . | ||
- | </ | ||
- | |||
- | ==== Setup.ins ==== | ||
- | <code winst> | ||
- | ; Author Soren Birk | ||
- | |||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | |||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $Uninstall$ | ||
- | DefVar $UninstallFile$ | ||
- | DefVar $ChosenList$ | ||
- | DefVar $SiteFile$ | ||
- | DefstringList $WebsitesList$ | ||
- | DefstringList $WebsitesListFiles$ | ||
- | DefstringList $UninstallAll$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | Set $ChosenList$ = GetProductProperty(" | ||
- | Set $SiteFile$ = " | ||
- | Set $Uninstall$ = GetProductProperty(" | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Rediger venligst punkterne herunder | ||
- | ; ---------------------------------------------------------------- | ||
- | Set $ProductId$ | ||
- | ; ---------------------------------------------------------------- | ||
- | comment " | ||
- | ShowBitmap " | ||
- | |||
- | if not ($Uninstall$ = " | ||
- | if FileExists(" | ||
- | comment "Start uninstall sub section" | ||
- | Sub " | ||
- | endif | ||
- | endif | ||
- | |||
- | Message " | ||
- | Set $WebsitesList$ = loadTextFile($SiteFile$) | ||
- | for %website% in $WebsitesList$ do PatchHosts_add " | ||
- | |||
- | |||
- | [PatchHosts_add] | ||
- | setAlias %website% | ||
- | </ | ||
- | ==== Uninstall.ins ==== | ||
- | <code winst> | ||
- | ; Author Soren Birk | ||
- | |||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | |||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $Uninstall$ | ||
- | DefVar $UninstallFile$ | ||
- | DefVar $ChosenList$ | ||
- | DefVar $SiteFile$ | ||
- | DefstringList $WebsitesList$ | ||
- | DefstringList $WebsitesListFiles$ | ||
- | DefstringList $UninstallAll$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | Set $ChosenList$ = GetProductProperty(" | ||
- | Set $SiteFile$ = " | ||
- | Set $Uninstall$ = GetProductProperty(" | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Rediger venligst punkterne herunder | ||
- | ; ---------------------------------------------------------------- | ||
- | Set $ProductId$ | ||
- | ; ---------------------------------------------------------------- | ||
- | comment " | ||
- | ShowBitmap " | ||
- | |||
- | Message " | ||
- | if not ($Uninstall$ = " | ||
- | if FileExists(" | ||
- | comment "Start uninstall sub section" | ||
- | Sub " | ||
- | endif | ||
- | else | ||
- | LogError " | ||
- | isFatalError | ||
- | endif | ||
- | </ | ||
- | ==== Delsub.ins ==== | ||
- | <code winst> | ||
- | ; Author Soren Birk | ||
- | |||
- | Message " | ||
- | |||
- | if ($Uninstall$ = " | ||
- | Message " | ||
- | comment " | ||
- | Set $WebsitesListFiles$ = getOutStreamFromSection (' | ||
- | for %websitelistfile% in $WebsitesListFiles$ do Sub_AddFileToList | ||
- | comment " | ||
- | for %website% in $UninstallAll$ do PatchHosts_remove " | ||
- | else | ||
- | Message " | ||
- | Set $UninstallFile$ = " | ||
- | Set $WebsitesList$ = loadTextFile($UninstallFile$) | ||
- | for %website% in $WebsitesList$ do PatchHosts_remove " | ||
- | endif | ||
- | |||
- | |||
- | [PatchHosts_remove] | ||
- | delAlias %website% | ||
- | |||
- | [DosInAnIcon_sitelists] | ||
- | @echo off | ||
- | dir " | ||
- | |||
- | [Sub_AddFileToList] | ||
- | comment " | ||
- | Set $WebsitesList$ = loadTextFile(" | ||
- | Set $UninstallAll$ = addListToList($UninstallAll$, | ||
- | </ | ||
- | ==== control-file ==== | ||
- | <code winst> | ||
- | [Package] | ||
- | version: 1 | ||
- | depends: | ||
- | |||
- | [Product] | ||
- | type: localboot | ||
- | id: block-websites | ||
- | name: Block Websites | ||
- | description: | ||
- | advice: | ||
- | version: 1.0 | ||
- | priority: 0 | ||
- | licenseRequired: | ||
- | productClasses: | ||
- | setupScript: | ||
- | uninstallScript: | ||
- | updateScript: | ||
- | alwaysScript: | ||
- | onceScript: | ||
- | customScript: | ||
- | userLoginScript: | ||
- | |||
- | [ProductProperty] | ||
- | type: unicode | ||
- | name: websiteslist | ||
- | multivalue: False | ||
- | editable: False | ||
- | description: | ||
- | values: [" | ||
- | default: [" | ||
- | |||
- | [ProductProperty] | ||
- | type: unicode | ||
- | name: uninstall | ||
- | multivalue: False | ||
- | editable: False | ||
- | description: | ||
- | values: [" | ||
- | default: [" | ||
- | </ | ||
- | ==== blocklist.txt example ==== | ||
- | <code winst> | ||
- | 127.0.0.1 www.netflix.com | ||
- | 127.0.0.1 www.facebook.com | ||
- | 127.0.0.1 www.youtube.com | ||
- | </ |