wafredir/README.md

115 lines
2.8 KiB
Markdown
Raw Normal View History

2020-05-29 23:45:41 +00:00
# wafredir
2020-05-30 04:10:23 +00:00
HTTP redirect builder for FortiWeb WAFs. Configure your WAF from a spreadsheet.
2020-05-30 04:30:27 +00:00
## Build
2020-05-30 04:10:23 +00:00
1. Install Go from https://golang.org
2. Open a terminal from this directory and run the command:
```shell
go build .
```
2020-05-30 04:30:27 +00:00
## Usage
2020-05-30 04:10:23 +00:00
2020-05-30 04:16:34 +00:00
Run the built executable from a terminal. Default arguments are used if not specifid
2020-05-30 04:30:27 +00:00
#### Arguments of wafredir:
2020-05-30 04:16:34 +00:00
2020-05-30 04:29:53 +00:00
**-action string**
2020-05-30 04:16:34 +00:00
default (config): action can be either 'config' or 'test'. 'config' will read the input csv file and generate FortiOS compliant configuration to create redirection policies. 'test' will read the input csv file and validate that the redirects are actually working by making requests at the source URL and validating a redirect to the destination URL actually occurs.
2020-05-30 04:29:53 +00:00
**-concurrentReq int**
2020-05-30 04:16:34 +00:00
default (8): only used with the action 'test'. Determines the maximum number concurrent HTTP GET requests which can be in flight at any given time.
2020-05-30 04:29:53 +00:00
**-csvfile string**
2020-05-30 04:16:34 +00:00
path to an input csv file. The first column of the file should be the source URL, the second column of the file should be the destination URL, and the third column should be the status code (for example 301 or 302). (default "redirects.csv")
2020-05-30 04:30:27 +00:00
#### Example Usage:
2020-05-30 04:16:34 +00:00
```shell
2020-05-30 04:17:06 +00:00
./wafredir -action="test" -concurrentReq=420 -csvfile="path/to/file.csv"
2020-05-30 04:16:34 +00:00
```
2020-05-30 04:10:23 +00:00
2020-05-30 04:30:27 +00:00
## Example input csv
2020-05-30 04:10:23 +00:00
The first column is the source URL, the second column is the destination URL, the third column is the redirect type, must be either 301 or 302.
```csv
http://myoldsite.com/boomer,https://mynewsite.io/zoomer,301
https://myoldblog.net/blog/post/1,https://mynewblog.ru/cykablyat,302
http://mysite.org,https://yoursite.net/referral/mysite,301
```
2020-05-30 04:30:27 +00:00
## Example output of config mode
2020-05-30 04:10:23 +00:00
```txt
2020-05-30 04:11:18 +00:00
------------------------
config waf url-rewrite url-rewrite-rule
edit "http://myoldsite.com/boomer"
set location https://mynewsite.io/zoomer
set action redirect-301
config match-condition
edit 0
set object http-url
set reg-exp /boomer$
set protocol-filter enable
set HTTP-protocol http
next
end
next
edit "https://myoldblog.net/blog/post/1"
set location https://mynewblog.ru/cykablyat
set action redirect
config match-condition
edit 0
set object http-url
set reg-exp /blog/post/1$
set protocol-filter enable
set HTTP-protocol https
next
end
next
edit "http://mysite.org"
set location https://yoursite.net/referral/mysite
set action redirect-301
config match-condition
edit 0
set object http-url
set reg-exp $
set protocol-filter enable
set HTTP-protocol http
next
end
next
end
config waf url-rewrite url-rewrite-policy
edit "myoldsite.com-redirects"
config rule
edit 0
set url-rewrite-rule-name http://myoldsite.com/boomer
next
end
next
edit "myoldblog.net-redirects"
config rule
edit 0
set url-rewrite-rule-name https://myoldblog.net/blog/post/1
next
end
next
edit "mysite.org-redirects"
config rule
edit 0
set url-rewrite-rule-name http://mysite.org
next
end
next
end
2020-05-30 04:10:23 +00:00
```