installing python libs over dashboard

main
alex 2023-08-18 09:34:51 +00:00
parent 065296935e
commit c6bf7f85a9
8 changed files with 313 additions and 207 deletions

View File

@ -1,5 +1,4 @@
matplotlib==3.7.2
numpy==1.24.3
numpy_stl==3.0.1
Pillow==9.5.0
Pillow==10.0.0

View File

@ -1,37 +0,0 @@
Brlapi==0.8.2
certifi==2020.6.20
chardet==4.0.0
chrome-gnome-shell==0.0.0
cupshelpers==1.0
dbus-python==1.2.16
distlib==0.3.6
distro==1.5.0
distro-info==1.0
filelock==3.10.7
httplib2==0.18.1
idna==2.10
louis==3.16.0
numpy==1.24.3
numpy-stl==3.0.1
Pillow==9.5.0
platformdirs==3.2.0
pycairo==1.16.2
pycups==2.0.1
pycurl==7.43.0.6
PyGObject==3.38.0
PySimpleSOAP==1.16.2
pysmbc==1.0.23
python-apt==2.2.1
python-debian==0.1.39
python-debianbts==3.1.0
python-utils==3.6.0
pyxdg==0.27
reportbug==7.10.3+deb11u1
requests==2.25.1
six==1.16.0
typing_extensions==4.6.3
unattended-upgrades==0.1
urllib3==1.26.5
vboxapi==1.0
virtualenv==20.21.0
xdg==5

View File

View File

@ -1,132 +1,171 @@
[
{
"id": 0,
"languages": [
{
"lang": "en",
"message": "%userId% has started group task %groupTaskId% %groupTaskName%"
},
{
"lang": "de",
"message": "%userId% hat die Gruppenaufgabe %groupTaskId% %groupTaskName% gestartet"
}
]
},
{
"id": 1,
"languages": [
{
"lang": "en",
"message": "%userId% has reloaded group tasks config of category %category%"
},
{
"lang": "de",
"message": "%userId% hat die Config der Category %category% neu geladen"
}
]
},
{
"id": 2,
"languages": [
{
"lang": "en",
"message": "%groupTaskId% status set to %status%"
},
{
"lang": "de",
"message": "%groupTaskId% Status auf %status% gesetzt"
}
]
},
{
"id": 3,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% was continued by %userId%"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% wurde von %userId% fortgeführt"
}
]
},
{
"id": 4,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% has failed and was started by %userId% to try again"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% ist fehlgeschlagen und wurde von %userId% neu gestartet"
}
]
},
{
"id": 5,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% status set to %status%"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% Status auf %status% gesetzt"
}
]
},
{
"id": 6,
"languages": [
{
"lang": "en",
"message": "--------- SERVER has started ---------"
},
{
"lang": "de",
"message": "--------- SERVER gestartet ---------"
}
]
},
{
"id": 7,
"languages": [
{
"lang": "en",
"message": "%userId% has requested checking for changes in the category groups. Result: %result%"
},
{
"lang": "de",
"message": "%userId% hat die Prüfung auf Änderungen in den Kategoriengruppen angefordert. Ergebnis: %result%"
}
]
},
{
"id": 8,
"languages": [
{
"lang": "en",
"message": "%userId% has executed action %action% on step %taskStepId% of %groupTaskId%"
},
{
"lang": "de",
"message": "%userId% hat Aktion %action% auf Schritt %taskStepId% von %groupTaskId% ausgeführt"
}
]
},
{
"id": 9,
"languages": [
{
"lang": "en",
"message": "System has started step %step% of %groupTaskId%"
},
{
"lang": "de",
"message": "System hat Schritt %step% von %groupTaskId% gestartet"
}
]
}
{
"id": 0,
"languages": [
{
"lang": "en",
"message": "%userId% has started group task %groupTaskId% %groupTaskName%"
},
{
"lang": "de",
"message": "%userId% hat die Gruppenaufgabe %groupTaskId% %groupTaskName% gestartet"
}
]
},
{
"id": 1,
"languages": [
{
"lang": "en",
"message": "%userId% has reloaded group tasks config of category %category%"
},
{
"lang": "de",
"message": "%userId% hat die Config der Category %category% neu geladen"
}
]
},
{
"id": 2,
"languages": [
{
"lang": "en",
"message": "%groupTaskId% status set to %status%"
},
{
"lang": "de",
"message": "%groupTaskId% Status auf %status% gesetzt"
}
]
},
{
"id": 3,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% was continued by %userId%"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% wurde von %userId% fortgeführt"
}
]
},
{
"id": 4,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% has failed and was started by %userId% to try again"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% ist fehlgeschlagen und wurde von %userId% neu gestartet"
}
]
},
{
"id": 5,
"languages": [
{
"lang": "en",
"message": "Step %taskStepId% of %groupTaskId% status set to %status%"
},
{
"lang": "de",
"message": "Schritt %taskStepId% von %groupTaskId% Status auf %status% gesetzt"
}
]
},
{
"id": 6,
"languages": [
{
"lang": "en",
"message": "--------- SERVER has started ---------"
},
{
"lang": "de",
"message": "--------- SERVER gestartet ---------"
}
]
},
{
"id": 7,
"languages": [
{
"lang": "en",
"message": "%userId% has requested checking for changes in the category groups. Result: %result%"
},
{
"lang": "de",
"message": "%userId% hat die Prüfung auf Änderungen in den Kategoriengruppen angefordert. Ergebnis: %result%"
}
]
},
{
"id": 8,
"languages": [
{
"lang": "en",
"message": "%userId% has executed action %action% on step %taskStepId% of %groupTaskId%"
},
{
"lang": "de",
"message": "%userId% hat Aktion %action% auf Schritt %taskStepId% von %groupTaskId% ausgeführt"
}
]
},
{
"id": 9,
"languages": [
{
"lang": "en",
"message": "System has started step %step% of %groupTaskId%"
},
{
"lang": "de",
"message": "System hat Schritt %step% von %groupTaskId% gestartet"
}
]
},
{
"id": 10,
"languages": [
{
"lang": "en",
"message": "%userId% has requested installing python packages for %groupId% of %category%"
},
{
"lang": "de",
"message": "%userId% hat die Installation der Python Pakete für %groupId% von %category% angefordert"
}
]
},
{
"id": 11,
"languages": [
{
"lang": "en",
"message": "Installing python packages for %groupId% of %category% failed. Error: %error%"
},
{
"lang": "de",
"message": "Installation der Python Pakete für %groupId% von %category% fehlgeschlagen. Fehler: %error%"
}
]
},
{
"id": 12,
"languages": [
{
"lang": "en",
"message": "Installing python packages for %groupId% of %category% finished. Log: %log%"
},
{
"lang": "de",
"message": "Installation der Python Pakete für %groupId% von %category% abgeschlossen. Log: %log%"
}
]
}
]

