Example #1
0
 def __init__(self, env, name=None, client=None, db=None):
     self.env = env
     if name:
         name = simplify_whitespace(name)
     if name:
         db = self.env.get_read_db()
         cursor = db.cursor()
         cursor.execute(
             "SELECT summary, action, lastrun "
             "FROM client_events "
             "WHERE name=%s", (name, ))
         row = cursor.fetchone()
         if not row:
             raise TracError('Client Event %s does not exist.' % name)
         self.md5 = md5(name).hexdigest()
         self.name = self._old_name = name
         self.summary = row[0] or ''
         self.action = row[1] or ''
         self.lastrun = row[2] or 0
         self._load_options(client, db)
     else:
         self.name = self._old_name = None
         self.summary = ''
         self.action = ''
         self.lastrun = 0
Example #2
0
    def _load_client_options(self, client, opttype, db):
        assert self.exists, 'Cannot update non-existent client event'
        assert opttype in ('summary', 'action'), 'Invalid options type'
        system = ClientEventsSystem(self.env)
        if 'summary' == opttype:
            thing = system.get_summary(self.summary)
            assert thing is not None, 'Invalid summary'
            self.summary_description = thing.get_description()
        else:
            thing = system.get_action(self.action)
            assert thing is not None, 'Invalid action'
            self.action_description = thing.get_description()

        options = {}
        table = 'client_event_' + opttype + '_options'
        cursor = db.cursor()
        cursor.execute(
            "SELECT name, value "
            "FROM " + table + " "
            "WHERE client_event=%s AND client=%s",
            (self._old_name, client or ''))
        for name, value in cursor:
            options[name] = value
        rv = {}
        for option in thing.options(client):
            option['md5'] = md5(option['name']).hexdigest()
            if options.has_key(option['name']):
                option['value'] = options[option['name']]
            else:
                option['value'] = ''
            rv[option['name']] = option
        return rv
Example #3
0
    def _load_client_options(self, client, opttype, db):
        assert self.exists, "Cannot update non-existent client event"
        assert opttype in ("summary", "action"), "Invalid options type"
        system = ClientEventsSystem(self.env)
        if "summary" == opttype:
            thing = system.get_summary(self.summary)
            assert thing is not None, "Invalid summary"
            self.summary_description = thing.get_description()
        else:
            thing = system.get_action(self.action)
            assert thing is not None, "Invalid action"
            self.action_description = thing.get_description()

        options = {}
        table = "client_event_" + opttype + "_options"
        cursor = db.cursor()
        cursor.execute(
            "SELECT name, value " "FROM " + table + " " "WHERE client_event=%s AND client=%s",
            (self._old_name, client or ""),
        )
        for name, value in cursor:
            options[name] = value
        rv = {}
        for option in thing.options(client):
            option["md5"] = md5(option["name"]).hexdigest()
            if options.has_key(option["name"]):
                option["value"] = options[option["name"]]
            else:
                option["value"] = ""
            rv[option["name"]] = option
        return rv
Example #4
0
 def select(cls, env, client=None, db=None):
     if not db:
         db = env.get_read_db()
     cursor = db.cursor()
     cursor.execute("SELECT name, summary, action, lastrun " "FROM client_events " "ORDER BY name")
     for name, summary, action, lastrun in cursor:
         clev = cls(env)
         clev.md5 = md5(name).hexdigest()
         clev.name = clev._old_name = name
         clev.summary = summary or ""
         clev.action = action or ""
         clev.lastrun = lastrun or 0
         clev._load_options(client, db)
         yield clev
Example #5
0
 def select(cls, env, client=None, db=None):
     if not db:
         db = env.get_read_db()
     cursor = db.cursor()
     cursor.execute("SELECT name, summary, action, lastrun "
                    "FROM client_events "
                    "ORDER BY name")
     for name, summary, action, lastrun in cursor:
         clev = cls(env)
         clev.md5 = md5(name).hexdigest()
         clev.name = clev._old_name = name
         clev.summary = summary or ''
         clev.action = action or ''
         clev.lastrun = lastrun or 0
         clev._load_options(client, db)
         yield clev
Example #6
0
 def _update_diagram(self, req, params):
     _, errors = self._validate_workflow(req, params)
     basename = 'error.png'
     if len(errors) == 0:
         script = self._create_dot_script(params)
         self._image_path_setup(req)
         dir = os.path.join(self.env.get_htdocs_dir(), 'tracworkflowadmin')
         basename = '%s.png' % md5(script).hexdigest()
         path = os.path.join(dir, basename)
         if self.diagram_cache and os.path.isfile(path):
             os.utime(path, None)
         else:
             self._create_diagram_image(path, dir, script, errors)
     data = {'result': (1, 0)[len(errors) == 0],     # 0 if cond else 1
             'errors': errors,
             'image_url': self._image_tmp_url(req, basename)}
     req.send(json.dumps(data))
