mirror of
https://gitlab.com/JKANetwork/powerfulcomputermanager.git
synced 2026-02-16 10:11:31 +01:00
New fixes
This commit is contained in:
@@ -12,7 +12,7 @@ from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
|||||||
|
|
||||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
|
|
||||||
BUILD=1
|
BUILD=2
|
||||||
APIC_VER=2
|
APIC_VER=2
|
||||||
|
|
||||||
# Load config to comunicate with API or use default
|
# Load config to comunicate with API or use default
|
||||||
@@ -183,7 +183,12 @@ def pAdminGroup(): #Admin see one group
|
|||||||
return render_template('/login.tmpl', title="Login")
|
return render_template('/login.tmpl', title="Login")
|
||||||
|
|
||||||
groupid=request.args.get('ID_G')
|
groupid=request.args.get('ID_G')
|
||||||
if groupid is not None and groupid.isnumeric():
|
groupname=request.args.get('GroupName')
|
||||||
|
|
||||||
|
if groupid is None and groupname is not None:
|
||||||
|
groupid = returnvalueapi('/get/groups?GroupName='+str(groupid),"ID_G")
|
||||||
|
|
||||||
|
if groupid is not None and str(groupid).isnumeric():
|
||||||
groupname=returnvalueapi('/get/groups?GroupID='+str(groupid),"Name")
|
groupname=returnvalueapi('/get/groups?GroupID='+str(groupid),"Name")
|
||||||
computers = returnTable("/get/computers",['ID_C','Name'])
|
computers = returnTable("/get/computers",['ID_C','Name'])
|
||||||
datagroup = (returnTable("/get/computersgrp?GroupID="+groupid,['ID_C','Name'])) #lista[0]¿
|
datagroup = (returnTable("/get/computersgrp?GroupID="+groupid,['ID_C','Name'])) #lista[0]¿
|
||||||
@@ -223,6 +228,15 @@ def pAdminGroupAddcook(): #Add cook form enter
|
|||||||
return redirect('/admin/group?ID_G='+groupid)
|
return redirect('/admin/group?ID_G='+groupid)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/admin/group/addgroup",methods=['GET'])
|
||||||
|
def pAdminGroupAddgroup(): #Add cook form enter
|
||||||
|
groupname=request.args.get('groupnameadd')
|
||||||
|
if groupname != None and groupname != "":
|
||||||
|
r = returnvalueapi("/add/group?GroupName="+groupname,field="RESULT")
|
||||||
|
if r == "OK":
|
||||||
|
return redirect('/admin/group?GroupName='+groupname)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/admin/group/addcomputer",methods=['GET'])
|
@app.route("/admin/group/addcomputer",methods=['GET'])
|
||||||
def pAdminGroupAddcomputer(): #Add computer form enter
|
def pAdminGroupAddcomputer(): #Add computer form enter
|
||||||
computertoadd=request.args.get('computeridadd')
|
computertoadd=request.args.get('computeridadd')
|
||||||
|
|||||||
@@ -1,6 +1,31 @@
|
|||||||
{# -*- coding: utf-8 -*- #}
|
{# -*- coding: utf-8 -*- #}
|
||||||
{% extends 'baseadmin.tmpl' %}
|
{% extends 'baseadmin.tmpl' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
<!-- Modal Add New Group -->
|
||||||
|
<div class="modal fade" id="modalCreateGroup" tabindex="-1" role="dialog" aria-labelledby="modalCreateGroupLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<form method="get" action="/admin/group/addgroup">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="modalCreateGroupLabel">Create new Group</h5>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<p>Add group<br>
|
||||||
|
<label for="groupname" class="col-form-label">Group name:</label>
|
||||||
|
<input type="text" class="form-control" name="groupnameadd" id="groupnameadd"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||||
|
<button type="submit" class="btn btn-primary">Create</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2>Groups</h2>
|
<h2>Groups</h2>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-striped table-sm">
|
<table class="table table-striped table-sm">
|
||||||
@@ -13,6 +38,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4"><a class="btn btn-outline-success btn-sm" data-toggle="modal" data-target="#modalCreateGroup">Create group</a></td>
|
||||||
|
</tr>
|
||||||
{% for item in tablegroups %} {#['ID_G','Name','Computers[ID_C,Name]','Cooks[CookName]']#}
|
{% for item in tablegroups %} {#['ID_G','Name','Computers[ID_C,Name]','Cooks[CookName]']#}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{item.0}}</td>
|
<td>{{item.0}}</td>
|
||||||
|
|||||||
25
api.py
25
api.py
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
BUILD = 28
|
BUILD = 29
|
||||||
API_VER = 2
|
API_VER = 2
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
import random
|
import random
|
||||||
@@ -61,7 +61,7 @@ def getComputerExists():
|
|||||||
return str({'RESULT': '1'})
|
return str({'RESULT': '1'})
|
||||||
elif sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"'")[0]['RESULT'] != 0: #Not UUID match, but computer exists
|
elif sql.select("SELECT COUNT(*) 'RESULT' FROM COMPUTERS WHERE Name='"+ComputerName+"'")[0]['RESULT'] != 0: #Not UUID match, but computer exists
|
||||||
return str({'TEXT': 'Error, computer and UUID doesn\'t match in database', 'RESULT': 'ERROR','EXITCODE':'2'})
|
return str({'TEXT': 'Error, computer and UUID doesn\'t match in database', 'RESULT': 'ERROR','EXITCODE':'2'})
|
||||||
if sqlAddComputers == True: #Computer doesn't exist, but you have enabled add all computers
|
if sqlAddComputers == 'True': #Computer doesn't exist, but you have enabled add all computers
|
||||||
sql.insert("INSERT INTO COMPUTERS (`Name`,`UUID`) VALUES('"+ComputerName+"','"+UUID+"')")
|
sql.insert("INSERT INTO COMPUTERS (`Name`,`UUID`) VALUES('"+ComputerName+"','"+UUID+"')")
|
||||||
return str({'RESULT': '1'})
|
return str({'RESULT': '1'})
|
||||||
else: #Computer doesn't exist and you don't want to be added
|
else: #Computer doesn't exist and you don't want to be added
|
||||||
@@ -71,6 +71,27 @@ def getComputerExists():
|
|||||||
return str({'RESULT': '1'})
|
return str({'RESULT': '1'})
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# getGroupID: Return GroupID from GroupName
|
||||||
|
# /get/groupid?
|
||||||
|
# @param ComputerName/ComputerID -> Computer to see groups (Not neccesary)
|
||||||
|
# @param GroupID -> For know Name of a GroupID
|
||||||
|
##
|
||||||
|
@app.route("/get/groupid",methods=['POST'])
|
||||||
|
def getGroupID(): #Get local groups of a Computer
|
||||||
|
logit(request.base_url)
|
||||||
|
GroupName=None
|
||||||
|
for key, value in request.args.to_dict().items():
|
||||||
|
if key == "GroupName":
|
||||||
|
GroupID = str(sql.select("SELECT ID_G FROM GROUPS WHERE Name='"+value+"'")[0]['ID_G'])
|
||||||
|
|
||||||
|
if GroupID is not None:
|
||||||
|
return GroupID
|
||||||
|
else:
|
||||||
|
return str({'TEXT': 'I need a valid GroupName for returning GroupID','RESULT':'ERROR'})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# getGroups: Know all groups, or groups of a computer
|
# getGroups: Know all groups, or groups of a computer
|
||||||
# /get/groups?
|
# /get/groups?
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Build 18. Using API 2
|
# Build 20. Using API 2
|
||||||
param([Int32]$startup=0)
|
param([Int32]$startup=0)
|
||||||
#Write-Host $startup
|
#Write-Host $startup
|
||||||
$srcdir = $PSCommandPath | Split-Path -Parent
|
$srcdir = $PSCommandPath | Split-Path -Parent
|
||||||
@@ -87,18 +87,18 @@ foreach ($CookName in $cooks){
|
|||||||
Write-Host "Se salta ya que no esta arrancando/apagandose el equipo..."
|
Write-Host "Se salta ya que no esta arrancando/apagandose el equipo..."
|
||||||
continue # Go for next
|
continue # Go for next
|
||||||
}
|
}
|
||||||
if ($cook.only64bit -eq 1 -and $64bit -eq $false) { # If script is only for 64 bit and system is 32 bit..
|
if ($cook.only64bit -eq 1 -and $64bit -eq $False) { # If script is only for 64 bit and system is 32 bit..
|
||||||
Write-Host "Se salta ya que es esta receta es solo para 64 bits..."
|
Write-Host "Se salta ya que es esta receta es solo para 64 bits..."
|
||||||
continue # Go for next
|
continue # Go for next
|
||||||
}
|
}
|
||||||
if ($cook.only32bit -eq 1 -and $64bit -eq $true) { # If script is only for 32 bit and system is 64 bit..
|
if ($cook.only32bit -eq 1 -and $64bit -eq $True) { # If script is only for 32 bit and system is 64 bit..
|
||||||
Write-Host "Se salta ya que es esta receta es solo para 32 bits..."
|
Write-Host "Se salta ya que es esta receta es solo para 32 bits..."
|
||||||
continue # Go for next
|
continue # Go for next
|
||||||
}
|
}
|
||||||
$err = 0
|
$err = 0
|
||||||
$exit = 0
|
$exit = 0
|
||||||
$inif = $false
|
$inif = $False
|
||||||
$if = $true
|
$if = $True
|
||||||
$filesCopied = New-Object System.Collections.ArrayList # For REPOTOLOCAL, has a list of files copied to delete when finish (Do not store forever in temp)
|
$filesCopied = New-Object System.Collections.ArrayList # For REPOTOLOCAL, has a list of files copied to delete when finish (Do not store forever in temp)
|
||||||
foreach ($step in $cook.steps){
|
foreach ($step in $cook.steps){
|
||||||
if ($err -eq 1 -and $noerror -eq 1){$err = 0; $errvar = ""} #If "noerror" is active, do not count errors
|
if ($err -eq 1 -and $noerror -eq 1){$err = 0; $errvar = ""} #If "noerror" is active, do not count errors
|
||||||
@@ -107,7 +107,7 @@ foreach ($CookName in $cooks){
|
|||||||
$param = $step[1]
|
$param = $step[1]
|
||||||
$param2 = $step[2]
|
$param2 = $step[2]
|
||||||
Write-Host $step[0] "-" $step[1]
|
Write-Host $step[0] "-" $step[1]
|
||||||
if($inif -eq $true -and $if -eq $false){ # Only can see "ENDIF" if is in IF and is not true
|
if($inif -eq $True -and $if -eq $False){ # Only can see "ENDIF" if is in IF and is not true
|
||||||
if ($step[0] -ne "ENDIF" -and $step[0] -ne "ELSE"){
|
if ($step[0] -ne "ENDIF" -and $step[0] -ne "ELSE"){
|
||||||
Write-Host $step[0] "Not executed, IF not meet"
|
Write-Host $step[0] "Not executed, IF not meet"
|
||||||
$step[0] = "" #Disable command
|
$step[0] = "" #Disable command
|
||||||
@@ -118,32 +118,42 @@ foreach ($CookName in $cooks){
|
|||||||
switch ($step[0].ToUpper()) { #Command
|
switch ($step[0].ToUpper()) { #Command
|
||||||
"UNINSTALL" { # Remove program
|
"UNINSTALL" { # Remove program
|
||||||
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
|
Get-Package -Name "$param*" -ErrorAction Continue #This will return error if program is not installed, do not see it.
|
||||||
if ($? -eq $true){ #If its True, is that package exists
|
if ($? -eq $True){ #If its True, is that package exists
|
||||||
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
|
Get-Package -Name "$param*" -ErrorVariable errvar | Uninstall-Package -ErrorVariable errvar
|
||||||
if ($? -eq $false){ # If fail then put 1 (When fail, powershell returns False)
|
if ($? -eq $False){ # If fail then put 1 (When fail, powershell returns False)
|
||||||
$err = 1
|
$err = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"SERV_DISABLE" { # Disable a service
|
"SERV_DISABLE" { # Disable a service
|
||||||
Set-Service $param -StartupType Disabled -Status Stopped -ErrorVariable errvar
|
Set-Service $param -StartupType Disabled -Status Stopped -ErrorVariable errvar
|
||||||
if ($? -eq $false){ #If its False, it was a problem
|
if ($? -eq $False){ #If its False, it was a problem
|
||||||
$err = 1
|
$err = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"SERV_ENABLE" { # Enable a service
|
"SERV_ENABLE" { # Enable a service
|
||||||
Set-Service $param -StartupType Automatic -Status Running -ErrorVariable errvar
|
Set-Service $param -StartupType Automatic -Status Running -ErrorVariable errvar
|
||||||
if ($? -eq $false){ #If its False, it was a problem
|
if ($? -eq $False){ #If its False, it was a problem
|
||||||
$err = 1
|
$err = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{$_ -in "KILL_PROCESS","KILLPROCESS"} {
|
{$_ -in "KILL_PROCESS","KILLPROCESS"} {
|
||||||
$p = Get-Process -Name "$param"
|
$p = Get-Process -Name "$param"
|
||||||
if ($? -eq $true){ # Only do something if exists
|
if ($? -eq $True){ # Only do something if exists
|
||||||
Stop-Process -InputObject $p -Force -ErrorVariable errvar -ErrorAction Continue
|
Stop-Process -InputObject $p -Force -ErrorVariable errvar -ErrorAction Continue
|
||||||
#if ($p.HasExited -eq $false){
|
#if ($p.HasExited -eq $false){
|
||||||
# $err = 1
|
# $err = 1
|
||||||
#}
|
#}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"CD" { #CHANGE DIR, ITS DANGEROUS. IF PARAM IS EMPTY, GO TO $env:temp
|
||||||
|
if ($param -eq ""){
|
||||||
|
Set-Location "$env:temp"
|
||||||
|
}else{
|
||||||
|
Set-Location "$param"
|
||||||
|
}
|
||||||
|
if ($? -eq $false){ # Location change error
|
||||||
|
$err = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"CMD" { # Run a cmd command. Note: Runs at high priv.
|
"CMD" { # Run a cmd command. Note: Runs at high priv.
|
||||||
@@ -177,15 +187,13 @@ foreach ($CookName in $cooks){
|
|||||||
$orig=$parts[0]
|
$orig=$parts[0]
|
||||||
$dest=$parts[1]
|
$dest=$parts[1]
|
||||||
Copy-Item "$orig" "$dest" -ErrorVariable errvar -Recurse -Force
|
Copy-Item "$orig" "$dest" -ErrorVariable errvar -Recurse -Force
|
||||||
if ($? -eq $false){ # Error in Copy
|
if ($? -eq $False){ # Error in Copy
|
||||||
$err = 1
|
$err = 1
|
||||||
}
|
}
|
||||||
}else{ #Doesn't sent right
|
}else{ #Doesn't sent right
|
||||||
$err = 1
|
$err = 1
|
||||||
$errvar = "Param not set right. Exiting..."
|
$errvar = "Param not set right. Exiting..."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
"REMOVE" { # Remove files / folders
|
"REMOVE" { # Remove files / folders
|
||||||
Remove-Item "$param" -Recurse -Force -ErrorAction Continue # They not see errors (Because error will be file not found)
|
Remove-Item "$param" -Recurse -Force -ErrorAction Continue # They not see errors (Because error will be file not found)
|
||||||
@@ -226,12 +234,12 @@ foreach ($CookName in $cooks){
|
|||||||
# True -> Exists ; False -> Not exists
|
# True -> Exists ; False -> Not exists
|
||||||
}
|
}
|
||||||
"IFSOFTWAREINST" { # If with software
|
"IFSOFTWAREINST" { # If with software
|
||||||
$inif = $true #This controls IF start/stop
|
$inif = $True #This controls IF start/stop
|
||||||
Get-Package -Name "$param*" -ErrorAction SilentlyContinue #This will return error if program is not installed, do not see it.
|
Get-Package -Name "$param*" -ErrorAction SilentlyContinue #This will return error if program is not installed, do not see it.
|
||||||
$if=$? # True -> Exists ; False -> Not exists
|
$if=$? # True -> Exists ; False -> Not exists
|
||||||
}
|
}
|
||||||
"IFSOFTWAREVER" { # If with software
|
"IFSOFTWAREVER" { # If with software
|
||||||
$inif = $true #This controls IF start/stop
|
$inif = $True #This controls IF start/stop
|
||||||
$parts = $param.Split(";")
|
$parts = $param.Split(";")
|
||||||
if ($parts[1] -ne ""){ #Exists uri and filename
|
if ($parts[1] -ne ""){ #Exists uri and filename
|
||||||
$p_name = $parts[0]
|
$p_name = $parts[0]
|
||||||
@@ -244,27 +252,29 @@ foreach ($CookName in $cooks){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"IFPATHEXISTS" { # If only if a path exists (File, Folder, Registry Key..)
|
"IFPATHEXISTS" { # If only if a path exists (File, Folder, Registry Key..)
|
||||||
$inif = $true #This controls IF start/stop
|
$inif = $True #This controls IF start/stop
|
||||||
Test-Path $param -PathType Any -ErrorAction SilentlyContinue
|
Test-Path $param -PathType Any -ErrorAction SilentlyContinue
|
||||||
$if=$?
|
$if=$?
|
||||||
}
|
}
|
||||||
"IFPWCMD" { # If with powershell command
|
"IFPWCMD" { # If with powershell command
|
||||||
$inif = $true #This controls IF start/stop
|
$inif = $True #This controls IF start/stop
|
||||||
Invoke-Expression $param #Executes powershell command
|
Invoke-Expression $param #Executes powershell command
|
||||||
$if=$? # True -> Exists ; False -> Not exists
|
$if=$? # True -> Exists ; False -> Not exists
|
||||||
}
|
}
|
||||||
"IF64BIT" { # If 64 bit computer
|
"IF64BIT" { # If 64 bit computer
|
||||||
|
$inif = $True
|
||||||
$if = $64bit # Its true if 64 bit computer
|
$if = $64bit # Its true if 64 bit computer
|
||||||
}
|
}
|
||||||
"IF32BIT" { # If 32 bit computer
|
"IF32BIT" { # If 32 bit computer
|
||||||
|
$inif = $True
|
||||||
$if = !$64bit # Its true if 32 bit computer, flipped boolean
|
$if = !$64bit # Its true if 32 bit computer, flipped boolean
|
||||||
}
|
}
|
||||||
"ELSE" { # Turn bool $if
|
"ELSE" { # Turn bool $if
|
||||||
$if = !$if
|
$if = !$if
|
||||||
}
|
}
|
||||||
"ENDIF"{ # End the if
|
"ENDIF"{ # End the if
|
||||||
$inif = $false
|
$inif = $False
|
||||||
$if = $true
|
$if = $True
|
||||||
}
|
}
|
||||||
"DOWNLOAD" { #Download a file. This is a bit problematic one, will use ; to separate download and filename, and its forced to use it..
|
"DOWNLOAD" { #Download a file. This is a bit problematic one, will use ; to separate download and filename, and its forced to use it..
|
||||||
$parts = $param.Split(";")
|
$parts = $param.Split(";")
|
||||||
@@ -290,7 +300,9 @@ foreach ($CookName in $cooks){
|
|||||||
$exit = 1
|
$exit = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Default {}
|
Default { ##DEFAULT, SAY COMMAND NOT VALID
|
||||||
|
Write-Host "Command not valid."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Send results
|
# Send results
|
||||||
@@ -306,6 +318,8 @@ foreach ($CookName in $cooks){
|
|||||||
}
|
}
|
||||||
Invoke-RestMethod -Method Post -Uri "$server/set/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
|
Invoke-RestMethod -Method Post -Uri "$server/set/cookstatus?ComputerName=$computerName&UUID=$UUID&CookName=$CookName&Revision=$CookRevision&Error=$err&ErrorDesc=$errvar" | out-null
|
||||||
|
|
||||||
|
#Return to $env:temp
|
||||||
|
Set-Location "$env:temp"
|
||||||
#Delete files copied to temp for saving space
|
#Delete files copied to temp for saving space
|
||||||
foreach ($element in $filesCopied) {
|
foreach ($element in $filesCopied) {
|
||||||
Remove-Item "$env:temp\$element" -ErrorAction SilentlyContinue -Recurse -Force
|
Remove-Item "$env:temp\$element" -ErrorAction SilentlyContinue -Recurse -Force
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2020/09/11
|
||||||
|
- Fixes in webui in some options
|
||||||
|
- Fix IF64BIT/IF32BIT, was not working
|
||||||
|
|
||||||
## 2020/07/16
|
## 2020/07/16
|
||||||
- Fixes and improvments to web gui
|
- Fixes and improvments to web gui
|
||||||
- General bugfix
|
- General bugfix
|
||||||
|
|||||||
Reference in New Issue
Block a user