Exemple #1
0
		def post(self):
			upload_files = self.get_uploads('icon')
			if upload_files != []:
				blob_info = upload_files[0]
				admin.Admin(self.request, self.response).post(icon_key=blob_info.key())
			else:
				admin.Admin(self.request, self.response).post()
Exemple #2
0
 def startAdminMode(self):
     self.view.window.destroy()
     adminlog = adminlogin.Adminlogin(self.sett.getAdminPWHash(),
                                      self.sett.getAdminIdentifier())
     if adminlog.isAccessGranted():
         adm = admin.Admin()
     return None
Exemple #3
0
	def run(self):
		if '--verbose' in sys.argv:
			self.output.test('Broken auth attacks...')
		try:
			logs.Logs(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			admin.Admin(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			files.Files(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			backdoor.Backdoor(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			backupdir.Backupdir(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			backupfile.Backupfile(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
			directories.Directories(
				agent=self.agent,proxy=self.proxy,
				redirect=self.redirect,timeout=self.timeout,
				url=self.url,cookie=self.cookie).run()
		except Exception,e:
			pass
Exemple #4
0
    def __init__(self):
        database.initDb()
        adminpanel = admin.Admin()
        verified = adminpanel.start()
        if verified:

            self.dashboard = dashboard.Dashboard()
        print("I DO NOT LIKE UNVERIFIED PEOPLE")
Exemple #5
0
 def startFirstRun(self):
     config = configurator.Configurator()
     if config.hasSucceeded():
         adminlog = adminlogin.Adminlogin(self.sett.getAdminPWHash(),
                                          self.sett.getAdminIdentifier())
         if adminlog.isAccessGranted():
             adm = admin.Admin()
     return None
    def backmenu(self):
        self.destroy()
        self.cur.execute("select designation from employees where empid = :1",
                         (self.empid, ))
        res = self.cur.fetchall()
        des = res[0][0]

        if des == "ADMIN":
            x = admin.Admin(self.empid, self.cur)
            x.back("HireFireRehire")
Exemple #7
0
    def Logoff(self):
        answer = tkinter.messagebox.askquestion("Logout", "Are you sure you want to logout? ")

        if answer == "yes":
            tkinter.messagebox.showinfo("Logout", "Goodbye")
            self.root.destroy()

            master = tk.Tk()
            root.geometry("350x200")
            login1 = login.Login(master)
            master.mainloop()
            if login1.dept == "Receiving":
                master = tk.Tk()
                master.geometry("650x500")
                master.configure(bg="light gray")
                receiving1 = receiving.Receiving(master)
                master.mainloop()
            elif login1.dept == "Assembly":
                workorder = selection.WOWindow(login1.dept)
                master = tk.Tk()
                master.geometry("665x340")
                master.title("Assembly")
                app = assembly_class.Assembly(master, "0002")
                master.mainloop()
            elif login1.dept == "Testing":
                workorder = selection.WOWindow(login1.dept)
                master = tk.Tk()
                master.geometry("680x500")
                master.title("Testing")
                app = testing.TestingWindow(master, "0003")
                master.mainloop()
            elif login1.dept == "Shipping":
                workorder = selection.WOWindow(login1.dept)
                master = tk.Tk()
                master.geometry("680x400")
                app = shipping.Shipping(master, "0004")
                master.mainloop()
            elif login1.dept == "Accounting":
                master = tk.Tk()
                master.geometry("500x300")
                master.title("Accounting")
                close_window = tk.Button(master, text="Close", command=master.quit)
                close_window.place(x=90, y=230)
                app = accounting(root, "0005")

            elif login1.dept == "Admin":
                master = tk.Tk()
                master.geometry("600x500")
                master.title("New User")
                master.configure(bg="light gray")
                admin1 = admin.Admin(master)
                master.mainloop()
    def backmenu(self):
        self.destroy()
        self.cur.execute("select designation from employees where empid = :1",
                         (self.empid, ))
        res = self.cur.fetchall()
        des = res[0][0]

        if des == "MANAGER":
            x = manager.Manager(self.empid, self.cur)
            x.back("Menu")

        elif des == "ADMIN":
            x = admin.Admin(self.empid, self.cur)
            x.back("Menu")
Exemple #9
0
 async def reload(self, ctx, *, module: str):
     if ctx.message.author.id in config.superusers:
         if module == 'webserver':
             await config.modules['webserver'].stop()
             webserver = importlib.reload(config.modules[module])
             config.modules['webserver'] = webserver
             await webserver.start()
             await ctx.channel.send("reloaded `" + module +
                                    "` succesfully!")
         elif module == 'config':
             config.reload()
             await ctx.channel.send("reloaded `" + module +
                                    "` succesfully!")
         elif module == 'logic':
             bot.remove_cog('Logic')
             logic = importlib.reload(config.modules['logic'])
             gameclass = logic.Logic(bot)
             bot.add_cog(gameclass)
         elif module == admin:
             bot.remove_cog('Admin')
             admin = importlib.reload(config.modules['admin'])
             adminclass = admin.Admin(bot)
             bot.add_cog(adminclass)
         elif module in config.modules and config.modules[module]:
             try:
                 bot.remove_cog(module.capitalize())
                 loadedmodule = importlib.reload(config.modules[module])
                 bot.add_cog(
                     getattr(loadedmodule, module.capitalize())(bot))
                 await ctx.channel.send("reloaded `" + module +
                                        "` succesfully!")
             except AttributeError:
                 importlib.reload(config.modules[module])
                 await ctx.channel.send("reloaded `" + module +
                                        "` succesfully?")
             except Exception as e:
                 print(e)
                 await ctx.channel.send("reloading `" + module +
                                        "` failed.")
         else:
             await ctx.channel.send('`' + module +
                                    "` isn't available for reloading.")
     else:
         await emformat.genericmsg(ctx.channel,
                                   "this command is restricted.", "error",
                                   "reload")
Exemple #10
0
 def run(self):
     print ""
     self.output.info('Starting bruteforce module...')
     file.File(agent=self.agent,
               proxy=self.proxy,
               redirect=self.redirect,
               timeout=self.timeout,
               url=self.url,
               cookie=self.cookie).run()
     admin.Admin(agent=self.agent,
                 proxy=self.proxy,
                 redirect=self.redirect,
                 timeout=self.timeout,
                 url=self.url,
                 cookie=self.cookie).run()
     backdoor.Backdoor(agent=self.agent,
                       proxy=self.proxy,
                       redirect=self.redirect,
                       timeout=self.timeout,
                       url=self.url,
                       cookie=self.cookie).run()
     bdir.Bdir(agent=self.agent,
               proxy=self.proxy,
               redirect=self.redirect,
               timeout=self.timeout,
               url=self.url,
               cookie=self.cookie).run()
     bfile.Bfile(agent=self.agent,
                 proxy=self.proxy,
                 redirect=self.redirect,
                 timeout=self.timeout,
                 url=self.url,
                 cookie=self.cookie).run()
     dir.Dir(agent=self.agent,
             proxy=self.proxy,
             redirect=self.redirect,
             timeout=self.timeout,
             url=self.url,
             cookie=self.cookie).run()
     log.Log(agent=self.agent,
             proxy=self.proxy,
             redirect=self.redirect,
             timeout=self.timeout,
             url=self.url,
             cookie=self.cookie).run()
Exemple #11
0
    def __init__(self):
        self.__window = Tk()
        self.__window.title("Admin")

        self.__username_label_su = Label(self.__window, text='Username: '******'Password: '******'*')

        self.__username_entry_su.grid(row=0, column=1)
        self.__password_entry_su.grid(row=1, column=1)

        self.__signup_button = Button(self.__window, text='SIGN UP',\
                                     command=self.sign_up)
        self.__signup_button.grid(row=2)

        self.__username_label_li = Label(self.__window, text='Username: '******'Password: '******'*')

        self.__username_entry_li.grid(row=0, column=4)
        self.__password_entry_li.grid(row=1, column=4)

        self.__login_button = Button(self.__window, text='LOGIN',\
                                     command=self.login)
        self.__login_button.grid(row=2, column=3)

        self.__admin = admin.Admin()

        mainloop()
Exemple #12
0
    def __init__(self):
        engine = create_engine(config.get('Database', 'db_url'), echo=False)
        session = scoped_session(sessionmaker(autoflush=True,
                                              autocommit=False))
        session.configure(bind=engine)

        data.Base.metadata.create_all(engine)

        self.scan_app_dir(session)

        self.apps = {}
        self.groups = {}

        self.login = auth.Login()
        self.admin = admin.Admin()
        self.user = user.User()
        self.statistics = statistics.Statistics()
        self.reports = reports.Reports()

        dbapps = session.query(data.Application).all()

        for dbapp in dbapps:
            app = self.load_app(dbapp)

            if app != None:
                self.apps[app.id] = app
                app.enabled = dbapp.enabled

        session.commit()
        session.remove()
        engine.dispose()

        self.server_map()
        field.objectify_clean()

        self.no_SSL = False
Exemple #13
0
import admin

admin_user = admin.Admin('Martin','Castro','*****@*****.**','CABA')
admin_user.privileges.set_privileges('can add post','can delete post','can ban user',
                                        'can be anything')
admin_user.greet_user()
admin_user.privileges.show_privileges()
import admin

my_admin = admin.Admin('le', 'xiaoyuan')
my_admin.privileges.show_privileges()
Exemple #15
0
import customer
import admin

cust=customer.Customer()
admin=admin.Admin()
cust.print()
admin.print()

class Bank:
    def main(self):

Exemple #16
0
import questions
import user
import admin

print("Welcome to the GCIT Library Management System!\n")
print("What kind of user are you?\n")
choice = input("1)Librarian\n2)Borrower\n3)Administrator\n")
if choice == "1":
    user_type = "librarian"
elif choice == "2":
    user_type = "borrower"
elif choice == "3":
    user_type = "administrator"

if choice == "1" or choice == "2":
    test_case = user.User(user_type,
                          questions.question_bank["start"][user_type],
                          questions.question_bank[user_type])
    test_case()
elif choice == "3":
    test_case = admin.Admin()
    test_case()
"""
9-12. Multiple Modules: Store the User class in one module, and store the 
Privileges and Admin classes in a separate module. In a separate file, create 
an Admin instance and call show_privileges() to show that everything is still 
working correctly.
"""

import admin

elliot = admin.Admin('elliot', 'alderson', 'ealderson', '*****@*****.**', 'NYC')
elliot.show_privileges()
import admin
import privileges

admin = admin.Admin('leon', 'kennedy', 25, 'seattle')
admin.privilege.show_privileges()
Exemple #19
0
import admin

adm = admin.Admin('chapter9-11 ','sehwan')
adm.greet_user()
adm.pri.show_privileges()
import admin

hiro_privileges = [
    "make a user tea", "give user criptic life advice", "not ever die"
]
admin_hiro = admin.Admin("hiro", "uncle", 64, "firenation", "jasmintea",
                         hiro_privileges)
admin_hiro.privileges.show_privileges()
Exemple #21
0
import users
import admin

admin1 = admin.Admin("name", "last name", "m", "somewhere",
                     "*****@*****.**",
                     ["can add post", "can delete post", "can ban user"])
admin1.privileges.show_privileges()
Exemple #22
0
import admin
Admin1 = admin.Admin('joe', 'jiang')
Admin1.privileges.show_privileges()
#9.10 imported restaurant

from restaurant import *

rest = Restaurant(
    "Hotel Sea Shell",
    "Cox's Bazar",
)
rest.describe_restaurant()

#9.11 imported admin

import admin

user_admin = admin.Admin("Istiaq ", "Ahmed Fahad", "0176610097")
user_admin.show_privilege()

#9.12 multiple modules

from admin2 import Admin

user_admin2 = Admin("Istiaq ", "Ahmed Fahad", "0176610097")
user_admin2.show_privilege()
print(user_admin2.phone_no)
Exemple #24
0
        genimg.make_question(id, q[1], q[2])
    config.config.set('settings', 'lastver', config.ver)

bot = commands.Bot(command_prefix=commands.when_mentioned_or(
    'kahoot ', 'k! ', 'k!'),
                   help_attrs={'enabled': False},
                   case_insensitive=True)
bot.remove_command('help')

print('configuring webserver...')
import webserver
config.modules['webserver'] = webserver

import admin
config.modules['admin'] = admin
adminclass = admin.Admin(bot)
bot.add_cog(adminclass)

import logic
config.modules['logic'] = logic
gameclass = logic.Logic(bot)
bot.add_cog(gameclass)


class Reload(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command(pass_context=True, no_pm=False)
    async def reload(self, ctx, *, module: str):
        if ctx.message.author.id in config.superusers:
    def Logoff(self):
        answer = tkinter.messagebox.askquestion(
            "Logout", "Are you sure you want to logout? ")

        if answer == "yes":
            tkinter.messagebox.showinfo("Logout", "Goodbye")
            self.root.destroy()

            root = Tk()
            root.geometry("350x200")
            root.title("Login")
            root.resizable(False, False)
            login1 = login.Login(root)
            root.mainloop()
            if login1.dept == "Receiving":
                root = Tk()
                root.geometry("400x500")
                root.title("Receiving")
                root.resizable(False, False)
                root.configure(bg="light gray")
                receiving1 = receiving.Receiving(root)
                root.mainloop()
            elif login1.dept == "Assembly":
                root = Tk()
                root.geometry("665x380")
                root.title("Assembly")
                root.resizable(False, False)
                app = assembly_class.Assembly(root, "0002")
                root.mainloop()
            elif login1.dept == "Testing":
                root = Tk()
                root.geometry("680x500")
                root.title("Testing")
                root.resizable(False, False)
                app = testing.TestingWindow(root, "0003")
                root.mainloop()
            elif login1.dept == "Shipping":
                root = Tk()
                root.geometry("665x380")
                root.title("Shipping")
                root.resizable(False, False)
                shipping.Shipping(root, "0004")
                root.mainloop()
            elif login1.dept == "Accounting":
                root = Tk()
                root.geometry("500x300")
                root.title("Accounting")
                root.resizable(False, False)
                close_window = Button(root, text="Close", command=root.quit)
                close_window.place(x=90, y=230)
                app = accounting.accounting(root, "0005")
                root.mainloop()
            elif login1.dept == "Admin":
                root = Tk()
                root.geometry("600x500")
                root.title("New User")
                root.resizable(False, False)
                root.configure(bg="light gray")
                admin1 = admin.Admin(root)
                root.mainloop()
            elif login1.dept == "Inventory":
                root = Tk()
                root.geometry("620x500")
                root.title("Inventory")
                root.resizable(False, False)
                app = inventory.Inventory(root)
                root.mainloop()
Exemple #26
0
class Root(controllers.RootController):
    user = srusers.User()
    fw = fw.FwServe()
    autosave = srautosave.Autosave()
    #feed = Feed()
    switchboard = switchboard.Switchboard()
    admin = admin.Admin()
    version = get_version()

    if config.get(
            "simulator.enabled"
    ):  # if simulation is enabled import the simulator controller
        import sim
        sim = sim.Sim()

    @expose()
    def index(self):
        """
        In case the apache rewrite rule isn't paying attention, serve up the
        index file from here.
        """
        loc = os.path.join(os.path.dirname(__file__), "static/index.html")
        return serveFile(loc)

    @expose("json")
    def info(self):
        info = dict(Version=self.version, User=str(srusers.get_curuser()))
        return dict(info=info)

    def get_project_path(self, path):
        """
        Get a project name and filepath from a path
        inputs:
            path - str to a file
        returns:
            tuple containing the project and path
        """
        root, project, file_path = path.split(os.path.sep, 2)
        return project, file_path

    def get_rev_id(self, team, project, revno=-1):
        """
        Get revision ID string from revision number.
        inputs:
            revno - revision number convertable with int().
                    if revno is -1 or not supplied, get latest revision id.
        returns:
            revision id string
        """

        b = open_branch(int(team), project)

        try:
            if revno == -1 or revno == "-1" or revno == "HEAD":  #TODO BZRPORT: stop anything calling "HEAD" string
                rev_id = b.last_revision()
            else:
                rev_id = b.get_rev_id(int(revno))

        except (TypeError):  # TODO BZRPORT: add bzr exception
            print "Getting ID for revno: %s failed, returning latest revision id." % revno
            rev_id = b.last_revision()

        return rev_id

    def get_file_revision(self, tree, fileid):
        """
        Get the id of the revision when the file was last modified.
        inputs: tree - a bzrlib tree of some kind
                fileid - file id of file in tree
        outputs: revid - revision id
        """
        return bzrlib.tree.Tree._file_revision(
            tree, fileid)  # static method for some reason

    @expose()
    @srusers.require(srusers.in_team())
    def checkout(self, team, project, simulator=False):
        """
        This function grabs a set of files and makes a zip available. Should be
        linked to directly.
        inputs:
            team & project - code to retrieve
            simulator - true if code is being delivered to a simulator.
        returns:
            A zip file as a downloadable file with appropriate HTTP headers
            sent.
        """
        b = open_branch(int(team), project)
        rev_tree = b.basis_tree()  # get latest revision tree for branch

        #Avoid using /tmp by writing into a memory based file
        zipData = StringIO.StringIO()
        zip = zipfile.ZipFile(zipData, "w", zipfile.ZIP_DEFLATED)
        #Need to lock_read before reading any file contents
        rev_tree.lock_read()
        try:
            #Get a list of files in the tree
            files = [
                f for f in rev_tree.iter_entries_by_dir()
                if f[1].kind == "file"
            ]
            for filename, file in files:
                #Set external_attr on a ZipInfo to make sure the files are
                #created with the right permissions
                info = zipfile.ZipInfo(filename.encode("ascii"))
                info.external_attr = 0666 << 16L
                #Read the file contents and add to zip
                zip.writestr(info, rev_tree.get_file(file.file_id).read())

            #Need a __init__ in the root of all code exports
            if not "__init__.py" in [f[0].encode("ascii") for f in files]:
                info = zipfile.ZipInfo("__init__.py")
                info.external_attr = 0666 << 16L
                zip.writestr(info, "")

        except:
            return "Error exporting project"
        finally:
            #Always unlock or get GC related errors
            rev_tree.unlock()
        zip.close()
        #Seek back to start of file so read() works later on
        zipData.seek(0)

        if not simulator:
            """
            The zipfile delivered to the robot is the contents of the
            repository as a zip inside another zip that contains firmware.
            """
            #Get a copy of the firmware zip, drop the code zip (in zipData)
            #in it and then put the resulting zip back into zipData
            sysZipData = open(config.get("robot.packagezip")).read()
            sysZipBuffer = StringIO.StringIO(sysZipData)

            sysZip = zipfile.ZipFile(sysZipBuffer, "a")
            info = zipfile.ZipInfo(ZIPNAME)
            info.external_attr = 0666 << 16L
            sysZip.writestr(info, zipData.read())
            sysZip.close()

            sysZipBuffer.seek(0)
            zipData = StringIO.StringIO(sysZipBuffer.read())

        #Set up headers for correctly serving a zipfile
        cherrypy.response.headers['Content-Type'] = \
                "application/x-download"
        cherrypy.response.headers['Content-Disposition'] = \
                'attachment; filename="' + ZIPNAME + '"'

        #Return the data
        return zipData.read()

    @expose("json")
    @srusers.require(srusers.in_team())
    def filesrc(self, team, file=None, revision=None):
        """
        Returns the contents of the file.
        """

        file_path = file  #save for later
        project, file = self.get_project_path(file_path)
        curtime = time.time()
        b = open_branch(int(team), project)

        #TODO: Need to security check here! No ../../ or /etc/passwd nautiness trac#208

        autosaved_code = self.autosave.getfilesrc(team, file_path, 1)

        if revision == None or revision == "HEAD":
            revno, revid = b.last_revision_info()
        else:
            revno = int(revision)
            revid = b.get_rev_id(revno)

        if file != None and file != "":  #TODO BZRPORT: URL checking
            #Load file from bzr
            # TODO BZRPORT: mime checking. Bzr doesn't have a mime property so the file will need to be checked with python
            try:
                branch_tree = b.repository.revision_tree(revid)
                file_id = branch_tree.path2id(file)
                b.lock_read()
                code = branch_tree.get_file_text(file_id)
                file_revid = self.get_file_revision(
                    branch_tree,
                    file_id)  # get revision the file was last modified
                file_revno = b.revision_id_to_revno(file_revid)
            except:
                code = "Error loading file '%s' at revision %s." % (file,
                                                                    revision)
                file_revno = 0
            # always unlock:
            finally:
                b.unlock()

        else:
            code = "Error loading file: No filename was supplied by the IDE.  Contact an SR admin!"
            revision = 0

        return dict(curtime=curtime,
                    code=code,
                    autosaved_code=autosaved_code,
                    file_rev=str(file_revno),
                    revision=revno,
                    path=file_path,
                    name=os.path.basename(file))

    @expose("json")
    @srusers.require(srusers.in_team())
    def gethistory(self, team, file, user=None, offset=0):
        """
        This function retrieves the bzr history for the given file(s)
        to restrict logs to particular user, supply a user parameter
        a maximum of 10 results are sent to the browser, if there are more than 10
        results available, overflow > 0.
        supply an offset to view older results: 0<offset < overflow; offset = 0 is the most recent logs
        """
        if file[:9] == 'New File ':
            return dict(path=file, history=[])

        file_path = file  #save for later
        project, file = self.get_project_path(file_path)
        b = open_branch(int(team), project)
        revisions = [
            b.repository.get_revision(r) for r in b.revision_history()
        ]

        #Get a list of authors
        authors = list(set([r.committer for r in revisions]))

        #If a user is passed, only show revisions committed by that user
        if user != None:
            revisions = [r for r in revisions if r.committer == user]

        #Only show revisions where the delta touches file
        fileid = b.basis_tree().path2id(file)
        if fileid == None:
            #File not found
            return dict()

        def revisionTouchesFile(revision):
            """
            Return true if the revision changed a the file referred to in fileid.
            """
            delta = b.get_revision_delta(
                b.revision_id_to_revno(revision.revision_id))
            return delta.touches_file_id(fileid)

        revisions = filter(revisionTouchesFile, revisions)

        #Calculate offsets for paging
        try:
            offset = int(offset)
        except ValueError:
            #Someone passed a string
            return dict()
        start = offset * 10
        end = start + 10
        maxval = len(revisions)
        if maxval % 10 > 0:
            overflow = maxval / 10 + 1
        else:
            overflow = maxval / 10

        revisions = revisions[start:end]
        revisions.reverse()

        return dict(path=file_path,
                    overflow=overflow,
                    offset=offset,
                    authors=authors,
                    history=[{
                        "author":
                        r.committer,
                        "date":
                        time.strftime("%H:%M:%S %d/%m/%Y",
                                      time.localtime(r.timestamp)),
                        "message":
                        r.message,
                        "rev":
                        b.revision_id_to_revno(r.revision_id)
                    } for r in revisions])

    @expose("json")
    @srusers.require(srusers.in_team())
    def polldata(self, team, files="", logrev=None):
        """Returns poll data:
            inputs: files - comma seperated list of files the client needs info
            on
            returns (json): A dictionary with an entry for each file (path is
            the key). Each value is a dictionary with information. The only key
            is revision, with a value of an integer of the current revision
            number in the repo"""
        pass  #TODO BZRPORT: Implement!

        #Default data
        r = {}
        l = {}
        client = Client(int(team))

        if files != "":
            files = files.split(",")
            rev = 0
            for file in files:
                r[file] = {}
                try:
                    info = client.info2(client.REPO + file)[0][1]
                    r[file]["rev"] = info["last_changed_rev"].number
                except pysvn.ClientError:
                    pass

        if logrev != None:
            try:
                newlogs = client.log(client.REPO,
                                     discover_changed_paths=True,
                                     revision_end=pysvn.Revision(
                                         pysvn.opt_revision_kind.number,
                                         int(logrev) + 1))

                l =[{"author":x["author"], \
                        "date":time.strftime("%H:%M:%S %d/%m/%Y", \
                        time.localtime(x["date"])), \
                        "message":x["message"], "rev":x["revision"].number,
                        "changed_paths":[(c.action, c.path) for c in \
                            x.changed_paths]} for x in newlogs]
            except pysvn.ClientError:
                #No commits recently, no data to return
                pass

        return dict(files=r, log=l)

    @expose("json")
    @srusers.require(srusers.in_team())
    def pollchanges(self, team, project, rev, date=0):
        """
        Used to determine if certain facets need updating.
        Currently this is only for the filelist, to remove the need to send the entire filelist just to see if its changed
        """
        b = open_branch(int(team), project)
        head_rev_id = self.get_rev_id(team, project, 'HEAD')
        target_rev_id = self.get_rev_id(team, project, rev)

        filelist = True
        if head_rev_id == target_rev_id:
            filelist = False

        return dict(filelist=filelist)

    @expose("json")
    @srusers.require(srusers.in_team())
    def delete(self, team, project, files, kind='SVN'):
        """
        Delete files from the repository, and prune empty directories.
        inputs: files - comma seperated list of paths
                kind - one of 'SVN' or 'AUTOSAVES'
        returns (json): Message - a message to show the user
        """

        if files != "":
            files = files.split(",")
            wt = WorkingTree(int(team), project)

            message = "Files deleted successfully: " + project + " >\n" + "\n".join(
                files)

            for f in files:
                self.autosave.delete(team, '/' + project + '/' + f)

            if kind == 'AUTOSAVES':
                return dict(Message="AutoSaves deleted successfully: \n" +
                            "\n".join(files))

            wt.remove(files)

            # find out current user
            ide_user = str(srusers.get_curuser())

            revproperties = {"authors": ide_user}
            wt.commit('Remove files: ' + ', '.join(files),
                      revprops=revproperties)
            wt.destroy()

            return dict(Message=message)

    @expose("json")
    @srusers.require(srusers.in_team())
    def savefile(self, team, filepath, rev, message, code):
        """
        Create/update contents of a file and attempt to commit.
        If file has been updated since submitted text was checked out,
            call update_merge to attempt to merge the changes.
        If file has not been updated since client checked it out,
            call commit_file_simple to commit the new version.

        inputs: path - path of file relative to project root.
                rev - revision of file when it was checked out by client.
        """

        project, filepath = self.get_project_path(filepath)

        projWrite = ProjectWrite(team, project, revno=rev)

        projWrite.update_file_contents(filepath, code)

        reloadfiles = "True"  # TODO: determine whether or not file list needs refreshing

        try:
            newrevno, newrevid = projWrite.commit(message)
            success = "True"
        except bzrlib.errors.OutOfDateTree:
            # a commit has occurred since code was opened.
            # A merge will need to take place
            code, newrevno, newrevid = projWrite.merge(filepath)
            if len(projWrite.conflicts) == 0:
                # TODO: when committing a merged transform preview affecting more than one file,
                #       the text changes do not commit despite the merge succeeding and returning correct text.
                #       solution for now is to open a new transform preview and pump the new code into it.
                pw2 = ProjectWrite(team, project)
                pw2.update_file_contents(filepath, code)
                newrevno, newrevid = pw2.commit(message)
                success = "AutoMerge"
                pw2.destroy()
            else:
                return dict(new_revision=newrevno,
                            code=code,
                            success="Merge",
                            file=filepath,
                            reloadfiles=reloadfiles)
        finally:
            projWrite.destroy()

        return dict(new_revision=str(newrevno),
                    code=code,
                    success=success,
                    file=filepath,
                    reloadfiles=reloadfiles)

    @expose("json")
    @srusers.require(srusers.in_team())
    def filelist(self, team, project, rootpath="/", rev=-1, date=0):
        """
        Returns a directory tree of the current repository.
        inputs: project - the bzr branch
                rootpath - to return file from a particular directory within the branch (recursive)
        returns: A tree as a list of files/directory objects:
            { tree : [{path : filepath
                       kind : FOLDER or FILE
                       children : [list as above]
                       name : name of file}, ...]}
        """

        b = open_branch(int(team), project)

        target_rev_id = self.get_rev_id(team, project, rev)
        self.user.set_setting('project.last', project)

        try:
            rev_tree = b.repository.revision_tree(target_rev_id)
        except:
            return {"error": "Error getting revision tree"}

        # Get id of root folder from which to list files. if it is not found it will return None
        rootid = rev_tree.path2id(rootpath)

        try:
            rev_tree.lock_read()
            # Get generator object containing file information from base rootid. If rootid=None, will return from root.
            files = rev_tree.inventory.iter_entries(rootid)
        except:  # TODO BZRPORT: Proper error handling
            return {"error": "Error getting file list"}
        # Always unlock tree:
        finally:
            rev_tree.unlock()

        #grab the autosave listings
        autosave_data = self.autosave.getfilesrc(team,
                                                 '/' + project + rootpath)

        def branch_recurse(project, path, entry, files, given_parent_id):
            """
            Travels recursively through a generator object provided by revision_tree.inventory.iter_items.
            Iter_items returns child items immediately after their parents, so by checking the parent_id field of the item with the actual id of the directory item that called it, we can check if we are still within that directory and therefore need to add the item as a child.
            This function will return a list of all children of a particular branch, along with the next items for analysis.
            Whenever it encounters a directory it will call itself to find the children.
            inputs: path - path of item to be analysed first
                    entry - InventoryEntry-derived object of item to be analysed first
                    files - generator object created by iter_items
                    given_parent_id - id (string) of calling directory
            returns: entry_list - list of children. if given_parent_id does not match entry.parent_id, this will be an empty list.
                     path - path of item that has not yet been added to the tree
                     entry - the entry object that has not yet been added to the tree.
                             if given_parent_id did not match entry.parent_id, then path and entry returned will be the same as path and entry called.
            """

            entry_list = []

            while entry.parent_id == given_parent_id:  # is a child of parent

                if entry.kind == "directory":
                    try:
                        next_path, next_entry = files.next()
                        children_list, next_path, next_entry = branch_recurse(
                            project, next_path, next_entry, files,
                            entry.file_id)
                    except StopIteration:  # No more files to iterate through after this one
                        next_entry = None  # break after adding this entry
                        children_list = [
                        ]  # no more items, so there can't be any children

                    entry_list.append({
                        "name": entry.name,
                        "path": project + path,
                        "kind": "FOLDER",
                        "autosave": 0,  # No autosave data for directories
                        "rev":
                        "-1",  #TODO BZRPORT: what's this show/for? yes, i know revision, i mean, current, or when it was created?
                        "children": children_list
                    })

                    if next_entry is None:
                        break  # there are no more iterations so break
                    else:
                        path = next_path
                        entry = next_entry  # now we'll use the returned entry

                else:
                    if project + path in autosave_data:
                        autosave_info = autosave_data[project + path]
                    else:
                        autosave_info = 0
                    entry_list.append({
                        "name": entry.name,
                        "path": project + path,
                        "kind": "FILE",
                        "autosave": autosave_info,
                        "rev":
                        "-1",  #TODO BZRPORT: what's this show/for? yes, i know revision, i mean, current, or when it was created?
                        "children": []
                    })

                    try:
                        path, entry = files.next()  # grab next entry
                    except StopIteration:  # No more files to iterate through
                        break

            return entry_list, path, entry

        # Determine tree_root string to pass to recursing function as a parent id
        if rootid == None:
            tree_root = "TREE_ROOT"
        else:
            tree_root = rootid

        try:
            first_path, first_entry = files.next()  # grab next entry
        except StopIteration:  # StopIteration caught on first pass: project tree must be empty
            return dict(tree=[])

        tree, last_path, last_entry = branch_recurse('/' + project + '/',
                                                     first_path, first_entry,
                                                     files, tree_root)

        return dict(tree=tree)

    #create a new directory
    @expose("json")
    @srusers.require(srusers.in_team())
    def newdir(self, team, path, msg):
        project, dirpath = self.get_project_path(path)
        projWrite = ProjectWrite(team, project)

        try:
            projWrite.new_directory(dirpath)
        except:  # TODO BZRPORT: replace with bzr error
            return dict( success=0, newdir = path,\
                        feedback="Error creating directory: " + path)

#TODO: try:
        revno, revid = projWrite.commit(msg)

        return dict( success=1, newdir = path,\
                feedback="Directory successfully created")

#        else: # directory wasn't created because it already existed
#            return dict( success=0, newdir = path,\
#                    feedback="Directory " + path + " already exists")

    @expose("json")
    @srusers.require(srusers.in_team())
    def projlist(self, team):
        """Returns a list of projects"""

        try:
            r = open_repo(int(team))
        except:
            #No repository present
            return dict(projects=[])

        self.user.set_setting('team.last', team)

        projects = []

        branches = r.find_branches()

        for branch in branches:
            projects.append(branch.nick)

        return dict(projects=projects)

    @expose("json")
    @srusers.require(srusers.in_team())
    def createproj(self, name, team):
        """Creates new project directory"""

        r = open_repo(int(team))

        if name.find(".") != -1:
            """No ../../ nastyness"""
            return nil

        url = srusers.get_svnrepo(team) + "/" + name

        r.bzrdir.create_branch_convenience(base=url, force_new_tree=False)

        return dict()

    @expose("json")
    @srusers.require(srusers.in_team())
    def revert(self, team, files, torev, message):

        file_list = files.split(',')
        if len(file_list) == 0:
            return dict(Message='Revert failed - no files specified', status=1)

        project, file = self.get_project_path(file_list[0])
        rev_spec = bzrlib.revisionspec.RevisionSpec.from_string(torev)
        file_list = [self.get_project_path(f)[1] for f in file_list]

        wt = WorkingTree(team, project)
        rev_tree = rev_spec.as_tree(wt.branch)

        wt.revert(file_list, rev_tree)

        # find out current user
        ide_user = str(srusers.get_curuser())

        revproperties = {"authors": ide_user}

        wt.commit(message, revprops=revproperties)
        newrev, id = wt.branch.last_revision_info()
        wt.destroy()

        return dict(new_revision=newrev,
                    code="",
                    success="Success !!!",
                    status=0)

        #from undelete
        return dict(fail=fail, success=','.join(success), status=status)

    @expose("json")
    @srusers.require(srusers.in_team())
    def calendar(self, mnth, yr, file, team):
        #returns data for calendar function

        if file == '/':  #no project selected
            return dict(path=file, history=[])

        month = int(mnth) + 1
        year = int(yr)
        b = open_branch(team, file)

        try:
            log = b.repository.get_revisions(b.revision_history())
        except:
            logging.debug("Log failed for %s" % file)
            print "failed to retrieve log"
            return dict(path=file, history=[])

        if len(log) == 0:  #if there's nothing there
            return dict(path=file, history=[])

        #get a list of users based on log authors
        start = datetime.datetime(year, month, 1, 0, 0, 0)

        if (month >= 12):
            end = datetime.datetime(year + 1, 1, 1, 0, 0,
                                    0)  #watchout for rollover
        else:
            end = datetime.datetime(year, month + 1, 1, 0, 0, 0)

        result = []

        for y in log:
            now = datetime.datetime(2000, 1, 1)
            #create a dummy datetime
            now = now.fromtimestamp(y.timestamp)
            if (start <= now < end):
                result.append(y)

        result.reverse()

        return dict(  path=file,\
                      history=[{"author":x.get_apparent_author(), \
                      "date":time.strftime("%Y/%m/%d/%H/%M/%S", \
                      time.localtime(x.timestamp)), \
                      "message":x.message, "rev":b.revision_id_to_revno(x.revision_id)} \
                      for x in result])

    @expose("json")
    @srusers.require(srusers.in_team())
    def move(self, team, src, dest, msg=""):
        #   the source and destination arguments may be directories or files
        #   directories rendered empty as a result of the move are automatically 'pruned'
        #   returns status = 0 on success

        src_proj, src_path = self.get_project_path(src)
        dest_proj, dest_path = self.get_project_path(dest)
        if src_proj != dest_proj:
            return dict(new_revision="0",
                        status="1",
                        message="Source and destination projects must match")

        wt = WorkingTree(int(team), src_proj)

        if not wt.has_filename(src_path):
            return dict(new_revision="0",
                        status="1",
                        message="Source file/folder doesn't exist: " + src)

        if not wt.has_filename(os.path.dirname(dest_path)):
            return dict(new_revision="0",
                        status="1",
                        message="Destination folder doesn't exist: " +
                        os.path.dirname(dest))

        if wt.has_filename(dest_path):
            return dict(new_revision="0",
                        status="1",
                        message="Destination already exists: " + dest)

        wt.rename_one(src_path, dest_path)

        # find out current user
        ide_user = str(srusers.get_curuser())

        revproperties = {"authors": ide_user}

        wt.commit('Move ' + src_path + ' to ' + dest_path,
                  revprops=revproperties)
        wt.destroy()

        self.autosave.move(team, src, dest)

        return dict(new_revision="0",
                    status="0",
                    message='Sucessfully moved file ' + src + ' to ' + dest)

    @expose("json")
    @srusers.require(srusers.in_team())
    def copyproj(self, team, src, dest):
        # Create a temporary directory
        tmpdir = tempfile.mkdtemp()
        #open the branch and sprout a new copy, in the temp dir
        b = open_branch(team, src)
        self.createproj(dest, team)
        nb = open_branch(team, dest)
        b.push(nb)
        return dict(status=0)

    @expose("json")
    @srusers.require(srusers.in_team())
    def copy(self, team, src="", dest="", msg="SVN Copy", rev="0"):
        return self.cp(team, src, dest, msg, rev)

    @srusers.require(srusers.in_team())
    def cp(self, team, src="", dest="", msg="Copy", rev="0"):

        project, src = self.get_project_path(src)
        dest_project, dest = self.get_project_path(dest)
        if dest_project != project:
            return dict(
                new_revision="0",
                status="1",
                message=
                "Copy Failed: Source and destination projects must match")

        if rev == "0":
            rev = None

        projWrite = ProjectWrite(team, project, revno=rev)

        if src == "":
            return dict(new_revision="0",
                        status="1",
                        msg="No Source file/folder specified")
        if dest == "":
            return dict(new_revision="0",
                        status="1",
                        msg="No Destination file/folder specified")

        try:
            projWrite.copy(src, dest)
            new_revno, new_rev_id = projWrite.commit(msg)

        except Exception, e:
            return dict(new_revision="0",
                        status="1",
                        message="Copy Failed: " + str(e))

        return dict(new_revision=str(new_revno),
                    status="0",
                    message="copy successful")
Exemple #27
0
	def __init__(self):
		Thread.__init__(self)
		self.status=1
		self.admin = admin.Admin()
		self.admin.deamon=True # Kill thread
Exemple #28
0
import admin as a

# from user import User
# from admin import Admin

c = a.Admin('lenny', 'Wite', 32)

c.privileges.show_priv()

#create at dev branch
Exemple #29
0
 choice = input()
 print(Fore.GREEN + dash)
 if choice == "1":
     print(Fore.YELLOW + "1.Admin")
     print(Fore.YELLOW + "2.User")
     choice_1 = input()
     print(Fore.GREEN + dash)
     if choice_1 == "1":
         code = input(Fore.LIGHTBLUE_EX + "Enter admin code ")
         if code == 'admin123456':
             lst = register.check("admin.csv")
             check = lst[0]
             print(Fore.GREEN + dash)
             if check:
                 while True:
                     admin_1 = admin.Admin(lst[1], lst[2])
                     print(Fore.YELLOW + "1.create event.")
                     print(Fore.YELLOW + "2.create off_ticket")
                     print(Fore.YELLOW + "3.remaining capacity")
                     print(Fore.YELLOW + "4.previous")
                     choice_11 = input()
                     print(Fore.GREEN + dash)
                     if choice_11 == "1":
                         while True:
                             event_info = admin.get_info()
                             check1 = event.check_id_event(event_info[0])
                             if check1 or check1 == None:
                                 check_1 = admin.create_event(event_info)
                                 if check_1:
                                     log.info_logger.info(f"{event_info} is created.")
                                     print(Fore.BLUE + "new event is created.")
Exemple #30
0
def menu_admin ():
    daftarAdmin = data_admin.Admin(None,None)
    daftarAdmin.daftar_data_admin()
    con.commit()