Coder Social home page Coder Social logo

python-antispam's Introduction

python-antispam

Prevents spam in your python web apps. Cloud features allow you to use additional anti-spam functionality. Cloud features allow you to use additional anti-spam functionality, such as: Personal IP/Email lists, blocking by country, language, stop words and etc.

Spam attacks log - allows to view all filtered requests in the "Log of spam attacks". The log contains a detailed information about each request for a time period. At any time, you can check the request and make sure that the filtering is correct. A Python API for antispam service cleantalk.org. Invisible protection from spam, no captches, no puzzles, no animals and no math.

How API stops spam?

API uses several simple tests to stop spammers.

  • Spam bots signatures.
  • Blacklists checks by Email, IP, web-sites domain names.
  • JavaScript availability.
  • Comment submit time.
  • Relevance test for the comment.

How API works?

API sends a comment's text and several previous approved comments to the servers. Servers evaluates the relevance of the comment's text on the topic, tests on spam and finaly provides a solution - to publish or put on manual moderation of comments. If a comment is placed on manual moderation, the plugin adds to the text of a comment explaining the reason for the ban server publishing.

Requirements

SPAM test for text comment sample

from cleantalk import CleanTalk
import json


ct = CleanTalk(auth_key='yourkey')
ct_result = ct.request(
                message = 'abc', # Required. Visitor comment
                sender_ip = '196.19.250.114', # Required. Visitor IP address
                sender_email = '[email protected]', # Required. Visitor email
                sender_nickname = 'spam_bot', # Required. Visitor nickname
                post_info= json.dumps({'post_url': 'https://yoursite.com'}) # Optional. Additional post info in JSON format.
                # event_token = 'xxx' # fill it with ct_bot_detector_event_token hidden input from your form (auto generate)
        )
#Check
if ct_result['allow']:
    print('Comment allowed. Reason ' + ct_result['comment'])
else:
    print('Comment blocked. Reason ' + ct_result['comment'])

API Response description

API returns Python dictionary object, where keys:

  • allow (0|1) - allow to publish or not, in other words spam or ham
  • comment (string) - server comment for requests.
  • id (string MD5 HEX hash) - unique request idenifier.

Installing via PyPi

Run the next command in the terminal:

pip install cleantalk-python-antispam

Then you can use Cleantalk class import:

from cleantalk_python_antispam.cleantalk import CleanTalk

For improve protection include javascript to your layout before </body> tag:

<script type="text/javascript" src="https://moderate.cleantalk.org/ct-bot-detector-wrapper.js"></script>

Changelog

Version 1.2

  • New. Now page URL could be added to the request.
  • Mod. Tests file updated.
  • Mod. Readme updated.

python-antispam's People

Contributors

alexandergull avatar begezavr avatar glomberg avatar safronik avatar shagimuratov avatar svfcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-antispam's Issues

How to pass the url of the current page?

Hello, please tell me how to transfer information about the current page? Suppose I have a URL_PAGE variable that stores the URL of the current page. How can I transfer information from it to you?

Test key Expired?

$ python3.9 tests.py
{'fast_submit': 0, 'blacklisted': 0, 'id': '5fa3512d42b75f1626043fb09c51aaa5', 'stop_queue': 0, 'allow': 1, 'js_disabled': 0, 'comment': '*** Trial period expired. Please subscribe to the service. ', 'inactive': 1, 'spam': 0, 'account_status': 0, 'codes': 'TRIAL_EXPIRED', 'version': '7.77'}
F{'spam': 0, 'stop_queue': 0, 'version': '7.77', 'comment': '
Trial period expired. Please subscribe to the service. ', 'id': 'a7475b5868bdf5bd005a8d077a6eed6c', 'account_status': 0, 'allow': 1, 'codes': 'TRIAL_EXPIRED', 'blacklisted': 0, 'fast_submit': 0, 'inactive': 1, 'js_disabled': 0}
.{'comment': '
Trial period expired. Please subscribe to the service. ***', 'inactive': 1, 'blacklisted': 0, 'account_status': 0, 'spam': 0, 'version': '7.77', 'js_disabled': 0, 'allow': 1, 'stop_queue': 0, 'fast_submit': 0, 'id': 'edda0dfe484cc4cb93b94e7e8a02a28c', 'codes': 'ALLOWED TRIAL_EXPIRED'}

Kindly advise?

pypi?

Is this available on PyPI? If not, is there any interest in making it available on the PYthon Package Index?

DOES NOT WORK!!!

DOES NOT WORK!!!

I put the cleantalk library in the application folder and imported it into views, the following code from views

def contactView(request): if request.method == 'GET': form = ContactForm() else: form = ContactForm(request.POST) if form.is_valid(): ct = CleanTalk(auth_key='111') ct_result = ct.request( subject = form.cleaned_data['subject'] name = form.cleaned_data['name'] from_email = form.cleaned_data['from_email'] message = form.cleaned_data['message'] ) if ct_result['allow']: msg = str(name) + '(' + str(from_email) + ')' + '\n отправил сообщение с темой "' + str(subject) + '":\n' + str(message) try: send_mail(subject, msg, '[email protected]', ['[email protected]'], fail_silently=False) except BadHeaderError: return HttpResponse('Обнаружен недопустимый заголовок.') return redirect('success') else: raise forms.ValidationError("Blocked!!!!") return render(request, "email.html", {'form': form})

Did you change something and not notify?

Did you change something and not notify?

the code:
ct_result = ct.request( message=content, # Visitor comment sender_ip=clientIP, # Visitor IP address sender_email=email, # Visitor email sender_nickname=author, # Visitor nickname js_on=1, # Is visitor has JavaScript submit_time=12, # Seconds from start form filling till the form POST post_info = json.dumps({'post_url': post_url}) # here is the place for page url )
gives an error message:
JSONDecodeError at /tkinterdesigner-graficheskij-interfejs-na-python/ Expecting value: line 1 column 1 (char 0)
the problem is in post_info = json.dumps({'post_url': post_url})

This line gives an error on two sites, I did not change anything in the site settings.

Originally posted by @mrkaban in #7 (comment)

Is python 3 supported? Поддерживается ли python 3?

The requirements specify Python 2.6 and above, so the question is, is python 3 supported? Although, judging by the fact that you only have one py file here, it means it is only for python 2.

Having such a module is good, great and ** very interesting **, but who is going to write sites in Python 2 now? Recent versions of Django no longer support Python 2.7, as it no longer receives security updates.

В требованиях указано Python 2.6 и выше, в связи с этим вопрос, поддерживается ли python 3? Хотя, если судить по тому, что у вас тут всего один файл py, значит он только для python 2.

Наличие такого модуля хорошо, замечательно и очень интересно, но кто сейчас будет писать сайты на Python 2? Последние версии Django уже по моему не поддерживают Python 2.7, так как он больше не получает обновлений безопасности.

Will this work with Django?

Will this work with Django?

How would we calculate the time taken to fill in the comment form or know if JS is on?

Thanks

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.