Пример #1
0
def chLink(link):
    log.log(request.remote_addr + ' -> REQUEST ' + str(request.method) + ' /' + link + '\n')
    if link == 'favicon.ico' or link == 'unsupported.link':
        return redirect('http://' + hostName)
    link = hostName + '/' + link
    if checkPwd(link):
        return render_template('redirector.html')
    else:
        return redirect(getLink(link))
Пример #2
0
def verifyPwd(link, pwd):
    log.log(request.remote_addr + ' -> REQUEST ' + str(request.method) + ' /' + link + '/' + pwd + '\n')
    link = hostName + '/' + link
    if checkPwd(link):
        if validatePwd(link, pwd):
            return redirect(getLink(link))
        else:
            return redirect('http://' + hostName)
    else:
        return redirect('http://' + hostName)
Пример #3
0
def prepareSql():
    with sqlite3.connect('linksData.db') as connect:
        cursor = connect.cursor()
        cursor.execute("""CREATE TABLE IF NOT EXISTS links
                       (shortlink TEXT NOT NULL PRIMARY KEY, link TEXT NOT NULL)
                       WITHOUT ROWID""")
        connect.commit()
        cursor.execute("""CREATE TABLE IF NOT EXISTS pwds
                       (shortlink TEXT NOT NULL PRIMARY KEY, pwd TEXT NOT NULL)
                       WITHOUT ROWID""")
        connect.commit()
        log.log('SQL Prepared stage done')
Пример #4
0
def index():
    log.log(request.remote_addr + ' -> REQUEST ' + str(request.method) + ' /' + '\n')
    if request.method == 'GET':
        return render_template('index.html')
    if request.method == 'POST':
        userType = request.form.get('userType')
        link = request.form.get('link_in')
        if link == '':
            return render_template('index.html')
        link_out = generateNewLink(link)
        log.log(request.remote_addr + ' -> REQUEST ' + str(userType) + ' created new link\n\t\t\t\t' + str(link) + '\n\t\t\t\t' + str(link_out) + '\n')
        if request.form.get('set_pwd'):
            pwd = request.form.get('pwd_in')
            setPwd(link_out, pwd)
        if userType not in ('telegramBot', 'vkBot'):
            return render_template('index.html', link_out=link_out)
        else:
            return link_out
Пример #5
0
def main(msg):
    if msg.text == '/start':
        bot.send_message(msg.chat.id, 'Добро пожаловать в сокращатель ссылок! '
                                      'Просто введите ссылку и получите ее сокращенный вариант')
        return
    payload = {'link_in': msg.text, 'userType': 'telegramBot'}
    try:
        response = requests.post('http://www.linkcut.ru', data=payload)
        text = response.text
    except requests.exceptions.ConnectionError:
        log.log('Connection Error')
        text = 'Временная ошибка сервера, попробуйте чуть позже'
    except requests.exceptions.BaseHTTPError:
        log.log('HTTP Error')
        text = 'Временная ошибка сервера, попробуйте чуть позже'
    bot.send_message(msg.chat.id, text)
    logText = 'UID: ' + str(msg.chat.id) + '\tGenerated link: ' + text + '\n'
    log.log(logText)
Пример #6
0
import cfg  # cfg must include your bot TOKEN
import requests
import s_logger as log

bot = telebot.TeleBot(cfg.TOKEN)


@bot.message_handler(content_types=['text'])
def main(msg):
    if msg.text == '/start':
        bot.send_message(msg.chat.id, 'Добро пожаловать в сокращатель ссылок! '
                                      'Просто введите ссылку и получите ее сокращенный вариант')
        return
    payload = {'link_in': msg.text, 'userType': 'telegramBot'}
    try:
        response = requests.post('http://www.linkcut.ru', data=payload)
        text = response.text
    except requests.exceptions.ConnectionError:
        log.log('Connection Error')
        text = 'Временная ошибка сервера, попробуйте чуть позже'
    except requests.exceptions.BaseHTTPError:
        log.log('HTTP Error')
        text = 'Временная ошибка сервера, попробуйте чуть позже'
    bot.send_message(msg.chat.id, text)
    logText = 'UID: ' + str(msg.chat.id) + '\tGenerated link: ' + text + '\n'
    log.log(logText)


