Skip to content

Instantly share code, notes, and snippets.

@yosignals
Created February 19, 2023 22:49
Show Gist options
  • Save yosignals/db1c2667fe072d125f840f18dc8ab181 to your computer and use it in GitHub Desktop.
Save yosignals/db1c2667fe072d125f840f18dc8ab181 to your computer and use it in GitHub Desktop.
CS TS Prop Builder
package main
import (
"bufio"
"fmt"
"os"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func main() {
// Create a new Fyne application
myApp := app.New()
// Create a new window
myWindow := myApp.NewWindow("CS TS Prop Builder")
// Create the UI elements
limitsScreenshotValidatedCheckbox := widget.NewCheck("Enable Screenshot Validation",
nil)
limitsScreenshotDataMaxlenEntry := widget.NewEntry()
limitsScreenshotUserMaxlenEntry := widget.NewEntry()
limitsScreenshotTitleMaxlenEntry := widget.NewEntry()
limitsScreenshotDiskusedPercentEntry := widget.NewEntry()
limitsKeystrokesValidatedCheckbox := widget.NewCheck("Enable Keystroke Validation",
nil)
limitsKeystrokesDataMaxlenEntry := widget.NewEntry()
limitsKeystrokesUserMaxlenEntry := widget.NewEntry()
limitsKeystrokesTitleMaxlenEntry := widget.NewEntry()
limitsKeystrokesDiskusedPercentEntry := widget.NewEntry()
limitsBeaconsMaxEntry := widget.NewEntry()
limitsBeaconRatePeriodEntry := widget.NewEntry()
limitsBeaconRateMaxperperiodEntry := widget.NewEntry()
limitsBeaconRateDisabledurationEntry := widget.NewEntry()
limitsBeaconsXSSValidatedCheckbox := widget.NewCheck("Perform XSS Validation on New Beacon Metadata", nil)
saveButton := widget.NewButton("Save", func() {
// Open the settings file for writing
file, err := os.OpenFile("settings.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC,
0644)
if err != nil {
fmt.Println("Error opening settings file:", err)
return
}
defer file.Close()
// Write the settings to the file
writer := bufio.NewWriter(file)
if limitsScreenshotValidatedCheckbox.Checked {
fmt.Fprintln(writer, "limits.screenshot_validated=true")
} else {
fmt.Fprintln(writer, "limits.screenshot_validated=false")
}
fmt.Fprintf(writer, "limits.screenshot_data_maxlen=%s\n", limitsScreenshotDataMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.screenshot_user_maxlen=%s\n", limitsScreenshotUserMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.screenshot_title_maxlen=%s\n", limitsScreenshotTitleMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.screenshot_diskused_percent=%s\n", limitsScreenshotDiskusedPercentEntry.Text)
if limitsKeystrokesValidatedCheckbox.Checked {
fmt.Fprintln(writer, "limits.keystrokes_validated=true")
} else {
fmt.Fprintln(writer, "limits.keystrokes_validated=false")
}
fmt.Fprintf(writer, "limits.keystrokes_data_maxlen=%s\n", limitsKeystrokesDataMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.keystrokes_user_maxlen=%s\n", limitsKeystrokesUserMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.keystrokes_title_maxlen=%s\n", limitsKeystrokesTitleMaxlenEntry.Text)
fmt.Fprintf(writer, "limits.keystrokes_diskused_percent=%s\n", limitsKeystrokesDiskusedPercentEntry.Text)
fmt.Fprintf(writer, "limits.beacons_max=%s\n", limitsBeaconsMaxEntry.Text)
fmt.Fprintf(writer, "limits.beacon_rate_period=%s\n", limitsBeaconRatePeriodEntry.Text)
fmt.Fprintf(writer, "limits.beacon_rate_maxperperiod=%s\n", limitsBeaconRateMaxperperiodEntry.Text)
fmt.Fprintf(writer, "limits.beacon_rate_disableduration=%s\n", limitsBeaconRateDisabledurationEntry.Text)
if limitsBeaconsXSSValidatedCheckbox.Checked {
fmt.Fprintln(writer, "limits.beacons_xssvalidated=true")
} else {
fmt.Fprintln(writer, "limits.beacons_xssvalidated=false")
}
writer.Flush()
// Show a message to the user
fyne.CurrentApp().SendNotification(&fyne.Notification{
Title: "Settings saved",
Content: "The settings have been saved to settings.txt",
})
})
// Create the layout
content := container.NewVBox(
widget.NewLabel("Screenshot Validation:"),
container.NewHBox(
limitsScreenshotValidatedCheckbox,
),
widget.NewLabel("Screenshot Data Max Length:"),
limitsScreenshotDataMaxlenEntry,
widget.NewLabel("Screenshot User Max Length:"),
limitsScreenshotUserMaxlenEntry,
widget.NewLabel("Screenshot Title Max Length:"),
limitsScreenshotTitleMaxlenEntry,
widget.NewLabel("Screenshot Disk Used Percent:"),
limitsScreenshotDiskusedPercentEntry,
widget.NewLabel("Keystroke Validation:"),
container.NewHBox(
limitsKeystrokesValidatedCheckbox,
),
widget.NewLabel("Keystrokes Data Max Length:"),
limitsKeystrokesDataMaxlenEntry,
widget.NewLabel("Keystrokes User Max Length:"),
limitsKeystrokesUserMaxlenEntry,
widget.NewLabel("Keystrokes Title Max Length:"),
limitsKeystrokesTitleMaxlenEntry,
widget.NewLabel("Keystrokes Disk Used Percent:"),
limitsKeystrokesDiskusedPercentEntry,
widget.NewLabel("Beacons Max:"),
limitsBeaconsMaxEntry,
widget.NewLabel("Beacon Rate Period:"),
limitsBeaconRatePeriodEntry,
widget.NewLabel("Beacon Rate Max Per Period:"),
limitsBeaconRateMaxperperiodEntry,
widget.NewLabel("Beacon Rate Disable Duration:"),
limitsBeaconRateDisabledurationEntry,
widget.NewLabel("Beacons XSS Validated:"),
container.NewHBox(
limitsBeaconsXSSValidatedCheckbox,
),
saveButton,
)
// Set the window content
myWindow.SetContent(content)
// Show the window
myWindow.ShowAndRun()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment