Giter Site home page Giter Site logo

mr6mjt / j_api Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 28 KB

Python API application designed to handle user registration, sign-in, and dynamic subdomain creation using CloudFlare API , Integrated with a MySQL database.

HTML 35.46% Python 35.18% CSS 4.59% PHP 24.78%

j_api's Introduction


Note: This Project Is Not Finished Yet, It Is Under Development.


Overview:

Python API application designed to handle user registration, sign-in, and dynamic subdomain creation using CloudFlare API. It utilizes a MySQL database to store user information and interacts with the local Apache server to manage virtual host configurations.

Components:

1-Imports:

The script imports necessary modules including pymysql for MySQL database connectivity, Flask for web server functionalities, CloudFlare for managing DNS records, and os for interacting with the operating system.

2-Configuration:

Database Connection: The script establishes a connection to a MySQL database using the pymysql.connect method. Database credentials such as host, username, and password are hardcoded in the script. CloudFlare API: It initializes a CloudFlare client using an email address and API token. The API token is stored as a global variable.

3-Flask Application:

The script initializes a Flask application instance.

4-Endpoints:

Registration Endpoint (/reg):

Handles POST requests for user registration. Checks if the provided email, username, or subdomain already exist in the database. If not, it inserts the user details into the database and creates a subdomain record using CloudFlare API. It also creates Apache virtual host configurations for the subdomain. Responds with a success message if registration is successful or appropriate error messages if user or subdomain already exists.

Sign-in Endpoint (/signin):

Handles POST requests for user sign-in. Verifies the provided email and password against the database. If the credentials match, it responds with a success message; otherwise, it responds with an error message.

5-Database Operations:

The script performs database operations using raw SQL queries. It checks for existing users during registration and verifies credentials during sign-in.

6-CloudFlare Integration:

It interacts with the CloudFlare API to manage DNS records for subdomains dynamically. It checks for the existence of a CloudFlare zone, creates DNS records for new subdomains, and handles errors appropriately.

7-Apache Integration:

It creates Apache virtual host configurations for new subdomains dynamically, writes configurations to disk, creates directories for subdomain content, and reloads Apache service to apply changes.



mv domain.ao.conf /etc/apache2/sites-available
sudo systemctl restart apache2 
cd /
pip install virtualenv
virtualenv venv
source ./venv/bin/activate
python reg.py 

Mahdi Jaber | 8 / 3 / 2024 12:30 PM

j_api's People

Contributors

mr6mjt avatar

Stargazers

 avatar Mahmoud Osman 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.