Exemplo n.º 1
0
    def remove_message(token, messageId):
        """
        This method will remove a message that was previously broadcasted.
        This method requires Edit Messages permission.
        
        More docs: https://app.cryptolens.io/docs/api/v3/RemoveMessage
        """

        try:
            response = HelperMethods.send_request("/message/RemoveMessage/", {
                "token": token,
                "Id": messageId
            })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (True, "")
Exemplo n.º 2
0
    def get_messages(token, channel="", time=0):
        """
        This method will return a list of messages that were broadcasted.
        You can create new messages here. Messages can be filtered based on the time and the channel.
        
        More docs: https://app.cryptolens.io/docs/api/v3/GetMessages
        """

        try:
            response = HelperMethods.send_request("/message/getmessages/", {
                "token": token,
                "Channel": channel,
                "Time": time
            })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj["messages"], "")
Exemplo n.º 3
0
    def extend_license(token, product_id, key, no_of_days):
        """
        This method will extend a license by a certain amount of days.
        If the key algorithm in the product is SKGL, the key string will
        be changed if necessary. Otherwise, if SKM15 is used, the key will
        stay the same. More about the way this method works in Remarks.
        
        More docs: https://app.cryptolens.io/docs/api/v3/ExtendLicense
        """

        response = ""

        try:
            response = HelperMethods.send_request("key/ExtendLicense", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Key" : key,\
                                                  "NoOfDays" : no_of_days})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (False, jobj["message"])
            else:
                return (False, "Could not contact the server.")

        return (True, jobj["message"])
Exemplo n.º 4
0
    def block_key(token, product_id, key):
        """
        This method will block a specific license key to ensure that the key
        cannot be accessible by most of the methods in the Web API 
        (activation, validation, optional field, and deactivation). Note,
        blocking the key will still allow you to access the key in Web API 3,
        unless otherwise stated for a given Web API 3 method. 
        To do the reverse, please see Unblock Key.
        
        More docs: https://app.cryptolens.io/docs/api/v3/BlockKey
        """

        response = ""

        try:
            response = HelperMethods.send_request("/key/BlockKey", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Key" : key})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (False, jobj["message"])
            else:
                return (False, "Could not contact the server.")

        return (True, jobj["message"])
Exemplo n.º 5
0
    def get_products(token):
        """
        This method will return the list of products. Each product contains fields such as
        the name and description, as well feature definitions and data objects. All the fields
        of a product are available here: https://app.cryptolens.io/docs/api/v3/model/Product
        
        More docs: https://app.cryptolens.io/docs/api/v3/GetProducts
        """

        try:
            response = HelperMethods.send_request("/product/getproducts/",
                                                  {"token": token})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj["products"], "")
Exemplo n.º 6
0
    def deactivate(token, product_id, key, machine_code, floating=False):
        """
        Calls the Deactivate method in Web API 3 and returns a tuple containing
        (Success, Message). If an error occurs, Success will be False. If
        everything went well, Sucess is true and no message will be returned.
        
        More docs: https://app.cryptolens.io/docs/api/v3/Deactivate
        """

        response = ""

        try:
            response = HelperMethods.send_request("key/deactivate", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Key" : key,\
                                                  "Floating" : floating,\
                                                  "MachineCode":machine_code})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (False, jobj["message"])
            else:
                return (False, "Could not contact the server.")

        return (True, "")
Exemplo n.º 7
0
    def create_trial_key(token, product_id, machine_code):
        """
        Calls the CreateTrialKey method in Web API 3 and returns a tuple containing
        (LicenseKeyString, Message). If an error occurs, LicenseKeyString will be None. If
        everything went well, no message will be returned.
        
        More docs: https://app.cryptolens.io/docs/api/v3/CreateTrialKey
        """

        response = ""

        try:
            response = HelperMethods.send_request("key/createtrialkey", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "MachineCode":machine_code})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj["key"], "")
Exemplo n.º 8
0
    def add_customer(token, name = "", email = "", company_name="",\
                     enable_customer_association = False,\
                     allow_activation_management = False ):
        """
        This method will add new customer.
        
        More docs: https://app.cryptolens.io/docs/api/v3/AddCustomer
        """

        try:
            response = HelperMethods.send_request("/customer/addcustomer/",\
                                                  {"token":token,\
                                                   "Name": name,\
                                                   "Email": email,\
                                                   "CompanyName": company_name,\
                                                   "EnableCustomerAssociation": enable_customer_association,\
                                                   "AllowActivationManagement": allow_activation_management
                                                   })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj, "")
Exemplo n.º 9
0
    def create_message(token, content="", channel="", time=0):
        """
        This method will create a new message.
        This method requires Edit Messages permission.
        
        More docs: https://app.cryptolens.io/docs/api/v3/CreateMessage
        """

        try:
            response = HelperMethods.send_request(
                "/message/CreateMessage/", {
                    "token": token,
                    "Channel": channel,
                    "Content": content,
                    "Time": time
                })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj["messageId"], "")
Exemplo n.º 10
0
    def block_key(token, product_id, key):
        """
        This method will block a specific license key to ensure that it will
        no longer be possible to activate it. Note, it will still be possible
        to access the license key using the GetKey method.
        To do the reverse, you can use the Unblock Key method.
        
        More docs: https://app.cryptolens.io/docs/api/v3/BlockKey
        """

        response = ""

        try:
            response = HelperMethods.send_request("/key/BlockKey", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Key" : key})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (False, jobj["message"])
            else:
                return (False, "Could not contact the server.")

        return (True, jobj["message"])
Exemplo n.º 11
0
    def activate(token, rsa_pub_key, product_id, key, machine_code, fields_to_return = 0,\
                 metadata = False, floating_time_interval = 0,\
                 max_overdraft = 0, friendly_name = None):
        """
        Calls the Activate method in Web API 3 and returns a tuple containing
        (LicenseKey, Message). If an error occurs, LicenseKey will be None. If
        everything went well, no message will be returned.
        
        More docs: https://app.cryptolens.io/docs/api/v3/Activate
        """

        response = Response("", "", 0, "")

        try:
            response = Response.from_string(HelperMethods.send_request("key/activate", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "key":key,\
                                                  "MachineCode":machine_code,\
                                                  "FieldsToReturn":fields_to_return,\
                                                  "metadata":metadata,\
                                                  "FloatingTimeInterval": floating_time_interval,\
                                                  "MaxOverdraft": max_overdraft,\
                                                  "FriendlyName" : friendly_name,\
                                                  "ModelVersion": 3 ,\
                                                  "Sign":"True",\
                                                  "SignMethod":1}))
        except HTTPError as e:
            response = Response.from_string(e.read())
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        pubkey = RSAPublicKey.from_string(rsa_pub_key)

        if response.result == 1:
            return (None, response.message)
        else:
            try:
                if HelperMethods.verify_signature(response, pubkey):
                    return (LicenseKey.from_response(response),
                            response.message)
                else:
                    return (None, "The signature check failed.")
            except Exception:
                return (None, "The signature check failed.")
Exemplo n.º 12
0
    def create_session(token, payment_form_id, currency, expires, price=None,\
                       heading = None, product_name = None, custom_field='',\
                       metadata = None):
        """
        This method will create a new session for a Payment Form.
        It allows you to customize appearance of the form (such as price, heading, etc).
        You should only create new sessions from a server side (i.e. never directly from your application).
        Note, session will only work once and it will eventually expire depending on Expires parameter.
        
        More docs: https://app.cryptolens.io/docs/api/v3/PFCreateSession
        """

        try:
            response = HelperMethods.send_request("/paymentform/CreateSession/",\
                                                  {"token":token,\
                                                   "PaymentFormId" : payment_form_id,\
                                                   "Price" : price,\
                                                   "Currency" : currency,\
                                                   "Heading": heading ,\
                                                   "ProductName": product_name,\
                                                   "CustomField" : custom_field,\
                                                   "Metadata" : metadata,\
                                                   "Expires" : expires,\
                                                   })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj, "")
