def add_admin(message): '''this function add new admin from bot''' au = whois(message.chat.username) if au[0] == True and au[1] <= 0: raw_name = message.text[10:] raw_name2 = raw_name.strip() raw_name3 = re.sub(r'\s+', ' ', raw_name2) #raw_name4 = raw_name3.split(' ') #if mane str - many elements in corteg name_level = raw_name3.split(' ') #print(len(name_level)) if len(name_level) == 2: name = name_level[0] level = name_level[1] else: bot.send_message( message.chat.id, 'нужно указать телеграм-нейм нового админа и его левел') exit() from create_database import add_admin_mikrotik result = add_admin_mikrotik(name, level) if result == True: text = 'новый администратор успешно создан' bot.send_message(message.chat.id, text) else: text = 'такой админ уже есть.' bot.send_message(message.chat.id, text) else: bot.send_message(message.chat.id, text_no_id) pass
def help_for_bot(message): #markup = types.InlineKeyboardMarkup() #btn_key_help = types.InlineKeyboardButton(text='start') #markup.add(btn_key_help) a = whois(message.chat.username) if a[0] == True and a[1] <= 1: bot.send_message(message.chat.id, text_help) else: bot.send_message(message.chat.id, text_no_id)
def send_list_active_vpn_user(message): '''this command print list all active user vpn''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: a = api_test3.list_vpn_active_user() b = str(a) bot.send_message(message.chat.id, b) else: bot.send_message(message.chat.id, text_no_id) pass
def create_user(message): '''this function create new user vpn, set random name - cocteil and generation password. send it in chat''' au = whois(message.chat.username) #print('я твое имя', au) if au[0] == True and au[1] <= 1: text = message.text[7:] text = text.strip() from generation_name2 import create_name zero_name = create_name() #print('я голый текст') if text == None: duration = 3600 elif text.isdigit() == True: #print('это же число!') if text == 0: duration = 3600 else: duration = int(text) * 3600 elif len(text) == 0: duration = 3600 else: #print('не поверишь, но ты тут') #add create_mit_name from create_mit_name import create_mit_name #print('а я текст который прилетит', text) row_name = create_mit_name(text) #print('я есть полученный текст в мит', row_name) #print(type(row_name)) duration = row_name[1] duration = int(duration) #print('я дуратион,', duration, 'мой тип', type(duration)) zero_name = row_name[0] #print('я зеро нейм', zero_name) bot.send_message(message.chat.id, 'пробуем принять имя') #exit() #zero_name = '' a = api_test3.create_vpn_user(zero_name, duration) b = a['name'] b = str(b) #print('имя', b) #print(type(b)) c = a['password'] c = str(c) #print(b) #print(c) d = 'логин ' + b + ' пароль ' + c bot.send_message(message.chat.id, d) else: bot.send_message(message.chat.id, 'что то не то с правами. не буду создавать') pass
def count_all_user(message): a = whois(message.chat.username) if a[0] == True and a[1] <= 1: a = api_test3.list_count_vpn_user() b = str(a) bot.send_message(message.chat.id, b) #bot.send_message(message.chat.id, text_help) else: bot.send_message(message.chat.id, text_no_id) pass
def count_active_user(message): '''thi function print all count vpn user''' au = whois(message.chat.username) print(au) if au[0] == True and au[1] <= 1: a = api_test3.list_count_activity_vpn_user() b = str(a) bot.send_message(message.chat.id, b) else: bot.send_message(message.chat.id, text_no_id) pass
def send_list_vpn_user_name(message): ''' this function list all user vpn''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: a = api_test3.list_vpn_user_name() b = str(a) bot.send_message(message.chat.id, b) elif au[0] == False: bot.send_message(message.chat.id, text_no_id) pass else: pass
def start(message): '''This function displays various menus depending on the administrator's level''' au = whois(message.chat.username) print(au) if au[0] == True and au[1] == 0: bot.send_message(message.chat.id, 'нажми любую кнопку', reply_markup=markup0) elif au[0] == True and au[1] == 1: bot.send_message(message.chat.id, 'нажми любую кнопку', reply_markup=markup1) elif au[0] == True and au[1] == 2: bot.send_message(message.chat.id, 'нажми любую кнопку', reply_markup=markup2) else: bot.send_message(message.chat.id, 'нажми любую кнопку', reply_markup=markup2)
def list_connect(message): '''this function print list all active vpn connection. no arguments''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: a = api_test3.list_active_connections() b = str(a) if len(a) != 0: bot.send_message(message.chat.id, b) else: bot.send_message(message.chat.id, 'активных соединений нет.') else: bot.send_message(message.chat.id, text_no_id) pass
def enable_user(message): """берет имя, которое надо разрешить""" au = whois(message.chat.username) if au[0] == True and au[1] <= 1: state = dbworker.get_current_state(message.chat.id) if state == config.States.S_START.value: bot.send_message(message.chat.id, 'введите имя разрешаемого пользователя') dbworker.set_state(message.chat.id, config.States.enable_get.value) elif state == config.States.enable_get.value: bot.send_message(message.chat.id, 'вы начали разрешать пользователя, но не завершили\ завершите разрешение, или сбросьте все командой /reset') else: bot.send_message(message.chat.id, 'что то пошло не так, я сбросил все к началу.') dbworker.set_state(message.chat.id, config.States.S_START.value) else: bot.send_message(message.chat.id, text_no_id)
def send_list_vpn_user_name(message): ''' this function list all user vpn''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: a = api_test3.list_vpn_user_name() #print(type(a)) #b = str(a) bot.send_message(message.chat.id, 'существуют следующие пользователи') temp_user_str = '' for i in a: temp_user_str = i + ', ' + temp_user_str bot.send_message(message.chat.id, temp_user_str) elif au[0] == False: bot.send_message(message.chat.id, text_no_id) pass else: pass
def enable_user(message): '''this function enable vpn user, if er exist''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: text = get_name_u(message, 7) text = text.strip() a = api_test3.enable_vpn_user(text) if a == True: bot.send_message(message.chat.id, 'пользователь разрешен.') else: bot.send_message(message.chat.id, 'нет такого пользователя. некого разрешать.') else: bot.send_message(message.chat.id, text_no_id) pass
def delete_name(message): '''this function delete vpn user if exist''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: text = get_name_u(message, 7) #print('в смысле нот тайп', text) text = text.strip() a = api_test3.remove_vpn_user(text) if a == True: from api_test3 import close_connection close_connection(text) bot.send_message(message.chat.id, 'пользователь удален') else: bot.send_message(message.chat.id, 'увы, такого пользователя нет.') else: bot.send_message(message.chat.id, text_no_id) pass
def disable_user(message): au = whois(message.chat.username) '''this function disable vpn user, if exist''' if au[0] == True and au[1] <= 1: text = get_name_u(message, 8) text = text.strip() a = api_test3.disable_vpn_user(text) if a == True: from api_test3 import close_connection close_connection(text) bot.send_message(message.chat.id, 'пользователь запрещен.') else: bot.send_message(message.chat.id, 'нет такого пользователя. некого запрещать.') else: bot.send_message(message.chat.id, text_no_id) pass
def delete_name(message): '''просим имя''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: state = dbworker.get_current_state(message.chat.id) if state == config.States.S_START.value: bot.send_message(message.chat.id, 'введите имя удаляемого пользователя') dbworker.set_state(message.chat.id, config.States.delete_del.value) elif state == config.States.delete_del.value: bot.send_message(message.chat.id, 'у вас есть неудаленный пользователь. продолжите \ удаление или выполните команду /reset для отмены.') else: dbworker.set_state(message.chat.id, config.States.S_START.value) bot.send_message(message.chat.id, 'что то пошло не так, я вернулся к исходному состоянию.\ начните всё с начала.') else: bot.send_message(message.chat.id, text_no_id) pass
def create_user(message): '''this function create new user vpn, set random name - cocteil and generation password. send it in chat''' au = whois(message.chat.username) if au[0] == True and au[1] <= 1: #dbworker.set_state(message.chat.id, config.States.S_ENTER_NAME.value) state = dbworker.get_current_state(message.chat.id) if state == config.States.S_START.value: bot.send_message(message.chat.id, text_get_name) dbworker.set_state(message.chat.id, config.States.S_ENTER_NAME.value) elif state == config.States.S_ENTER_NAME.value: bot.send_message(message.chat.id, 'введите имя') elif state == config.States.S_ENTER_TIME.value: bot.send_message(message.chat.id, 'введите время') elif state == config.States.S_ENTER_FINAL.value: final_create(message) else: bot.send_message(message.chat.id, text_get_name) dbworker.set_state(message.chat.id, config.States.S_ENTER_NAME.value) else: bot.send_message(message.chat.id, 'что то не то с правами. не буду создавать') pass
def help_for_bot(message): a = whois(message.chat.username) if a[0] == True and a[1] <= 1: bot.send_message(message.chat.id, text_help) else: bot.send_message(message.chat.id, text_no_id)