Beispiel #1
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     registration = api.portal.get_tool(name="portal_registration")
     pas = api.portal.get_tool(name="acl_users")
     generator = getUtility(IUUIDGenerator)
     properties = dict(fullname=data["fullname"], token=django_random.get_random_string(length=12))
     existing = api.user.get(username=data["email"])
     if not existing:
         user_id = generator()
         user_email = data["email"]
         password = django_random.get_random_string(8)
         properties["workspace"] = user_id
         properties["email"] = user_email
         registration.addMember(user_id, password)
         pas.updateLoginName(user_id, user_email)
         user = api.user.get(username=user_id)
         user.setMemberProperties(mapping=properties)
     else:
         user = existing
     user_id = user.getId()
     for group in data["groups"]:
         api.group.add_user(groupname=group, username=user_id)
     IStatusMessage(self.request).addStatusMessage(
         _(u"A new user acount has successfully been created"), type="info"
     )
     next_url = context.absolute_url()
     return self.request.response.redirect(next_url)
Beispiel #2
0
 def _processData(self, data):
     context = aq_inner(self.context)
     itemdata = {}
     tool = getUtility(ISurveyTool)
     session = tool.get()
     state = session['survey-state']
     if 'puid' not in state:
         code = django_random.get_random_string(length=12)
         state['puid'] = code
         tool.add('survey-state', state)
         survey = tool.get()
     else:
         survey = session
     answers = json.dumps(survey)
     token = django_random.get_random_string(length=24)
     now = datetime.now()
     timestamp = api.portal.get_localized_time(datetime=now)
     index = self.generate_index()
     new_title = str(index) + ' - ' + timestamp
     itemdata['title'] = new_title
     container = context
     item = createContentInContainer(
         container,
         'egomotion.sitecontent.answer',
         checkConstraints=False, **itemdata)
     setattr(item, 'answers', answers)
     setattr(item, 'participant', index)
     modified(item)
     item.reindexObject(idxs='modified')
     #token = django_random.get_random_string(length=24)
     #code = django_random.get_random_string(length=12)
     #results = answers['survey-state']
     token_info = {}
     token_info['idx'] = index
     token_info['token'] = token
     token_info['code'] = code
     token_info['timestamp'] = timestamp
     token_info['ip'] = state['pip']
     tool.add('token', token_info)
     uid = IUUID(item)
     stored_info = self.update_survey_information(uid)
     if stored_info:
         setattr(context, 'clients', stored_info['clients'])
         setattr(context, 'participants', stored_info['participants'])
         modified(context)
     url = context.absolute_url()
     base_url = url + '/@@survey-save?uuid=' + uid
     next_url = base_url + '&token=' + token
     return self.request.response.redirect(next_url)
Beispiel #3
0
 def _create_report(self):
     context = aq_inner(self.context)
     date = datetime.datetime.now()
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='xpose.seodash.report',
         id=token,
         title='Report {0} {1}'.format(date.strftime("%B"),
                                       date.strftime("%Y")),
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     template_file = os.path.join(os.path.dirname(__file__),
                                  'report.json')
     template = Template(open(template_file).read())
     template_vars = {
         'id': uuid_tool.uuid4(),
         'uid': uuid,
         'timestamp': int(time.time()),
         'created': datetime.datetime.now(),
         'dashboard': api.content.get_uuid(obj=context),
     }
     report = template.substitute(template_vars)
     setattr(item, 'report', report)
     modified(item)
     item.reindexObject(idxs='modified')
     return uuid
Beispiel #4
0
 def _create_panel(self):
     context = aq_inner(self.context)
     token = django_random.get_random_string(length=24)
     title = self.request.form.get('title')
     new_title = 'row'
     if title:
         new_title = title
     block = {
         'id': token,
         'title': new_title,
         'status': 'visible',
         'klass': 'pp-row-default',
         'panels': [
             {
                 'uuid': None,
                 'component': u"placeholder",
                 'grid-col': 12,
                 'klass': 'pp-column'
             }
         ]
     }
     items = getattr(context, 'panelPageLayout', None)
     if items is None:
         items = list()
     items.append(block)
     setattr(context, 'panelPageLayout', items)
     modified(context)
     context.reindexObject(idxs='modified')
     url = '{0}/@@panelpage-editor'.format(context.absolute_url())
     return url
