Esempio n. 1
0
    def fill_from_xml(self, xml, plugin_guid):
        self.name = xml.name
        self.code = xml.source
        self.class_name = xml.class_name
        self.is_button_macros = xml.is_button
        self.on_board = xml.on_board
        self.guid = xml.guid
        self.timer_guid = xml.timer_guid
        self.custom_event_guid = xml.custom_event_guid
        self.description = xml.description
        self.plugin_guid = plugin_guid
        self.page = xml.page
        self.type = xml.type

        if not self.type or self.type == self.MacrosType.UNKNOWN:
            self.type = self.MacrosType.BUTTON if self.is_button_macros == "1" else \
                        self.MacrosType.EVENT

        picture_name = ""
        self.macros_picture = ""
        if xml.macros_picture:
            self.macros_picture = picture_name = str(uuid4())
            application.storage.write(picture_name,
                                      base64.b64decode(xml.macros_picture))

        self.save()
Esempio n. 2
0
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        self.id = Database.macrosdb().commit(
            """INSERT INTO timer (name, period, guid, plugin_guid) VALUES (?,?,?,?)""",
            (self.name, self.period, self.guid, self.plugin_guid))

        self.register()
        return self
Esempio n. 3
0
def run(request):
	sess = request.session()
	for uploaded_file in request.files.itervalues():
		fileid = str(uuid4())
		uploaded_file.autoremove = False
		#managers.file_manager.file_upload[fileid] = attach
		sess.files[fileid] = uploaded_file
		request.write(str(fileid)+'\n')
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        #raise Exception(self.guid, self.name)
        self.id = Database.macrosdb().commit(
            """INSERT INTO custom_event (name, guid, plugin_guid) VALUES (?,?,?)""",
            (self.name, self.guid, self.plugin_guid))

        self.register()
        return self
Esempio n. 5
0
	def create_server_action(self, actionname,  value):
		if not managers.acl_manager.session_user_has_access2(self.id, self.id, security.modify_application):
			raise VDOM_exception_sec(_("Modifying application is not allowed"))
		self.__sem.lock()
		try:
			_id = str(uuid4())
			self.global_actions[_id] = {}
			self.global_actions[_id][actionname.lower()] = VDOM_server_action(value, _id, "", "", "", actionname)
			
		finally:
			self.__sem.unlock()	
Esempio n. 6
0
    def __insert(self):
        """ Creates valid INSERT sql query """

        if self.guid_key and self.guid_key in self.fields_list:
            setattr(self, self.guid_key, str(uuid4()))

        primary_key_db = self.database().commit(
            *self._sql_request(statement=self.STATEMENT_INSERT, instance=self))

        setattr(self, self.primary_key, primary_key_db)
        return self
Esempio n. 7
0
def session_put(key, value):
    if value:
        session_key = request.shared_variables[key]
        if not session_key:
            session_key = str(uuid4())
        session[session_key] = value
        response.shared_variables[key] = session_key
    else:
        session_key = request.shared_variables[key]
        if session.get(session_key):
            del session[session_key]
        del response.shared_variables[key]
Esempio n. 8
0
	def modify_resource(self, sid, appid, objid, resid, attrname, operation, param):
		if not managers.acl_manager.session_user_has_access2(appid, appid, security.modify_application):
			raise VDOM_exception(_("Modifying resource is not allowed"))
		app = managers.xml_manager.get_application(appid)
		obj = app.search_object(objid)
		# check if need to backup this resource
		need_backup = False
		key = objid + attrname
		s = managers.session_manager.get_session(sid)
		last = s.value("resource_editor_last")
		if key != last:
			need_backup = True
			s.value("resource_editor_last", "")
			if obj.has_attribute("resource_cache"):
				obj.set_attribute("resource_cache", "")
		# go
		ro = managers.resource_manager.get_resource(appid, resid)
		if not ro:
			return (False, _("Resource not found"))
		if not obj.has_attribute(attrname):
			return (False, _("Object has no attribute '%s'") % str(attrname))
		if not obj.has_attribute("resource_cache"):
			return (False, _("Object has no attribute 'resource_cache'"))
		res_data = ro.get_data()
		try:
			(data, msg, rest_wh) = getattr(self, operation)(s, app, obj, resid, attrname, res_data, ro, param)
			# save data in new resource
			if data:
				attributes = {
					"id" : str(uuid4()),
					"name" : ro.name,
					"res_format": ro.res_format
					}
				managers.resource_manager.add_resource(appid, None, attributes, data)
				if need_backup:
					obj.set_attribute("resource_cache", "#Res(%s)" % resid)
					s.value("resource_editor_last", key)
