Skip to content

Commit

Permalink
create panic handler for internal error
Browse files Browse the repository at this point in the history
  • Loading branch information
0c34 committed Oct 25, 2017
1 parent e74790d commit 29b4c40
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
6 changes: 4 additions & 2 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ body {
height: 100%;
background: #f4f4f4;
}
.header{

.header {
background-image: url("http://localhost:8082/public/img/header.png");
width: 1140px;
height: 100px;
margin-bottom: 20px;
}

.nav-side-menu {
overflow: auto;
font-family: verdana;
Expand All @@ -22,7 +24,6 @@ body {
border: 1px solid #428bca;
color: #000;
border-radius: 4px;
margin-bottom: 20px
}

.nav-side-menu .brand {
Expand Down Expand Up @@ -237,6 +238,7 @@ body {

.footer {
position: relative;
margin-top: 10px;
bottom: 0;
/* width: 100%; */
/* Set the fixed height of the footer here */
Expand Down
16 changes: 4 additions & 12 deletions templates/template.sqli.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
{{define "template.sqli"}}
{{template "template.header" .}}
{{template "template.sidebar" .}}
{{define "template.sqli"}} {{template "template.header" .}} {{template "template.sidebar" .}}
<div class="col-md-9">
<div class="panel panel-primary">
<div class="panel-heading">SQL Injection</div>
<div class="panel-body">
<div class="pnl">
<span class="subheader">SQL Injection Vulnerability</span>
<!-- <span class="subheader">SQL Injection Vulnerability</span> -->
<p>
data :
{{.error}}
{{.name}}
{{.city}}
{{.number}}
{{.uid}}
data : {{.error}} {{.name}} {{.city}} {{.number}} {{.uid}}

</p>
</div>
</div>
</div>
</div>
{{template "template.footer"}}
{{ end }}
{{template "template.footer"}} {{ end }}
23 changes: 23 additions & 0 deletions util/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package middleware
import(
"log"
"time"
"errors"
"net/http"

"govwa/user/session"
Expand Down Expand Up @@ -36,6 +37,28 @@ func (this *Class) AuthCheck(h httprouter.Handle) httprouter.Handle {
return
}

h(w, r, ps)
}
}

func (this *Class)CapturePanic(h httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var err error
defer func() {
r := recover()
if r != nil {
switch t := r.(type) {
case string:
err = errors.New(t)
case error:
err = t
default:
err = errors.New("Unknown error")
}
log.Println(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}()
h(w, r, ps)
}
}
2 changes: 1 addition & 1 deletion vulnerability/sqli/sqli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func New()SQLI{

func (self SQLI)SetRouter(r *httprouter.Router){
mw := middleware.New()
r.GET("/sqli1", mw.AuthCheck(sqli1Handler))
r.GET("/sqli1", mw.CapturePanic(mw.AuthCheck(sqli1Handler)))
}

func sqli1Handler(w http.ResponseWriter, r *http.Request, _ httprouter.Params){
Expand Down

0 comments on commit 29b4c40

Please sign in to comment.