2019-12-07 19:25:39 +00:00
package main
import (
"github.com/atotto/clipboard"
"github.com/getlantern/systray"
"github.com/pkg/browser"
"postwoman.io/proxy/icons"
2019-12-18 18:04:25 +00:00
"postwoman.io/proxy/inputbox"
2019-12-07 23:24:21 +00:00
"postwoman.io/proxy/libproxy"
"postwoman.io/proxy/notifier"
2019-12-07 19:25:39 +00:00
) ;
2020-06-08 23:34:55 +00:00
var VersionName string ;
var VersionCode string ;
2019-12-07 19:25:39 +00:00
var mStatus * systray . MenuItem ;
var mCopyAccessToken * systray . MenuItem ;
func main ( ) {
systray . Run ( onReady , onExit ) ;
}
func onReady ( ) {
systray . SetIcon ( icon . Data ) ;
2020-06-08 23:34:55 +00:00
systray . SetTooltip ( "Proxywoman v" + VersionName + " (" + VersionCode + ") - created by NBTX" ) ;
2019-12-07 19:25:39 +00:00
/** Set up menu items. **/
// Status
mStatus = systray . AddMenuItem ( "Starting..." , "" ) ;
mStatus . Disable ( ) ;
mCopyAccessToken = systray . AddMenuItem ( "Copy Access Token..." , "" ) ;
mCopyAccessToken . Disable ( ) ;
systray . AddSeparator ( ) ;
// Open Postwoman Interface
mOpenPostwoman := systray . AddMenuItem ( "Open Postwoman" , "" ) ;
systray . AddSeparator ( ) ;
// View Help
mViewHelp := systray . AddMenuItem ( "Help..." , "" ) ;
// Set Proxy Authentication Token
mSetAccessToken := systray . AddMenuItem ( "Set Access Token..." , "" ) ;
// Check for Updates
mUpdateCheck := systray . AddMenuItem ( "Check for Updates..." , "" ) ;
systray . AddSeparator ( ) ;
// Quit Proxy
2020-06-08 20:50:58 +00:00
mQuit := systray . AddMenuItem ( "Quit Proxywoman" , "" ) ;
2019-12-07 19:25:39 +00:00
/** Start proxy server. **/
go runPostwomanProxy ( ) ;
/** Wait for menu input. **/
for {
select {
case <- mOpenPostwoman . ClickedCh :
_ = browser . OpenURL ( "https://postwoman.io/" ) ;
case <- mCopyAccessToken . ClickedCh :
2019-12-07 23:24:21 +00:00
_ = clipboard . WriteAll ( libproxy . GetAccessToken ( ) ) ;
2020-06-08 20:50:58 +00:00
_ = notifier . Notify ( "Proxywoman" , "Proxy Access Token copied..." , "The Proxy Access Token has been copied to your clipboard." , notifier . GetIcon ( ) ) ;
2019-12-07 19:25:39 +00:00
case <- mViewHelp . ClickedCh :
2020-06-08 20:50:58 +00:00
_ = browser . OpenURL ( "https://github.com/postwoman-io/proxywoman/wiki" ) ;
2019-12-07 19:25:39 +00:00
case <- mSetAccessToken . ClickedCh :
2020-06-08 20:50:58 +00:00
newAccessToken , success := inputbox . InputBox ( "Proxywoman" , "Please enter the new Proxy Access Token...\n(Leave this blank to disable access checks.)" , "" ) ;
2019-12-07 19:25:39 +00:00
if success {
2019-12-07 23:24:21 +00:00
libproxy . SetAccessToken ( newAccessToken ) ;
2019-12-18 18:04:25 +00:00
if len ( newAccessToken ) == 0 {
2020-06-08 20:50:58 +00:00
_ = notifier . Notify ( "Proxywoman" , "Proxy Access check disabled." , "**Anyone can access your proxy server!** The Proxy Access Token check has been disabled." , notifier . GetIcon ( ) ) ;
2019-12-07 23:24:21 +00:00
} else {
2020-06-08 20:50:58 +00:00
_ = notifier . Notify ( "Proxywoman" , "Proxy Access Token updated..." , "The Proxy Access Token has been updated." , notifier . GetIcon ( ) ) ;
2019-12-07 23:24:21 +00:00
}
2019-12-07 19:25:39 +00:00
}
case <- mUpdateCheck . ClickedCh :
// TODO: Add update check.
_ = browser . OpenURL ( "https://github.com/NBTX/postwoman-proxy" ) ;
case <- mQuit . ClickedCh :
systray . Quit ( ) ;
return ;
}
}
}
func onExit ( ) {
}
func runPostwomanProxy ( ) {
2019-12-07 23:53:44 +00:00
libproxy . Initialize ( "postwoman" , "127.0.0.1:9159" , onProxyStateChange , true , nil ) ;
2019-12-07 19:25:39 +00:00
}
func onProxyStateChange ( status string , isListening bool ) {
mStatus . SetTitle ( status ) ;
if isListening {
mCopyAccessToken . Enable ( ) ;
}
}