Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from wufeifei/develop
Browse files Browse the repository at this point in the history
add author for rule
  • Loading branch information
FeeiCN authored Sep 10, 2016
2 parents 0363c2e + d6bb714 commit 5a979a8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
11 changes: 4 additions & 7 deletions app/controller/backend/RulesController.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@web.route(ADMIN_URL + '/rules/<int:page>', methods=['GET'])
@login_required
def rules(page):

per_page = 10
cobra_rules = CobraRules.query.order_by(CobraRules.id.desc()).limit(per_page).offset((page - 1) * per_page).all()
cobra_vuls = CobraVuls.query.all()
Expand Down Expand Up @@ -79,10 +78,9 @@ def rules(page):
@web.route(ADMIN_URL + '/add_new_rule', methods=['GET', 'POST'])
@login_required
def add_new_rule():

if request.method == 'POST':
vc = ValidateClass(request, 'vul_type', 'language', 'regex_location', 'regex_repair', 'repair_block',
'description', 'repair', 'level')
'description', 'repair', 'author', 'level')
ret, msg = vc.check_args()
if not ret:
return jsonify(tag="danger", msg=msg)
Expand All @@ -96,6 +94,7 @@ def add_new_rule():
block_repair=vc.vars.repair_block,
description=vc.vars.description,
repair=vc.vars.repair,
author=vc.vars.author,
status=1,
level=vc.vars.level,
created_at=current_time,
Expand All @@ -121,7 +120,6 @@ def add_new_rule():
@web.route(ADMIN_URL + '/del_rule', methods=['POST'])
@login_required
def del_rule():

vc = ValidateClass(request, "rule_id")
vc.check_args()
vul_id = vc.vars.rule_id
Expand All @@ -141,11 +139,9 @@ def del_rule():
@web.route(ADMIN_URL + '/edit_rule/<int:rule_id>', methods=['GET', 'POST'])
@login_required
def edit_rule(rule_id):

if request.method == 'POST':

vc = ValidateClass(request, "vul_type", "language", "regex_location", "regex_repair", "block_repair",
"description", "rule_id", "repair", "status", "level")
vc = ValidateClass(request, "vul_type", "language", "regex_location", "regex_repair", "block_repair", "description", "rule_id", "repair", "author", "status", "level")
ret, msg = vc.check_args()

if not ret:
Expand All @@ -159,6 +155,7 @@ def edit_rule(rule_id):
r.regex_repair = vc.vars.regex_repair
r.description = vc.vars.description
r.repair = vc.vars.repair
r.author = vc.vars.author
r.status = vc.vars.status
r.level = vc.vars.level
r.updated_at = datetime.datetime.now()
Expand Down
4 changes: 3 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ class CobraRules(db.Model):
block_repair = db.Column(TINYINT(2), nullable=False, default=None)
description = db.Column(db.String(256), nullable=False, default=None)
repair = db.Column(db.String(512), nullable=False, default=None)
author = db.Column(db.String(56), nullable=False, default=None)
status = db.Column(TINYINT(2), nullable=False, default=None)
level = db.Column(TINYINT(2), nullable=False, default=None)
created_at = db.Column(db.DateTime, nullable=False, default=None)
updated_at = db.Column(db.DateTime, nullable=False, default=None)