#				old_w = old_h = None
#				if rest_wh:
#					try:
#						old_w = obj.width
#						old_h = obj.height
#					except:
#						rest_wh = False
				obj.set_attribute(attrname, "#Res(%s)" % attributes["id"])
				if rest_wh:
					obj.set_attributes(rest_wh)
#					obj.set_attributes({"width": old_w, "height": old_h})
			if data: return (True, data)
			else: return (True, msg)
		except Exception, e:
			return (False, str(e))
Esempio n. 9
0
    def __insert(self):
        self.guid = str(uuid4()) if self.guid is None else self.guid
        self.id = Database.macrosdb().commit(
            "INSERT INTO macros (name, code, class_name, is_button_macros,"
            "on_board, picture, guid, page, description, zindex, timer_guid,"
            "plugin_guid, namespace, page, custom_event_guid,type) VALUES"
            "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
            "",
            (self.name, self.code, self.class_name, self.is_button_macros,
             self.on_board, self.macros_picture, self.guid, self.page,
             self.description, self.zindex, self.timer_guid, self.plugin_guid,
             self.plugin_guid, self.page, self.custom_event_guid, self.type))

        return self
Esempio n. 10
0
    def fill_from_xml(self, xml):
        self.name = xml.name
        self.description = xml.description
        self.guid = xml.guid
        self.version = xml.version
        self.author = xml.author
        self.protected = xml.protected

        plugin_picture_name = ""
        self.picture = ""
        if xml.picture:
            self.picture = plugin_picture_name = str(uuid4())
            application.storage.write(plugin_picture_name,
                                      base64.b64decode(xml.picture))
        self.save()
Esempio n. 11
0
 def regenerate_uuid(self, recursive=False):
     """
     Create new guids, if needed - recursively
     """
     self.id = str(uuid.uuid4())
     if not recursive:
         return
     
     all_objects = {self.id: self}
     self.objects = {}
     
     for child in self.objects_list:
         all_objects.update(child.regenerate_uuid(recursive=recursive))
         self.objects[child.id] = child
         
     return all_objects
Esempio n. 12
0
 def __init__(self, vdomtype, name, action_name):
     self.name = name
     self.actions = {
         "name": {}, 
         "id": {}
     }
     self.attributes = DummyAttributes()
     self.containers = {}
     self.dynamic = {(action_name, self.name): 1}
     self.id = str(uuid.uuid4())
     self.libraries = {}
     self.objects = {}
     self.objects_list = []
     self.objects_by_name = {self.name: self}
     self.order = 0
     self.type = vdomtype
     self.types = {self.type.id: self.type}
Esempio n. 13
0
	def create(self, xml_obj = None):
		if not xml_obj:	# create new xml object
			xml_obj = xml_object(VDOM_CONFIG["APPLICATION-XML-TEMPLATE"])
			new_id = str(uuid4())
			inf = xml_obj.get_child_by_name("information")
			_id = inf.get_child_by_name("id")
			_id.value = new_id
			_sv = inf.get_child_by_name("serverversion")
			_sv.value = VDOM_server_version
		# base
		self.__xml_obj = xml_obj
		VDOM_parser.create(self, xml_obj)
		# parse #Res() links in all objects
		self.__parse_links(self)
		# write to resource manager which objects use which resources
		for oid in self.__all_objects:
			obj = self.__all_objects[oid]
			for res_id in obj.resources.keys():
				attributes = {"id" : res_id}
				if managers.resource_manager.check_resource(self.id, attributes):
					managers.resource_manager.add_resource(self.id, obj.id, attributes, None)
		for res_id in self.resources.keys():
			attributes = {"id" : res_id}
			if managers.resource_manager.check_resource(self.id, attributes):
				managers.resource_manager.add_resource(self.id, self.id, attributes, None)
		# check if need to create structure
		if len(self.structure_element.children) == 0:
			# generate structure
			for o in self.objects_list:
				i = xml_object(name="Object")
				self.structure_element.children.append(i)
				i.attributes["ID"] = o.id
				i.attributes["Top"] = "0"
				i.attributes["Left"] = "0"
				i.attributes["ResourceID"] = ""
		self.do_parse_structure(self.structure_element)
		
		self.sync()
		del self.o_tmp
