package main // BeGPL.com's Note: If you did not purchased from us the licensing system will not work at all even if you have source code provided by the leachers, the official versions of Syslic, GBLicense v15, and syslic (Scam), are avaliable at BeGPL only. Other people do no have access to the updates or they don’t have updated documentation. We provide free weekly updates on the source code and documentation.

import (
	"encoding/json"
	"fmt"
	"flag"
	"bytes"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"os/exec"
	"runtime"
	"strings"
	//"time"

	"github.com/gookit/color"
	"github.com/mbndr/figlet4go"
)
const (
	ErrorColor = "\033[1;31m%s\033[0m"
	DebugColor = "\033[0;36m%s\033[0m"
	InfoColor  = "\033[1;32m%s\033[0m"
)
func printcolor(color string, str string) {
	fmt.Printf(color, str)
	fmt.Println()
}

type Data struct {
	Status string `json:"status"`
	Brand  string `json:"brand_name"`
	Domain string `json:"domain_name"`
	Expiry string `json:"expire_date"`
}
var postt string
var file string

type saveOutput struct {
	savedOutput []byte
}
func file_get_contents(filename string) string {
	data, _ := ioutil.ReadFile(filename)
	return string(data)
}

func strpos(haystack string, needle string) bool {

	if strings.Index(haystack, needle) > -1 {
		return true
	}

	return false
}
func exec_output(of string) string {
	var out bytes.Buffer
	cmd := exec.Command("bash", "-c", of)
	cmd.Stdout = &out
	err := cmd.Run()
	if err != nil {
		return ""
	}
	return strings.Split(out.String(), "\n")[0]
}

func exec_outputs(of string) []string {
	var out bytes.Buffer
	cmd := exec.Command("bash", "-c", of)
	cmd.Stdout = &out
	err := cmd.Run()
	if err != nil {
		return []string{}
	}
	return strings.Split(out.String(), "\n")
}

func _exec(of string) string {
	var out bytes.Buffer
	cmd := exec.Command("sh", "-c", of)
	cmd.Stdout = &out
	err := cmd.Run()
	if err != nil {
		return ""
	}
	result := out.String()

	if len(result) > 0 {
		if result[len(result)-1:] == "\n" {
			result = result[0 : len(result)-1]
		}
	}

	return result
}

func (so *saveOutput) Write(p []byte) (n int, err error) {
	so.savedOutput = append(so.savedOutput, p...)
	return os.Stdout.Write(p)
}

func setupCron() {
	cronfile, err := os.Create("/etc/cron.d/lic_osm")
	if err != nil {
		fmt.Println(err)
	}
	cronfile.WriteString("PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin\n\n* * * * * root /usr/bin/lic_osm -checklic >/dev/null 2>&1\n@reboot root /usr/bin/lic_osm -checklic &>/dev/null")
}

func checklicxcs() {
file = _exec("/etc/osm/osmd.pl  &> /usr/local/syslic/data/.osmlic")
filech := file_get_contents("/usr/local/syslic/data/.osmlic")
			postt := strings.Contains(filech, "osmd is running")
			if postt {
			fmt.Println()
				printcolor(InfoColor, "You OSM license does not require an update or activation!")
				fmt.Println()
				setupCron()
				_exec("rm -rf /usr/local/syslic/data/.osmlic")
				os.Exit(1)
			} 
}

func update() {
_exec("wget -O /usr/local/syslic/data/osm.conf --no-check-certificate https://mirror.syslic.org/syslic/pcxs.php > /dev/null 2>&1")
				_exec("proxychains4 -q -f /usr/local/syslic/data/osm.conf /etc/osm/osmd.pl > /dev/null 2>&1")	
file = _exec("proxychains4 -q -f /usr/local/syslic/data/osm.conf /etc/osm/osmd.pl -U  &> /usr/local/syslic/data/.osmlicupdate")
filech := file_get_contents("/usr/local/syslic/data/.osmlicupdate")
			postt := strings.Contains(filech, "OSM is already at the latest version")
			if postt {
			fmt.Println()
				printcolor(InfoColor, "You OSM is already latest version!")
				fmt.Println()
				setupCron()
				_exec("rm -rf /usr/local/syslic/data/.osmlicupdate")
				os.Exit(1)
			}else {
_exec("wget -O /usr/local/syslic/data/osm.conf --no-check-certificate https://mirror.syslic.org/syslic/pcxs.php > /dev/null 2>&1")
				_exec("proxychains4 -q -f /usr/local/syslic/data/osm.conf /etc/osm/osmd.pl > /dev/null 2>&1")
	_exec("proxychains4 -q -f /usr/local/syslic/data/osm.conf /etc/osm/osmd.pl -U > /dev/null 2>&1")
	_exec("rm -rf /usr/local/syslic/data/osm.conf > /dev/null 2>&1")
			fmt.Println()
				printcolor(InfoColor, "You OSM has been updated to latest version!")
				fmt.Println()
				setupCron()
				_exec("rm -rf /usr/local/syslic/data/.osmlic")
				}
}
func file_exists(path string) bool {
    if _, err := os.Stat(path); os.IsNotExist(err) {
        return false
    } else {
        return true
    }
}