Beispiel #5
0
 def create_user(self, data):
     registration = api.portal.get_tool(name='portal_registration')
     pas = api.portal.get_tool(name='acl_users')
     generator = getUtility(IUUIDGenerator)
     existing_user = api.user.get(username=data['email'])
     info = {}
     if existing_user is not None:
         user = existing_user
         user_id = user.getId()
         info['created'] = False
     else:
         user_id = generator()
         user_email = data['email']
         password = django_random.get_random_string(8)
         properties = data['properties']
         properties['workspace'] = user_id
         properties['email'] = user_email
         properties['creation_time'] = DateTime()
         user = registration.addMember(
             user_id,
             password
         )
         pas.updateLoginName(user_id, user_email)
         user.setMemberProperties(mapping=properties)
         info['created'] = True
     info['userid'] = user_id
     return info
Beispiel #6
0
 def _access_token(self, user):
     stored_token = user.getProperty('token', '')
     if len(stored_token):
         token = stored_token
     else:
         token = django_random.get_random_string(length=12)
         user.setMemberProperties(mapping={'token': token})
     return token
Beispiel #7
0
 def _access_token(self, user):
     new_token = django_random.get_random_string(length=12)
     stored_token = user.getProperty('token', '')
     if len(stored_token):
         token = stored_token
     else:
         token = new_token
     return token
Beispiel #8
0
 def _create_incident(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     api.content.create(type='wigo.statusapp.incident',
                        id=token,
                        title=new_title,
                        container=context,
                        safe_id=True)
     url = context.absolute_url()
     return self.request.response.redirect(url)
Beispiel #9
0
 def _create_report_object(self):
     context = aq_inner(self.context)
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='xdash.boards.report',
         id=token,
         title=token,
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     return uuid
Beispiel #10
0
 def _create_report(self):
     context = aq_inner(self.context)
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='xpose.seodash.report',
         id=token,
         title='report-{0}'.format(token),
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     return uuid
Beispiel #11
0
 def _create_panel(self, component):
     context = aq_inner(self.context)
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='ade25.panelpage.panel',
         id=token,
         title=token,
         container=context,
         safe_id=True
     )
     setattr(item, 'component', component)
     uuid = api.content.get_uuid(obj=item)
     return uuid
Beispiel #12
0
 def _create_report(self):
     container_uid = self.traverse_subpath[1]
     dashboard = api.content.get(UID=container_uid)
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='xpose.seodash.report',
         id=token,
         title=token,
         container=dashboard,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     return uuid
