Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

增加支持post, put, delete方法监控 #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ Web组件主要用于
# set $GOPATH and $GOROOT
mkdir -p $GOPATH/src/github.com/urlooker
cd $GOPATH/src/github.com/urlooker
git clone https://github.com/URLooker/web.git
git clone https://github.com/xiaolezheng/web.git
cd web
go get ./...
./control build
2 changes: 2 additions & 0 deletions cron/fetcher.go
Original file line number Diff line number Diff line change
@@ -80,6 +80,8 @@ func newDetectedItem(s *model.Strategy, ip string, idc string) g.DetectedItem {
Sid: s.Id,
Keywords: s.Keywords,
Data: s.Data,
Method: s.Method,
PostData: s.PostData,
Tag: s.Tag,
ExpectCode: s.ExpectCode,
Timeout: s.Timeout,
2 changes: 2 additions & 0 deletions g/var.go
Original file line number Diff line number Diff line change
@@ -14,11 +14,13 @@ type DetectedItem struct {
Sid int64 `json:"sid"`
Domain string `json:"domain"`
Target string `json:"target"`
Method string `json:"method"`
Ip string `json:"ip"`
Keywords string `json:"keywords"`
Timeout int `json:"timeout"`
Creator string `json:"creator"`
Data string `json:"data"`
PostData string `json:"post_data`
Tag string `json:"tag"`
ExpectCode string `json:"expect_code"`
Idc string `json:"idc"`
4 changes: 4 additions & 0 deletions handler/stra_handler.go
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ func AddStrategyPost(w http.ResponseWriter, r *http.Request) {
var s = model.Strategy{}
s.Creator = me.Name
s.Url = url
s.Method = param.String(r, "method", "GET")
s.ExpectCode = param.String(r, "expect_code", "200")
s.Timeout = param.Int(r, "timeout", 3000)
s.MaxStep = param.Int(r, "max_step", 3)
@@ -54,6 +55,7 @@ func AddStrategyPost(w http.ResponseWriter, r *http.Request) {
s.Note = param.String(r, "note", "")
s.Keywords = param.String(r, "keywords", "")
s.Data = param.String(r, "data", "")
s.PostData = param.String(r, "post_data", "")
s.Tag = tagStr

_, err = s.Add()
@@ -110,6 +112,7 @@ func UpdateStrategy(w http.ResponseWriter, r *http.Request) {

s.Creator = username
s.Url = url
s.Method = param.String(r, "method", "GET")
s.ExpectCode = param.String(r, "expect_code", "200")
s.Timeout = param.Int(r, "timeout", 3000)
s.MaxStep = param.Int(r, "max_step", 3)
@@ -118,6 +121,7 @@ func UpdateStrategy(w http.ResponseWriter, r *http.Request) {
s.Note = param.String(r, "note", "")
s.Keywords = param.String(r, "keywords", "")
s.Data = param.String(r, "data", "")
s.PostData = param.String(r, "post_data", "")
s.Tag = tagStr

err = s.Update()
2 changes: 2 additions & 0 deletions model/strategy.go
Original file line number Diff line number Diff line change
@@ -9,12 +9,14 @@ import (
type Strategy struct {
Id int64 `json:"id"`
Url string `json:"url"`
Method string `json:"method"`
Keywords string `json:"keywords"`
Timeout int `json:"timeout"`
Creator string `json:"creator"`
ExpectCode string `json:"expect_code"`
Note string `json:"note"`
Data string `json:"data"`
PostData string `json:"post_data"`
Tag string `json:"tag"`
MaxStep int `json:"max_step"`
Times int `json:"times"`
2 changes: 2 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -5,10 +5,12 @@ DROP TABLE IF EXISTS `strategy`;
CREATE TABLE `strategy` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`url` varchar(1024) NOT NULL,
`method` varchar(10) NOT NULL DEFAULT 'GET',
`keywords` varchar(255) NOT NULL DEFAULT '',
`timeout` varchar(255) NOT NULL DEFAULT '',
`creator` varchar(255) NOT NULL DEFAULT '',
`data` varchar(255) NOT NULL DEFAULT '',
`post_data` varchar(1000) NOT NULL DEFAULT '',
`expect_code` varchar(255) NOT NULL DEFAULT '',
`tag` varchar(255) NOT NULL DEFAULT '',
`note` varchar(255) NOT NULL DEFAULT '',
10 changes: 8 additions & 2 deletions static/js/g.js
Original file line number Diff line number Diff line change
@@ -60,9 +60,11 @@ function get_strategy(id){
url = "/strategy/" + id
$.post(url, {}, function(res){
$("#url").val(res.data.url)
$("#method").val(res.data.method)
$("#expect_code").val(res.data.expect_code)
$("#timeout").val(res.data.timeout)
$("#data").val(res.data.data)
$("#post_data").val(res.data.post_data)
$("#keywords").val(res.data.keywords)
$("#note").val(res.data.note)
$("#times").val(res.data.times)
@@ -74,6 +76,7 @@ function get_strategy(id){
function update_strategy(id){
$.post('/strategy/' + id + '/edit', {
"url": $('#url').val(),
"method": $('#method').val(),
"expect_code": $('#expect_code').val(),
"timeout": $('#timeout').val(),
"times": $('#times').val(),
@@ -82,7 +85,8 @@ function update_strategy(id){
"tags": $('#tags').val(),
"note": $('#note').val(),
"keywords": $('#keywords').val(),
"data": $('#data').val()
"data": $('#data').val(),
"post_data": $('#post_data').val()
}, function(json) {
handle_json(json, function (){location.reload()})
});
@@ -91,6 +95,7 @@ function update_strategy(id){
function add_strategy() {
$.post("/strategy/add", {
"url": $('#url').val(),
"method": $('#method').val(),
"expect_code": $('#expect_code').val(),
"timeout": $('#timeout').val(),
"times": $('#times').val(),
@@ -99,7 +104,8 @@ function add_strategy() {
"tags": $('#tags').val(),
"note": $('#note').val(),
"keywords": $('#keywords').val(),
"data": $('#data').val()
"data": $('#data').val(),
"post_data": $('#post_data').val()
}, function(json){
handle_json(json, function(){
location.href=$("/").val();
16 changes: 16 additions & 0 deletions views/strategy/create.html
Original file line number Diff line number Diff line change
@@ -18,6 +18,17 @@
<textarea type="text" class="form-control target" id="url" placeholder="http://blog.x2know.org 支持批量,每行一个"/></textarea>
</div>
</div>
<div class='form-group'>
<label class='control-label' for='TargetNeedToMonitor'>方法</label>
<div class="input-group">
<select id="method">
<option value="GET" selected>GET</option>
<option value="PUT">PUT</option>
<option value="POST">POST</option>
<option value="DELETE">DELETE</option>
</select>
</div>
</div>
<div class='form-group'>
<label for='TargetNeedToMonitor'>期望返回状态码</label>
<div class='controls'>
@@ -69,6 +80,11 @@ <h4 class="panel-title">
<input class='form-control' type='text' placeholder='监控要登录状态访问的url时填写' id='data'></input>
</div>

<div class='form-group'>
<label for='TargetNeedToMonitor'>提交数据</label>
<input class='form-control' type='text' placeholder='提交的数据,method为非GET时' id='post_data'></input>
</div>

<div class='form-group'>
<label for='TargetNeedToMonitor'>tags</label>
<textarea type="text" class="form-control " id="tags" value="" placeholder="向falcon推送数据时使用, 形式为 a=b 每行一个"/></textarea>
16 changes: 15 additions & 1 deletion views/strategy/edit.html
Original file line number Diff line number Diff line change
@@ -22,6 +22,17 @@
<textarea type="text" class="form-control target" id="url" placeholder="http://blog.x2know.org"/></textarea>
</div>
</div>
<div class='form-group'>
<label class='control-label' for='TargetNeedToMonitor'>方法</label>
<div class="input-group">
<select id="method">
<option value="GET">GET</option>
<option value="PUT">PUT</option>
<option value="POST">POST</option>
<option value="DELETE">DELETE</option>
</select>
</div>
</div>
<div class='form-group'>
<label for='TargetNeedToMonitor'>期望返回状态码(可填1个数字:4 表示4** 2个数字40 表示40* 3个数字403)</label>
<div class='controls'>
@@ -72,7 +83,10 @@ <h4 class="panel-title">
<label for='TargetNeedToMonitor'>Cookie</label>
<input class='form-control' type='text' placeholder='需要POST的数据(get方法不用填写)' id='data'></input>
</div>

<div class='form-group'>
<label for='TargetNeedToMonitor'>提交数据</label>
<input class='form-control' type='text' placeholder='提交的数据,method为非GET时' id='post_data'></input>
</div>
<div class='form-group'>
<label for='TargetNeedToMonitor'>tags</label>
<textarea type="text" class="form-control " id='tags' value="" placeholder="向falcon推送数据时使用, 形式为 a=b 每行一个"/></textarea>