Exemplo n.º 1
0
		linkappend = 'gh_sid=' + sid

joinStr = ""
criteriaStr = ""
galaxyCriteriaStr = ""
orderCol = "spawnID"
orderStr = " ORDER BY " + orderCol + " DESC"
groupType = 1
galaxyState = 0
errorStr = ""
percVals = percVals.replace("%","")

if galaxy == "":
	errorStr = "Error: No Galaxy Specified"
else:
	galaxyState = dbShared.galaxyState(galaxy)

if (resGroup != "any" and resGroup != ""):
	joinStr = joinStr + " INNER JOIN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup='" + resGroup + "' GROUP BY resourceType) rtgg ON rt1.resourceType = rtgg.resourceType"
if (resCategory != "any" and resCategory != ""):
	joinStr = joinStr + " INNER JOIN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup='" + resCategory + "' GROUP BY resourceType) rtgc ON rt1.resourceType = rtgc.resourceType"

criteriaStr = "tResources.galaxy=" + galaxy

if (planet == "" and planetName != ""):
	planet = dbShared.getPlanetID(planetName)
if (planet != "any" and planet != ""):
	joinStr = joinStr + " INNER JOIN tResourcePlanet ON tResources.spawnID = tResourcePlanet.spawnID"
	criteriaStr += " AND planetID=" + planet

if (resType != "any" and resType != ""):
Exemplo n.º 2
0
def main():
	resHTML = '<h2>That resource does not exist</h2>'
	resHistory = ''
	useCookies = 1
	linkappend = ''
	logged_state = 0
	currentUser = ''
	galaxy = ''
	spawnName = ''
	uiTheme = ''
	galaxyState = 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)
			galaxyState = dbShared.galaxyState(spawn.spawnGalaxy)
			if galaxyState == 1:
				resHTML = spawn.getHTML(logged_state, 0, "")
			else:
				resHTML = spawn.getHTML(0, 0, "")

			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
	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(), planetList=ghLists.getPlanetList(), spawnName=spawnName, resHTML=resHTML, resHistory=resHistory)
Exemplo n.º 3
0
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)
if (sess != ''):
    logged_state = 1
    currentUser = sess

# Main program

print 'Content-type: text/html\n'
if (logged_state > 0):
    try:
        conn = dbShared.ghConn()
        cursor = conn.cursor()
    except Exception:
        result = "Error: could not connect to database"

    if (cursor):
        if (dbShared.galaxyState(galaxy) == 1):
            markAll = 0
            cursor.execute(
                'SELECT spawnID, resourceType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, unavailable, enteredBy FROM tResources WHERE galaxy='
                + galaxy + ' AND spawnName="' + spawnName + '";')
            row = cursor.fetchone()

            if (row != None):
                spawnID = str(row[0])

            if (planets == "all"):
                markAll = 1
                sqlStr = "UPDATE tResourcePlanet SET unavailable=NOW(), unavailableBy='" + currentUser + "' WHERE spawnID=" + spawnID + ";"
            else:
                # try to look up planet by name if an ID was not provided
                if (planets.isdigit() != True):
Exemplo n.º 5
0
		linkappend = 'gh_sid=' + sid

joinStr = ""
criteriaStr = "unavailable IS NULL"
unPlanetStr = ",'all'"
orderStr = ""
groupType = 1
formatStyle = 0
resBoxMargin = "4px"
galaxyState = 0
errorStr = ""

if galaxy == "":
	errorStr = "No Galaxy Specified"
else:
	galaxyState = dbShared.galaxyState(galaxy)

if (resGroup != "any" and resGroup != ""):
	joinStr = joinStr + " INNER JOIN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup='" + resGroup + "' GROUP BY resourceType) rtgg ON rt1.resourceType = rtgg.resourceType"
if (resCategory != "any" and resCategory != ""):
	joinStr = joinStr + " INNER JOIN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup='" + resCategory + "' GROUP BY resourceType) rtgc ON rt1.resourceType = rtgc.resourceType"

if (unavailableDays != None and unavailableDays.isdigit()):
	if (unavailableDays == "0"):
		criteriaStr = "galaxy=" + galaxy + " AND unavailable IS NULL"
	else:
		if (resType != "any" and resType != "") or (resGroup != "any" and resGroup != ""):
			criteriaStr = "galaxy=" + galaxy + " AND (unavailable IS NULL OR DATEDIFF(NOW(),unavailable) <= " + unavailableDays + ")"
		else:
			errorStr = "You must select a resource type or group when searching for unavailable resources."
