def executeCommand(self,command):
        log("IN command %s" % (command.name))
        table64 = command.getValue("table64")
        
        tableJSON = table64.decode('base64','strict')
        tableDict = json.loads(tableJSON)
        
        #get event ID
        db = mongo.MongoDBComponents(info.dbIP,info.dbPort)
        allEvents = db.find_all(info.dbDefault, info.rootTableCollectionName)
        
        #$to do: need a better way to do this ...
        #max = allEvents.count
        maxEvent = 0
        for ev in allEvents:
            maxEvent += 1;
            
        tableNumber = maxEvent + 1

        # move this block to function ...
        
        tableDict['tableNumber'] = tableNumber
        
        mongo.newMongo(info).save(info.dbDefault,info.rootTableCollectionName, tableDict)

        log("recieved table JSON %s" % (tableJSON) )
        panel = command.getValue("panel")

        s = "Saved new Table Event #%s" % ( str(tableNumber) )

        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        
        command.outCommands.append(displayCmd)       
    def executeCommand(self, command):
        name=command.params[0].val

        displayCmd = Command("ReturnCommand")
        displayCmd.addParameter('echo', name )
        
        command.outCommands.append(displayCmd)
 def test_Ping(self):
     passed = "Gandalf"
     c = Command("Ping")
     c.addParameter("name",passed)
     re = Framework().processCommand(c,info.commandDomainTuple)
     self.assertEquals(re.commands[0].name,"ReturnCommand")
     s = re.commands[0].params[0].val
     self.assertEquals(s,passed)     
 def executeCommand(self,command):
     log("IN command %s" % (command.name))
     panel = command.getValue("panel")
     
     db = mongo.MongoDBComponents(info.dbIP,info.dbPort)
     allEvents = db.find_all(info.dbDefault, info.rootTableCollectionName)
     
     s = "<table border='0' cellspacing='0' cellpadding='5'>"
     s += "<tr class='clsGridHeaderRow'>"
     s += "<td>table #</td>"
     s += "<td>venue</td>"
     s += "<td>street</td>"
     s += "<td>street2</td>"
     s += "<td>city</td>"
     s += "<td>state</td>"
     s += "<td>zip</td>"
     s += "<td>country</td>"
     s += "<td>date</td>"
     s += "<td>time</td>"
     s += "<td>hosts</td>"
     s += "<td>guests</td>"
     s += "<td colspan='3'>actions</td>"
     s += "</tr>"
     
     
     
     for ev in allEvents:
         s += "<tr class='clsGridRow'>"
         s += "<td>{0}</td>".format(ev['tableNumber'])
         s += "<td>{0}</td>".format(ev['location']['venue'])
         s += "<td>{0}</td>".format(ev['location']['street'])
         s += "<td>{0}</td>".format(ev['location']['street2'])
         s += "<td>{0}</td>".format(ev['location']['city'])
         s += "<td>{0}</td>".format(ev['location']['state'])
         s += "<td>{0}</td>".format(ev['location']['zip'])
         s += "<td>{0}</td>".format(ev['location']['country'])
         s += "<td>{0}</td>".format(ev['meta']['date'])
         s += "<td>{0}</td>".format(ev['meta']['time'])
         s += "<td>{0}</td>".format(len(ev['hosts']))
         s += "<td>{0}</td>".format(len(ev['guests']))
         s += "<td><input class='clsGridButton' type='button' value='edit' id='cmd_{0}_edit' onclick=\"FWK.say('EditEvent','{1}','{2}');\" /></td>".format(ev['tableNumber'],ev['_id'],panel)
         s += "<td><input class='clsGridButton' type='button' value='delete' id='cmd_{0}_delete' onclick=\"FWK.say('DeleteEvent','{1}','{2}','{3}');\" /></td>".format(ev['tableNumber'],ev['_id'],panel,ev['tableNumber'])
         s += "<td><input class='clsGridButton' type='button' value='process invites' id='cmd_{0}_proc' onclick=\"FWK.say('ProcessInvites','{1}','{2}');\" /></td>".format(ev['tableNumber'],ev['_id'],panel)
         s+= "</tr>"
     
     
     s += "</table>"
     
     
     displayCmd = Command('Display')
     displayCmd.addParameter('panel', panel)
     displayCmd.addParameter('html64', Utils().pack(s) )
     
     command.outCommands.append(displayCmd)   
    def test_ShowEvents(self):
        c = Command("ShowEvents")
        c.addParameter("panel",'west')
        re = Framework().processCommand(c, info.commandDomainTuple)
        
        print "returned command [%s] had %s parameters" % (re.commands[0].name,len(re.commands[0].params))
   
        
  

  
        
        
    def executeCommand(self,command):
        panel = command.getValue("panel")

        Utils().removeFile(info.LogFile)
        
        s = "removed server log file permanently"
        log("command %s - %s" % (command.name,s)) #log after the fact to make sure log file is clean looking ( not half the log event from this command
        
       
        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        command.outCommands.append(displayCmd)        
    def executeCommand(self,command):
        log("IN command %s" % (command.name))
        table_id = command.getValue("table_id")
        panel = command.getValue("panel")
        
        mdb = mongo.MongoDBComponents(info.dbIP,info.dbPort)
        mdb.deleteDocument(info.dbDefault, info.rootTableCollectionName, {'_id': OID.ObjectId(table_id) } )
        s = "Deleted Table #%s" % ( str(table_id) )

        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        
        command.outCommands.append(displayCmd)    
 def test_CallingPing(self):
     name = "bunny"
     c = Command("Ping")
     c.addParameter("name",name)
    
     kontext = Kontext()
     kontext.setKeyValue("user", "grant")
     itinerary = Itinerary(kontext)
     itinerary.addInCommand(c)
     
     re = fwk().processItinerary(itinerary)
     
     self.assertEquals(re.outCommands[0].name,"ReturnCommand")
     self.assertEquals(re.outCommands[0].params[0].name,"echo")
     self.assertEquals(re.outCommands[0].params[0].val,name)
 def test_CommandsReflect(self):
        
         kontext = Kontext()
         kontext['REFERER'] = 'From a UNIT TEST'
         
         c = Command("CommandsReflect")
         c.addParameter("panel",u"west")
        
 
         it = Itinerary(kontext)
         it.addInCommand(c)
         it = fwk().processItinerary(it)
         
         retJSON = fwk().CommandsToJSON(it.outCommands,it.kontext)
         print retJSON
 def test_Ping(self):
         
         kontext = Kontext()
         kontext['REFERER'] = 'From a UNIT TEST'
         
         c = Command("Ping")
         c.addParameter("name",u"echo")
         c.addParameter("age",44)
 
         it = Itinerary(kontext)
         it.addInCommand(c)
         it = fwk().processItinerary(it)
         
         retJSON = fwk().CommandsToJSON(it.outCommands,it.kontext)
         print retJSON
    def executeCommand(self,command):
        log("IN command %s" % (command.name))
        panel = command.getValue("panel")
        s = "<div class='clsPanel'>"
        s += "<b>Information about this Application</b>"
        s += "<div class='clsAbout'>{0} ver {1}.{2}.{3}</div>".format(info.appName,info.versionMajor,info.versionMinor,info.versionRevision)
        s += "<div class='clsAbout'>db://{0}:{1} db name: {2}</div>".format(info.dbIP,info.dbPort,info.dbDefault)
        s += "<div class='clsAbout'>session {0} path</div>".format(command.kontext['SessionGUID'])
        s += ""
        s += "</div>"

        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        command.outCommands.append(displayCmd)
    def executeCommand(self,command):

        username = command.getValue("username")
        oldpassword= command.getValue("oldPassword")
        newpassword = command.getValue("newPassword")
        newpasswordConfirm = command.getValue("newPasswordConfirm")
        log("IN command %s" % (command.name))
        
        from src.framework.core import UserHelper
        
        s = UserHelper().passwd(username, oldpassword, newpassword, newpasswordConfirm)
       
        replyCmd = Command('Alert')
        replyCmd.addParameter('msg', Utils().pack(s) )
        command.outCommands.append(replyCmd)
    def executeCommand(self,command):

        
        log("IN command %s" % (command.name))
        panel = command.getValue("panel")
        s = "<div class='clsPageHeader'>{0}</div>".format(strings.HELP_HEADER)
        s += "<div>"
        s += "<input type='text' class='clsCommandLineInactive' value=''  title='type command here' id='txtCommandLine' />"
        s += "<input type='button' value='exec' id='cmdProcessCommand' onclick=\"FWK.say('ProcCommandLine','txtCommandLine');\" />"
        s += "</div>"
        
        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        command.outCommands.append(displayCmd)
    def executeCommand(self,command):
        
        what = command.getValue("what")
        panel = command.getValue("panel")
        orient = command.getValue("orientation")
        
        
        
        s = "<div class='clsToc'>"
        s += "<table class='clsGrid' border='1' cellspacing='0'>"
        
        
        
        if orient == 'horizontal':
            s += "<tr>"

        nav = info.vertNav[what]
        counter = 0
        
        for n in nav:
            counter += 1
            if orient == 'vertical':
                s += "</tr>"
                
            s += "<td valign='bottom'>"
            s += "<div class='clsVertNavItem' id='dvToc_{0}'".format(str(counter))
            s += " onclick=\"FWK.pressNav('dvToc_',this,'clsVertNavItem'); {0}\" >".format(n['A'])
            s += n['name']
            s += "</div>"
            s += "</td>"
            
            if orient == 'vertical':
                s += "</tr>"
        
        if orient == 'horizontal':
            s += "</tr>"
        
        s += "</table>"
        s += "</div>"
        
        s64 = s.encode('base64','strict')
        s64 = urllib.quote(s64)

        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', s64 )
        command.outCommands.append(displayCmd)
    def executeCommand(self,command):

        
        log("IN command %s" % (command.name))
        panel = command.getValue("panel")
        
        s = "<div class='clsPageHeader'>{0}</div>".format(strings.SUPPORT_HEADER)
        supportPeople = info.supportContacts
        for supp in supportPeople:
            s += "<div>"
            s += "<a href='mailto:{0}'>{1}</a>".format(supp['email'],supp['name'])
            s += "</div>"
        
        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        command.outCommands.append(displayCmd)
    def executeCommand(self,command):

        
        log("IN command %s" % (command.name))
        
        kredbits = Utils().unpack( command.kontext['kreds']).split('_')
        username = kredbits[0]
        
        panel = command.getValue("panel")
        s = "<div class='clsPageHeader'>{0}</div>".format(strings.PWDRESET_HEADER)
        s += "<div>"
        s += "<table>"
        
        s += "<tr><td>"
        s += "user:</td><td>"
        s += "<input type='text' class='clsTextbox' value='{0}'  title='user' id='txtUsername' />".format( username )
        s += "</td></tr>"
        
        s += "<tr><td>"
        s += "old password:</td><td>"
        s += "<input type='password' class='clsTextbox' value=''  title='old password' id='txtPwdOld' />"
        s += "</td></tr>"
        
        s += "<tr><td>"
        s += "new password:</td><td>"
        s += "<input type='password' class='clsTextbox' value=''  title='new password' id='txtPwdNew' />"
        s += "</td></tr>"
        
        s += "<tr><td>confirm password:</td><td>"
        s += "<input type='password' class='clsTextbox' value=''  title='confirm new password' id='txtPwdConfirm' />"
        s += "</td></tr>"
        
        s += "<tr><td>"
        s += "<input type='button' value='save' id='cmdProcessCommand' onclick=\"FWK.say('Passwd','txtUsername','txtPwdOld','txtPwdNew','txtPwdConfirm');\" />"
        s += "</td></tr>"
        
        s += "</table>"
        s += "</div>"
        
        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', Utils().pack(s) )
        command.outCommands.append(displayCmd)
 def executeCommand(self,command):
     
     log("IN command %s" % (command.name))
     panel = command.getValue("panel")
     
     s = "<div class='clsPanel'>"
     
     from src.framework import coreCommands
     from src.custom import domainCommands
     
     s += "<div class='clsHeader'>core commands</div>"
     s = self.listCmds(s,'coreCommands', dir(coreCommands) ,info.commandCoreTuple)
     s += "<div class='clsHeader'>custom commands</div>"
     s = self.listCmds(s, 'domainCommands',dir(domainCommands),info.commandDomainTuple)
     
     
     
     s += "</div>"
     
     
     displayCmd = Command('Display')
     displayCmd.addParameter('panel', panel)
     displayCmd.addParameter('html64', Utils().pack(s) )
     command.outCommands.append(displayCmd)
 def executeCommand(self,command):
    
     panel = command.getValue("panel")
     lines = command.getValue("lines")
     intLines = int(lines)
     
     
     s = "<div id='windowRemoteLog' class='clsPanel'>"
     s += "<b>Server Log Remote View</b>"
     s += "<span id='xRemoteLog' title='close panel' class='clsXWindowX' onclick=\" FWK.say('ClearXwindow',this.id); \">x</span>"
     s += "<div class='clsLog'><textarea id='TexAreaLog' class='clsTextAreaLog'>"
     s += Utils().tail(info.LogFile,intLines)
     s += "</textarea></div>"
   
     s += "<div class='clsAbout'><input type='button' value='clear server log' onclick=\" FWK.say('RemoveRemoteLog','%s',25); \" /></div>" % panel
     s += "</div>"
     
     log("IN command %s( %s %s)" % (command.name,lines,panel)) #log after the fact to make sure log file is clean looking ( not half the log event from this command
     
     
     displayCmd = Command('Display')
     displayCmd.addParameter('panel', panel)
     displayCmd.addParameter('html64', Utils().pack(s) )
     command.outCommands.append(displayCmd)        
 def test_ShowToc(self):
         
         kontext = Kontext()
         kontext['REFERER'] = 'From a UNIT TEST'
         
         c = Command("ShowToc")
         c.addParameter("panel",u"west")
         c.addParameter("what","admin")
         c.addParameter("orientation","vertical")
 
         it = Itinerary(kontext)
         it.addInCommand(c)
         it = fwk().processItinerary(it)
         
         retJSON = fwk().CommandsToJSON(it.outCommands,it.kontext)
         print retJSON
 def executeCommand(self,command):
     log("IN command %s" % (command.name))
     panel = command.getValue("panel")
     table_id = command.getValue("table_id")
     mongoHelper, tableDoc = tp.targetMongo(info.dbDefault,info.rootTableCollectionName,
                                  {'_id':OID.ObjectId(table_id)},
                                  info)
     
     #fix the error on passing back ObjectId -- need to translate this back on saveing ...
     tableDoc['_id'] = table_id
     
     tableJSON = json.dumps(tableDoc)
     
     
     loadJS = Command('LoadAppSpecificJS')
     loadJS.addParameter('panel', panel)
     loadJS.addParameter('JSON64', Utils().pack(tableJSON) )
     loadJS.addParameter('JSmoduleToCall','APP.inviteMx')
     command.outCommands.append(loadJS)
    def executeCommand(self,command):
        log("IN command %s" % (command.name))
        
        panel = command.getValue("panel")
        
        s = "<div class='clsNavigationPanel'>"
        s += "<table class='clsGrid' border='0' cellspacing='0'>"
        s += "<tr>"
        s += "<td>"
        s += "<div class='clsNavigationPanel'><img src='./images/{0}' /></div>".format(info.appLogoImage)
        s += "</td>"

        nav = info.nav
        counter = 0
        for n in nav:
            counter += 1
            s += "<td class='clsNavElement' valign='bottom'>"
            s += "<div id='dvNav_{0}' class='clsHyperlink' ".format(str(counter))
            s += " onclick=\"FWK.pressNav('dvNav_',this,'clsHyperlink'); {0}\" >".format(n['A'])
            s += n['name']
            s += "</div>"
            s += "</td>"
            
        
        s += "</tr>"
        
        s += "</table>"
        s += "</div>"
        
        s64 = s.encode('base64','strict')
        s64 = urllib.quote(s64)

        
        
        
        
        displayCmd = Command('Display')
        displayCmd.addParameter('panel', panel)
        displayCmd.addParameter('html64', s64 )
        command.outCommands.append(displayCmd)
        
        w = "{0} ver{1}.{2}.{3}".format(info.appName,info.versionMajor,info.versionMinor,info.versionRevision)
        w64 = Utils().pack(w)
        DisplayWindowTitle = Command('DisplayWindowTitle')
        DisplayWindowTitle.addParameter('html64', w64 )
        command.outCommands.append(DisplayWindowTitle)
    def executeCommand(self,command):
        panel = command.getValue("panel")
        usr  = command.getValue("usr").decode('base64','strict')
        pwd =  command.getValue("pwd").decode('base64','strict')
       
        from src.framework import mongo
        userInDB = mongo.MongoDBComponents(info.dbIP,info.dbPort).find_one(info.dbDefault, info.userCollection, {'username': usr } )
        s = strings.NO_SUCH_USER
        if(userInDB):
            #user found
            
            if userInDB['locked']:
                s = strings.ACCOUNT_LOCKED
            elif(userInDB['password'] == pwd):
                #user authenticated
                
                #?reset pwd attempts
                pwdAttempts = int(userInDB['passwordAttempts'])
                if(pwdAttempts > 0):
                    userInDB['passwordAttempts'] = 0
                    mongo.newMongo(info).save(info.dbDefault,info.userCollection, userInDB)
                    
                s = strings.WELCOME + " " + userInDB['username']
                
                """display navigation"""
                showNavigation = Command('ShowNavigation')
                showNavigation.addParameter('panel', panel)
                command.outCommands.append(showNavigation)

                """set session timeout value"""
                setKontext = Command('SetKontext')
                setKontext.addParameter('sessionTimeoutMinutes', info.sessionTimeoutMinutes)
                command.outCommands.append(setKontext)

                """set kredentials"""
                setKreds = Command('SetKontext')
                kredPair = "%s_%s" % ( userInDB['username'], userInDB['password'] )
                setKreds.addParameter('kreds',Utils().pack(kredPair))
                command.outCommands.append(setKreds)
                
            else:
                #bad passowrd
                pwdAttempts = int(userInDB['passwordAttempts'])
                if(pwdAttempts >= info.passwordAttempts):
                    userInDB['locked'] = True
                    s = strings.ACCOUNT_LOCKED
                    log("ACCOUNT LOCKED {0} password attempted > {1} times".format(usr,pwdAttempts))
                else:
                    userInDB['passwordAttempts'] = pwdAttempts + 1
                    s = strings.WRONG_PASSWORD % (str( info.passwordAttempts - pwdAttempts))
                    log("BAD PASSWORD {0} password attempted > {1} times".format(usr,pwdAttempts))
                    
                #save bad password update
                mongo.newMongo(info).save(info.dbDefault,info.userCollection, userInDB)   

       
        displayCmd = Command('Alert')
        displayCmd.addParameter('msg', Utils().pack(s) )
        command.outCommands.append(displayCmd)    
 def test_commandCreation(self):
     c = Command("testCommand")
     c.addParameter("name","grant")
     c.addParameter("age",43)
     print c.JSON
    def executeCommand(self,command):
        
        import uuid
        g = uuid.uuid1()
        gs = Utils().pack(str(g))
        panel = command.getValue("panel")
        
        log("setting SessionGUID %s" % (gs))
        command.kontext['SessionGUID'] = gs
        setKontext = Command('SetKontext')
        setKontext.addParameter('SessionGUID', gs)
        command.outCommands.append(setKontext)

        Framework().intializeSystem(info)

        if( info.authenticateUser == True ):
            
            
            s = "<div><form id='frmLogin'>"
            s += "<table cellpadding='5'><tr><td>"
            s += "<img src='%s' />"
            s += "</td><td>"
            s += "<table>"
            s += "<tr><td>"
            s += "<DIV class='clsTextbox'>username:</DIV> </td>"            
            s += "<td>"            
            s += "<input type='text' value='' id='txtUsr'/>"
            s += "</td></tr>"
            s += "<tr><td>"
            s += "<DIV class='clsTextbox'>password: </DIV></td>"            
            s += "<td>"               
            s += "<input type='password' value='' id='txtPwd' />"
            s += "</td></tr>"
            s += "<tr><td>&nbsp;</td><td>"
            s += "<input type='button' value='%s' onclick=\" FWK.say('LocalLogin','%s'); \" />"
            s += "</td></tr></table></td></tr></table></form></div>"
            
            
            s = s % (info.LoginLogoURL,strings.LOGIN,panel)
            
            
            beforescript = """ 
            //JavaScript
            displayMsg('Please enter your username and password',msgCode.info);
            """
            
            afterscript = """
            try { document.getElementById('txtUsr').focus(); } catch (expp) {} 
            
            """
            
            displayCmd = Command('Display')
            displayCmd.addParameter('panel', panel)
            displayCmd.addParameter('html64', Utils().pack(s) )
            displayCmd.beforeload_JScript = Utils().pack(beforescript)
            displayCmd.afterload_JScript = Utils().pack(afterscript)
            
            
            command.outCommands.append(displayCmd)   
        else:
            """display navigation"""
            showNavigation = Command('ShowNavigation')
            showNavigation.addParameter('panel', panel)
            command.outCommands.append(showNavigation)
 def executeCommand(self,command):
     log("%s signed out" % (command.kontext['SessionGUID'])) 
     
     displayCmd = Command('Intialize')
     displayCmd.addParameter('panel', 'farnorth')
     command.outCommands.append(displayCmd)