log.log('Started LinkCut Telegram Bot')
bot.polling(none_stop=True)
Пример #7
0
def log_the_status_code(response):
    if type(response) is not None:
        #print(request.remote_addr)
        status = response.status
        log.log(request.remote_addr + ' <- RESPONSE ' + str(status) + '\n')
    return response
Пример #8
0
        return redirect('http://' + hostName)
    link = hostName + '/' + link
    if checkPwd(link):
        return render_template('redirector.html')
    else:
        return redirect(getLink(link))


@app.route('/<link>/<pwd>', methods=['GET'], strict_slashes=False)
def verifyPwd(link, pwd):
    log.log(request.remote_addr + ' -> REQUEST ' + str(request.method) + ' /' + link + '/' + pwd + '\n')
    link = hostName + '/' + link
    if checkPwd(link):
        if validatePwd(link, pwd):
            return redirect(getLink(link))
        else:
            return redirect('http://' + hostName)
    else:
        return redirect('http://' + hostName)


if __name__ == '__main__':
    prepareSql()
    if os.path.exists('iter.pkl'):
        with open('iter.pkl', 'rb') as file:
            last = pickle.load(file)
    else:
        save()
    log.log('\n' + 28 * '_' + '\nStarting the core of linkcut web app\nHostname: ' + cfg.hostName + '\n' + 28 * '_' + '\n')
    app.run(host=hostName, port='80', debug=False)
Пример #9
0
def main():
    log.log('LinkCut Vk Bot Started\n')
    try:
        for event in poll.listen():
            if event.type == VkBotEventType.MESSAGE_NEW and event.message:
                if event.from_user and (event.message['text'] != '' or event.message['attachments'] != []):
                    uid = event.message['from_id']
                    umsg = str(event.message['text'])
                    if umsg == '':
                        at = event.message['attachments']
                        at = at[0]
                        # for link in at:
                        if at['type'] == 'link':
                            link = at['link']
                            umsg = link['url']
                        else:
                            umsg = 'Ошибка'
                    if umsg.lower() == 'начать':
                        msg = 'Добро пожаловать! Для сокращения ссылки просто напишите ее сюда :)'
                    elif umsg.lower() == 'ошибка':
                        msg = 'Произошла оказия, попробуйте еще раз'
                    else:
                        payload = {'link_in': umsg, 'userType': 'vkBot'}
                        try:
                            response = requests.post('http://www.linkcut.ru', data=payload)
                            msg = response.text
                        except requests.exceptions.ConnectionError:
                            log.log('Connection Error')
                            msg = 'Временная ошибка сервера, попробуйте чуть позже'
                        except requests.exceptions.BaseHTTPError:
                            log.log('HTTP error')
                            msg = 'Временная ошибка сервера, попробуйте чуть позже'
                    log.log('UID: ' + str(uid) + '\tMSG: ' + umsg + '\tRequest: ' + msg)
                    vk.messages.send(
                        random_id=get_random_id(),
                        message=msg,
                        user_id=uid
                    )
                if event.from_chat:
                    log.log('its chat')
                if event.from_group:
                    log.log('its group')
    except vk_api.ApiError as err:
        log.log('Error occurs: ' + str(err.error))
    except vk_api.ApiHttpError as err:
        log.log('Error occurs: ' + str(err.values))
    except vk_api.VkRequestsPoolException as err:
        log.log('Error occurs: ' + str(err.error))
    except requests.exceptions.ReadTimeout as err:
        log.log('Error occurs: ' + str(err.error))
        sleep(3)