Improve backwards compatibility with getHandshakeFileFor

The getHandshakeFile function was using "path.Dir(shakesFileName)", which drops the last element of the path.  This is not backwards compatible with prior versions that used the variable as the dir name. In particular this change causes pwnagotchi to store handshakes in /root instead of /root/handshakes.
This commit checks for an existing directory at shakesFileName and will use that as the path instead of taking the parent directory of the path.
This commit is contained in:
Sniffleupagus 2024-11-13 11:33:25 -08:00 committed by GitHub
parent 00854261a4
commit cb5f7679d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net"
"os"
"path"
"github.com/bettercap/bettercap/v2/network"
@ -27,6 +28,11 @@ func (mod *WiFiModule) getHandshakeFileFor(ap *network.AccessPoint) string {
shakesFileName := mod.shakesFile
if !mod.shakesAggregate {
parentDir := path.Dir(shakesFileName)
// check for existing directory at "shakesFileName" for backwards compatibility
fileInfo, err := os.Stat(shakesFileName)
if (err == nil) && (fileInfo.IsDir()) {
parentDir = shakesFileName
}
shakesFileName = path.Join(parentDir, fmt.Sprintf("%s.pcap", ap.PathFriendlyName()))
}
return shakesFileName