aboutsummaryrefslogtreecommitdiff
path: root/vendor
diff options
context:
space:
mode:
authorSina Ghaderi <sina@snix.ir>2021-03-03 12:14:34 +0330
committerSina Ghaderi <sina@snix.ir>2021-03-03 12:14:34 +0330
commit089a22141be6e685ac051f2cf7767c3adf7ba44d (patch)
tree7bbe3f36d483b37e78604392acc0cc5648d39aaf /vendor
pushing to github ...
Diffstat (limited to 'vendor')
-rw-r--r--vendor/networks/action.go59
-rw-r--r--vendor/somecall/somecalls.go72
-rw-r--r--vendor/sysexit/sysexit.go37
3 files changed, 168 insertions, 0 deletions
diff --git a/vendor/networks/action.go b/vendor/networks/action.go
new file mode 100644
index 0000000..4b7caed
--- /dev/null
+++ b/vendor/networks/action.go
@@ -0,0 +1,59 @@
+package networks
+
+import (
+ "bufio"
+ "fmt"
+ "net"
+ "somecall"
+ "sysexit"
+)
+
+// NetListen ...
+func NetListen(listenaddr string) {
+ l, err := net.Listen("tcp", listenaddr)
+ if err != nil {
+ panic(sysexit.Errsig{Why: err, Cod: 1, Pid: somecall.Getpid()})
+ }
+
+ defer l.Close()
+ sysexit.Inform("application is listening on address", listenaddr)
+ for {
+ conn, err := l.Accept()
+ if err != nil {
+ sysexit.Inform(err.Error())
+ continue
+ }
+
+ go cachethecon(conn)
+ }
+
+}
+
+func cachethecon(con net.Conn) {
+ defer func() {
+ con.Close()
+ sysexit.Inform(con.RemoteAddr(), "connection closed by peer")
+ }()
+
+ sysexit.Inform(con.RemoteAddr(), "connection established")
+ if _, err := con.Write([]byte("help banner for this terminal: system cdrom --> type 1 to eject and 0 to rollin \n")); err != nil {
+ sysexit.Inform(err.Error())
+ return
+ }
+ scanner := bufio.NewScanner(con)
+ for scanner.Scan() {
+ if makeanaction, ok := somecall.TakeAction[scanner.Text()]; ok {
+ if err := makeanaction(somecall.UDEVLINK); err != nil {
+ fmt.Fprintln(con, "fatal error: "+err.Error())
+ continue
+ }
+ fmt.Fprintln(con, "operation completed successfully, check the cdrom.")
+ continue
+ }
+ fmt.Fprintln(con, "fatal error: unknow input parameters, please input either 1 or 0")
+ }
+ if err := scanner.Err(); err != nil {
+ sysexit.Inform(err.Error())
+ return
+ }
+}
diff --git a/vendor/somecall/somecalls.go b/vendor/somecall/somecalls.go
new file mode 100644
index 0000000..2feba57
--- /dev/null
+++ b/vendor/somecall/somecalls.go
@@ -0,0 +1,72 @@
+package somecall
+
+import (
+ "os"
+ "syscall"
+ "sysexit"
+)
+
+// lets make some calls for you ;) pull a few strings.. and see whats happened
+const (
+ SYSCDROMEJECTSW = 0x530f
+ SYSCDROMEJECT = 0x5309
+ CDROMCLOSETRAY = 0x5319
+)
+
+// UDEVLINK --> change this if u want mess with another device
+var UDEVLINK string
+
+// Getpid ...
+func Getpid() uintptr {
+ pid, _, err := syscall.Syscall(syscall.SYS_GETPID, 0, 0, 0)
+ if err != 0 {
+ panic(sysexit.Errsig{Why: os.NewSyscallError("SYS_GETPID", err), Cod: 1})
+ }
+ return pid
+}
+
+// Getuid ...
+func Getuid() uintptr {
+ uid, _, err := syscall.Syscall(syscall.SYS_GETUID, 0, 0, 0)
+ if err != 0 {
+ panic(sysexit.Errsig{Why: os.NewSyscallError("SYS_GETPID", err), Cod: 1})
+ }
+ return uid
+}
+
+// TakeAction ...
+var TakeAction = map[string]func(device string) error{
+ "1": func(device string) error {
+ rom, err := os.OpenFile(device, syscall.O_RDONLY|syscall.O_NONBLOCK, 0666)
+ if err != nil {
+ return err
+ }
+ defer rom.Close()
+
+ _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, rom.Fd(), uintptr(SYSCDROMEJECT), 0)
+ if errno != 0 {
+ return os.NewSyscallError("SYS_IOCTL", errno)
+ }
+ _, _, errno = syscall.Syscall(syscall.SYS_IOCTL, rom.Fd(), uintptr(SYSCDROMEJECT), 0)
+ if errno != 0 {
+ return os.NewSyscallError("SYS_IOCTL", errno)
+ }
+
+ return nil
+
+ },
+ "0": func(device string) error {
+ rom, err := os.OpenFile(device, syscall.O_RDONLY|syscall.O_NONBLOCK, 0666)
+ if err != nil {
+ return err
+ }
+ defer rom.Close()
+
+ _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, rom.Fd(), uintptr(CDROMCLOSETRAY), 0)
+ if errno != 0 {
+ return os.NewSyscallError("SYS_IOCTL", errno)
+ }
+
+ return nil
+ },
+}
diff --git a/vendor/sysexit/sysexit.go b/vendor/sysexit/sysexit.go
new file mode 100644
index 0000000..f98303e
--- /dev/null
+++ b/vendor/sysexit/sysexit.go
@@ -0,0 +1,37 @@
+package sysexit
+
+import (
+ "fmt"
+ "log"
+ "os"
+)
+
+const (
+ reset string = "\033[0m"
+ erred = "\033[31m"
+ yello = "\033[33m"
+)
+
+// Errsig ...
+type Errsig struct {
+ Why error
+ Cod int
+ Pid uintptr
+}
+
+//HandlePan ...
+func HandlePan() {
+ if hap := recover(); hap != nil {
+ if ms, owkey := hap.(Errsig); owkey {
+ fmt.Println(erred+"fatal:"+reset, ms.Why, "\nprocess", ms.Pid, "exit with ststus", ms.Cod)
+ os.Exit(ms.Cod)
+ }
+ panic(hap)
+ }
+}
+
+// Inform ...
+func Inform(h ...interface{}) {
+ h = append([]interface{}{(yello + "info:" + reset)}, h...)
+ log.Println(h...)
+}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR