Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 17 additions & 5 deletions powerindex/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def scrub_github_token(value):

return value

def scrub_password(key, value):
"""Helper function to scrub password values with specific replacements"""
password_replacements = {
'admin_password': 'an_admin_password',
'mgmt_password': 'an_mgmt_password'
}
return password_replacements.get(key, value)

def read_config():
config = {}
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -74,8 +82,12 @@ def read_config():
# Strip quotes and whitespace from value
value = value.strip().strip('"\'')

# Scrub any GitHub tokens in the value
value = scrub_github_token(value)
# Scrub passwords with specific replacements
if key in ['admin_password', 'mgmt_password']:
value = scrub_password(key, value)
else:
# Scrub any GitHub tokens in the value
value = scrub_github_token(value)

config[key] = value
except Exception as e:
Expand Down Expand Up @@ -134,7 +146,7 @@ def index():
global config
search_query = request.args.get('search', '').lower()
selected_script = request.args.get('script', '')
scripts = get_shell_scripts()
scripts = sorted(get_shell_scripts()) # Sort the scripts alphabetically

if search_query:
scripts = [script for script in scripts if search_query in script.lower()]
Expand All @@ -148,7 +160,7 @@ def index():
rendered_content = render_script_with_variables(script_content, config)

return render_template('index.html',
scripts=scripts,
scripts=scripts,
search_query=search_query,
selected_script=selected_script,
script_content=script_content,
Expand Down Expand Up @@ -211,4 +223,4 @@ def execute_script():
return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8001)
app.run(debug=True, host='localhost', port=8001)
55 changes: 55 additions & 0 deletions powerindex/static/noun-aardvark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions powerindex/static/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
function searchConfig() {
const input = document.getElementById('configSearch');
const filter = input.value.toLowerCase();
const table = document.getElementById('configTable');
const rows = table.getElementsByTagName('tr');

for (let i = 1; i < rows.length; i++) { // Start from 1 to skip header
const row = rows[i];
const cells = row.getElementsByTagName('td');
const key = cells[0].textContent || cells[0].innerText;
const value = cells[1].textContent || cells[1].innerText;

if (key.toLowerCase().indexOf(filter) > -1 ||
value.toLowerCase().indexOf(filter) > -1) {
row.style.display = '';
} else {
row.style.display = 'none';
}
}
}

function copyToClipboard(text) {
const evt = event;
navigator.clipboard.writeText(text).then(function() {
const button = evt.target;
const originalText = button.textContent;
button.textContent = 'Copied!';
setTimeout(() => {
button.textContent = originalText;
}, 2000);
}).catch(function(err) {
console.error('Failed to copy text: ', err);
});
}

function copyScriptContent(elementId) {
const evt = event;
const content = document.getElementById(elementId).textContent;
navigator.clipboard.writeText(content).then(function() {
const button = evt.target;
const originalText = button.textContent;
button.textContent = 'Copied!';
setTimeout(() => {
button.textContent = originalText;
}, 2000);
}).catch(function(err) {
console.error('Failed to copy text: ', err);
});
}

function searchOutput(elementId) {
const searchText = document.getElementById(elementId + 'Search').value.toLowerCase();
const outputElement = document.getElementById(elementId);
let content = outputElement.textContent; // Use textContent instead of innerHTML for initial content

// Clear any existing highlights
content = content.replace(/<mark class="highlight-search">/g, '')
.replace(/<\/mark>/g, '');

if (!searchText) {
outputElement.innerHTML = content;
return;
}

// Simple text replacement with highlighting
const regex = new RegExp(searchText, 'gi');
content = content.replace(regex, match =>
`<mark class="highlight-search">${match}</mark>`
);

outputElement.innerHTML = content;
}