Exemplo n.º 13
0
    def get_web_api_log(token, product_id = 0, key = "", machine_code="", friendly_name = "",\
                        limit = 10, starting_after = 0, ending_before=0, order_by=""):
        """
        This method will retrieve a list of Web API Logs. All events that get
        logged are related to a change of a license key or data object, eg. when
        license key gets activated or when a property of data object changes. More details
        about the method that was called are specified in the State field.
        
        More docs: https://app.cryptolens.io/docs/api/v3/GetWebAPILog
        """

        response = ""

        try:
            response = HelperMethods.send_request("ai/getwebapilog", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Key":key,\
                                                  "MachineCode":machine_code,\
                                                  "FriendlyName":friendly_name,\
                                                  "Limit": limit,\
                                                  "StartingAfter": starting_after,\
                                                  "OrderBy" : order_by,\
                                                  "EndingBefore": ending_before})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj["logs"], "")
Exemplo n.º 14
0
    def increment_int_value_to_key(token, product_id, key, object_id,\
                                   int_value=0, enable_bound=False, bound=0):
        """
        This method will increment the int value of a data object associated with a license key.
        
        When creating an access token to this method, remember to include "IncrementIntValue" permission and 
        set the "Lock to key" value to -1.
        
        More docs: https://app.cryptolens.io/docs/api/v3/IncrementIntValue (see parameters under Method 2)
        """

        try:
            response = HelperMethods.send_request("/data/IncrementIntValueToKey/",\
                                                  {"token":token,\
                                                   "ProductId" : product_id,\
                                                   "Key" : key,\
                                                   "Id" : object_id,\
                                                   "IntValue": int_value ,\
                                                   "EnableBound": str(enable_bound),\
                                                   "Bound" : bound
                                                   })
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj, "")
Exemplo n.º 15
0
 def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\
              metadata = False, floating_time_interval = 0):
     
     """
     Calls the GetKey method in Web API 3 and returns a tuple containing
     (LicenseKey, Message). If an error occurs, LicenseKey will be None. If
     everything went well, no message will be returned.
     
     More docs: https://app.cryptolens.io/docs/api/v3/GetKey
     """
     
     response = Response("","",0,"")
     
     try:
         response = Response.from_string(HelperMethods.send_request("key/getkey", {"token":token,\
                                               "ProductId":product_id,\
                                               "key":key,\
                                               "FieldsToReturn":fields_to_return,\
                                               "metadata":metadata,\
                                               "FloatingTimeInterval": floating_time_interval,\
                                               "Sign":"True",\
                                               "SignMethod":1}))
     except Exception:
         return (None, "Could not contact the server.")
     
     pubkey = RSAPublicKey.from_string(rsa_pub_key)
 
     if response.result == 1:
         return (None, response.message)
     else:
         try:
             if HelperMethods.verify_signature(response, pubkey):
                 return (LicenseKey.from_response(response), response.message)
             else:
                 return (None, "The signature check failed.")
         except Exception:
             return (None, "The signature check failed.")