View File

@ -931,3 +931,92 @@ func StartGroupTask(userId string, groupTask structs.GroupTasks) {
},
})
}
func InstallPythonDependencies(userId string, category, groupId string) {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 10,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "userId", Value: userId},
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
},
})
messageBody := struct {
Category string
GroupId string
}{
Category: category,
GroupId: groupId,
}
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependencies,
Body: messageBody,
})
// check if requirements.txt exists
if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + groupId + "/requirements.txt"); errors.Is(err, os.ErrNotExist) {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 11,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "error", Value: "requirements.txt not found"},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFailed,
Body: messageBody,
})
return
}
// install python dependencies
cmd := exec.Command("pip3", "install", "-r", config.Cfg.FolderPaths.GroupTasksGroups+groupId+"/requirements.txt")
out, err := cmd.CombinedOutput()
if err != nil {
logger.AddGroupTasksLog(structs.LogMessage{
Id: 11,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "error", Value: err.Error()},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFailed,
Body: messageBody,
})
return
}
logger.AddGroupTasksLog(structs.LogMessage{
Id: 12,
Type: utils.LogTypeInfo,
Messages: []structs.LogData{
{Type: "category", Value: category},
{Type: "groupId", Value: groupId},
{Type: "log", Value: string(out)},
},
})
socketclients.BroadcastMessageToUsersWithPermission(
systempermissions.ConvertXYPermission(utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, category),
structs.SendSocketMessage{
Cmd: utils.SentCmdInstallingPythonDependenciesFinished,
Body: messageBody,
})
}

View File