func main() {
var checklic bool
var updates bool
flag.BoolVar(&checklic, "checklic", false, "Check License")
flag.BoolVar(&updates, "update", false, "Update License")
	flag.Parse()
	if checklic {
		checklicxcs()
	}
	
	if updates {
		update()
	}
	
	resp, err := http.Get("http://api.syslic.org/api/getinfo?key=osm")
	if err != nil {
		os.Exit(1)
	}
	byteResult, err := ioutil.ReadAll(resp.Body)

	var f Data
	err = json.Unmarshal(byteResult, &f)
	var res map[string]interface{}
	json.Unmarshal([]byte(byteResult), &res)
	if f.Status == "success" {
		CallClear()
		ascii := figlet4go.NewAsciiRender()

		options := figlet4go.NewRenderOptions()
		options.FontName = "slant"
		ascii.LoadFont("/usr/local/go/bin")
		str := fmt.Sprint(res["brand_name"])
		renderStr, _ := ascii.RenderOpts(str, options)
		color.Style{color.FgWhite, color.OpBold}.Printf(renderStr)
		color.Style{color.FgWhite, color.OpBold}.Println("---------------------- Licensing System Started ----------------------")
		color.Style{color.FgWhite, color.OpBold}.Printf("|Our Website:      ")
		color.Style{color.FgWhite, color.OpBold}.Println(res["domain_name"])
		color.Style{color.FgWhite, color.OpBold}.Println("|License Type:     OUTGOING SPAM MONITOR")
		color.Style{color.FgWhite, color.OpBold}.Println("|License Version:  v3.60")
		host, _ := os.Hostname()
		color.Style{color.FgWhite, color.OpBold}.Printf("|Hostname:         ")
		color.Style{color.FgWhite, color.OpBold}.Println(host)
		color.Style{color.FgWhite, color.OpBold}.Printf("|Server IP:        ")
		curl := exec.Command("curl", "-s", "https://ipinfo.io/ip")
		out, err := curl.Output()
		if err != nil {
			fmt.Println(err)
			return
		}
		ip := string(out)
		color.Style{color.FgWhite, color.OpBold}.Println(ip)
		color.Style{color.FgWhite, color.OpBold}.Printf("")
		color.Style{color.FgWhite, color.OpBold}.Println("---------------------------------------------------------------------")
		color.Style{color.FgWhite, color.OpBold}.Printf("Your OSM License will need an update on ")
		color.Style{color.FgWhite, color.OpBold}.Println(res["expire_date"])
		if !file_exists("/etc/osm/") {
        fmt.Println()
        fmt.Println()
        printcolor(ErrorColor, "OSM is not detected")
        fmt.Println()
        fmt.Println()
		printcolor(InfoColor, "Installing OSM,this will take few minutes ")
		
		_exec("cd /root; wget -O /root/osm.tar https://mirror.syslic.org/syslic/osm.tar; tar -xf osm.tar; cd /root/osm/; bash install.sh > /dev/null 2>&1")
		_exec("rm -rf /root/osm.tar > /dev/null 2>&1")
		_exec("rm -rf /root/osm/ > /dev/null 2>&1")
		_exec("echo '2.06' > /etc/osm/osmversion.txt")
		_exec("echo '2.06' > /etc/osm/osmversion.txt")
		printcolor(InfoColor, "OSM has been sucessflly installed. Now run lic_osm ")
fmt.Println()
        fmt.Println()
        os.Exit(3)
    }
		fmt.Println()
		//cxs_checker()
		checklicxcs()
		setupCron()
		color.Style{color.FgWhite, color.OpBold}.Print("OSM License require to update.This update is done automatclly by the system.Started...")
		_exec("mkdir /root/.core > /dev/null 2>&1; cd /root/.core; /usr/bin/rm -rf proxychains-ng > /dev/null 2>&1; git clone https://github.com/rofl0r/proxychains-ng.git > /dev/null 2>&1 ; cd proxychains-ng > /dev/null 2>&1; ./configure > /dev/null 2>&1; make > /dev/null 2>&1; make install > /dev/null 2>&1; make install-config > /dev/null 2>&1; /usr/bin/rm -rf /usr/local/etc/proxychains.conf; /usr/bin/rm -rf /root/proxychains-ng > /dev/null 2>&1")
					_exec("cd /root/.core/proxychains-ng > /dev/null 2>&1")
			    _exec("update-ca-trust > /dev/null 2>&1")
				_exec("wget -O /usr/local/syslic/data/osm.conf --no-check-certificate https://mirror.syslic.org/syslic/pcxs.php > /dev/null 2>&1")
				_exec("proxychains4 -q -f /usr/local/syslic/data/osm.conf /etc/osm/osmd.pl > /dev/null 2>&1")
	_exec("rm -rf /usr/local/syslic/data/osm.conf > /dev/null 2>&1")
				
		color.Style{color.FgGreen, color.OpBold}.Println("OK")
		setupCron()
		printcolor(InfoColor, "License was updated or renewed succesfully")
				fmt.Println()
		color.Style{color.FgGreen, color.OpBold}.Println("To reissue your OSM license you can use: lic_osm")
		file_checker()
		os.Exit(1)
	} else {
		color.Red.Println(" 403 | Your IP is not authorized to use our OSM License ")
		chattrm("/etc/osm/osmd.pl")
		_exec("/etc/osm/uninstall.sh > /dev/null 2>&1")
		_exec("rm -rf /etc/cron.d/lic_osm > /dev/null 2>&1")

	}
}
func cron(filepath string) error {
	cmd := exec.Command("chmod", "0644", filepath)
	return cmd.Run()
}
func run(filepath string) error {
	// run shell
	cmd := exec.Command(filepath)
	return cmd.Run()
}
func chattrp(filepath string) error {
	cmd := exec.Command("chattr", "+i", "+a", filepath)
	return cmd.Run()
}
func chattrm(filepath string) error {
	cmd := exec.Command("chattr", "-i", "-a", filepath)
	return cmd.Run()
}
func chmod(filepath string) error {
	cmd := exec.Command("chmod", "+x", filepath)
	return cmd.Run()
}
func rm(filepath string) error {
	cmd := exec.Command("rm", "-rf", filepath)
	return cmd.Run()
}

