Skip to content

Commit

Permalink
Remove files on vpn exit
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhuff386 committed Aug 2, 2015
1 parent b5c68bd commit 447b861
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions service/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type OutputData struct {
}

type Profile struct {
remPaths []string `json:"-"`
cmd *exec.Cmd `json:"-"`
Id string `json:"id"`
Data string `json:"-"`
Expand Down Expand Up @@ -277,11 +278,16 @@ func (p *Profile) clearStatus(start time.Time) {
p.ClientAddr = ""
p.ServerAddr = ""
p.update()

for _, path := range p.remPaths {
os.Remove(path)
}
}()
}

func (p *Profile) Start(timeout bool) (err error) {
start := time.Now()
p.remPaths = []string{}

p.Status = "connecting"
p.Timestamp = start.Unix()
Expand All @@ -300,6 +306,7 @@ func (p *Profile) Start(timeout bool) (err error) {
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, confPath)

var authPath string
if p.Username != "" || p.Password != "" {
Expand All @@ -308,6 +315,7 @@ func (p *Profile) Start(timeout bool) (err error) {
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, authPath)
}

p.update()
Expand All @@ -324,24 +332,31 @@ func (p *Profile) Start(timeout bool) (err error) {
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, upPath)

downPath, e := p.writeDown()
if e != nil {
err = e
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, downPath)

preDownPath, e := p.writePreDown()
if e != nil {
err = e
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, preDownPath)

blockPath, e := p.writeBlock()
if e != nil {
err = e
p.clearStatus(start)
return
}
p.remPaths = append(p.remPaths, blockPath)

args = append(args, "--script-security", "2",
"--up", upPath,
Expand Down

0 comments on commit 447b861

Please sign in to comment.