Skip to content

amassivus/webconsole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

web console

web console

License

web console

Copyright (C) 2024-2025 QB Networks

Copyright (C) 2017-2025 Masscollabs Services

Copyright (C) 2017-2025 Procyberian and contributors

Copyright (C) 2017-2025 Mass Collaboration Labs and contributors

Copyright (C) 2017-2025 amassivus and contributors

Copyright (C) 2024-2025 godigitalist and contributors

Copyright (C) 2024-2025 bilsege and contributors

Copyright (C) 2024-2025 Birleşik Dergi Yazarları

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

how to

write me a web console and terminal based on for debian 12 gnu linux to connect remote or local computers via ssh protocol and I want to write and run this code inside a virtualenv and please write a .gitignore for this virtualenv and all source code

Alright! I'll guide you through setting up a web console and terminal for Debian 12 GNU/Linux to connect to remote or local computers via SSH using Flask, paramiko, and flask-socketio. We'll also set this up within a virtual environment and provide a .gitignore file.

Step 1: Set Up Your Project and Virtual Environment

Create a new directory for your project and navigate into it:

mkdir webconsole
cd webconsole

Create a virtual environment and activate it:

python3 -m venv venv
source venv/bin/activate

Step 2: Install Required Packages

Install the necessary packages within your virtual environment:

pip install flask paramiko flask-socketio eventlet

Step 3: Create Your Flask App

Create a new file named app.py and add the following code:

from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit
import paramiko
import threading

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, async_mode='eventlet')

def ssh_connect(hostname, username, password, cmd):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname, username=username, password=password)
    stdin, stdout, stderr = client.exec_command(cmd)
    return stdout.read().decode(), stderr.read().decode()

@socketio.on('execute_command')
def handle_execute_command(json):
    hostname = json['hostname']
    username = json['username']
    password = json['password']
    command = json['command']
    stdout, stderr = ssh_connect(hostname, username, password, command)
    emit('command_output', {'stdout': stdout, 'stderr': stderr})

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    socketio.run(app)

Step 4: Create the HTML Template

Create a directory named templates and within it, create a file named index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Web Console</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.socket.io/4.1.2/socket.io.min.js"></script>
</head>
<body>
    <h1>Web Console</h1>
    <input type="text" id="hostname" placeholder="Hostname">
    <input type="text" id="username" placeholder="Username">
    <input type="password" id="password" placeholder="Password">
    <input type="text" id="command" placeholder="Command">
    <button id="execute">Execute</button>
    <pre id="output"></pre>

    <script>
        $(document).ready(function() {
            var socket = io.connect('http://' + document.domain + ':' + location.port);

            $('#execute').click(function() {
                var hostname = $('#hostname').val();
                var username = $('#username').val();
                var password = $('#password').val();
                var command = $('#command').val();

                socket.emit('execute_command', {
                    'hostname': hostname,
                    'username': username,
                    'password': password,
                    'command': command
                });
            });

            socket.on('command_output', function(data) {
                $('#output').text(data.stdout + data.stderr);
            });
        });
    </script>
</body>
</html>

Step 5: Create a .gitignore File

Create a .gitignore file in the root of your project directory and add the following entries:

# Virtualenv
venv/
env/
.venv/
.env
pip-log.txt
pip-delete-this-directory.txt

# Python
*.pyc
*.pyo
*.pyd
__pycache__/
*.swp
*.swo
*.swn
*.bak

# Flask
*.log
*.pot
*.mo
*.pyc
*.pyo
__pycache__/

# Environment variables
.env

# System Files
.DS_Store
Thumbs.db
*.~lock.*

# JetBrains IDE files
.idea/
.vscode/

# Coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
*.cover

# Test reports
*.cover
*.py,cover
.tox
noxfile_config.json

Step 6: Run Your Flask App

With your virtual environment activated, run the Flask app:

python app.py

Step 7: Access the Web Console

Open your web browser and navigate to http://localhost:5000. You should see the web console interface where you can enter SSH credentials and commands to execute on the remote server.

This setup should get you started with a web console and terminal that connects to remote or local computers via SSH. If you need any further customization or assistance, feel free to ask! Enjoy coding! 🌟

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published