77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
from flask import Flask, render_template, jsonify, request, redirect, url_for, flash
|
|
from cgminer_api import CgminerAPI
|
|
from config_manager import ConfigManager
|
|
import os
|
|
import subprocess
|
|
|
|
app = Flask(__name__)
|
|
app.secret_key = 'necrohash_miner_control_secret'
|
|
|
|
miner_api = CgminerAPI()
|
|
config_mgr = ConfigManager()
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('dashboard.html', active_page='dashboard')
|
|
|
|
@app.route('/settings')
|
|
def settings():
|
|
config = config_mgr.load_config()
|
|
return render_template('settings.html', config=config, active_page='settings')
|
|
|
|
@app.route('/api/data')
|
|
def api_data():
|
|
summary = miner_api.summary()
|
|
devs = miner_api.devs()
|
|
pools = miner_api.pools()
|
|
|
|
# Process data for easier frontend consumption
|
|
data = {
|
|
'summary': summary['SUMMARY'][0] if summary and 'SUMMARY' in summary else {},
|
|
'devs': devs['DEVS'] if devs and 'DEVS' in devs else [],
|
|
'pools': pools['POOLS'] if pools and 'POOLS' in pools else []
|
|
}
|
|
return jsonify(data)
|
|
|
|
@app.route('/save_settings', methods=['POST'])
|
|
def save_settings():
|
|
# Construct config object from form
|
|
# Note: cgminer config structure handling
|
|
|
|
new_config = config_mgr.load_config() # Start with existing
|
|
|
|
# Update simple fields
|
|
new_config['gridseed-options'] = f"freq={request.form.get('freq', '850')}"
|
|
|
|
# Update pool (handling single pool for simplicity in this MVP, extended later)
|
|
pool_url = request.form.get('pool_url')
|
|
pool_user = request.form.get('pool_user')
|
|
pool_pass = request.form.get('pool_pass')
|
|
|
|
if pool_url:
|
|
# Replace first pool or add if empty
|
|
pool_data = {"url": pool_url, "user": pool_user, "pass": pool_pass}
|
|
if new_config.get('pools'):
|
|
new_config['pools'][0] = pool_data
|
|
else:
|
|
new_config['pools'] = [pool_data]
|
|
|
|
if config_mgr.save_config(new_config):
|
|
flash('Einstellungen gespeichert. Bitte Miner neu starten.', 'success')
|
|
else:
|
|
flash('Fehler beim Speichern.', 'danger')
|
|
|
|
return redirect(url_for('settings'))
|
|
|
|
@app.route('/control/restart')
|
|
def restart_miner():
|
|
# Attempt to restart via API first, if fails, might need system command
|
|
result = miner_api.restart()
|
|
if result:
|
|
return jsonify({'status': 'success', 'message': 'Restart command sent'})
|
|
return jsonify({'status': 'error', 'message': 'Could not contact miner'})
|
|
|
|
if __name__ == '__main__':
|
|
# Run on all interfaces
|
|
app.run(host='0.0.0.0', port=5000, debug=True)
|