Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
b46f04344d | |||
dbb85e950b | |||
e6e48920d8 | |||
acc8d4e0f5 | |||
750ce7e6d8 | |||
643d7991fd | |||
44d5506a8f | |||
4d5f344b88 | |||
759a5aec9c | |||
a3982e2904 | |||
5dea25453c | |||
775052865c | |||
c67d91fa2c | |||
37c918804a | |||
f528ab6e38 | |||
138f1b4882 |
9
Makefile
9
Makefile
@ -2,17 +2,20 @@
|
|||||||
|
|
||||||
GO111MODULE=on
|
GO111MODULE=on
|
||||||
|
|
||||||
VERSION=0.0.02
|
VERSION=0.0.11
|
||||||
USER_GH=eyedeekay
|
USER_GH=eyedeekay
|
||||||
|
|
||||||
version:
|
version:
|
||||||
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION) -d "I2P Router Checking CLI utility"
|
gothub release -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION) -d "I2P Router Checking CLI utility"
|
||||||
|
|
||||||
|
delete:
|
||||||
|
gothub delete -s $(GITHUB_TOKEN) -u $(USER_GH) -r checki2cp -t v$(VERSION)
|
||||||
|
|
||||||
GO_COMPILER_OPTS = -a -tags netgo -ldflags '-w -extldflags "-static"'
|
GO_COMPILER_OPTS = -a -tags netgo -ldflags '-w -extldflags "-static"'
|
||||||
|
|
||||||
build: fmt test clean
|
build: fmt test clean
|
||||||
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS) && \
|
cd ./i2cpcheck && go build $(GO_COMPILER_OPTS)
|
||||||
GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
|
cd ./i2cpcheck && GOOS=windows GOARCH=amd64 go build $(GO_COMPILER_OPTS) -buildmode=exe -o i2cpcheck.exe
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v
|
go test -v
|
||||||
|
125
checki2cp.go
125
checki2cp.go
@ -3,8 +3,12 @@ package checki2p
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/eyedeekay/go-i2cp"
|
"github.com/eyedeekay/go-i2cp"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,15 +29,23 @@ func checkfileexists(path string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func home() string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return "\\i2p"
|
||||||
|
}
|
||||||
|
return "/.i2p"
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
I2CP_HOST string = ""
|
I2CP_HOST string = ""
|
||||||
I2CP_PORT string = ""
|
I2CP_PORT string = ""
|
||||||
WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\i2p\i2psvc.exe`
|
WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\i2p\i2psvc.exe`
|
||||||
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
|
I2PD_WINDOWS_DEFAULT_LOCATION string = `C:\\Program Files\I2Pd\i2pd.exe`
|
||||||
LINUX_SYSTEM_LOCATION string = "/usr/bin/i2prouter"
|
LINUX_SYSTEM_LOCATION []string = []string{"/usr/bin/i2prouter", "/usr/sbin/i2prouter"}
|
||||||
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
|
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
|
||||||
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
|
I2P_ASUSER_HOME_LOCATION string = inithome(home())
|
||||||
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
|
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
|
||||||
|
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckIC2PIsRunning is frequently the only thing I need a reliable, non-SAM
|
// CheckIC2PIsRunning is frequently the only thing I need a reliable, non-SAM
|
||||||
@ -70,7 +82,11 @@ func CheckI2PIsInstalledDefaultLocation() (bool, error) {
|
|||||||
log.Println("Windows i2p router detected")
|
log.Println("Windows i2p router detected")
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if checkfileexists(LINUX_SYSTEM_LOCATION) {
|
if checkfileexists(LINUX_SYSTEM_LOCATION[0]) {
|
||||||
|
log.Println("Linux i2p router detected")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if checkfileexists(LINUX_SYSTEM_LOCATION[1]) {
|
||||||
log.Println("Linux i2p router detected")
|
log.Println("Linux i2p router detected")
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -90,9 +106,8 @@ func UserFind() string {
|
|||||||
str := os.Getenv("SUDO_USER")
|
str := os.Getenv("SUDO_USER")
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
if str, err := os.UserHomeDir(); err == nil {
|
if un, err := user.Current(); err == nil {
|
||||||
x := strings.Split(str, "/")
|
return un.Name
|
||||||
return strings.Replace(x[len(x)-1], "/", "", -1)
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -113,7 +128,11 @@ func CheckI2PUserName() (string, error) {
|
|||||||
log.Println("Windows i2p router detected")
|
log.Println("Windows i2p router detected")
|
||||||
return "i2psvc", nil
|
return "i2psvc", nil
|
||||||
}
|
}
|
||||||
if checkfileexists(LINUX_SYSTEM_LOCATION) {
|
if checkfileexists(LINUX_SYSTEM_LOCATION[0]) {
|
||||||
|
log.Println("Linux i2p router detected")
|
||||||
|
return "i2psvc", nil
|
||||||
|
}
|
||||||
|
if checkfileexists(LINUX_SYSTEM_LOCATION[1]) {
|
||||||
log.Println("Linux i2p router detected")
|
log.Println("Linux i2p router detected")
|
||||||
return "i2psvc", nil
|
return "i2psvc", nil
|
||||||
}
|
}
|
||||||
@ -127,3 +146,83 @@ func CheckI2PUserName() (string, error) {
|
|||||||
}
|
}
|
||||||
return "", nil
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindI2PIsInstalledDefaultLocation looks in various locations for the
|
||||||
|
// presence of an I2P router, reporting back the location
|
||||||
|
func FindI2PIsInstalledDefaultLocation() (string, error) {
|
||||||
|
if checkfileexists(I2PD_WINDOWS_DEFAULT_LOCATION) {
|
||||||
|
log.Println("Windows i2pd router detected")
|
||||||
|
return I2PD_WINDOWS_DEFAULT_LOCATION, nil
|
||||||
|
}
|
||||||
|
if checkfileexists(I2PD_LINUX_SYSTEM_LOCATION) {
|
||||||
|
log.Println("Linux i2pd router detected")
|
||||||
|
return I2PD_LINUX_SYSTEM_LOCATION, nil
|
||||||
|
}
|
||||||
|
if checkfileexists(WINDOWS_DEFAULT_LOCATION) {
|
||||||
|
log.Println("Windows i2p router detected")
|
||||||
|
return WINDOWS_DEFAULT_LOCATION, nil
|
||||||
|
}
|
||||||
|
if checkfileexists(LINUX_SYSTEM_LOCATION[0]) {
|
||||||
|
log.Println("Linux i2p router detected")
|
||||||
|
return LINUX_SYSTEM_LOCATION[0], nil
|
||||||
|
}
|
||||||
|
if checkfileexists(LINUX_SYSTEM_LOCATION[1]) {
|
||||||
|
log.Println("Linux i2p router detected")
|
||||||
|
return LINUX_SYSTEM_LOCATION[1], nil
|
||||||
|
}
|
||||||
|
if checkfileexists(HOME_DIRECTORY_LOCATION) {
|
||||||
|
log.Println("Linux i2p router detected")
|
||||||
|
return HOME_DIRECTORY_LOCATION, nil
|
||||||
|
}
|
||||||
|
if checkfileexists(OSX_DEFAULT_LOCATION) {
|
||||||
|
log.Println("OSX i2p router detected")
|
||||||
|
return OSX_DEFAULT_LOCATION, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("i2p router not found.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConditionallyLaunchI2P() (bool, error) {
|
||||||
|
ok, err := CheckI2PIsInstalledDefaultLocation()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
if ok, err := CheckI2PIsRunning(); err == nil {
|
||||||
|
if !ok {
|
||||||
|
path, err := FindI2PIsInstalledDefaultLocation()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
cmd := exec.Command(path, "start")
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return false, fmt.Errorf("I2P router startup failure", err)
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}else{
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false, fmt.Errorf("I2P is not a default location, please set $I2P environment variable")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -27,3 +27,11 @@ func TestRouter(t *testing.T) {
|
|||||||
t.Log("I2P is in a default location, user feedback is needed")
|
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)
|
||||||
|
}
|
||||||
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module github.com/eyedeekay/checki2cp
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require github.com/eyedeekay/go-i2cp v0.0.0-20190716135428-6d41bed718b0
|
Binary file not shown.
@ -13,19 +13,30 @@ func main() {
|
|||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
log.Println("I2P is running, successfully confirmed I2CP")
|
log.Println("I2P is running, successfully confirmed I2CP")
|
||||||
os.Exit(0)
|
|
||||||
} else {
|
} else {
|
||||||
log.Println("I2P is not running, further testing is needed")
|
log.Println("I2P is not running, further testing is needed")
|
||||||
}
|
}
|
||||||
|
firewallport, err := checki2p.GetFirewallPort()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println("I2P's firewall port is:", firewallport)
|
||||||
|
|
||||||
ok, err = checki2p.CheckI2PIsInstalledDefaultLocation()
|
ok, err = checki2p.CheckI2PIsInstalledDefaultLocation()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
log.Println("I2P is installed, successfully confirmed")
|
log.Println("I2P is installed, successfully confirmed")
|
||||||
|
path, err := checki2p.FindI2PIsInstalledDefaultLocation()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println("I2P is installed at:", path)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
} else {
|
} else {
|
||||||
log.Println("I2P is not a default location, user feedback is needed")
|
log.Println("I2P is not a default location, user feedback is needed")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user