else:
Exemplo n.º 6
0
def main():
    # Get current url
    try:
        url = os.environ['SCRIPT_NAME']
    except KeyError:
        url = ''

    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', '')
    else:
        currentUser = ''
        sid = form.getfirst('gh_sid', '')

    spawnName = form.getfirst('spawn', '')
    galaxy = form.getfirst('galaxy', '')
    planets = form.getfirst('planets', '')
    # escape input to prevent sql injection
    sid = dbShared.dbInsertSafe(sid)
    spawnName = dbShared.dbInsertSafe(spawnName)
    galaxy = dbShared.dbInsertSafe(galaxy)
    planets = dbShared.dbInsertSafe(planets)

    # Get a session
    logged_state = 0

    sess = dbSession.getSession(sid)
    if (sess != ''):
        logged_state = 1
        currentUser = sess

    # Main program
    print 'Content-type: text/html\n'
    if (logged_state > 0):
        if (dbShared.galaxyState(galaxy) == 1):
            spawnID = dbShared.getSpawnID(spawnName, galaxy)
            result = removeSpawn(spawnID, planets, currentUser, galaxy)
        else:
            result = "Error: That Galaxy is Inactive."

    else:
        result = "Error: You must be logged in to mark a resource unavailable."

    print result
    if (result.find("Error:") > -1):
        sys.exit(500)
    else:
        sys.exit(200)