Beispiel #13
0
 def _create_banner(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     item = api.content.create(
         type='atix.sitecontent.contentbanner',
         id=token,
         title=new_title,
         container=context,
         safe_id=True
     )
     url = item.absolute_url() + '/@@edit-banner-image'
     return self.request.response.redirect(url)
Beispiel #14
0
 def _create_panel(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     api.content.create(
         type='atix.sitecontent.contentblock',
         id=token,
         title=new_title,
         container=context,
         safe_id=True
     )
     url = context.absolute_url()
     return self.request.response.redirect(url)
Beispiel #15
0
 def _create_panel(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     api.content.create(
         type='ade25.panelpage.contentpanel',
         id=token,
         title=new_title,
         container=context,
         safe_id=True
     )
     url = context.absolute_url()
     next_url = url + '&token=' + token
     return self.request.response.redirect(next_url)
Beispiel #16
0
 def _create_token(self, data):
     context = aq_inner(self.context)
     idx = int(data['tokenidx'])
     records = self._get_records()
     keys = []
     if records is not None:
         keys = list(records)
     for x in range(int(idx)):
         token = django_random.get_random_string(length=40)
         keys.append(safe_unicode(token))
     self._set_records(tuple(keys))
     msg = _(u"Successfully generated API access tokens")
     api.portal.show_message(msg, request=self.request)
     url = '{0}/@@api-settings'.format(context.absolute_url())
     return self.request.response.redirect(url)
Beispiel #17
0
 def _create_dashboard(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         container=context,
         type='xpose.seodash.dashboard',
         id=token,
         title=new_title,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     portal_url = api.portal.get().absolute_url()
     next_url = portal_url + '/adm/@@manage-dashboards?uuid=' + uuid
     return self.request.response.redirect(next_url)
Beispiel #18
0
 def _create_panel(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     item = api.content.create(
         type='atix.sitecontent.contentblock',
         id=token,
         title=new_title,
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     url = context.absolute_url()
     base_url = url + '/@@setup-block?uuid=' + uuid
     next_url = base_url + '&token=' + token
     return self.request.response.redirect(next_url)
Beispiel #19
0
 def _update_dashboard(self, data):
     context = aq_inner(self.context)
     item_uid = self.traverse_subpath[0]
     item = api.content.get(UID=item_uid)
     token = django_random.get_random_string(length=24)
     project = {"id": token, "title": data["title"], "ga": "", "xo": data["title"], "ac": data["title"]}
     items = getattr(item, "projects", None)
     if items is None:
         items = list()
     items.append(project)
     setattr(item, "projects", items)
     modified(item)
     item.reindexObject(idxs="modified")
     base_url = context.absolute_url()
     url = "{0}/@@manage-dashboards?uuid={1}".format(base_url, item_uid)
     return self.request.response.redirect(url)
 def _create_dashboard(self, data):
     context = aq_inner(self.context)
     new_title = data['title']
     token = django_random.get_random_string(length=12)
     item = api.content.create(
         type='xpose.seodash.dashboard',
         title=new_title,
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     #item_id = item.getId()
     #api.content.rename(obj=context[item_id],
     #                   new_id=uuid)
     url = context.absolute_url()
     base_url = url + '/@@setup-workspace?uuid=' + uuid
     next_url = base_url + '&token=' + token
     return self.request.response.redirect(next_url)
Beispiel #21
0
 def _create_report(self):
     context = aq_inner(self.context)
     project_list = getattr(context, 'projects')
     date = datetime.datetime.now()
     token = django_random.get_random_string(length=24)
     item = api.content.create(
         type='xpose.seodash.report',
         id=token,
         title='Report {0} {1}'.format(date.strftime("%B"),
                                       date.strftime("%Y")),
         container=context,
         safe_id=True
     )
     uuid = api.content.get_uuid(obj=item)
     template_file = os.path.join(os.path.dirname(__file__),
                                  'report.json')
     template = Template(open(template_file).read())
     template_vars = {
         'id': uuid_tool.uuid4(),
         'uid': uuid,
         'timestamp': int(time.time()),
         'created': datetime.datetime.now(),
         'dashboard': api.content.get_uuid(obj=context),
         'project': json.dumps(project_list[0]),
         'xd1uid': uuid_tool.uuid4(),
         'xd2uid': uuid_tool.uuid4(),
         'xd3uid': uuid_tool.uuid4(),
         'xd4uid': uuid_tool.uuid4(),
         'xd5uid': uuid_tool.uuid4(),
         'xd6uid': uuid_tool.uuid4(),
         'xd7uid': uuid_tool.uuid4()
     }
     report = template.substitute(template_vars)
     tmpl = report.replace('\n', '')
     setattr(item, 'report', tmpl)
     projects = self.project_info()
     project = projects[0]
     pid = project['title']
     setattr(item, 'projectId', pid)
     modified(item)
     item.reindexObject(idxs='modified')
     return uuid
Beispiel #22
0
 def applyChanges(self, data):
     context = aq_inner(self.context)
     user_id = django_random.get_random_string(length=12)
     properties = dict(
         fullname=data['fullname'],
     )
     user = api.user.create(
         username=data['email'],
         email=data['email'],
         properties=properties,
     )
     api.group.add_user(
         groupname=data['usergroup'],
         username=user.getId()
     )
     IStatusMessage(self.request).addStatusMessage(
         _(u"New user account has been created succesfully"),
         type='info')
     next_url = context.absolute_url() + '/@@manage-users'
     return self.request.response.redirect(next_url)
Beispiel #23
0
 def render(self):
     form = self.request.form
     data = {}
     unwanted = ('_authenticator', 'form.button.Submit')
     for value in form:
         if value not in unwanted:
             data[value] = form[value]
     tool = getUtility(ISurveyTool)
     now = datetime.now()
     timestamp = api.portal.get_localized_time(datetime=now,
                                               long_format=True)
     client_ip = self.get_client_ip()
     if client_ip is None:
         userinfo = timestamp
     else:
         userinfo = client_ip + '-' + timestamp
     name = 'survey-state'
     puid = django_random.get_random_string()
     if not self.has_active_session():
         data['puid'] = puid
     else:
         session = tool.get()
         try:
             current_session = session[name]
             saved_puid = current_session['puid']
             data['puid'] = saved_puid
         except KeyError:
             data['puid'] = puid
     data['pip'] = client_ip
     tool.add(name, data)
     time_info = _(u"Autosave %s") % userinfo
     msg = _(u"Survey state automatically saved")
     results = {'success': True,
                'message': msg,
                'timestamp': time_info
                }
     self.request.response.setHeader('Content-Type',
                                     'application/json; charset=utf-8')
     return json.dumps(results)
Beispiel #24
0
class IAPISettings(Interface):
    princexml_server_url = schema.TextLine(
        title=u'PrinceXML server url',
        description=u'required in order to convert documents',
        default=u'http://localhost:6543/convert',
        required=False)

    google_maps_api_key = schema.TextLine(title=u'Google Maps API Key',
                                          default=None,
                                          required=False)

    google_api_email = schema.TextLine(title=u'Google API Email',
                                       default=None,
                                       required=False)

    google_api_service_key_file = schema.ASCII(
        title=u"Google API Service Key File",
        description=u'Private key file',
        required=False,
    )

    google_analytics_id = schema.TextLine(
        title=u'Google Analytics ID',
        description=u'for use with gathering content statistics',
        required=False)

    gtm_id = schema.TextLine(title=u'Google Tag Manager Container ID',
                             description=u'Provided by Google',
                             required=False)

    gtm_enabled = schema.Bool(
        title=u'Enable Google Tag Manager Throughout Site', default=False)

    recaptcha_public_key = schema.TextLine(title=u'Recaptcha 3 Public Key',
                                           required=False)

    recaptcha_private_key = schema.TextLine(title=u'Recaptcha 3 Private Key',
                                            required=False)

    aws_s3_key = schema.TextLine(title=u'AWS S3 Key',
                                 required=False,
                                 default=None)

    aws_s3_secret = schema.TextLine(title=u'AWS S3 Secret',
                                    required=False,
                                    default=None)

    aws_s3_bucket_name = schema.TextLine(title=u'AWS S3 Bucket',
                                         required=False,
                                         default=None)

    aws_s3_host_endpoint = schema.TextLine(
        title=u'AWS Host endpoint',
        description=u'Leave empty unless you know what you are doing here.',
        required=False,
        default=None)

    aws_s3_base_url = schema.TextLine(
        title=u'AWS File Base Url',
        description=
        u'If you are providing your own domain name to serve files from',
        required=False,
        default=None)

    plivo_auth_id = schema.TextLine(title=u'Plivo Auth ID',
                                    description=u'Text messaging API',
                                    required=False)

    plivo_auth_token = schema.TextLine(title=u'Plivo Auth Token',
                                       required=False)

    plivo_phone_number = schema.TextLine(
        title=u'Plivo Source Number',
        description=u'For making text messages from',
        required=False)

    etherpad_url = schema.TextLine(
        title=u'Etherpad URL',
        description=
        u'The full address of your Etherpad server, e.g. http://127.0.0.1:9001',
        required=False)

    etherpad_api_key = schema.TextLine(
        title=u'Etherpad API Key',
        description=
        u'The hexadecimal string taken from your Etherpad installation'
        's APIKEY.txt',
        required=False)

    cf_api_key = schema.TextLine(
        title=u'Cloudflare API Key',
        description=u'Setting an API Key here and enabling cache purging '
        u'activates purging against Cloudflare.',
        required=False)

    cf_email = schema.TextLine(
        title=u'Cloudflare Email',
        description=u'One associated with cloudflare api key',
        required=False)

    cf_zone_id = schema.TextLine(title=u'Cloudflare Zone ID', required=False)

    rocket_chat_front_page = schema.TextLine(
        title=u'Rocket.Chat User URL',
        description=u'URL of the Rocket.Chat server to connect to',
        required=False)

    rocket_chat_secret = schema.TextLine(
        title=u'Rocket.Chat secret',
        description=
        u'Text string used to salt Rocket.Chat authentication tokens',
        required=False,
        default=unicode(django_random.get_random_string(64)))

    matomo_base_url = schema.URI(
        title=u'Matomo instance base URL',
        description=u'used to query social media share outlinks via Matomo API, '
        'e.g. https://castlecms.innocraft.cloud',
        default=None,
        required=False)

    matomo_token_auth = schema.TextLine(
        title=u'Matomo authentication token',
        description=
        u'from your Matomo account settings, under Platform > API, User Authentication.',
        default=u'',
        required=False)

    matomo_site_id = schema.TextLine(
        title=u'Matomo Site ID',
        description=
        u'from your Matomo account settings, under Websites > Manage.',
        default=u'1',
        required=False)
Beispiel #25
0
def GenerateSecret(length=64):
    return django_random.get_random_string(length)
Beispiel #26
0
 def _access_token(self, user):
     new_token = django_random.get_random_string(length=12)
     token = user.getProperty('token', new_token)
     return token
Beispiel #27
0
 def generate_session_token():
     random_salt = django_random.get_random_string()
     return hashlib.sha1(str(uuid.uuid4()) + random_salt).hexdigest()
Beispiel #28
0
class IAPISettings(Interface):
    princexml_server_url = schema.TextLine(
        title=u'PrinceXML server url',
        description=u'required in order to convert documents',
        default=u'http://localhost:6543/convert',
        required=False)

    google_maps_api_key = schema.TextLine(title=u'Google Maps API Key',
                                          default=None,
                                          required=False)

    google_api_email = schema.TextLine(title=u'Google API Email',
                                       default=None,
                                       required=False)

    google_api_service_key_file = schema.ASCII(
        title=u"Google API Service Key File",
        description=u'Private key file',
        required=False,
    )

    google_analytics_id = schema.TextLine(
        title=u'Google Analytics ID',
        description=u'for use with gathering content statistics',
        required=False)

    recaptcha_public_key = schema.TextLine(title=u'Recaptcha 3 Public Key',
                                           required=False)

    recaptcha_private_key = schema.TextLine(title=u'Recaptcha 3 Private Key',
                                            required=False)

    aws_s3_key = schema.TextLine(title=u'AWS S3 Key',
                                 required=False,
                                 default=None)

    aws_s3_secret = schema.TextLine(title=u'AWS S3 Secret',
                                    required=False,
                                    default=None)

    aws_s3_bucket_name = schema.TextLine(title=u'AWS S3 Bucket',
                                         required=False,
                                         default=None)

    aws_s3_host_endpoint = schema.TextLine(
        title=u'AWS Host endpoint',
        description=u'Leave empty unless you know what you are doing here.',
        required=False,
        default=None)

    aws_s3_base_url = schema.TextLine(
        title=u'AWS File Base Url',
        description=
        u'If you are providing your own domain name to serve files from',
        required=False,
        default=None)

    plivo_auth_id = schema.TextLine(title=u'Plivo Auth ID',
                                    description=u'Text messaging API',
                                    required=False)

    plivo_auth_token = schema.TextLine(title=u'Plivo Auth Token',
                                       required=False)

    plivo_phone_number = schema.TextLine(
        title=u'Plivo Source Number',
        description=u'For making text messages from',
        required=False)

    etherpad_url = schema.TextLine(title=u'Etherpad Url', required=False)

    etherpad_api_key = schema.TextLine(title=u'Etherpad API Key',
                                       required=False)

    cf_api_key = schema.TextLine(
        title=u'Cloudflare API Key',
        description=u'Setting an API Key here and enabling cache purging '
        u'activates purging against Cloudflare.',
        required=False)

    cf_email = schema.TextLine(
        title=u'Cloudflare Email',
        description=u'One associated with cloudflare api key',
        required=False)

    cf_zone_id = schema.TextLine(title=u'Cloudflare Zone ID', required=False)

    rocket_chat_front_page = schema.TextLine(
        title=u'Rocket.Chat User URL',
        description=u'URL of the Rocket.Chat server to connect to',
        required=False)

    rocket_chat_secret = schema.TextLine(
        title=u'Rocket.Chat secret',
        description=
        u'Text string used to salt Rocket.Chat authentication tokens',
        required=False,
        default=unicode(django_random.get_random_string(64)))
Beispiel #29
0
 def _generate_txn_id(self):
     key = django_random.get_random_string(length=24)
     return key