def __init__(self, vul_id, language, regex_location, regex_repair, block_repair, description, repair, status, level, created_at=None, updated_at=None):
def __init__(self, vul_id, language, regex_location, regex_repair, block_repair, description, repair, status, author, level, created_at=None, updated_at=None):
self.vul_id = vul_id
self.language = language
self.regex_location = regex_location
Expand All @@ -98,6 +99,7 @@ def __init__(self, vul_id, language, regex_location, regex_repair, block_repair,
self.description = description
self.repair = repair
self.status = status
self.author = author
self.level = level
self.created_at = created_at
self.updated_at = updated_at
Expand Down
12 changes: 12 additions & 0 deletions app/templates/asset/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ $("#main-div").delegate("span", "click", function () {
var regex_repair = $("#regex-repair").val();
var block_reapir = $("#repair-block:checked").val();
var repair = $("#repair").val();
var author = $("input[name=author]").val();
var status = $("#status:checked").val();
var level = $("#level:checked").val();

Expand Down Expand Up @@ -165,6 +166,10 @@ $("#main-div").delegate("span", "click", function () {
showAlert('danger', 'repair can not be blank.', '#edit-rule-result');
return false;
}
if (!author || author == "") {
showAlert('danger', 'author can not be blank.', '#edit-rule-result');
return false;
}
if (!status || status == "") {
showAlert('danger', 'status error.', '#edit-rule-result');
return false;
Expand All @@ -184,6 +189,7 @@ $("#main-div").delegate("span", "click", function () {
'description': description,
'rule_id': cid,
'repair': repair,
'author': author,
'status': status,
'level': level
};
Expand Down Expand Up @@ -568,6 +574,7 @@ $("#show_all_rules").click(function () {
var repair_block = $("#repair-block:checked").val();
var description = $("#description").val();
var repair = $("#repair").val();
var author = $("input[name=author]").val();
var level = $("#level:checked").val();

// check data
Expand Down Expand Up @@ -599,6 +606,10 @@ $("#show_all_rules").click(function () {
showAlert('danger', 'repair can not be blank.', '#add-new-rule-result');
return false;
}
if (!author || author == "") {
showAlert('danger', 'author can not be blank.', '#add-new-rule-result');
return false;
}
if (!level || level == "") {
showAlert('danger', 'level can not be blank.', "#add-new-rule-result");
return false;
Expand All @@ -613,6 +624,7 @@ $("#show_all_rules").click(function () {
'repair_block': repair_block,
'description': description,
'repair': repair,
'author': author,
'level': level
};
$.post('add_new_rule', data, function (res) {
Expand Down
24 changes: 18 additions & 6 deletions app/templates/backend/rule/add_new_rule.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<form role="form">
<div style="margin-top: 20px;">
<div class="form-group col-md-3" style="padding-left: 0;">
<div class="form-group col-md-2">
<label for="vul_type">Author</label>
<input type="text" name="author" class="form-control" value="" placeholder="多个以,分隔">
</div>
<div class="form-group col-md-4" style="padding-left: 0;">
<label for="vul_id">Vul type</label>
<select id="vul_type" class="form-control">
{% for vul in data.vul_type %}
Expand All @@ -10,7 +13,7 @@
{% endfor %}
</select>
</div>
<div class="form-group col-md-3" style="padding-right: 0;">
<div class="form-group col-md-6" style="padding-right: 0;">
<label for="add-rule-language">Language</label>
<select id="add-rule-language" class="form-control">
{% for lang in data.languages %}
Expand All @@ -20,7 +23,17 @@
{% endfor %}
</select>
</div>
<div class="form-group col-md-3" style="padding-left: 50px">

<div class="form-group col-md-4">
<label for="status">Status</label>
<label class="radio" style="padding-left: 25px;">
<input type="radio" name="status" id="status" value="1"> On
</label>
<label class="radio" style="padding-left: 25px;">
<input type="radio" name="status" id="status" value="0"> Off
</label>
</div>
<div class="form-group col-md-4" style="padding-left: 50px">
<label>Repair Block</label>
<label class="radio" style="padding-left: 25px;">
<input type="radio" name="repair-block" id="repair-block" value="0">
Expand All @@ -31,7 +44,7 @@
<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span> Function Down
</label>
</div>
<div class="form-group col-md-3">
<div class="form-group col-md-4">
<label>Level</label>
<label class="radio" style="padding-left: 20px;">
<input type="radio" name="level" id="level" value="1"> Low
Expand All @@ -43,7 +56,6 @@
<input type="radio" name="level" id="level" value="3" checked> High
</label>
</div>
</div>
<div class="form-group">
<label for="regex-location">Regex Location</label>
<textarea class="form-control" id="regex-location" placeholder="Please input location regex."></textarea>
Expand Down
10 changes: 7 additions & 3 deletions app/templates/backend/rule/edit_rule.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<form role="form">
<div class="form-group col-md-6" style="padding-left: 0">
<div class="form-group col-md-2">
<label for="vul_type">Author</label>
<input type="text" name="author" class="form-control" value="{{ data.rule.author }}" placeholder="多个以,分隔">
</div>
<div class="form-group col-md-4" style="padding-left: 0">
<label for="vul_type">Vul type</label>
<select id="vul_type" class="form-control">
{% for vul in data.all_vuls %}
Expand Down Expand Up @@ -72,7 +76,7 @@

<div id="edit-rule-result" hidden></div>
<div style="text-align: center">
<button type="button" class="btn btn-success" id="edit-rule-button" style="width: 150px;margin: 20px;">Save</button>
<button type="button" class="btn btn-primary" id="back-rule-button" style="width: 150px;margin: 20px;">Back</button>
<button type="button" class="btn btn-success" id="edit-rule-button" style="width: 150px;margin: 20px;">Save</button>
<button type="button" class="btn btn-primary" id="back-rule-button" style="width: 150px;margin: 20px;">Back</button>
</div>
</form>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ smmap==0.9.0
SQLAlchemy==1.0.13
visitor==0.1.3
Werkzeug==0.11.9
ConcurrentLogHandler==0.9.1

0 comments on commit 5a979a8

Please sign in to comment.