diff --git a/.env b/.env new file mode 100644 index 0000000..080d87b --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +E-mail_for_checking_email=nono +Password_for_checking_mail=none +Instagram_username=none +Instagram_password=none +TELE_API_KEY=none +Open_Weather_API=none \ No newline at end of file diff --git a/Initialize.py b/Initialize.py new file mode 100644 index 0000000..2f6b71c --- /dev/null +++ b/Initialize.py @@ -0,0 +1,60 @@ +import os +from cryptography.fernet import Fernet +with open('crypt.key', 'wb') as filekey: + filekey.write(key) +def init_var(): + mod={ + "E-mail_for_checking_email":"", + "Password_for_checking_mail":"", + "Instagram_username":"", + "Instagram_password":"", + "Telegram_bot_API":"", + "Open_Weather_API":"" + } + data=open("kets.env","r") + dada=data.readlines() + for val in dada: + print(val) + k,v=val.strip().split(":",1) + if k in mod: + new_value = input(f"Enter a new value for {k}: ") + mod[k] = new_value + data.close() + data=open("kets.env","w") + for key, value in mod.items(): + data.write(f"{key}:{value}\n") + data.close() + data=open("kets.env","r") + dada=data.read() + print(dada) +def encrypt(): + key = Fernet.generate_key() + with open('crypt.key', 'wb') as filekey: + filekey.write(key) + print("new key gen") + with open('crypt.key', 'rb') as filekey: + key = filekey.read() + fernet = Fernet(key) + with open('kets.env', 'rb') as file: + original = file.read() + encrypted = fernet.encrypt(original) + with open('kets.env', 'wb+') as encrypted_file: + encrypted_file.write(encrypted) + enc=encrypted_file.read() + print(enc) +def decrypt(): + try: + with open('crypt.key', 'rb') as filekey: + key = filekey.read() + fernet = Fernet(key) + with open('.env', 'rb') as file: + original = file.read() + decrypted = fernet.decrypt(original) + with open('.env', 'wb+') as decrypted_file: + decrypted_file.write(decrypted) + print("decrypted") + except: + print("Invalid Key or Already decrypted") +decrypt() +init_var() +encrypt() \ No newline at end of file diff --git a/README.md b/README.md index 592a303..fea3ba0 100644 --- a/README.md +++ b/README.md @@ -77,17 +77,32 @@ BotFather is the official bot used to create and manage Telegram bots. Here are pillow pypdf (version 2.0 as latest 3.0 has some issues) + + cryptography + + dotenv + + instagrapi 4. Configure email and API tokens -5.Run this script in Python IDLE or in some IDE +5. Run Initialize.py script in Python IDLE or in some IDE first to configure all needed credentials + +6. Then, Run multi_bot.py to start the bot ## Security -Our goal is to provide secure environment so we have no unneccessary online communication like analytics it's just standalone on your desk -As we give our E-Mail id to our bot we don't know how secure is this we are working on that to improvise the privacy. + Our goal is to provide secure environment so we have no unneccessary online communication like analytics it's just standalone on your desk + + As we give our E-Mail id to our bot we don't know how secure is this we are working on that to improvise the privacy. + + We have included environmental variable to store all the credentials which is encrypted while executing initialize.py and will be only decrypted during bot startup + + The most important thing is that it is based on rolling codes and the encryption key changes everytime you start the bot and is stored securely +## Feature request + If you guys are into some feature just feel free to contact me through [TELEGRAM](https://t.me/philo_thee_philix) ## Disclaimer -Anyone can download or copy our code to use and redistribute but if you copy the whole code to someother projects kindly don't forget to give credits + Anyone can download or copy our code to use and redistribute but if you copy the whole code to someother projects kindly don't forget to give credits diff --git a/crypt.key b/crypt.key new file mode 100644 index 0000000..e69de29 diff --git a/multi_bot.py b/multi_bot.py index c928d3f..b9ac5ff 100644 --- a/multi_bot.py +++ b/multi_bot.py @@ -10,21 +10,74 @@ import re from instagrapi import Client from instagrapi.exceptions import LoginRequired +from dotenv import load_dotenv # # # INITIALIZE ALL REQUIRED KEYS AND CREDENTIALS BELOW FOR PROPER WORKING OF BOT # # -OW_API = "" -TELE_API_KEY = "" -USERNAME,PASSWORD="", "" +from cryptography.fernet import Fernet #Variable initializing + is_weather="0" sos_active="0" reels_active="0" string=" " cl = Client() tempdir=os.getcwd() +Credentials={} + + +#Code for handling credential encryption and decryption +a=1 +if a==1: + try: + with open('crypt.key', 'rb') as filekey: + key = filekey.read() + + fernet = Fernet(key) + with open('.env', 'rb') as file: + original = file.read() + decrypted = fernet.decrypt(original) + with open('.env', 'wb+') as decrypted_file: + decrypted_file.write(decrypted) + dnc=decrypted_file.read() + print("decrypted") + except : + print("Invalid Key or Already decrypted") + + #loading credentials and keys from env file + load_dotenv(tempdir+"\.env") + username=os.getenv("E-mail_for_checking_email") + password=os.getenv("Password_for_checking_mail") + TELE_API_KEY = os.getenv("TELE_API_KEY") + print(TELE_API_KEY) + OW_API = os.getenv("Open_Weather_API") + USERNAME = os.getenv("Instagram_username") + PASSWORD = os.getenv("Instagram_password") + with open(".env","r") as credentials: + Credentials=credentials.readlines() + print(Credentials) + key = Fernet.generate_key() + with open('crypt.key', 'wb') as filekey: + filekey.write(key) + print("new key gen") + try: + with open('crypt.key', 'rb') as filekey: + key = filekey.read() + fernet = Fernet(key) + with open('.env', 'rb') as file: + original = file.read() + encrypted = fernet.encrypt(original) + with open('.env', 'wb+') as encrypted_file: + encrypted_file.write(encrypted) + enc=encrypted_file.read() + print("encrypted") + except: + print("encrypt failed") + +print(Credentials) + # Directory creation and verification def init_dirs(): req_dir=("reels","temppdf","merged","tempimg") @@ -108,8 +161,6 @@ def junk_removal(): @bot.message_handler(commands=["check_email"]) def check_email(message): mail = imaplib.IMAP4_SSL("imap.gmail.com") - username = "philosanjaychamberline.26csb@licet.ac.in" - password = "456@Icam" mail.login(username, password) mail.select("inbox") result, data = mail.search(None, "UNSEEN") diff --git a/session.json b/session.json new file mode 100644 index 0000000..e69de29