from otree.api import * import base64 import binascii import json,os class C(BaseConstants): NAME_IN_URL = 'redirect_pay' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 ONLINE = bool(int(open('online.txt').read())) if os.path.exists('online.txt') else True class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): pass # FUNCTIONS def cryptodome_encrypt(data, passphrase): """ # https://gist.github.com/eoli3n/d6d862feb71102588867516f3b34fef1 Encrypt using AES-256-CBC with random/shared iv 'passphrase' must be in hex, generate with 'openssl rand -hex 32' Encrypt using AES-128-CBC with random/shared iv 'passphrase' must be in hex, generate with 'openssl rand -hex 16' """ try: from Crypto.Cipher import AES from Crypto import Random key = binascii.unhexlify(passphrase) pad = lambda s : s+chr(16-len(s)%16)*(16-len(s)%16) iv = Random.get_random_bytes(16) cipher = AES.new(key, AES.MODE_CBC, iv) encrypted_64 = base64.b64encode(cipher.encrypt(pad(data).encode())).decode('ascii') iv_64 = base64.b64encode(iv).decode('ascii') json_data = {} json_data['iv'] = iv_64 json_data['data'] = encrypted_64 clean = base64.b64encode(json.dumps(json_data).encode('ascii')) except Exception as e: print("Cannot encrypt datas...") print(e) # exit(1) return clean.decode() # PAGES class RedirectPage(Page): @staticmethod def vars_for_template(player: Player): label=False if not player.participant.label or (player.participant.label in player.session.config.get('bot_labels',[])) or not C.ONLINE else player.participant.label redirect_phrase=''; redirect_page = '' detour_ces = True if not (not label): sitefolder='CES2026N3' redirect_phrase='Vous allez être redirigé vers la page des coordonnées bancaires pour le paiement.' gain_security_key='d6c057707e929187c367f7ee032123af' passphrase = 'puQuoushichoo6que' if detour_ces: sitestart='https://leep-redirect-iban.s2ch.fr/room/'+sitefolder data = { 'gain' : float(player.participant.payoff_plus_participation_fee()), 'pass' : passphrase, 'don' : player.participant.vars.get("donation", 0), 'asso' : player.participant.vars.get("association", ''), 'label' : label, } if 'overbooked' in player.participant.vars and player.participant.vars['overbooked']: data['overbooking'] = True if 'overbooking' in player.session.config and player.session.config['overbooking'] and player.participant.payoff == 0: data['overbooking'] = True jsdata=json.dumps(data) redirect_page = sitestart+'?participant_label='+label+'&data='+cryptodome_encrypt(jsdata,gain_security_key) else: from urllib.request import urlopen sitestart='https://s2ch-experiences.huma-num.fr/enligne' data=dict( gainEUR=str(player.participant.payoff_plus_participation_fee()).split(' ')[0].replace(',','.'), Finished=1, ) jsdata=json.dumps(data) f = urlopen(sitestart+'/expe/'+sitefolder+'/connect.php?name='+str(label)+'&status=setvarsgetlinkcode&iv=json&encdata='+cryptodome_encrypt(jsdata,gain_security_key)) key=f.read().decode('utf-8') redirect_page = sitestart+'/expe/'+sitefolder+'/paydistrib.php?name='+str(label)+'&key='+key # print(key) return {'redirect_phrase' : redirect_phrase, 'redirect_page' : redirect_page} page_sequence = [RedirectPage]