Code Monkey home page Code Monkey logo

ccbox's Introduction

Virtual Drive Management System

Table of Contents

Overview

This project is a Virtual Drive Management System that allows users to register, log in, and manage their virtual drives. The system supports mounting directories and interacting with Azure Storage. It includes a web server implemented with Flask and Tornado, and an API server for CLI interactions.

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/yourproject.git
    cd yourproject
  2. Set up a virtual environment and install dependencies:

    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  3. Install teh module:

    python install .

Usage

Authentication

The authentication.py module handles user registration and login. Here is an example of how to use it:

from ccbox.authentication import Authentication

# Register a new user
authenticated_user = Authentication.register("username", "password")

# Log in an existing user
authenticated_user = Authentication.login("username", "password")

Virtual Drive

The virtual_drive.py module allows users to manage their virtual drives. Here is an example of how to use it:

from ccbox.virtual_drive import Virtual_Drive, Folder

# Initialize a virtual drive
virtual_drive = Virtual_Drive()

# Mount a directory
virtual_drive.mount_directory("/path/to/mount")

# Add Azure Storage Handler and upload contents
from ccbox.storage_handler import AzureStorageHandler
account_url = 'https://saccbox.blob.core.windows.net'
container_name = f'virtual-drive-{virtual_drive._id}'
azure_storage = AzureStorageHandler(account_url, container_name=container_name)
virtual_drive.add_remote(azure_storage)
virtual_drive.upload_contents()

Web Server

The web server is implemented using Flask and Tornado. It provides endpoints for user registration, login, and virtual drive management.

Running the Web Server

  1. Ensure you have the web_server.py script ready as provided earlier.

  2. Start the web server:

    python web_server.py
  3. The server will start on port 5000 by default. You can access the following endpoints:

    • Register a new user:

      curl -X POST http://localhost:5000/register -H "Content-Type: application/json" -d '{"username":"yourusername","password":"yourpassword"}'
    • Log in a user:

      curl -X POST http://localhost:5000/login -H "Content-Type: application/json" -d '{"username":"yourusername","password":"yourpassword"}'
    • Mount a directory:

      curl -X POST http://localhost:5000/mount -H "Content-Type: application/json" -d '{"username":"yourusername","dir_path":"/path/to/mount"}'
    • Get virtual drive contents:

      curl -X GET http://localhost:5000/virtual_drive/yourusername/contents

API Server

The API server provides CLI-based interactions with the Virtual Drive Management System.

Running the API Server

  1. Ensure you have the api_server.py script ready as provided earlier.

  2. Start the API server:

    python api_server.py
  3. The server will run on localhost and port 9999 by default. The setup.py scirpt has an entry point to the cli.py file so you will be able to run the commands from your command line interface.:

    ccbox
  4. Available commands include:

    • Register a new user:

      ccbox register --username <username> --password <password>

      Follow the prompts to enter username and password.

    • Log in a user:

      ccbox login --username <username> --password <password>

      Follow the prompts to enter username and password.

    • Mount:

      ccbox mount --username <username> --dir <dir_path>

      Follow the prompts to enter the mounted directory's path.

    • Contents:

      ccbox contents --username <username> 

      Follow the prompts to enter the mounted directory's path.

    • Quit the connection:

      ccbox quit

Database Integration

The application uses SQLite for database integration. Here is an example of user database interaction. Currently there is not threading implementation:

import sqlite3

class UserDatabase:
    def __init__(self, db_path='users.db'):
        self.connection = sqlite3.connect(db_path, check_same_thread=False)
        self.cursor = self.connection.cursor()
        self.create_table()

    def create_table(self):
        self.cursor.execute('''
            CREATE TABLE IF NOT EXISTS users (
                username TEXT PRIMARY KEY,
                password TEXT NOT NULL
            )
        ''')
        self.connection.commit()

    def add_user(self, username, password):
        self.cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username, password))
        self.connection.commit()

    def get_user(self, username):
        self.cursor.execute('SELECT * FROM users WHERE username = ?', (username,))
        return self.cursor.fetchone()

    def user_exists(self, username):
        user = self.get_user(username)
        return user is not None

# Example usage
user_db = UserDatabase()
user_db.add_user('testuser', 'testpass')
print(user_db.user_exists('testuser'))

License

This project is licensed under the MIT License. See the LICENSE file for more details.


ccbox's People

Contributors

billvamva avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.