Esempio n. 14
0
	def __do_create_object(self, typeid, parent = None, do_compute=True):
		"""create object, return tuple (name, id)"""
		type_obj = self.xml_manager.get_type(typeid)
		#doc = self.get_xml()
		obj_id = str(uuid4())
		obj_name = type_obj.name.lower() + "_" + "_".join(obj_id.lower().split("-"))

		target = self
		if parent: target = parent
		if not parent:
			if 3 != type_obj.container:
				raise VDOM_exception_param(_("Object '%s' can't be top-level container" % type_obj.name))
		else:
			if parent.type.name not in type_obj.containers and parent.type.render_type not in type_obj.containers:
				debug("!!!!!!!!!!!!!!!!Parent = %s" % parent.id)
				raise VDOM_exception_param(_("Object '%s' can't be created inside '%s'" % (type_obj.name, parent.type.name)))

		x = xml_object(name="Object")
		target.objects_element.children.append(x)
		x.attributes["Name"] = obj_name
		x.attributes["ID"] = obj_id
		x.attributes["Type"] = typeid
		x.children.append(xml_object(name="Actions"))
		x.children.append(xml_object(name="Objects"))
		attr_x = xml_object(name="Attributes")
		x.children.append(attr_x)

		# process all object attributes
		for a in type_obj.get_attributes().values():
			a_x = xml_object(name="Attribute")
			attr_x.children.append(a_x)
			a_x.attributes["Name"] = a.name
			if "zindex" == a.name and parent:
				# calc max zindex for parent's children
				maxz = 0
				for q in parent.objects_list:
					if "zindex" in q.attributes:
						curz = int(q.attributes.zindex)
						if maxz < curz: maxz = curz
				a_x.value = str(maxz)
			else:
				a_x.value = a.default_value

		# parse new object
		obj = self.parse_object(x, parent)
		target.get_objects()[obj.id] = obj
		target.get_objects_list().append(obj)
		# parse links
		self.__parse_links(obj)
		# add to all objects hash
		self.__all_objects[obj.id] = obj
		if parent:
			parent.objects_by_name[obj_name] = obj
			obj.toplevel = parent.toplevel
		else:
			obj.toplevel = obj

		obj.invalidate()

		managers.request_manager.get_request().container_id = obj.toplevel.id
		if do_compute:
			managers.engine.compute(self, obj, parent)

		if parent:
			managers.dispatcher.dispatch_handler(self.id, parent.id, "add_child", {"child_id":obj.id})
		else:
			self.__create_structure_object(obj)
		return (obj_name, obj_id)
Esempio n. 15
0
            node = XMLMacros(dom)

            for child in node.childs:
                child = XMLMacros(child)
                if child.name and child.source:
                    macros = Macros()
                    macros.name = child.name
                    macros.code = child.source
                    macros.class_name = child.class_name
                    macros.is_button_macros = child.is_button
                    macros.on_board = child.on_board

                    picture_name = ""
                    macros.macros_picture = ""
                    if child.macros_picture:
                        macros.macros_picture = picture_name = str(uuid4())
                        application.storage.write(
                            picture_name,
                            base64.b64decode(child.macros_picture))

                    macros.save()
                else:
                    self.growl.title = lang["error"]
                    self.growl.text = lang["xml_not_correctr_error"]
                    self.growl.visible = "1"

    if "op" in request.arguments and request.arguments.get("op") == "export":
        plugin = Plugins.get_by_id(session.get("plugin_id", ""))
        output = plugin.export()
        output_len = output.tell()
        output.seek(0)
