def main(): # Get current url try: url = os.environ['REQUEST_URI'] except KeyError: url = '' uiTheme = '' form = cgi.FieldStorage() # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' try: avatarResult = cookies['avatarAttempt'].value except KeyError: avatarResult = '' try: galaxy = cookies['galaxy'].value except KeyError: galaxy = ghShared.DEFAULT_GALAXY else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') avatarResult = form.getfirst('avatarAttempt', '') sid = form.getfirst('gh_sid', '') galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' created = datetime.fromtimestamp(time.time()) inGameInfo = '' pictureName = '' userPictureName = '' friendCountStr = '' donateTotal = '' userTitle = '' donorBadge = '' email = '' defaultAlertTypes = 0 sharedInventory = 0 sharedRecipes = 0 siteAlertCheckStr = '' emailAlertCheckStr = '' mobileAlertCheckStr = '' reputation = 0 resScore = 0 mapScore = 0 repColor = 'grey' resColor = 'grey' mapColor = 'grey' abilities = [] if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid) if (sess != ''): logged_state = 1 currentUser = sess if (useCookies == 0): linkappend = 'gh_sid=' + sid conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute( 'SELECT userID, emailAddress, themeName FROM tUsers WHERE userID="' + currentUser + '"') row = cursor.fetchone() if (row != None): email = row[1] uiTheme = row[2] cursor.close() conn.close() else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' path = [] uid = '' template = 'user.html' userPage = 'root' if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] # get user attributes if len(path) > 0: uid = dbShared.dbInsertSafe(path[0]) if len(path) > 1: userPage = path[1] if userPage == 'inventory': template = 'inventory.html' else: created = dbShared.getUserAttr(uid, 'created') inGameInfo = dbShared.getUserAttr(uid, 'inGameInfo') userPictureName = dbShared.getUserAttr(uid, 'pictureName') defaultAlerts = dbShared.getUserAttr(uid, 'defaultAlertTypes') if defaultAlerts > 0: if defaultAlerts % 2 == 1: siteAlertCheckStr = ' checked="checked"' if defaultAlerts >= 4: mobileAlertCheckStr = ' checked="checked"' if defaultAlerts != 1 and defaultAlerts != 4 and defaultAlerts != 5: emailAlertCheckStr = ' checked="checked"' sharedInventory = dbShared.getUserAttr(uid, 'sharedInventory') sharedRecipes = dbShared.getUserAttr(uid, 'sharedRecipes') donateTotal = dbShared.getUserDonated(uid) userTitle = dbShared.getUserTitle(uid) userStats = dbShared.getUserStats(uid, galaxy).split(',') resScore = int(userStats[0]) mapScore = int(userStats[1]) reputation = int(userStats[2]) if resScore != None: if resScore > 2000: resColor = '#ffcc00' elif resScore > 500: resColor = '#3366ff' elif resScore > 25: resColor = '#009933' if mapScore != None: if mapScore > 400: mapColor = '#ffcc00' elif mapScore > 100: mapColor = '#3366ff' elif mapScore > 5: mapColor = '#009933' if reputation != None: if reputation > 100: repColor = '#ffcc00' elif reputation > 50: repColor = '#3366ff' elif reputation > 10: repColor = '#009933' elif reputation < 0: repColor = '#800000' if userPictureName == '': userPictureName = 'default.jpg' if donateTotal != '': donorBadge = '<img src="/images/coinIcon.png" width="16" title="This user has donated to the site" alt="coin" />' # get friend count conn = dbShared.ghConn() cursor = conn.cursor() cursor.execute( 'SELECT Count(uf1.added) FROM tUserFriends uf1 INNER JOIN tUserFriends uf2 ON uf1.friendID=uf2.userID AND uf1.userID=uf2.friendID WHERE uf1.userID="' + uid + '"') row = cursor.fetchone() if (row != None): friendCountStr = '(' + str(row[0]) + ')' cursor.close() conn.close() # Load list of unlocked abilities for k, v in ghShared.ABILITY_DESCR.iteritems(): if reputation >= ghShared.MIN_REP_VALS[ k] and ghShared.MIN_REP_VALS[k] != -99: a = userAbility(k, v, True) a.minReputation = ghShared.MIN_REP_VALS[k] abilities.append(a) convertGI = ghShared.convertText(inGameInfo, "js") tmpStat = dbShared.friendStatus(uid, currentUser) joinedStr = 'Joined ' + ghShared.timeAgo(created) + ' ago' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template(template) if userPage == 'inventory': print template.render( uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(galaxy), resourceGroupList=ghLists.getResourceGroupList(), resourceTypeList=ghLists.getResourceTypeList(galaxy), uid=uid, editable=(uid == currentUser and logged_state == 1)) else: print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), themeList=ghLists.getThemeList(), uid=uid, convertGI=convertGI, sid=sid, avatarResult=avatarResult, email=email, donorBadge=donorBadge, joinedStr=joinedStr, userPictureName=userPictureName, tmpStat=tmpStat, userTitle=userTitle, friendCountStr=friendCountStr, userAbilities=abilities, resScore=resScore, mapScore=mapScore, reputation=reputation, resColor=resColor, mapColor=mapColor, repColor=repColor, siteAlertCheckStr=siteAlertCheckStr, emailAlertCheckStr=emailAlertCheckStr, mobileAlertCheckStr=mobileAlertCheckStr, sharedInventory=sharedInventory, sharedRecipes=sharedRecipes)
elif (messageAction == 'createuserfail'): theMessage = 'You account could not be created: ' + messageReason elif (messageAction == 'verifysuccess'): theMessage = 'Your account is now verified. Please login above.' elif (messageAction == 'verifymailsuccess'): theMessage = 'Your e-mail address change is now verified. Your user profile should now reflect the change.' elif (messageAction == 'verifyfail'): theMessage = 'Account verification failed: ' + messageReason elif (messageAction == 'addschematicfail'): theMessage = 'Add Schematic Action failed: ' + messageReason else: theMessage = 'Welcome to Galaxy Harvester! Be sure to visit the help section (from the link at the bottom of any page) to get the most out of your time here.' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('message.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), theMessage=theMessage)
def main(): # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() uiTheme = '' # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' # Get recipe id from path path = [] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] recipeHTML = '' slotHTML = '' schemImageName = '' schematicDetailsHTML = '' ingTypes = '' ingGroups = '' pageType = 'recipe' if len(path) > 0: recipeID = dbShared.dbInsertSafe(path[0]) url = url + '/' + recipeID r = ghObjectRecipe.schematicRecipe() if logged_state == 1: # Look up recipe info try: conn = dbShared.ghConn() cursor = conn.cursor() except Exception: recipeHTML = "Error: could not connect to database" if (cursor and recipeID.isdigit()): cursor.execute( 'SELECT recipeID, userID, tRecipe.schematicID, recipeName, (SELECT imageName FROM tSchematicImages si WHERE si.schematicID=tRecipe.schematicID AND si.imageType=1) AS schemImage, schematicName, complexity FROM tRecipe INNER JOIN tSchematic ON tRecipe.schematicID = tSchematic.schematicID WHERE recipeID=' + recipeID + ';') row = cursor.fetchone() if (row != None): if row[1] == currentUser: # main recipe data if (row[4] != None): schemImageName = row[4] else: schemImageName = 'none.jpg' r.recipeID = row[0] r.schematicID = row[2] r.recipeName = row[3] r.schematicImage = schemImageName # schematic quality data schematicDetailsHTML = '<div><a href="' + ghShared.BASE_SCRIPT_URL + 'schematics.py/' + row[ 2] + '" title="Go to schematic page.">' + row[ 5] + '</a></div>' schematicDetailsHTML += '<div>Complexity: ' + str( row[6]) + '</div>' expGroup = '' expProp = '' schematicDetailsHTML += '<td valign="top"><h3>Qualities</h3><ul id="qualitiesList" style="margin-top:6px;">' expCursor = conn.cursor() expCursor.execute( 'SELECT tSchematicQualities.expQualityID, expProperty, expGroup, statName, statWeight, weightTotal FROM tSchematicQualities INNER JOIN tSchematicResWeights ON tSchematicQualities.expQualityID = tSchematicResWeights.expQualityID WHERE schematicID="' + r.schematicID + '" ORDER BY expGroup, expProperty, statName;') expRow = expCursor.fetchone() while (expRow != None): if (expGroup != expRow[2]): tmpName = expRow[2].replace('_', ' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="groupText">' + tmpName + '</li>' expGroup = expRow[2] if (expProp != expRow[1]): tmpName = expRow[1].replace('_', ' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="schemQualityProperty altText">' + tmpName + '</li>' expProp = expRow[1] schematicDetailsHTML += '<li class="schemQualityItem" tag="' + expRow[ 3] + ':' + str( (expRow[4] * 1.0 / expRow[5]) * 100 ) + '"><span class="inlineBlock" style="width:100px;">' + ghNames.getStatName( expRow[3]) + (': </span><span>%.0f' % ( (expRow[4] * 1.0 / expRow[5]) * 100) ) + '%</span></li>' expRow = expCursor.fetchone() expCursor.close() # Look up ingredient data ri = None sqlStr = 'SELECT si.ingredientName, ingredientResource, ingredientObject, ingredientQuantity, ingredientContribution, rt.containerType tcontainer, rg.containerType gcontainer, rt.resourceTypeName, rg.groupName, ingredientQuality FROM tSchematicIngredients si LEFT JOIN (SELECT ingredientName, ingredientResource, ingredientQuality FROM tRecipeIngredients WHERE recipeID=' + str( r.recipeID ) + ') ri ON si.ingredientName = ri.ingredientName LEFT JOIN tResourceType rt ON si.ingredientObject = rt.resourceType LEFT JOIN tResourceGroup rg ON si.ingredientObject = rg.resourceGroup WHERE schematicID="' + r.schematicID + '" ORDER BY ingredientQuantity DESC, si.ingredientName' ingCursor = conn.cursor() ingCursor.execute(sqlStr) ingRow = ingCursor.fetchone() while (ingRow != None): if ingRow[5] == None: if ingRow[6] == None: container = 'default' objectName = ingRow[2].rpartition( '/')[2].replace('_', ' ') if objectName[-4:] == '.iff': objectName = objectName[:-4] else: ingGroups += '"' + ingRow[2] + '",' container = ingRow[6] objectName = ingRow[8] else: ingTypes += '"' + ingRow[2] + '",' container = ingRow[5] objectName = ingRow[7] # get details of ingredient resource for schematic resDetails = '' if ingRow[1] != None and (ingRow[5] != None or ingRow[6] != None): spawn = resource.getResource( conn, logged_state, currentUser, ingRow[1], None, None) resDetails = 'Loaded with: ' + spawn.spawnName + ', ' + spawn.resourceTypeName + '<br />' + spawn.getStatList( ) r.recipeIngredients.append( ghObjectRecipe.recipeIngredient( ingRow[2], ingRow[1], ingRow[0], ingRow[3], container, objectName, ingRow[9], resDetails)) ingRow = ingCursor.fetchone() ingCursor.close() if ingTypes != '': ingTypes = ingTypes[:-1] if ingGroups != '': ingGroups = ingGroups[:-1] slotHTML = r.getIngredientSlots() else: recipeHTML = "That is not your recipe." else: recipeHTML = "The recipe ID given could not be found." cursor.close() else: # Render recipe home if any non number in sub path pageType = 'home' conn.close() else: recipeHTML = "You must be logged in to manage recipes." else: recipeHTML = 'You have not specified a recipe to edit, would you like to create a new one?<div style="float:right;"><button type=button value="New Recipe" class="ghButton" onclick="addRecipe();">New Recipe</button></div>' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('recipe.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), recipeHTML=recipeHTML, slotHTML=slotHTML, schematicDetailsHTML=schematicDetailsHTML, ingTypes=ingTypes, ingGroups=ingGroups, pageType=pageType, recipeID=r.recipeID, recipeName=r.recipeName, schemImageName=schemImageName)
def main(): resHTML = '<h2>That resource does not exist</h2>' resHistory = '' useCookies = 1 linkappend = '' logged_state = 0 currentUser = '' galaxy = '' spawnName = '' spawnID = 0 uiTheme = '' galaxyState = 0 userReputation = 0 # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() # Get Cookies cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' else: loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: if (uiTheme == ''): uiTheme = 'crafter' path = [''] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] if len(path) > 1: galaxy = dbShared.dbInsertSafe(path[0]) spawnName = dbShared.dbInsertSafe(path[1]) if galaxy != '': conn = dbShared.ghConn() spawn = getResource(conn, logged_state, currentUser, None, galaxy, spawnName) if spawn != None: spawnID = spawn.spawnID galaxyState = dbShared.galaxyState(spawn.spawnGalaxy) # Only show update tools if user logged in and has positive reputation stats = dbShared.getUserStats(currentUser, galaxy).split(",") userReputation = int(stats[2]) resHTML = spawn.getHTML(0, "", logged_state > 0 and galaxyState == 1, userReputation) resHistory = getResourceHistory(conn, spawn.spawnID) conn.close() else: resHTML = '<h2>No Galaxy/Resource name given</h2>' else: resHTML = '<h2>No Galaxy/Resource name given</h2>' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('resource.html') print template.render( uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), spawnName=spawnName, resHTML=resHTML, resHistory=resHistory, showAdmin=(userReputation >= ghShared.MIN_REP_VALS['EDIT_RESOURCE_GALAXY_NAME']), spawnID=spawnID, spawnGalaxy=galaxy)
def main(): # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' uiTheme = '' schematicID = '' schemImageAttempt = '' schemHTML = '<h2>That schematic does not exist.</h2>' form = cgi.FieldStorage() # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' try: schemImageAttempt = cookies['schemImageAttempt'].value except KeyError: schemImageAttempt = '' try: galaxy = cookies['galaxy'].value except KeyError: galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') schemImageAttempt = form.getfirst('schemImageAttempt', '') galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' path = [] s = None if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] favHTML = '' if len(path) > 0: schematicID = dbShared.dbInsertSafe(path[0]) url = url + '/' + schematicID if (schematicID != 'index') and (schematicID != 'home'): # Build the schematic object try: conn = dbShared.ghConn() cursor = conn.cursor() except Exception: errorstr = "Error: could not connect to database" if (cursor): cursor.execute( 'SELECT schematicName, complexity, xpAmount, (SELECT imageName FROM tSchematicImages tsi WHERE tsi.schematicID=tSchematic.schematicID AND tsi.imageType=1) AS schemImage FROM tSchematic WHERE schematicID="' + schematicID + '";') row = cursor.fetchone() if (row != None): # main schematic data if (row[3] != None): schemImageName = row[3] else: schemImageName = 'none.jpg' s = ghObjectSchematic.schematic() s.schematicID = schematicID s.schematicName = row[0] s.complexity = row[1] s.xpAmount = row[2] s.schematicImage = schemImageName ingCursor = conn.cursor() ingCursor.execute( 'SELECT ingredientName, ingredientType, ingredientObject, ingredientQuantity, res.resName FROM tSchematicIngredients LEFT JOIN (SELECT resourceGroup AS resID, groupName AS resName FROM tResourceGroup UNION ALL SELECT resourceType, resourceTypeName FROM tResourceType) res ON ingredientObject = res.resID WHERE schematicID="' + schematicID + '" ORDER BY ingredientType, ingredientQuantity DESC;') ingRow = ingCursor.fetchone() while (ingRow != None): tmpName = ingRow[2] tmpName = tmpName.replace('shared_', '') if (ingRow[1] == 0): # resource if (ingRow[4] != None): tmpLink = '</td><td><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + ingRow[ 2] + '">' + ingRow[4] + '</a>' else: tmpLink = '</td><td><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + ingRow[ 2] + '">' + ingRow[2] + '</a>' else: # component tmpLink = getComponentLink(conn, tmpName, ingRow[1]) s.ingredients.append( ghObjectSchematic.schematicIngredient( ingRow[0], ingRow[1], tmpName, ingRow[3], ingRow[4], tmpLink)) ingRow = ingCursor.fetchone() ingCursor.close() # schematic quality data expGroup = '' expProp = '' qg = None qp = None expCursor = conn.cursor() expCursor.execute( 'SELECT tSchematicQualities.expQualityID, expProperty, expGroup, statName, statWeight, weightTotal FROM tSchematicQualities INNER JOIN tSchematicResWeights ON tSchematicQualities.expQualityID = tSchematicResWeights.expQualityID WHERE schematicID="' + schematicID + '" ORDER BY expGroup, expProperty, statName;') expRow = expCursor.fetchone() while (expRow != None): if expRow[1] != expProp: if qp != None: qg.properties.append(qp) qp = None qp = ghObjectSchematic.schematicQualityProperty( expRow[1], expRow[5]) expProp = expRow[1] if expRow[2] != expGroup: if qg != None: s.qualityGroups.append(qg) qg = None qg = ghObjectSchematic.schematicQualityGroup( expRow[2]) expGroup = expRow[2] sw = ghObjectSchematic.schematicStatWeight( expRow[0], expRow[3], expRow[4], expRow[5]) qp.statWeights.append(sw) expRow = expCursor.fetchone() if qp != None: qg.properties.append(qp) if qg != None: s.qualityGroups.append(qg) expCursor.close() # Get list of schematics this one can be used in useCursor = conn.cursor() useCursor.execute( 'SELECT tSchematicIngredients.schematicID, s2.schematicName FROM tSchematicIngredients INNER JOIN tSchematic ON tSchematicIngredients.ingredientObject = tSchematic.objectPath OR tSchematicIngredients.ingredientObject = tSchematic.objectGroup INNER JOIN tSchematic s2 ON tSchematicIngredients.schematicID=s2.schematicID WHERE tSchematic.schematicID = "' + schematicID + '" GROUP BY tSchematicIngredients.schematicID;') useRow = useCursor.fetchone() while (useRow != None): s.schematicsUsedIn.append([useRow[0], useRow[1]]) useRow = useCursor.fetchone() useCursor.close() if logged_state > 0: favCursor = conn.cursor() favSQL = ''.join(( 'SELECT itemID FROM tFavorites WHERE favType=4 AND userID="', currentUser, '" AND favGroup="', schematicID, '" AND galaxy=', galaxy)) favCursor.execute(favSQL) favRow = favCursor.fetchone() if favRow != None: favHTML = ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 4, \'' + schematicID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16On.png" /></a></div>' else: favHTML = ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 4, \'' + schematicID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16Off.png" /></a></div>' favCursor.close() cursor.close() conn.close() pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('schematics.html') print template.render( uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), schematicTabList=ghLists.getSchematicTabList(), objectTypeList=ghLists.getObjectTypeList(), noenergyTypeList=ghLists.getOptionList( 'SELECT resourceType, resourceTypeName FROM tResourceType WHERE resourceCategory != "energy" ORDER BY resourceTypeName;' ), resourceGroupList=ghLists.getResourceGroupList(), schematicID=schematicID, schematic=s, favHTML=favHTML)
def main(): useCookies = 1 linkappend = '' logged_state = 0 currentUser = '' msgHTML = '' galaxy = '' uiTheme = '' galaxyName = '' galaxyState = 0 galaxyCheckedNGE = '' galaxyWebsite = '' galaxyAdminList = [] galaxyPlanetList = [] availablePlanetList = [] galaxyAdmins = [] # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() # Get Cookies cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' else: loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: if (uiTheme == ''): uiTheme = 'crafter' path = [''] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] if len(path) > 0: galaxy = dbShared.dbInsertSafe(path[0]) conn = dbShared.ghConn() galaxyAdminList = dbShared.getGalaxyAdminList(conn, currentUser) availablePlanetList = getPlanetList(conn, galaxy, 1) if galaxy.isdigit(): # get the galaxy details for edit galaxyCursor = conn.cursor() galaxyCursor.execute('SELECT galaxyName, galaxyState, galaxyNGE, website FROM tGalaxy WHERE galaxyID={0};'.format(galaxy)) galaxyRow = galaxyCursor.fetchone() if galaxyRow != None: galaxyName = galaxyRow[0] galaxyState = galaxyRow[1] if galaxyRow[2] > 0: galaxyCheckedNGE = 'checked' galaxyWebsite = galaxyRow[3] galaxyCursor.close() galaxyPlanetList = getPlanetList(conn, galaxy, 0) galaxyAdmins = dbShared.getGalaxyAdmins(conn, galaxy) conn.close() else: galaxyAdmins = [currentUser] msgHTML = '<h2>Please enter galaxy details for review.</h2>' else: msgHTML = '<h2>No Galaxy found in URL path.</h2>' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(os.environ['HTTP_USER_AGENT']) template = env.get_template('galaxy.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, pictureName=pictureName, loginResult=loginResult, linkappend=linkappend, url=url, imgNum=ghShared.imgNum, galaxyID=galaxy, galaxyList=ghLists.getGalaxyList(), msgHTML=msgHTML, galaxyName=galaxyName, galaxyState=galaxyState, galaxyCheckedNGE=galaxyCheckedNGE, galaxyWebsite=galaxyWebsite, galaxyStatusList=ghLists.getGalaxyStatusList(), galaxyPlanetList=galaxyPlanetList, availablePlanetList=availablePlanetList, galaxyAdminList=galaxyAdminList, galaxyAdmins=galaxyAdmins)
def main(): resHTML = '<h2>That resource type does not exist</h2>' resHistory = '' useCookies = 1 linkappend = '' logged_state = 0 currentUser = '' typeGroup = 'type' typeID = '' typeName = '' uiTheme = '' # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() # Get Cookies cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' try: galaxy = cookies['galaxy'].value except KeyError: galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) else: loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY) # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: if (uiTheme == ''): uiTheme = 'crafter' path = [''] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] try: conn = dbShared.ghConn() except Exception: errorstr = "Error: could not connect to database" if path[0] != '': typeID = dbShared.dbInsertSafe(path[0]) cursor = conn.cursor() if (cursor): cursor.execute( 'SELECT resourceTypeName, rg1.groupName, rg2.groupName, rt.containerType, CRmin, CRmax, CDmin, CDmax, DRmin, DRmax, FLmin, FLmax, HRmin, HRmax, MAmin, MAmax, PEmin, PEmax, OQmin, OQmax, SRmin, SRmax, UTmin, UTmax, ERmin, ERmax, rt.resourceCategory, rt.resourceGroup FROM tResourceType rt INNER JOIN tResourceGroup rg1 ON rt.resourceCategory = rg1.resourceGroup INNER JOIN tResourceGroup rg2 ON rt.resourceGroup = rg2.resourceGroup WHERE resourceType="' + typeID + '";') row = cursor.fetchone() if (row != None): typeName = row[0] else: # look up group info if not found as a type typeGroup = 'group' cursor.execute( 'SELECT groupName, (SELECT rg.groupName FROM tResourceGroupCategory rgc INNER JOIN tResourceGroup rg ON rgc.resourceCategory = rg.resourceGroup WHERE rgc.resourceGroup=tResourceGroup.resourceGroup AND rg.groupLevel = tResourceGroup.groupLevel -1) AS resCat, "" AS resourceGroup, Max(tResourceType.containerType) AS contType, Min(CRmin), Max(CRmax), Min(CDmin), Max(CDmax), Min(DRmin), Max(DRmax), Min(FLmin), Max(FLmax), Min(HRmin), Max(HRmax), Min(MAmin), Max(MAmax), Min(PEmin), Max(PEmax), Min(OQmin), Max(OQmax), Min(SRmin), Max(SRmax), Min(UTmin), Max(UTmax), Min(ERmin), Max(ERmax), (SELECT rgc.resourceCategory FROM tResourceGroupCategory rgc INNER JOIN tResourceGroup rg ON rgc.resourceCategory = rg.resourceGroup WHERE rgc.resourceGroup=tResourceGroup.resourceGroup AND rg.groupLevel = tResourceGroup.groupLevel -1) AS catID FROM tResourceGroup, tResourceType WHERE tResourceGroup.resourceGroup="' + typeID + '" AND tResourceType.resourceType IN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup="' + typeID + '" GROUP BY resourceType);') row = cursor.fetchone() if (row != None): typeName = row[0] else: typeGroup = '' favHTML = '' if logged_state > 0: favCursor = conn.cursor() favSQL = ''.join(( 'SELECT itemID FROM tFavorites WHERE favType=2 AND userID="', currentUser, '" AND favGroup="', typeID, '" AND galaxy=', galaxy)) favCursor.execute(favSQL) favRow = favCursor.fetchone() if favRow != None: favHTML = ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 2, \'' + typeID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16On.png" /></a></div>' else: favHTML = ' <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 2, \'' + typeID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16Off.png" /></a></div>' favCursor.close() if typeName != '' and typeName != None: resHTML = '<div style="font-size:16px;font-weight:bold;">' + favHTML + typeName if row != None and row[3] != None: if row[1] != typeName: resHTML += '<div style="float:right;"><img src="/images/resources/' + row[ 3] + '.png" /></div></div>' else: resHTML += '</div>' # breadcrumb to resource type if not top level category if row[1] != typeName: resHTML += '<h3 style="margin-bottom:12px;">' if row[26] != 'resource': resHTML += '<a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + str( row[26]) + '">' + str(row[1]) + '</a>' else: resHTML += row[1] if typeGroup == 'type': resHTML += ' > <a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + row[ 27] + '">' + row[2] + '</a>' resHTML += ' > ' + typeName + '</h3>' # min/max stats table resHTML += '<table class="resAttr resourceStats"><tr>' resHTML += '<td><td class="header"><span>CR</span></td><td class="header"><span>CD</span></td><td class="header"><span>DR</span></td><td class="header"><span>FL</span></td><td class="header"><span>HR</span></td><td class="header"><span>MA</span></td><td class="header"><span>PE</span></td><td class="header"><span>OQ</span></td><td class="header"><span>SR</span></td><td class="header"><span>UT</span></td><td class="header"><span>ER</span></td></tr>' resHTML += '<tr><td class="header">Min</td><td>' + z2b( row[4] ) + '</td><td>' + z2b(row[6]) + '</td><td>' + z2b( row[8] ) + '</td><td>' + z2b(row[10]) + '</td><td>' + z2b( row[12]) + '</td><td>' + z2b( row[14]) + '</td><td>' + z2b( row[16]) + '</td><td>' + z2b( row[18]) + '</td><td>' + z2b( row[20]) + '</td><td>' + z2b( row[22]) + '</td><td>' + z2b( row[24]) + '</td></tr>' resHTML += '<tr><td class="header">Max</td><td>' + z2b( row[5] ) + '</td><td>' + z2b(row[7]) + '</td><td>' + z2b( row[9] ) + '</td><td>' + z2b(row[11]) + '</td><td>' + z2b( row[13]) + '</td><td>' + z2b( row[15]) + '</td><td>' + z2b( row[17]) + '</td><td>' + z2b( row[19]) + '</td><td>' + z2b( row[21]) + '</td><td>' + z2b( row[23]) + '</td><td>' + z2b( row[25]) + '</td></tr>' resHTML += '</table>' else: resHTML += '</div>' cursor.close() else: resHTML = '<h1>Resource Type Groups</h1>' resHTML += '<div id="resTypeInfo">You have reached the resource type page. From here, you can browse to any resource type and view things like: best spawns, schematics, creatures, and min/max stats.</div>' creature = max([ typeID.find('bone_'), typeID.find('hide_'), typeID.find('meat_'), typeID.find('milk_') ]) if typeID == '': # Print the plain group list for pre-IE9 because it does not support rotate css tmpAgent = os.environ.get("HTTP_USER_AGENT", "unknown") if tmpAgent == 'unknown' or (tmpAgent.find("IE") > -1 and tmpAgent.find("MSIE 9.0") == -1): resTree = getResourceGroupsPlain() else: resTree = getResourceTree() else: resTree = '' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') # Get reputation to determine editing abilities stats = dbShared.getUserStats(currentUser, galaxy).split(",") userReputation = int(stats[2]) admin = dbShared.getUserAdmin(conn, currentUser, galaxy) conn.close() print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('resourcetype.html') print template.render( uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), typeGroup=typeGroup, typeID=typeID, resHTML=resHTML, creature=creature, resTree=resTree, editCreatures=(userReputation >= ghShared.MIN_REP_VALS['ADD_CREATURE'] or admin), resourceType=typeID)
def main(): # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' uiTheme = '' form = cgi.FieldStorage() # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') vid = form.getfirst('v', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('help.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), vid=vid)
if '@eyepaste.com' in email: errorstr = errorstr + "Error: disposable emails not allowed.\n" # CAPTCHAv3 validation https://developers.google.com/recaptcha/docs/v3 if ghShared.RECAPTCHA_ENABLED: if tokenCAPTCHA: scoreCAPTCHA = getCAPTCHA(tokenCAPTCHA) if scoreCAPTCHA == -1: errorstr = errorstr + "Error: CAPTCHA problem, please contact support." elif not scoreCAPTCHA > 0.5: sys.stderr.write( "Registration failure due to low CAPTCHA score {0}".format( str(scoreCAPTCHA))) errorstr = errorstr + "Error: Robot detected\n" else: if 'HTTP_USER_AGENT' in os.environ and ghShared.getMobilePlatform( os.environ["HTTP_USER_AGENT"]) != '': errorstr = errorstr + "Error: Sorry, mobile joining is temporarily unavailable. Please visit Galaxy Harvester from a web browser to join. https://galaxyharvester.net" else: errorstr = errorstr + "Error: No CAPTCHA token found\n" if errorstr != "": result = "createuserfail" else: # For passing in to message for on success errorstr = email # Prepare encrypted password and verification code crypt_pass = hashlib.sha1(dbInfo.DB_KEY3 + userpass).hexdigest() verify_code = uuid.uuid4().hex conn = dbShared.ghConn() # Do not allow duplicate email