@ -41,38 +41,41 @@ var (
// commands sent to web clients
const (
SentCmdInitUserSocketConnection = 1
SentCmdUpdateConnectedUsers = 2
SentCmdNewGroupTaskStarted = 3
SentCmdNewGroupTaskStep = 4
SentCmdUpdateGroupTaskStep = 5
SentCmdUpdateGroupTask = 6
SentCmdReloadingGroupTasks = 7
SentCmdGroupTasksReloaded = 8
SentCmdUpdateUserSessions = 9
SentCmdUpdateAllUsersUserAvatar = 10
SentCmdNewScanner = 11
SentCmdDeleteScanner = 12
SentCmdUpdateScannerUsedBy = 13
SentCmdScanResult = 14
SentCmdUpdateScannerLastUsed = 15
SentCmdTaskLocked = 16
SentCmdTaskUnlocked = 17
SentCmdUserProfileUpdated = 18
SentCmdAdminAreaNewRoleCreated = 19
SentCmdAdminAreaRoleUpdated = 20
SentCmdAdminAreaUpdateRoleSortingOrder = 21
SentCmdAdminAreaRoleDeleted = 22
SentCmdAllUsersUserRoleUpdated = 23
SentCmdRolePermissionsUpdated = 24
SentCmdErrorNoPermissions = 25
SentCmdAllUsersNewUserCreated = 26
SentCmdAllUsersUserDeleted = 27
SentCmdAllUsersUserDeactivation = 28
SentCmdGroupTasksCategoryGroupChanges = 29
SentCmdNewUserApiKeyCreated = 30
SentCmdDeletedUserApiKey = 31
SentCmdNewApiKeyUsageCount = 32
SentCmdInitUserSocketConnection = 1
SentCmdUpdateConnectedUsers = 2
SentCmdNewGroupTaskStarted = 3
SentCmdNewGroupTaskStep = 4
SentCmdUpdateGroupTaskStep = 5
SentCmdUpdateGroupTask = 6
SentCmdReloadingGroupTasks = 7
SentCmdGroupTasksReloaded = 8
SentCmdUpdateUserSessions = 9
SentCmdUpdateAllUsersUserAvatar = 10
SentCmdNewScanner = 11
SentCmdDeleteScanner = 12
SentCmdUpdateScannerUsedBy = 13
SentCmdScanResult = 14
SentCmdUpdateScannerLastUsed = 15
SentCmdTaskLocked = 16
SentCmdTaskUnlocked = 17
SentCmdUserProfileUpdated = 18
SentCmdAdminAreaNewRoleCreated = 19
SentCmdAdminAreaRoleUpdated = 20
SentCmdAdminAreaUpdateRoleSortingOrder = 21
SentCmdAdminAreaRoleDeleted = 22
SentCmdAllUsersUserRoleUpdated = 23
SentCmdRolePermissionsUpdated = 24
SentCmdErrorNoPermissions = 25
SentCmdAllUsersNewUserCreated = 26
SentCmdAllUsersUserDeleted = 27
SentCmdAllUsersUserDeactivation = 28
SentCmdGroupTasksCategoryGroupChanges = 29
SentCmdNewUserApiKeyCreated = 30
SentCmdDeletedUserApiKey = 31
SentCmdNewApiKeyUsageCount = 32
SentCmdInstallingPythonDependencies = 33
SentCmdInstallingPythonDependenciesFailed = 34
SentCmdInstallingPythonDependenciesFinished = 35
)
// commands received from web clients
@ -97,6 +100,7 @@ const (
ReceivedCmdHandleUserActionTaskStep = 18
ReceivedCmdCreateNewUserApiKey = 19
ReceivedCmdDeleteUserApiKey = 20
ReceivedCmdGroupTasksInstallPythonDependencies = 21
)
const (
@ -126,12 +130,13 @@ var (
)
const (
_groupTasks = "group_tasks."
PermissionGroupTasksOverviewXYNewTask = _groupTasks + "overview.XY.new_task"
PermissionGroupTasksOverviewXYReloadGroupConfig = _groupTasks + "overview.XY.reload_group_config"
PermissionGroupTasksOverviewXYView = _groupTasks + "overview.XY.view"
PermissionGroupTasksHistory = _groupTasks + "history"
PermissionGroupTasksCheckingForCategoryGroupChanges = _groupTasks + "checking_for_category_group_changes"
_groupTasks = "group_tasks."
PermissionGroupTasksOverviewXYNewTask = _groupTasks + "overview.XY.new_task"
PermissionGroupTasksOverviewXYReloadGroupConfig = _groupTasks + "overview.XY.reload_group_config"
PermissionGroupTasksOverviewXYInstallPythonDependencies = _groupTasks + "overview.XY.install_python_dependencies"
PermissionGroupTasksOverviewXYView = _groupTasks + "overview.XY.view"
PermissionGroupTasksHistory = _groupTasks + "history"
PermissionGroupTasksCheckingForCategoryGroupChanges = _groupTasks + "checking_for_category_group_changes"
PermissionAllUsersCreateNewUser = "all_users.create_new_user"
PermissionAllUsersActionChangeRole = "all_users.action.change_role"
@ -169,5 +174,6 @@ var SystemPermissions = []string{
var DynamicGroupTasksPermissions = []string{
PermissionGroupTasksOverviewXYNewTask,
PermissionGroupTasksOverviewXYReloadGroupConfig,
PermissionGroupTasksOverviewXYInstallPythonDependencies,
PermissionGroupTasksOverviewXYView,
}

View File

@ -397,6 +397,14 @@ func RunHub() {
case utils.ReceivedCmdDeleteUserApiKey:
socketclients.DeleteUserApiKey(data.Conn.Locals("userId").(string), receivedMessage.Body["Id"].(string))
break
case utils.ReceivedCmdGroupTasksInstallPythonDependencies:
if !socketclients.HasXYPermission(data.Conn.Locals("userId").(string), utils.PermissionGroupTasksOverviewXYInstallPythonDependencies, receivedMessage.Body["category"].(string)) {
socketclients.SendErrorMessageNoPermissions(data.Conn.Locals("sessionId").(string))
break
}
grouptasks.InstallPythonDependencies(data.Conn.Locals("userId").(string), receivedMessage.Body["category"].(string), receivedMessage.Body["groupId"].(string))
break
default:
log.Error().Msgf("Received unknown message: %v", receivedMessage)

2
start.sh Executable file
View File

@ -0,0 +1,2 @@
screen -dmS admin-dashboard-backend | exit 0
screen -S admin-dashboard-backend -p 0 -X stuff 'go run main.go\n'