Forum Freedom-IP VPN

Forum d'entraide de la communauté Freedom-IP VPN

Vous n'êtes pas identifié(e).

#1 Re : Aide Linux » pas de navigation internet » 2016-01-10 14:04:03

tu peut me donner le retour de la commande suivante

ls ~/Téléchargements/fip-linux

#2 Re : Aide Linux » pas de navigation internet » 2016-01-10 08:36:55

Bonjour,
Tu peux utiliser la commande suivante si pass_vpn est dans le répertoire ~/Téléchargements/fip-linux

cd ~/Téléchargements/fip-linux/ && sudo openvpn --config ~/Téléchargements/fip-linux/NL-\(Netherlands\).ovpn --auth-user-pass pass_vpn

#3 Re : Aide Linux » pas de navigation internet » 2016-01-09 09:54:19

Salut,
pourrais-tu me donner le retour de la commande suivante ?

ls && sudo openvpn --config ~/Téléchargements/fip-linux/NL-\(Netherlands\).ovpn --auth-user-pass pass_vpn

Merci,
Didier

#4 Re : Aide Linux » pas de navigation internet » 2016-01-08 22:41:16

Bonsoir,
Ils doivent être dans le répertoire courant, si je ne me trompe pas

A+,
Didier

#5 Re : Aide Linux » pas de navigation internet » 2016-01-06 10:27:35

Bonjour Chicard,
il semble y avoir des règles restrictive dans ton pare feu, pourrais-tu donner le retour de la commande suivante ?

sudo iptables -L

Si le retour est le suivant

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

C'est qu'il n'y a pas de pare feu, donc un soucis avec Network manager, sa arrive plus souvent que l'on le voudrait.
Dans ce cas utilise la ligne de commande
voici un exemple

sudo openvpn --config ~/freedom-ip/LT-\(Lithuania\).ovpn --auth-user-pass pass_vpn

dans cette exemple j'ai enregistré mon ID et mot de passe VPN dans le fichier pass_vpn

le fichier pass_vpn se présente comme sa

FIP_xxxxxxxxxxxxxx
mot de passe

A+,
Didier.

P.S. : le fichier pass_vpn doit être dans le répertoire courant  wink

#6 Re : Applications Freedom-IP » Amélioration de l'API » 2015-12-05 14:05:57

Bonjour Patrick,
En fait pour le moment il n'y a que hmz qui puisse voir ce qu'il ce passe

#7 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-29 15:58:35

Bonjour,
bon, je crois que je vais laisser les pro de Windows nous faire l’exécutable (il y aura bien une âme charitable  kiss )

je n'ai pas rencontré le soucis avec les accents que tu as remonté plus haut Patrick, je ne peut donc pas tester cette solution

#! /usr/bin/python3
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

from time import time
from platform import system
from json import loads
from base64 import encodestring
from urllib.parse import urlencode
from urllib.request import Request, urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password, verbeux):
        self.v=verbeux
        self.user=user
        self.password=encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                self.v and print("FAIL %s" % e)
                if e.code==401:
                    self.v and print(u"INFO Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                self.v and print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    self.v and print(u"[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        try:
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
        except:
            ret = '{"status":"retour nul"}'
            pass
#        print(repr(ret))
        return ret

    def _info(self, recherche):
        if system() != 'Linux':
            self.v and print("INFO Demande "+recherche)
        else:
            self.v and print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            if system() != 'Linux':
                self.v and print("OK "+recherche)
            else:
                self.v and print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            if system() != 'Linux':
                self.v and print("FAIL Erreur "+status)
            else:
                self.v and print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])
    timer.start()
    api_ret=[]
    fip=api(user, password, True)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        if system() != 'Linux':
            print("Arbre retour fonction :".format(list_api[x]))
        else:
            print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    if system() != 'Linux':
        print("Chronomètre :")
    else:
        print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

A+,
Didier.

#8 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 16:53:48

il n'a pas aimé l'accent sur "vérifier".
tu as bien utilisé python 3 ?
en même temps tu peut utiliser l'exe que j'ai mis plus haut

#11 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 13:53:39

je vais devenir dingue, donc il y a un autre soucis  cry

#12 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 13:35:59

l'API ne retourne pas d'information pour userInfo car il n'y a rien a dire neutral , depuis le début je l'avais sous les yeux ops cry (vas falloir que je m’achète des lunettes glasses )
Ce code devrait fonctionner, en tout cas sous linux, je ne sais pas ce que le passage a python 3 vas avoir changé sous Windows roll

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        try:
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
        except:
            ret = '{"status":"retour nul"}'
            pass
        print(repr(ret))
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

Edit : en fait metalux et toi n'avez certainement pas d'abonnement, d’où le manque d'information sur userinfo, si ce n'est pas le cas c'est un soucis de l'API d'hmz
et oui Veni Vidi Vici

A+,
Didier.

#13 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 13:22:32