Example #7
0
 def __init__(self, env, name=None, client=None, db=None):
     self.env = env
     if name:
         name = simplify_whitespace(name)
     if name:
         db = self.env.get_read_db()
         cursor = db.cursor()
         cursor.execute("SELECT summary, action, lastrun " "FROM client_events " "WHERE name=%s", (name,))
         row = cursor.fetchone()
         if not row:
             raise TracError("Client Event %s does not exist." % name)
         self.md5 = md5(name).hexdigest()
         self.name = self._old_name = name
         self.summary = row[0] or ""
         self.action = row[1] or ""
         self.lastrun = row[2] or 0
         self._load_options(client, db)
     else:
         self.name = self._old_name = None
         self.summary = ""
         self.action = ""
         self.lastrun = 0
Example #8
0
File: __init__.py Project: t2y/trac
def md5crypt(password, salt, magic='$1$'):
    """Based on FreeBSD src/lib/libcrypt/crypt.c 1.2

    :param password: the plain text password to crypt
    :param salt: the raw salt
    :param magic: our magic string
    """
    # /* The password first, since that is what is most unknown */
    # /* Then our magic string */
    # /* Then the raw salt */
    m = md5(password + magic + salt)

    # /* Then just as many characters of the MD5(pw,salt,pw) */
    mixin = md5(password + salt + password).digest()
    for i in range(0, len(password)):
        m.update(mixin[i % 16])

    # /* Then something really weird... */
    # Also really broken, as far as I can tell.  -m
    i = len(password)
    while i:
        if i & 1:
            m.update('\x00')
        else:
            m.update(password[0])
        i >>= 1

    final = m.digest()

    # /* and now, just to make sure things don't run too fast */
    for i in range(1000):
        m2 = md5()
        if i & 1:
            m2.update(password)
        else:
            m2.update(final)

        if i % 3:
            m2.update(salt)

        if i % 7:
            m2.update(password)

        if i & 1:
            m2.update(final)
        else:
            m2.update(password)

        final = m2.digest()

    # This is the bit that uses to64() in the original code.

    itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

    rearranged = ''
    for a, b, c in ((0, 6, 12), (1, 7, 13), (2, 8, 14), (3, 9, 15), (4, 10,
                                                                     5)):
        v = ord(final[a]) << 16 | ord(final[b]) << 8 | ord(final[c])
        for i in range(4):
            rearranged += itoa64[v & 0x3f]
            v >>= 6

    v = ord(final[11])
    for i in range(2):
        rearranged += itoa64[v & 0x3f]
        v >>= 6

    return magic + salt + '$' + rearranged
Example #9
0
def md5crypt(password, salt, magic='$1$'):
    # /* The password first, since that is what is most unknown */
    # /* Then our magic string */
    # /* Then the raw salt */
    m = md5(password + magic + salt)

    # /* Then just as many characters of the MD5(pw,salt,pw) */
    mixin = md5(password + salt + password).digest()
    for i in range(0, len(password)):
        m.update(mixin[i % 16])

    # /* Then something really weird... */
    # Also really broken, as far as I can tell.  -m
    i = len(password)
    while i:
        if i & 1:
            m.update('\x00')
        else:
            m.update(password[0])
        i >>= 1

    final = m.digest()

    # /* and now, just to make sure things don't run too fast */
    for i in range(1000):
        m2 = md5()
        if i & 1:
            m2.update(password)
        else:
            m2.update(final)

        if i % 3:
            m2.update(salt)

        if i % 7:
            m2.update(password)

        if i & 1:
            m2.update(final)
        else:
            m2.update(password)

        final = m2.digest()

    # This is the bit that uses to64() in the original code.

    itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

    rearranged = ''
    for a, b, c in ((0, 6, 12), (1, 7, 13), (2, 8, 14), (3, 9, 15), (4, 10, 5)):
        v = ord(final[a]) << 16 | ord(final[b]) << 8 | ord(final[c])
        for i in range(4):
            rearranged += itoa64[v & 0x3f]
            v >>= 6

    v = ord(final[11])
    for i in range(2):
        rearranged += itoa64[v & 0x3f]
        v >>= 6

    return magic + salt + '$' + rearranged