Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 45 additions & 228 deletions src/job-frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"archive/zip"
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
Expand All @@ -18,8 +17,7 @@ import (
)

const (
WEBHOOK_URL = "https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz"
JobFrameVersion = "v3.0.0"
JobFrameVersion = "v3.0.1"
VERSION = JobFrameVersion
APP_NAME = "CIN Framework CLI"
COPYRIGHT_TEXT = "Β© CIN Framework β€” All Rights Reserved."
Expand Down Expand Up @@ -141,14 +139,13 @@ func enableWindowsColorSupport() {
}

type Config struct {
ErrorTrackingEnabled bool `json:"error_tracking_enabled"`
AdminMode bool `json:"admin_mode"`
ColorEnabled bool `json:"color_enabled"`
LastUpdated string `json:"last_updated"`
Version string `json:"version"`
FrameworkVersion string `json:"framework_version"`
FrameworkInstalled bool `json:"framework_installed"`
InstalledLibraries map[string][]string `json:"libraries_installed"`
AdminMode bool `json:"admin_mode"`
ColorEnabled bool `json:"color_enabled"`
LastUpdated string `json:"last_updated"`
Version string `json:"version"`
FrameworkVersion string `json:"framework_version"`
FrameworkInstalled bool `json:"framework_installed"`
InstalledLibraries map[string][]string `json:"libraries_installed"`
}

type GitHubRelease struct {
Expand All @@ -157,11 +154,10 @@ type GitHubRelease struct {
}

var (
errorTrackingEnabled = true
adminMode = false
colorEnabled = false
configFilePath = ".cin-cli/config.json"
config *Config
adminMode = false
colorEnabled = false
configFilePath = ".cin-cli/config.json"
config *Config
)

func main() {
Expand Down Expand Up @@ -236,8 +232,7 @@ func processCommand(args []string) {

case "help":
showHelp()
case "tracking":
handleTrackingCommand(args[1:])

case "config":
handleConfigCommand(args[1:])
case "sudo":
Expand All @@ -253,40 +248,7 @@ func processCommand(args []string) {
default:
fmt.Printf("Unknown command: %s\n", command)
fmt.Println("Type 'help' to show available commands")
if errorTrackingEnabled {
sendErrorNotification("Unknown command", fmt.Sprintf("Command '%s' not recognized", command))
}
}
}

func handleTrackingCommand(args []string) {
if len(args) == 0 {
fmt.Printf("%sUsage:%s tracking [enable|disable|status]\n", getColorDim(), getColorReset())
return
}

subCommand := strings.ToLower(args[0])

switch subCommand {
case "enable":
errorTrackingEnabled = true
config.ErrorTrackingEnabled = true
saveConfig()
fmt.Printf("%s[SUCCESS]%s %sDiagnostic reporting enabled%s\n", getColorGreen(), getColorReset(), getColorWhite(), getColorReset())
case "disable":
errorTrackingEnabled = false
config.ErrorTrackingEnabled = false
saveConfig()
fmt.Printf("%s[INFO]%s %sDiagnostic reporting disabled%s\n", getColorBlue(), getColorReset(), getColorWhite(), getColorReset())
case "status":
if errorTrackingEnabled {
fmt.Printf("%s[STATUS]%s Diagnostic reporting status: %sENABLED%s\n", getColorCyan(), getColorReset(), getColorGreen(), getColorReset())
} else {
fmt.Printf("%s[STATUS]%s Diagnostic reporting status: %sDISABLED%s\n", getColorCyan(), getColorReset(), getColorRed(), getColorReset())
}
default:
fmt.Printf("%s[ERROR]%s Unknown tracking parameter: %s%s%s\n", getColorRed(), getColorReset(), getColorYellow(), subCommand, getColorReset())
fmt.Printf("%sUsage:%s tracking [enable|disable|status]\n", getColorDim(), getColorReset())
}
}

Expand All @@ -312,9 +274,7 @@ func showHelp() {
// General Commands
fmt.Printf(" %s%-25s%s - %sShow this help%s\n", getColorYellow(), "help", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sClear the screen%s\n", getColorYellow(), "clear", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sEnable diagnostic reporting%s\n", getColorYellow(), "tracking enable", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sDisable diagnostic reporting%s\n", getColorYellow(), "tracking disable", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sShow current tracking status%s\n", getColorYellow(), "tracking status", getColorReset(), getColorWhite(), getColorReset())

fmt.Printf(" %s%-25s%s - %sDisplay current configuration%s\n", getColorYellow(), "config show", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sShow configuration file path%s\n", getColorYellow(), "config path", getColorReset(), getColorWhite(), getColorReset())
fmt.Printf(" %s%-25s%s - %sReset configuration to defaults%s\n", getColorYellow(), "config reset", getColorReset(), getColorWhite(), getColorReset())
Expand Down Expand Up @@ -359,10 +319,10 @@ func showConfig() {

fmt.Printf("\n%s%sCurrent Configuration:%s\n", getColorBold(), getColorCyan(), getColorReset())
fmt.Printf("%s%s%s\n", getColorDim(), strings.Repeat("─", 40), getColorReset())
fmt.Printf("%sError Tracking:%s %s%v%s\n", getColorYellow(), getColorReset(), getColorWhite(), config.ErrorTrackingEnabled, getColorReset())

fmt.Printf("%sAdmin Mode:%s %s%v%s\n", getColorYellow(), getColorReset(), getColorWhite(), config.AdminMode, getColorReset())
fmt.Printf("%sColor Mode:%s %s%v%s\n", getColorYellow(), getColorReset(), getColorWhite(), config.ColorEnabled, getColorReset())
fmt.Printf("%sNotification System:%s %s%s%s\n", getColorYellow(), getColorReset(), getColorWhite(), getNotificationStatus(), getColorReset())

fmt.Printf("%sVersion:%s %s%s%s\n", getColorYellow(), getColorReset(), getColorWhite(), config.Version, getColorReset())
fmt.Printf("%sLast Updated:%s %s%s%s\n", getColorYellow(), getColorReset(), getColorWhite(), config.LastUpdated, getColorReset())
fmt.Printf("%s%s%s\n", getColorDim(), strings.Repeat("─", 40), getColorReset())
Expand All @@ -371,26 +331,16 @@ func showConfig() {
fmt.Println()
}

func getNotificationStatus() string {
return "Configured"
}

func getDefaultNotificationEndpoint() string {
return WEBHOOK_URL
}

func resetConfig() {
config = &Config{
ErrorTrackingEnabled: true,
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
}
errorTrackingEnabled = config.ErrorTrackingEnabled
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
}
adminMode = config.AdminMode
colorEnabled = config.ColorEnabled
saveConfig()
Expand Down Expand Up @@ -599,14 +549,13 @@ func initializeConfig() {
func loadConfig() {
if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
config = &Config{
ErrorTrackingEnabled: true,
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
}
saveConfig()
fmt.Printf("%s[INFO]%s Created new configuration file: %s%s%s\n", getColorBlue(), getColorReset(), getColorCyan(), configFilePath, getColorReset())
Expand All @@ -615,14 +564,13 @@ func loadConfig() {
if err != nil {
fmt.Printf("%s[WARNING]%s Could not read config file: %s%v%s\n", getColorYellow(), getColorReset(), getColorRed(), err, getColorReset())
config = &Config{
ErrorTrackingEnabled: true,
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
}
return
}
Expand All @@ -631,14 +579,13 @@ func loadConfig() {
if err != nil {
fmt.Printf("%s[WARNING]%s Could not parse config file: %s%v%s\n", getColorYellow(), getColorReset(), getColorRed(), err, getColorReset())
config = &Config{
ErrorTrackingEnabled: true,
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
AdminMode: false,
ColorEnabled: false,
LastUpdated: time.Now().Format(time.RFC3339),
Version: VERSION,
FrameworkVersion: "",
FrameworkInstalled: false,
InstalledLibraries: make(map[string][]string),
}
return
}
Expand All @@ -654,7 +601,6 @@ func loadConfig() {
saveConfig() // Save immediately to persist the version update
}

errorTrackingEnabled = config.ErrorTrackingEnabled
adminMode = config.AdminMode
colorEnabled = config.ColorEnabled
fmt.Printf("%s[INFO]%s Configuration loaded from: %s%s%s\n", getColorBlue(), getColorReset(), getColorCyan(), configFilePath, getColorReset())
Expand All @@ -677,136 +623,7 @@ func saveConfig() {
}
}

func getSafeSystemInfo() map[string]string {
info := make(map[string]string)

info["os"] = runtime.GOOS
info["arch"] = runtime.GOARCH
info["go_version"] = runtime.Version()
info["num_cpu"] = fmt.Sprintf("%d", runtime.NumCPU())
info["num_goroutine"] = fmt.Sprintf("%d", runtime.NumGoroutine())

if hostname, err := os.Hostname(); err == nil {
if len(hostname) > 3 {
info["hostname_prefix"] = hostname[:3] + "***"
} else {
info["hostname_prefix"] = "***"
}
}

username := os.Getenv("USERNAME")
if username == "" {
username = os.Getenv("USER")
}
if len(username) > 2 {
info["user_prefix"] = username[:2] + "***"
} else {
info["user_prefix"] = "***"
}

info["app_name"] = APP_NAME
info["app_version"] = VERSION
info["purpose"] = "System diagnostics and user experience improvement"

return info
}

func sendErrorNotification(errorType, errorMessage string) {
if !errorTrackingEnabled {
return
}

go func() {
notificationEndpoint := getDefaultNotificationEndpoint()

sysInfo := getSafeSystemInfo()

message := map[string]interface{}{
"embeds": []map[string]interface{}{
{
"title": APP_NAME + " - System Diagnostic Alert (v" + VERSION + ")",
"description": "**Enterprise-Grade Error Monitoring & Analytics**\n\n*Automated system health monitoring for optimal performance and reliability. This diagnostic report ensures continuous service quality and proactive issue resolution.*",
"color": 3066993,
"thumbnail": map[string]interface{}{
"url": ICON_URL,
},
"fields": []map[string]interface{}{
{
"name": "Incident Classification",
"value": fmt.Sprintf("```\n%s\n```", errorType),
"inline": true,
},
{
"name": "Priority Level",
"value": "```\nMedium\n```",
"inline": true,
},
{
"name": "\u200B",
"value": "\u200B",
"inline": true,
},
{
"name": "Technical Details",
"value": fmt.Sprintf("```yaml\nError: %s\nStatus: Under Investigation\nImpact: Minimal\n```", errorMessage),
"inline": false,
},
{
"name": "System Architecture",
"value": fmt.Sprintf("```yaml\nOperating System: %s\nProcessor Architecture: %s\nRuntime Version: %s\nCPU Cores Available: %s\n```",
sysInfo["os"], sysInfo["arch"], sysInfo["go_version"], sysInfo["num_cpu"]),
"inline": true,
},
{
"name": "Application Metadata",
"value": fmt.Sprintf("```yaml\nProduct: %s\nVersion: %s\nLicense: Enterprise\nCompliance: ISO 27001\n```",
sysInfo["app_name"], sysInfo["app_version"]),
"inline": true,
},
{
"name": "Security & Privacy Compliance",
"value": fmt.Sprintf("```yaml\nDevice Identifier: %s\nUser Session: %s\nData Protection: GDPR Compliant\nEncryption: AES-256\nAnonymization: Active\n```",
sysInfo["hostname_prefix"], sysInfo["user_prefix"]),
"inline": false,
},
{
"name": "Event Timestamp",
"value": fmt.Sprintf("`%s`", time.Now().Format("Monday, January 2, 2006 at 15:04:05 UTC")),
"inline": true,
},
{
"name": "Geographic Region",
"value": "`Global Enterprise Network`",
"inline": true,
},
},
"footer": map[string]interface{}{
"text": COPYRIGHT_TEXT,
"icon_url": ICON_URL,
},
"timestamp": time.Now().Format(time.RFC3339),
},
},
}

jsonData, err := json.Marshal(message)
if err != nil {
return
}

client := &http.Client{
Timeout: 15 * time.Second,
}
resp, err := client.Post(notificationEndpoint, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
return
}
defer resp.Body.Close()
}()
}

// Framework Management Functions

func handleInstallCommand(args []string) {
if len(args) == 0 {
fmt.Printf("%s[ERROR]%s Usage: install [framework|library] [options]\n", getColorRed(), getColorReset())
Expand Down