Exemplo n.º 16
0
    def create_key(token, product_id, period = 0,\
                   f1=False,\
                   f2=False,\
                   f3=False,\
                   f4=False,\
                   f5=False,\
                   f6=False,\
                   f7=False,\
                   f8=False,\
                   notes="",\
                   block=False,\
                   customer_id=0,\
                   new_customer=False,\
                   add_or_use_existing_customer=False,\
                   trial_activation=False,\
                   max_no_of_machines=0,\
                   no_of_keys=1):
        """
        This method allows you to create a new license key. The license can
        either be standalone or associated to a specific customer. It is also
        possible to add a new customer and associate it with the newly created
        license using NewCustomer parameter. If you would like to avoid
        duplicates based on the email, you can use the AddOrUseExistingCustomer
        parameter.
        
        More docs: https://app.cryptolens.io/docs/api/v3/CreateKey/
        """

        response = ""

        try:
            response = HelperMethods.send_request("key/createkey", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Period":period,\
                                                  "F1": f1,\
                                                  "F2": f2,\
                                                  "F3": f3,\
                                                  "F4": f4,\
                                                  "F5": f5,\
                                                  "F6": f6,\
                                                  "F7": f7,\
                                                  "F8": f2,\
                                                  "Notes": notes,\
                                                  "Block": block,\
                                                  "CustomerId": customer_id,\
                                                  "NewCustomer": f2,\
                                                  "AddOrUseExistingCustomer": add_or_use_existing_customer,\
                                                  "TrialActivation": trial_activation,\
                                                  "MaxNoOfMachines": max_no_of_machines,\
                                                  "NoOfKeys":no_of_keys})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj, "")
Exemplo n.º 17
0
    def create_key(token, product_id, period = 0,\
                   f1=False,\
                   f2=False,\
                   f3=False,\
                   f4=False,\
                   f5=False,\
                   f6=False,\
                   f7=False,\
                   f8=False,\
                   notes="",\
                   block=False,\
                   customer_id=0,\
                   new_customer=False,\
                   add_or_use_existing_customer=False,\
                   trial_activation=False,\
                   max_no_of_machines=0,\
                   no_of_keys=1,\
                   name = None,\
                   email = None,\
                   company_name=None,\
                   enable_customer_association = False,\
                   allow_activation_management = False ):
        """
        This method allows you to create a new license key. The license can
        either be standalone or associated to a specific customer. It is also
        possible to add a new customer and associate it with the newly created
        license using NewCustomer parameter. If you would like to avoid
        duplicates based on the email, you can use the AddOrUseExistingCustomer
        parameter.
        
        The parameters "name", "email", "company_name", "enable_customer_association"
        and "allow_activation_management" are used to create a new customer (or update an existing one)
        and automatically associate it with the newly created license. Please note that you need to use an
        access token with both "CreateKey" and "AddCustomer" permissions. Moreover, either
        the parameter "new_customer" or "add_or_use_existing_customer" need to be set to True.
        
        More docs: https://app.cryptolens.io/docs/api/v3/CreateKey/
        """

        response = ""

        try:
            response = HelperMethods.send_request("key/createkey", {"token":token,\
                                                  "ProductId":product_id,\
                                                  "Period":period,\
                                                  "F1": f1,\
                                                  "F2": f2,\
                                                  "F3": f3,\
                                                  "F4": f4,\
                                                  "F5": f5,\
                                                  "F6": f6,\
                                                  "F7": f7,\
                                                  "F8": f8,\
                                                  "Notes": notes,\
                                                  "Block": block,\
                                                  "CustomerId": customer_id,\
                                                  "NewCustomer": new_customer,\
                                                  "AddOrUseExistingCustomer": add_or_use_existing_customer,\
                                                  "TrialActivation": trial_activation,\
                                                  "MaxNoOfMachines": max_no_of_machines,\
                                                  "NoOfKeys":no_of_keys,\
                                                  "Name": name,\
                                                  "Email": email,\
                                                  "CompanyName": company_name,\
                                                  "EnableCustomerAssociation": enable_customer_association,\
                                                  "AllowActivationManagement": allow_activation_management})
        except HTTPError as e:
            response = e.read()
        except URLError as e:
            return (None,
                    "Could not contact the server. Error message: " + str(e))
        except Exception:
            return (None, "Could not contact the server.")

        jobj = json.loads(response)

        if jobj == None or not ("result" in jobj) or jobj["result"] == 1:
            if jobj != None:
                return (None, jobj["message"])
            else:
                return (None, "Could not contact the server.")

        return (jobj, "")