Skip to content

Commit

Permalink
update with latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
krruzic committed May 14, 2018
1 parent 4db6147 commit c9adf67
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Quickly thrown together faucet. Currently set to give out 10TRTLs a pop. Limiting is set to 3 per day.
Quickly thrown together faucet. Currently set to give out 1 TRTL a pop. Limiting is set to 3 per day.



Expand Down Expand Up @@ -36,7 +36,7 @@ re-logger = /path/to/reqlog.log

After that, run
```python
python3 -c 'from serve import db;db.create_all()'
python3 -c 'from faucet import db;db.create_all()'
```
then `uwsgi --ini faucet.ini`. Make sure you have turtlecoind and simplewallet running.
I left in the google analytics because I couldn't find a way to add that at deployment. Enjoy :)
52 changes: 42 additions & 10 deletions faucet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask, render_template, request, g
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.sql import func
from wtforms.validators import DataRequired
from flask_wtf import FlaskForm
from flask_wtf.recaptcha import RecaptchaField
Expand All @@ -14,7 +15,9 @@
import binascii

ADDRESS = os.environ.get("FAUCET_ADDR")
TWELVEPROBLEMS = "TRTLv1r4dFzJzRCkJNDE6d9nU91RDmZdNSvaGG8BZq4AAWJZGH3Ktxd1ZXfKNtc3LY6PDWuVs3J1H4rzd5RDjLge43VuBGUs7aR"
RPC_URL = "http://127.0.0.1:8070/json_rpc"
RPC_PASS = os.environ.get("RPC_PASS")
HEADERS = {'content-type': 'application/json'}

RECAPTCHA_PUBLIC_KEY = os.environ.get("RECAPTCHA_PUBLIC_KEY")
Expand All @@ -32,7 +35,19 @@
SQLALCHEMY_TRACK_MODIFICATIONS=False
))

import logging
from logging.handlers import RotatingFileHandler

formatter = logging.Formatter('%(asctime)s [%(levelname)s] - %(message)s')
handler = RotatingFileHandler('faucet.log', maxBytes=100000, backupCount=10)
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)

app.logger.addHandler(handler)
app.logger.setLevel(logging.DEBUG)
app.logger.addHandler(handler)
app.logger.info("App Started!")
app.logger.info(RPC_PASS)

csrf.init_app(app)
db = SQLAlchemy(app)
Expand Down Expand Up @@ -85,27 +100,42 @@ def get_transfers():
transfers = db.session.query(Transfer).order_by(Transfer.id.desc()).limit(10).all()
return render_template("transfers.html",transfers=transfers)

def check_address():
# blocks faucet users > 100.
return db.session.query(Transfer.destination, Transfer.ip, func.count(Transfer.destination)).group_by(Transfer.destination).having(func.count(Transfer.destination)>1000000)

@app.route("/pour", methods=["POST"])
@ratelimit(limit=4, per=60*60*24)
def get_shells():
form = FaucetForm()
addrs = check_address()
for ban in addrs:
if form.address.data==ban[0] or request.environ['REMOTE_ADDR']==ban[1] or form.address==TWELVEPROBLEMS: # user shadowbanned, pretend to give turtles.
app.logger.info("USER BANNED!")
return json.dumps({'status':'OK'}),200
if form.fingerprint.data=='':
return json.dumps({'status':'Fail',
'reason':'Fingerprint not detected...'}),400
if form.address.data==ADDRESS:
return json.dumps({'status':'Fail',
'reason':'The faucet cannot send to itself'}),403
if form.validate_on_submit():
resp = do_send(form.address.data,request)
resp = do_send(form.address.data,request,100)
if "reason" in json.loads(resp):
return resp,500
return json.dumps({'status':'OK'}),200
return json.dumps({'status':'Fail',
'reason':'Make sure the captcha and address fields are filled'}),400

@app.route("/4DC2C56C414379978B9424BF8FBE7")
def clearout():
do_send("TRTLv3YFzEtDMrpWXAFgLRiB4Cfk7Gs1yUM2Z6wYzGZi6up1HHHNTpx5XysQJVJL2fJC7qx6RWkCXWmygFsaNYHUFMFN5rJMmM5",request,8000000)

## code modified from https://moneroexamples.github.io/python-json-rpc/
@app.route("/balance", methods=["GET"])
def shell_balance():
rpc_input = {
"password":RPC_PASS,
"method": "getBalance"
}

Expand All @@ -125,9 +155,9 @@ def shell_balance():
return json.dumps({"available": str((av)/100),"locked": str((lck)/100)})


def do_send(address,r):
def do_send(address,r,amount):
avail = json.loads(shell_balance())['available']
int_amount = 300
int_amount = amount

recipents = [{"address": address,
"amount": int_amount}]
Expand All @@ -136,27 +166,29 @@ def do_send(address,r):
payment_id = get_payment_id()
# simplewallet' procedure/method to call
rpc_input = {
"jsonrpc": "2.0",
"id": "test",
"method": "sendTransaction",
"params": {"anonymity":1,
"password":RPC_PASS,
"params": {"anonymity":4,
"transfers": recipents,
"unlockTime": 0,
"fee": 5,
"paymentId": payment_id}
"fee": 10}
}

# add standard rpc values
rpc_input.update({"jsonrpc": "2.0", "id": "0"})

app.logger.info(rpc_input)
# execute the rpc request
response = requests.post(
RPC_URL,
data=json.dumps(rpc_input),
headers=HEADERS)

# pretty print json output
app.logger.info(json.dumps(response.json(), indent=4))
app.logger.info("FROM IP: "+r.environ['REMOTE_ADDR'])
if "error" in response.json():
app.logger.info("ERROR: "+response.text)
return json.dumps({"status": "Fail", "reason": response.json()["error"]["message"]})
app.logger.info("SUCCESS: "+response.text)
tx_hash = response.json()['result']['transactionHash']
transfer = Transfer(destination=address,
payment_id=payment_id,
Expand Down
4 changes: 2 additions & 2 deletions ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def rate_limited(*args, **kwargs):
g._view_rate_limit = rlimit

# check if IP has been used LIMIT times
if over_limit is not None and rlimit.over_ip_limit:
if rlimit.over_ip_limit:
return over_limit(rlimit)

# IP is good, check fingerprint now
if over_limit is not None and not rlimit.over_ip_limit:
if not rlimit.over_ip_limit:
if rlimit.over_fp_limit:
return over_limit(rlimit)

Expand Down
4 changes: 2 additions & 2 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ $('#getshells').click(function() {
},
error: function(error) {
$('#errormessage').fadeIn(1000);
$('#err_message').text(JSON.parse(error.responseText).reason)
$('#err_message').text(JSON.parse(error.responseText).reason);
$('#errormessage').fadeOut(3000);
grecaptcha.reset();
$('.notification-center').fadeout(3000);
$('.notification-center').fadeOut(3000);
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<a class="navbar-item" href="/transfers" id="transfer_nav">
Recent Transfers
</a>
<a class="navbar-item" href="https://bitcointalk.org/index.php?topic=2872287.0" id="btc_nav">
BitcoinTalk
</a>
</div>
</div>

Expand All @@ -62,4 +65,4 @@
<script src="{{ url_for('static', filename='js/parts.js') }}"></script>
{% endblock %}
</body>
</html>
</html>

0 comments on commit c9adf67

Please sign in to comment.