5 Commits

Author SHA1 Message Date
idk
c67d91fa2c do a new release 2020-01-21 21:36:28 -05:00
idk
37c918804a do a new release 2020-01-21 21:36:06 -05:00
idk
f528ab6e38 add checkfirewallport 2020-01-21 21:33:10 -05:00
idk
138f1b4882 use user.Current to determine user when not root 2019-10-27 13:34:19 -04:00
idk
2595c6833a windows fixes 2019-10-26 23:13:06 -04:00
4 changed files with 52 additions and 11 deletions

View File

@ -2,20 +2,17 @@
GO111MODULE=on
VERSION=0.0.01
VERSION=0.0.05
USER_GH=eyedeekay
version:
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION) -d "I2P Router Checking CLI utility"
fmt:
gofmt -w *.go canal/main.go
GO_COMPILER_OPTS = -a -tags netgo -ldflags '-w -extldflags "-static"'
build: fmt test clean
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS) && \
GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS)
cd ./i2cpcheck && GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
test:
go test -v

View File

@ -3,8 +3,11 @@ package checki2p
import (
"fmt"
"github.com/eyedeekay/go-i2cp"
"io/ioutil"
"log"
"os"
"os/user"
"runtime"
"strings"
)
@ -25,6 +28,13 @@ func checkfileexists(path string) bool {
return false
}
func home() string {
if runtime.GOOS == "windows" {
return "\\i2p"
}
return "/.i2p"
}
var (
I2CP_HOST string = ""
I2CP_PORT string = ""
@ -32,6 +42,7 @@ var (
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
LINUX_SYSTEM_LOCATION string = "/usr/bin/i2prouter"
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
I2P_ASUSER_HOME_LOCATION string = inithome(home())
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
)
@ -90,9 +101,8 @@ func UserFind() string {
str := os.Getenv("SUDO_USER")
return str
}
if str, err := os.UserHomeDir(); err == nil {
x := strings.Split(str, "/")
return strings.Replace(x[len(x)-1], "/", "", -1)
if un, err := user.Current(); err == nil {
return un.Name
}
return ""
}
@ -103,7 +113,7 @@ func UserFind() string {
func CheckI2PUserName() (string, error) {
if checkfileexists(I2PD_WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2pd router detected")
return "i2pd.exe", nil
return "i2pd", nil
}
if checkfileexists(I2PD_LINUX_SYSTEM_LOCATION) {
log.Println("Linux i2pd router detected")
@ -111,7 +121,7 @@ func CheckI2PUserName() (string, error) {
}
if checkfileexists(WINDOWS_DEFAULT_LOCATION) {
log.Println("Windows i2p router detected")
return "i2psvc.exe", nil
return "i2psvc", nil
}
if checkfileexists(LINUX_SYSTEM_LOCATION) {
log.Println("Linux i2p router detected")
@ -127,3 +137,22 @@ func CheckI2PUserName() (string, error) {
}
return "", nil
}
// GetFirewallPort finds the configured UDP port of your I2P router to help
// configure firewalls. It does this by finding the router.config and reading
// it.
func GetFirewallPort() (string, error) {
log.Println(I2P_ASUSER_HOME_LOCATION)
file, err := ioutil.ReadFile(I2P_ASUSER_HOME_LOCATION + "/router.config")
if err != nil {
return "", err
}
lines := strings.Split(string(file), "\n")
for index, line := range lines {
if strings.HasPrefix(line, "i2np.udp.port") {
log.Println(line, index)
return strings.Replace(line, "i2np.udp.port=", "", -1), nil
}
}
return "", fmt.Errorf("Improperly formed router.config file")
}

View File

@ -27,3 +27,11 @@ func TestRouter(t *testing.T) {
t.Log("I2P is in a default location, user feedback is needed")
}
}
func TestFirewallPort(t *testing.T) {
port, err := GetFirewallPort()
if err != nil {
t.Fatal(err)
}
t.Log("Port was", port)
}

View File

@ -17,6 +17,12 @@ func main() {
} else {
log.Println("I2P is not running, further testing is needed")
}
firewallport, err := checki2p.CheckFirewallPort()
if err != nil {
log.Fatal(err)
}
log.Println("I2P's firewall port is:", firewallport)
ok, err = checki2p.CheckI2PIsInstalledDefaultLocation()
if err != nil {
log.Fatal(err)
@ -28,4 +34,5 @@ func main() {
log.Println("I2P is not a default location, user feedback is needed")
os.Exit(1)
}
}