function executeScript(scriptName) {
const button = document.querySelector('.execute-button');
button.disabled = true;
button.textContent = 'Executing...';

// Clear both search boxes when executing new script
document.getElementById('stdoutSearch').value = '';
document.getElementById('headersSearch').value = '';

fetch('/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ script: scriptName })
})
.then(response => response.json())
.then(data => {
const stdoutElement = document.getElementById('stdout');
const headersElement = document.getElementById('headers');

if (data.is_json) {
stdoutElement.innerHTML = data.stdout;
} else {
stdoutElement.textContent = data.stdout || '';
}

// Always use innerHTML for headers as it contains highlighted JSON
headersElement.innerHTML = data.headers || '';

document.getElementById('stderr').textContent = data.stderr || '';
button.textContent = 'Execute';
button.disabled = false;
})
.catch(error => {
console.error('Error:', error);
document.getElementById('stderr').textContent = 'Error executing script: ' + error;
button.textContent = 'Execute';
button.disabled = false;
});
}
54 changes: 44 additions & 10 deletions powerindex/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ body {
}

.container {
max-width: 1200px;
max-width: 95%;
margin: 0 auto;
padding: 20px;
}
Expand All @@ -92,7 +92,7 @@ input[type="text"] {
button {
padding: 8px 16px;
font-size: 16px;
background-color: #4CAF50;
background-color: var(--govuk-green);
color: white;
border: none;
border-radius: 4px;
Expand All @@ -101,26 +101,29 @@ button {
}

button:hover {
background-color: #45a049;
background-color: #005a30;
}

.content-wrapper {
display: flex;
gap: 20px;
margin-top: 20px;
width: 100%;
}

.script-list {
list-style: none;
padding: 0;
flex: 0 0 300px;
min-width: 200px;
max-width: 400px;
margin: 0;
}

.script-list li {
background: white;
margin: 8px 0;
padding: 12px;
margin: 2px 0;
padding: 0 8px;
border-radius: 4px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
Expand All @@ -131,14 +134,15 @@ button:hover {
display: block;
padding: 8px;
border-radius: 4px;
font-family: var(--monospace-font);
}

.script-list li a:hover {
background-color: #f6f8fa;
}

.script-list li a.selected {
background-color: #fff3b0;
background-color: var(--govuk-yellow);
}

.script-content {
Expand All @@ -153,6 +157,20 @@ button:hover {
margin-top: 0;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
display: flex;
align-items: center;
gap: 10px;
background-color: var(--govuk-yellow);
border-radius: 4px;
padding: 4px;
font-family: var(--monospace-font);
justify-content: space-between;
}

.script-content h3 .execute-button {
order: 2;
margin-left: 10px;
flex-shrink: 0;
}

.script-content pre {
Expand Down Expand Up @@ -327,8 +345,9 @@ tr:hover {
text-decoration: none;
color: #24292e;
display: block;
padding: 8px;
padding: 2px;
border-radius: 4px;
font-family: var(--monospace-font);
}

.script-item a:hover {
Expand All @@ -337,10 +356,12 @@ tr:hover {

.script-item a.selected {
background-color: var(--govuk-yellow);
color: var(--govuk-black);
font-weight: bold;
}

.execute-button {
background-color: #2ea44f;
background-color: var(--govuk-green);
color: white;
border: 1px solid rgba(27, 31, 35, 0.15);
border-radius: 6px;
Expand All @@ -352,11 +373,11 @@ tr:hover {
}

.execute-button:hover {
background-color: #2c974b;
background-color: #005a30;
}

.execute-button:active {
background-color: #298e46;
background-color: #004424;
}

.output-boxes {
Expand Down Expand Up @@ -444,4 +465,17 @@ tr:hover {
/* Make sure no other styles are overriding our highlight */
#headers mark.highlight-search {
background-color: var(--govuk-yellow) !important;
}

.title-container {
display: flex;
align-items: center;
justify-content: center;
gap: 20px;
margin-bottom: 20px;
}

.title-logo {
height: 100px;
width: auto;
}
Loading