Esempio n. 16
0
def main():

    import json, localization, base64
    from xml.dom.minidom import parseString
    from class_macro import Macros
    from class_plugins import Plugins
    from class_timer import Timer
    from class_custom_event import CustomEvent
    from class_xml_macro import XMLMacros
    from class_xml_timer import XMLTimer
    from class_xml_custom_event import XMLCustomEvent
    from class_xml_plugin import XMLPlugin
    from class_xml_plugin_db import XMLPluginDB
    from class_xml_resource import XMLResource
    from utils.uuid import uuid4
    from widget_localization import LocalizationWidget
    from widget_plugins import WidgetPlugins
    from VEE_resources import create_plugin_dir, ResourceFolderManager
    from VEE_sqlite3 import DatabaseManager

    lang = localization.get_lang()

    if "formbutton_save_plugin" in request.arguments:
        plugin = Plugins()
        plugin.guid = str(uuid4())
        plugin.name = request.arguments.get("formtext_name", "")
        plugin.author = request.arguments.get("formtext_author", "")
        plugin.description = request.arguments.get("formtextarea_description",
                                                   "")
        plugin.version = request.arguments.get("formtext_version", "")
        plugin.zindex = "1"

        if "uploader" in request.arguments:
            file = request.arguments.get("uploader", "", castto=Attachment)
            if file:
                plugin.picture = str(uuid4())
                application.storage.write(plugin.picture, file.handler.read())

        plugin.save()
        create_plugin_dir(plugin.guid)

    if "formbutton_upload_plugin" in request.arguments:
        if request.arguments.get("uploader", "", castto=Attachment):
            try:
                file = request.arguments.get("uploader", "", castto=Attachment)
                xml_data = file.handler.read()

                dom = parseString(xml_data)
                node = XMLPlugin(dom)

                if not Plugins.get_by_guid(node.guid):
                    plugin = Plugins()
                    plugin.name = node.name
                    plugin.description = node.description
                    plugin.guid = node.guid
                    plugin.version = node.version
                    plugin.author = node.author
                    plugin.protected = node.protected

                    plugin_picture_name = ""
                    plugin.picture = ""
                    if node.picture:
                        plugin.picture = plugin_picture_name = str(uuid4())
                        application.storage.write(
                            plugin_picture_name,
                            base64.b64decode(node.picture))
                    plugin.save()
                    create_plugin_dir(plugin.guid)

                    for child in node.childs:

                        if child.tag == "timer":
                            child = XMLTimer(child)

                            if child.name:
                                timer = Timer()
                                timer.fill_from_xml(child, node.guid)
                        elif child.tag == "custom_event":
                            child = XMLCustomEvent(child)

                            if child.name:
                                custom_event = CustomEvent()
                                custom_event.fill_from_xml(child, node.guid)
                        elif child.tag == "macro":
                            child = XMLMacros(child)
                            if child.name and child.source:
                                macros = Macros()
                                macros.fill_from_xml(child, node.guid)
                        elif child.tag == "database":
                            child = XMLPluginDB(child)
                            if child.name:
                                DatabaseManager(plugin.guid).import_db(
                                    child.name,
                                    base64.b64decode(child.db_source))
                        elif child.tag == "resource":
                            child = XMLResource(child)

                            if child.name:
                                ResourceFolderManager(plugin.guid).import_res(
                                    child.name,
                                    base64.b64decode(child.res_source))
                        else:
                            raise Exception(
                                lang.get("xml_not_correctr_error",
                                         "xml_not_correctr_error"))
                else:
                    raise Exception(lang.get("plugin_exist", "plugin_exist"))

            except Exception, ex:
                self.growl.title = lang["error"]
                self.growl.text = ex
                self.growl.show = "1"
Esempio n. 17
0
		plugin.guid = node.guid
		plugin.version = node.version
		plugin.author = node.author

		exist_plugin = Plugins.get_by_guid(plugin.guid)
		if exist_plugin:
			if exist_plugin.version > plugin.version:
				raise Exception("You can't install old version plugin")
			else:
				if exist_plugin.picture:
					application.storage.delete( exist_plugin.picture )
				exist_plugin.delete()

		plugin.picture = ""
		if node.picture:
			plugin.picture = str(uuid4())
			application.storage.write( plugin.picture, base64.b64decode(node.picture))

		plugin.save()

		create_plugin_dir( plugin.guid )
		dbManager = DatabaseManager( plugin.guid )
		resManager = ResourceFolderManager( plugin.guid )

		for child in node.childs:

			if child.tag == "timer":
				child = XMLTimer( child )
				if child.name:
					timer = Timer()
					timer.fill_from_xml( child, node.guid )