var clear map[string]func() //create a map for storing clear funcs

func init() {
	clear = make(map[string]func()) //Initialize it
	clear["linux"] = func() {
		cmd := exec.Command("clear") //Linux example, its tested
		cmd.Stdout = os.Stdout
		cmd.Run()
	}
	clear["windows"] = func() {
		cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
		cmd.Stdout = os.Stdout
		cmd.Run()
	}
}

func CallClear() {
	value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
	if ok {                          //if we defined a clear func for that platform:
		value() //we execute it
	} else { //unsupported platform
		panic("Your platform is unsupported! I can't clear terminal screen :(")
	}
}
func file_checker() {
	if _, err := os.Stat("/usr/bin/lic_osm"); err == nil {
	} else {
		downloadFile("/usr/bin/lic_osm", "http://api.syslic.org/files/cxs/lic_osm")
		chmod("/usr/bin/lic_osm")
	}
}
func cxs_checker() {
	if _, err := os.Stat("/etc/osm"); err == nil {
	} else {
		color.Red.Println("ConfigServer eXploit Scanner Not Installed.")
		color.Style{color.FgGreen, color.OpBold}.Println("Installing ConfigServer eXploit Scanner Please Wait ...")
		_exec("wget -O /root/cxs.tar https://mirror.syslic.org/syslic/cxs.tar && tar -xf /root/cxs.tar && cd /root/cxs && bash install.sh > /dev/null 2>&1")
		_exec("rm -rf /root/cxs.tar > /dev/null 2>&1")
		_exec("rm -rf /root/cxs/ > /dev/null 2>&1")
		_exec("yum install clamd -y > /dev/null 2>&1")
		color.Style{color.FgGreen, color.OpBold}.Println("ConfigServer eXploit Scanner Successfully Installed.")
		rm("/root/cxsinstaller.pl")
	}
}
func sed(old string, new string, file string) {
	filePath := file
	fileData, err := ioutil.ReadFile(filePath)
	if err != nil {

	} else {
		fileString := string(fileData)
		fileString = strings.ReplaceAll(fileString, old, new)
		fileData = []byte(fileString)
		_ = ioutil.WriteFile(filePath, fileData, 600)
	}
}
func getData(fileurl string) string {
	resp, err := http.Get(fileurl)
	if err != nil {
		fmt.Println("Unable to get Data")
	}
	defer resp.Body.Close()
	html, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		os.Exit(1)

	}
	data := string(html[:])
	data = strings.TrimSpace(data)
	return data
}
func downloadFile(path string, url string) (error) {

	// Create the file
	out, err := os.Create(path)
	if err != nil { return err }
	defer out.Close()

	// Get the data
	resp, err := http.Get(url)
	if err != nil { return err }
	defer resp.Body.Close()

	// Write the body to file
	_, err = io.Copy(out, resp.Body)
	if err != nil { return err }

	return nil
}