Exemplo n.º 7
0
def main():
	# Get current url
	try:
		url = os.environ['SCRIPT_NAME']
	except KeyError:
		url = ''

	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', '')
	else:
		currentUser = ''
		loginResult = 'success'
		sid = form.getfirst('gh_sid', '')

	numRows = form.getfirst("numRows", "")
	# Get form info
	galaxy = form.getfirst("galaxy", "")
	planet = form.getfirst("planet", "")
	spawnID = form.getfirst("resID", "")
	spawnName = form.getfirst("resName", "")
	resType = form.getfirst("resType", "")
	forceOp = form.getfirst("forceOp", "")
	sourceRow = form.getfirst("sourceRow", "")
	CR = form.getfirst("CR", "")
	CD = form.getfirst("CD", "")
	DR = form.getfirst("DR", "")
	FL = form.getfirst("FL", "")
	HR = form.getfirst("HR", "")
	MA = form.getfirst("MA", "")
	PE = form.getfirst("PE", "")
	OQ = form.getfirst("OQ", "")
	SR = form.getfirst("SR", "")
	UT = form.getfirst("UT", "")
	ER = form.getfirst("ER", "")
	# escape input to prevent sql injection
	sid = dbShared.dbInsertSafe(sid)
	numRows = dbShared.dbInsertSafe(numRows)
	galaxy = dbShared.dbInsertSafe(galaxy)
	planet = dbShared.dbInsertSafe(planet)
	spawnID = dbShared.dbInsertSafe(spawnID)
	spawnName = dbShared.dbInsertSafe(spawnName)
	resType = dbShared.dbInsertSafe(resType)
	forceOp = dbShared.dbInsertSafe(forceOp)
	sourceRow = dbShared.dbInsertSafe(sourceRow)
	CR = dbShared.dbInsertSafe(CR)
	CD = dbShared.dbInsertSafe(CD)
	DR = dbShared.dbInsertSafe(DR)
	FL = dbShared.dbInsertSafe(FL)
	HR = dbShared.dbInsertSafe(HR)
	MA = dbShared.dbInsertSafe(MA)
	PE = dbShared.dbInsertSafe(PE)
	OQ = dbShared.dbInsertSafe(OQ)
	SR = dbShared.dbInsertSafe(SR)
	UT = dbShared.dbInsertSafe(UT)
	ER = dbShared.dbInsertSafe(ER)

	spawnName = spawnName.lower()

	# Get a session
	logged_state = 0

	sess = dbSession.getSession(sid)
	if (sess != ''):
		logged_state = 1
		currentUser = sess

	#  Check for errors
	errstr = ""
	if (len(spawnName) < 1 and spawnID == ""):
		errstr = errstr + "Error: no resource name. \r\n"
	if ((resType == "none" or len(resType) < 1) and spawnID == "" and forceOp != "verify"):
		errstr = errstr + "Error: no resource type. \r\n"
	else:
		#  Some automated updaters post reptillian meat as 'reptilian', normalize
		resType = resType.replace("reptilian", "reptillian")

	if spawnID == "":
		if galaxy == "":
			errstr = errstr + "Error: no galaxy selected. \r\n"
		else:
			# try to look up spawnID for editing and verifying
			spawnID = dbShared.getSpawnID(spawnName, galaxy)

	if re.search('\W', spawnName):
		errstr = errstr + "Error: spawn name contains illegal characters."
	if (forceOp != "edit" and planet.isdigit() == False):
		# attempt to lookup planet by name
		if planet != "":
			planet = dbShared.getPlanetID(planet)
		if planet.isdigit() == False:
			errstr = errstr + "Error: planet must be provided to post resource unless editing."

	postBlockedSeconds = dbShared.getUserPostBlockedSecondsRemaining(currentUser, 'r')
	if dbShared.getUserPostBlockedSecondsRemaining(currentUser, 'r') > 0:
		errstr = errstr + "Error: You are currently blocked from adding or updating resources due to recent activity.  Your cooldown ends in less than " + str((postBlockedSeconds / 3600) + 1) + " hours."

	if (errstr == ""):
		result = ""
		galaxyState = dbShared.galaxyState(galaxy)
		if (logged_state > 0 and galaxyState == 1):
			if (spawnName == "" or spawnName == None):
				spawnName = ghNames.getSpawnName(spawnID)

			if (spawnID>-1):
				# spawn already entered
				if (forceOp == "edit"):
					result = "edit: "
					result = result + addResStats(spawnID, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, forceOp, currentUser, galaxy)
				else:
					result = addResPlanet(spawnID, planet, spawnName, currentUser, galaxy)
					result = result + '  ' + addResStats(spawnID, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, forceOp, currentUser, galaxy)
			else:
				# new spawn
				result = addResource(spawnName, galaxy, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, currentUser)
				spawnID = dbShared.getSpawnID(spawnName, galaxy)
				result = addResPlanet(spawnID, planet, spawnName, currentUser, galaxy) + '  ' + result

		else:
			if logged_state > 0:
				result = "Error: You cannot add resource data for an Inactive Galaxy."
			else:
				result = "Error: must be logged in to add resources"
	else:
		result = errstr

	print 'Content-type: text/xml\n'
	doc = minidom.Document()
	eRoot = doc.createElement("result")
	doc.appendChild(eRoot)

	eName = doc.createElement("spawnName")
	tName = doc.createTextNode(spawnName)
	eName.appendChild(tName)
	eRoot.appendChild(eName)
	eText = doc.createElement("resultText")
	tText = doc.createTextNode(result)
	eText.appendChild(tText)
	eRoot.appendChild(eText)
	eSource = doc.createElement("sourceRow")
	tSource = doc.createTextNode(sourceRow)
	eSource.appendChild(tSource)
	eRoot.appendChild(eSource)
	print doc.toxml()

	if (result.find("Error:") > -1):
		sys.exit(500)
	else:
		sys.exit(200)
Exemplo n.º 8
0
	logged_state = 1
	currentUser = sess


# Main program

print 'Content-type: text/html\n'
if (logged_state > 0):
	try:
		conn = dbShared.ghConn()
		cursor = conn.cursor()
	except Exception:
		result = "Error: could not connect to database"

	if (cursor):
		if (dbShared.galaxyState(galaxy) == 1):
			markAll = 0
			cursor.execute('SELECT spawnID, resourceType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER FROM tResources WHERE galaxy=' + galaxy + ' AND spawnName="' + spawnName + '";')
			row = cursor.fetchone()

			if (row != None):
				spawnID = str(row[0])
		
			if (planets == "all"):
				markAll = 1
				sqlStr = "UPDATE tResourcePlanet SET unavailable=NOW(), unavailableBy='" + currentUser + "' WHERE spawnID=" + spawnID + ";"
			else:
				# try to look up planet by name if an ID was not provided
				if (planets.isdigit() != True):
					planets = dbShared.getPlanetID(planets)
				sqlStr = "UPDATE tResourcePlanet SET unavailable=NOW(), unavailableBy='" + currentUser + "' WHERE spawnID=" + spawnID + " AND planetID=" + planets + ";"