-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All: Initial client cert notification support using systemd
- Loading branch information
1 parent
30669d9
commit cd9bbea
Showing
11 changed files
with
304 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
/.envrc | ||
/geteduroam-cli | ||
/geteduroam-gui | ||
/geteduroam-notifcheck | ||
/shell.nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"time" | ||
|
||
"golang.org/x/exp/slog" | ||
|
||
"github.com/geteduroam/linux-app/internal/config" | ||
"github.com/geteduroam/linux-app/internal/log" | ||
"github.com/geteduroam/linux-app/internal/nm" | ||
"github.com/geteduroam/linux-app/internal/notification" | ||
) | ||
|
||
const usage = `Usage of %s: | ||
-h, --help Prints this help information | ||
This CLI binary is needed for periodically checking for validity and giving notifications when the eduroam connection added by geteduroam is about to expire. | ||
It gives a warning 10 days before expiry, and then every day. You can schedule to start this binary daily yourself or rely on the built-in systemd user timer. | ||
You also need notify-send installed to send the actual notifications. | ||
Log file location: %s | ||
` | ||
|
||
func main() { | ||
program := "geteduroam-notifcheck" | ||
lpath, err := log.Location(program) | ||
if err != nil { | ||
lpath = "N/A" | ||
} | ||
flag.Usage = func() { fmt.Printf(usage, program, lpath) } | ||
flag.Parse() | ||
log.Initialize("geteduroam-notifcheck", false) | ||
cfg, err := config.Load() | ||
if err != nil { | ||
slog.Error("no previous state", "error", err) | ||
return | ||
} | ||
con, err := nm.PreviousCon(cfg.UUID) | ||
if err != nil { | ||
slog.Error("no connection with uuid", "uuid", cfg.UUID, "error", err) | ||
return | ||
} | ||
if con == nil { | ||
slog.Error("connection is nil") | ||
return | ||
} | ||
|
||
if cfg.Validity == nil { | ||
slog.Info("validity is nil") | ||
return | ||
} | ||
valid := *cfg.Validity | ||
now := time.Now() | ||
diff := valid.Sub(now) | ||
days := int(diff.Hours() / 24) | ||
|
||
var text string | ||
if days > 10 { | ||
slog.Info("the connection is still valid for more than 10 days", "days", days) | ||
return | ||
} | ||
if days < 0 { | ||
text = "profile is expired" | ||
} | ||
if days == 0 { | ||
text = "profile expires today" | ||
} | ||
if days > 0 { | ||
text = fmt.Sprintf("profile expires in %d days", days) | ||
} | ||
msg := fmt.Sprintf("Your eduroam %s. Re-run geteduroam to renew the profile", text) | ||
err = notification.Send(msg) | ||
if err != nil { | ||
slog.Error("failed to send notification", "error", err) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.