Patrick essaye sa, je crois avoir vue le soucis

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
            print(repr(ret))
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server']#,'userInfo','livestats']
    api_ret.append(fip.Server())
#    api_ret.append(fip.userInfo())
#    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

#14 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 12:43:48

Bonjour David,
hmz m'a dit comment récupérer les informations.

Edit : nouvel essais, ont finira par l'avoir cette erreur ridicule  devil

en Python3

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.readline().decode(encoder)).strip("'<>() ").replace('\'', '\"')
            print(repr(ret))
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

#15 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 11:42:09

Une petite question tu fais les essais VPN en marche ou non  ?

Edit : en fait cher moi sa fonctionne avec ou sans VPN

#16 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 11:34:26

#! /usr/bin/python3
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = str(response.read().decode(encoder)).strip("'<>() ").replace('\'', '\"')
#            print(ret)
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

#18 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 11:14:15

#! /usr/bin/python3
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import time, platform, json, base64
from urllib.parse import urlencode
from urllib.request import Request
from urllib.request import urlopen

try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password.encode()).decode().replace('\n', '')

    def _past(self, url, args):
        req = Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urlopen(req, context=gcontext, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urlopen(req, timeout = 5)
            except Exception as e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encoder=response.headers['content-type'].split('charset=')[-1]
            ret = response.read().decode(encoder)
#            print(ret)
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=json.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=json.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=json.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print('Temp consultation API :', t1)
    print('Temp exploration arbres :', timer.interval-t1)
    print('Temp consultation API + exploration arbres :', timer.interval)


if __name__ == '__main__':
    _test()

#19 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-28 10:21:20

Bonjour,
un nouvelle essais, avant de changer de version de python et passer a python 3  cry
cette fois je demande au script de décoder les informations et de les transformer en unicode, pour éliminer les problèmes de codage (après tous pourquoi pas  tongue )

#! /usr/bin/python
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import urllib, urllib2, time, platform, simplejson, base64
try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password)

    def _past(self, url, args):
        params = urllib.urlencode(args)
        req = urllib2.Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urllib2.urlopen(req, context=gcontext, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urllib2.urlopen(req, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            encode=response.headers['content-type'].split('charset=')[-1]
            decode = unicode(response.read(), encode)
            print(decode)
            ret=decode#.encode('utf-8')
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=simplejson.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=simplejson.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=simplejson.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print 'Temp consultation API :', t1
    print 'Temp exploration arbres :', timer.interval-t1
    print 'Temp consultation API + exploration arbres :', timer.interval


if __name__ == '__main__':
    _test()

j’attends vos retour avec impatience  big_smile

A+,
Didier.

@Metalux, viens faire un tour sur le salon IRC s'il te plaît, j'aimerais tester un truc... Merci

#21 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-26 20:16:29

ont vas finir par pourrir le topic  big_smile

aller nouvelle essais cette fois on sort les données de la fonction et on fait le traitement plus tard

#! /usr/bin/python
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import urllib, urllib2, time, platform, simplejson, base64
try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password)

    def _past(self, url, args):
        params = urllib.urlencode(args)
        req = urllib2.Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urllib2.urlopen(req, context=gcontext, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urllib2.urlopen(req, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            ret=response.read()
        else:
            ret = "{}"
        return ret

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=simplejson.loads(self._info("Server"))
        return self._verif(response, "Server")

    def userInfo(self):
        response=simplejson.loads(self._info("userInfo"))
        return self._verif(response, "userInfo")

    def livestats(self):
        response=simplejson.loads(self._info("livestats"))
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print 'Temp consultation API :', t1
    print 'Temp exploration arbres :', timer.interval-t1
    print 'Temp consultation API + exploration arbres :', timer.interval


if __name__ == '__main__':
    _test()

pour info tout les codes que je vous aient proposé fonctionne parfaitement cher moi

#22 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-26 19:28:32

J'y perd mon latin.
En plus vous n'avez pas l'erreur sur le même caractère yikes

#23 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-26 19:08:09

et avec ceci, au cas ou il y aurait un retour a la ligne caché

#! /usr/bin/python
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import urllib, urllib2, time, platform, simplejson, base64
try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password)

    def _past(self, url, args):
        params = urllib.urlencode(args)
        req = urllib2.Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urllib2.urlopen(req, context=gcontext, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urllib2.urlopen(req, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            data=simplejson.loads(response.read().replace('\r', '').replace('\n', ''))
        else:
            data = ""
        return data

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=self._info("Server")
        return self._verif(response, "Server")

    def userInfo(self):
        response=self._info("userInfo")
        return self._verif(response, "userInfo")

    def livestats(self):
        response=self._info("livestats")
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print 'Temp consultation API :', t1
    print 'Temp exploration arbres :', timer.interval-t1
    print 'Temp consultation API + exploration arbres :', timer.interval


if __name__ == '__main__':
    _test()

#24 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-26 19:01:17

En fait c'est comme si il n'y avait rien a traiter  hmm

#25 Re : Applications Freedom-IP » Amélioration de l'API » 2015-11-26 18:07:48

Re,
essaye donc ceci Patrick

#! /usr/bin/python
# -*- coding: utf-8 -*-
# Par Didier-T pour les utilisateurs de Freedom-IP
# Version 3

########################################################################
#                                                                      #
#                            UTILISATION                               #
#                                                                      #
########################################################################
#                                                                      #
# from API_lib import api                                              #
#                                                                      #
# user="Identifiant VPN"                                               #
# password="Mot de passe VPN"                                          #
#                                                                      #
# IsLogged=api.Server()                                                #
# FairUse=api.userInfo()                                               #
# DNSConfig=api.livestats()                                            #
#                                                                      #
########################################################################

########################################################################
#                                                                      #
#                   UTILISATION FONCTION TEST API                      #
#                                                                      #
########################################################################
#                                                                      #
# python API_lib.py user password                                      #
#                                                                      #
########################################################################

import urllib, urllib2, time, platform, simplejson, base64
try:
    import ssl
except:
    pass

class api():
    def __init__(self, user, password):
        self.user=user
        self.password=base64.encodestring(password)

    def _past(self, url, args):
        params = urllib.urlencode(args)
        req = urllib2.Request(url, headers=args)
        if platform.system() != 'Linux':
            gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
            try:
                response = urllib2.urlopen(req, context=gcontext, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        else:
            try:
                response = urllib2.urlopen(req, timeout = 5)
            except Exception, e:
                print("[\033[31mFAIL\033[0m] %s" % e)
                if e.code==401:
                    print("[\033[33mINFO\033[0m] Veuillez vérifier vos identifiants ")
                response = ""
                pass
        if response != "":
            data=simplejson.loads(response.read())
        else:
            data = ""
        return data

    def _info(self, recherche):
        print("[\033[33mINFO\033[0m] Demande "+recherche)

        if recherche=="Server":
            url='https://api.freedom-ip.com/Server/all'
        elif recherche=="userInfo":
            url='https://api.freedom-ip.com/Account/userInfo'
        elif recherche=="livestats":
            url='https://api.freedom-ip.com/Account/livestats'

        return self._past(url, {'X-FIP-USER':self.user, 'X-FIP-PASSWORD':self.password})


    def _verif(self, informations, recherche):
        try:
            status=informations["status"]
        except:
            status="success"
        if status=="success":
            print("[\033[32m OK \033[0m] "+recherche)
            return informations
        else:
            print("[\033[31mFAIL\033[0m] Erreur "+status)
            exit(1)


    def Server(self):
        response=self._info("Server")
        return self._verif(response, "Server")

    def userInfo(self):
        response=self._info("userInfo")
        return self._verif(response, "userInfo")

    def livestats(self):
        response=self._info("livestats")
        return self._verif(response, "livestats")

def arbres(jstr):
    tableau=[]

    def decoupage(nom, valeur):
        if type(valeur)==list:
            nb=0
            for x in valeur:
                decoupage(nom+"["+str(nb)+"]", x)
                nb+=1
        elif type(valeur)==dict:
            for x in valeur:
                decoupage(nom+"["+x+"]", valeur[x])
        else:
            try:
                tableau.append(nom+"="+valeur)
            except:
                tableau.append(nom+"="+str(valeur))

    if type(jstr)==list:
        nb=0
        for x in jstr:
            decoupage("["+str(nb)+"]", x)
            nb+=1
    elif type(jstr)==dict:
        for x in jstr:
            decoupage("["+x+"]", jstr[x])
    else:
        tableau.append(str(jstr))

    return tableau




def _test():
    import sys

    class Timer(object):
        def start(self):
            if hasattr(self, 'interval'):
                del self.interval
            self.start_time = time.time()
        def inter(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
        def stop(self):
            if hasattr(self, 'start_time'):
                self.interval = time.time() - self.start_time
                del self.start_time

    timer = Timer()
    user=str(sys.argv[1])
    password=str(sys.argv[2])

    timer.start()
    api_ret=[]
    fip=api(user, password)
    list_api=['Server','userInfo','livestats']
    api_ret.append(fip.Server())
    api_ret.append(fip.userInfo())
    api_ret.append(fip.livestats())

    timer.inter()
    t1=timer.interval

    for x in range(0,len(api_ret)):
        print("\033[41mArbre retour fonction \033[1m{}()\033[0;41m :\033[0m".format(list_api[x]))
        print('\n'.join(arbres(api_ret[x])))
        print('\n')

    print("\033[41mChronomètre :\033[0m")
    timer.stop()
    print 'Temp consultation API :', t1
    print 'Temp exploration arbres :', timer.interval-t1
    print 'Temp consultation API + exploration arbres :', timer.interval


if __name__ == '__main__':
    _test()

Pied de page des forums

Propulsé par FluxBB