add checkfirewallport
This commit is contained in:
2
Makefile
2
Makefile
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
GO111MODULE=on
|
GO111MODULE=on
|
||||||
|
|
||||||
VERSION=0.0.03
|
VERSION=0.0.04
|
||||||
USER_GH=eyedeekay
|
USER_GH=eyedeekay
|
||||||
|
|
||||||
version:
|
version:
|
||||||
|
30
checki2cp.go
30
checki2cp.go
@ -3,9 +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/user"
|
"os/user"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func inithome(str string) string {
|
func inithome(str string) string {
|
||||||
@ -25,6 +28,13 @@ 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 = ""
|
||||||
@ -32,6 +42,7 @@ var (
|
|||||||
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 = "/usr/bin/i2prouter"
|
||||||
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
|
I2PD_LINUX_SYSTEM_LOCATION string = "/usr/sbin/i2pd"
|
||||||
|
I2P_ASUSER_HOME_LOCATION string = inithome(home())
|
||||||
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
|
HOME_DIRECTORY_LOCATION string = inithome("/i2p/i2prouter")
|
||||||
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
|
OSX_DEFAULT_LOCATION string = inithome("/Library/Application Support/i2p/clients.config")
|
||||||
)
|
)
|
||||||
@ -126,3 +137,22 @@ 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")
|
||||||
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
||||||
|
@ -17,6 +17,12 @@ func main() {
|
|||||||
} 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.CheckFirewallPort()
|
||||||
|
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)
|
||||||
@ -28,4 +34,5 @@ func main() {
|
|||||||
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