Esempio n. 18
0
	def parse_body(self,mail):
		body = ""
		#self.content_type = MailContentType("text/html","utf8",{})
		body_charset = "utf8"
		#TODO: check this code for multipart messages with different attachments
		if mail.is_multipart():
			for part in mail.walk():
				if part.get_content_maintype() == "multipart":
					boundary = ""
					double_data = "False"
		
					for p in range(len(part.get_payload())):
						if part.get_boundary() and boundary == part.get_boundary():
							double_data = "True"
						else:
							double_data = "False"
						boundary = part.get_boundary()
						for subpart in part.get_payload(p).walk():
							if ("content-disposition" in subpart and "attachment" in subpart["content-disposition"]):
								oAttach = subpart.get_payload()
								guid = str(uuid4())
		
								#application.storage.write(guid, base64.b64decode(oAttach))
		
								attachment_object = MailAttachment()
								attachment_object.guid = guid
								
								if "Content-Transfer-Encoding" in subpart and subpart["Content-Transfer-Encoding"].lower() == "quoted-printable":
									try:
										attachment_object.data = quopri.decodestring(oAttach)
									except Exception, ex:
										pass								
								else:
									try:
										attachment_object.data= base64.b64decode(oAttach)
									except Exception, ex:
										pass
															
								#attachment_object.data = base64.b64decode(oAttach)
		
								try:
									filename = email.Header.decode_header(subpart.get_filename())
									attachment_object.filename = filename[0][0].decode(filename[0][1]) if filename[0][1] else filename[0][0]
								except:
									attachment_object.filename = subpart.get_filename()
		
								attachment_object.mail_id = ""
								attachment_object.location = "inbox"
								
								self.attach.append(attachment_object)
							else:
								if double_data == "True":
									body = ""
								if "Content-Type" in subpart and "charset" in subpart["Content-Type"]:
									body_charset = subpart["Content-Type"].split('=')[1]
									self.content_charset = body_charset.strip('"')
									body_content_type = subpart["Content-Type"].split(';')[0]
									self.content_type = body_content_type
								if "Content-Transfer-Encoding" in subpart and subpart["Content-Transfer-Encoding"].lower() == "base64":
									try:
										body += base64.b64decode(subpart.get_payload())
									except Exception, ex:
										pass
								elif "Content-Transfer-Encoding" in subpart and subpart["Content-Transfer-Encoding"].lower() == "quoted-printable":
									try:
										body += quopri.decodestring(subpart.get_payload())
									except Exception, ex:
										pass
								else:
									if not isinstance(subpart.get_payload(), list):
										body += subpart.get_payload()
Esempio n. 19
0
    if "formbutton_apply" in request.arguments:

        source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
            "codeeditor_macros_body", "")
        name = self.form_macros.formtext_name.value = request.arguments.get(
            "formtext_name", "")
        event = self.form_macros.formlist_event_list.selectedvalue = request.arguments.get(
            "formlist_event_list")
        is_button = self.form_macros.formcheckbox_is_button.state = request.arguments.get(
            "formcheckbox_is_button", "0")
        on_board = self.form_macros.formcheckbox_is_button.state = request.arguments.get(
            "formcheckbox_on_board", "0")
        picture = request.arguments.get("uploader", "", castto=Attachment)
        picture_name = ""
        if picture:
            picture_name = str(uuid4())
            application.storage.write(picture_name, picture.handler.read())
        elif macros_id:
            macros_object = Macros.get_by_id(macros_id)
            picture_name = macros_object.macros_picture
            self.form_macros.hypertext_img.htmlcode = "<img src='/get_image?id=%s'/>" % picture_name if picture_name else ""
        #raise Exception(event)
        class_name = ""
        if not source or not name:
            self.growl.title = lang["error"]
            self.growl.text = lang["fill_all_fields_error"]
            self.growl.visible = "1"
        else:
            if is_button == "0":
                for e in events:
                    if e.id == int(event):