def execute_sql_from_file(db, filename, commit_after, leave_cursor_open): status, populate_tables = file_io.readFromFile(filename) for index in xrange(0, len(populate_tables)): populate_tables[index] = string.strip(populate_tables[index]) if populate_tables[index] == '': del populate_tables[index] result = execute_sql_item_list(db, populate_tables, 1, 1, commit_after, leave_cursor_open) if result["status"] != 'success': return { 'status': 'error', 'message': "Failed to execute all SQL statements in file", 'result': None } return { 'status': 'success', 'message': "All SQL statements in file executed correctly", 'result': None }
def create_declarations(self): status, declaration_template_lines = file_io.readFromFile(self.application_name + '.template') line_index = 0 for line in declaration_template_lines: field = string.split(line) if len(field) < 3: line_index = line_index + 1 continue if field[0][:len('tec_info')] == "tec_info": if field[1] == '=': if field[2] == "'{{{TEC_DB_NAME}}}'": declaration_template_lines[line_index] = field[0] + ' ' + field[1] + " '" + self.db_name + "'" line_index = line_index + 1 status, output = file_io.writeToFile('declarations.py', declaration_template_lines) if status != 'success': print output sys.exit(1)
def getDetails(file=None): details = {'name': '', 'date': '', 'version': '', 'description': ''} if file == None: return details path, filename = os.path.split(file) filename, ext = os.path.splitext(filename) # if the filename has more than 1 period in it replace them with _ if string.count(filename, ".") > 1: filename = string.replace(filename, ".", "_") file = path + '/' + filename + ext status, lines = file_io.readFromFile(file) if status != 'success': print "Can't read file" sys.exit() descIdx = 0 descEnd = 0 i = 0 oldversion = 0 for line in lines: word = string.split(line) if len(word) == 0: continue else: end_index = len(word) - 1 if string.find(word[0], 'Data') != -1: details['name'] = string.join(word[3:end_index]) elif string.find(word[0], 'Version') != -1: details['version'] = string.join(word[1:end_index]) elif string.find(word[0], 'Date') != -1: if word[2] == '[': oldversion = 1 continue details['date'] = string.join(word[2:end_index]) #details['date'] = string.split(details['date'],'@')[0] elif string.find(word[0], 'Description') != -1: descIdx = i + oldversion elif (oldversion == 0) and (string.upper(word[0][:7]) == '</TABLE'): descEnd = i + oldversion elif (oldversion == 1) and (string.upper(word[0][:6]) == '</BODY'): descEnd = i + oldversion i = i + 1 details['description'] = string.join(lines[descIdx:descEnd]) if oldversion == 0: details['description'] = string.split(details['description'], '<TD>')[2] details['description'] = string.split(details['description'], '<BR>')[0] else: details['description'] = string.split(details['description'], '<BR>')[1] return details
def getDetailsFromFile(file=None, original=None): details = {'name': '', 'date': '', 'version': '', 'description': ''} if file == None: return details status, lines = file_io.readFromFile(file) oldversion = 0 descIdx = 0 descEnd = 0 i = 0 for line in lines: word = string.split(line) if len(word) == 0: continue else: end_index = len(word) - 1 if string.find(word[0], 'Data') != -1: details['name'] = string.join(word[3:end_index]) elif string.find(word[0], 'Version') != -1: details['version'] = string.join(word[1:end_index]) elif string.find(word[0], 'Date') != -1: if word[2] == '[': oldversion = 1 dir, filename = os.path.split(file) mod = os.stat(dir + '/' + original)[stat.ST_MTIME] details['date'] = time.strftime('%m/%d/%y', time.localtime(mod)) continue details['date'] = string.join(word[2:end_index]) elif string.find(word[0], 'Description') != -1: descIdx = i + oldversion elif (oldversion == 0) and (string.upper(word[0][:7]) == '</TABLE'): descEnd = i + oldversion elif (oldversion == 1) and (string.upper(word[0][:6]) == '</BODY'): descEnd = i + oldversion i = i + 1 details['description'] = string.join(lines[descIdx:descEnd]) if oldversion == 0: details['description'] = string.split(details['description'], '<TD>')[2] details['description'] = string.split(details['description'], '<BR>')[0] else: details['description'] = string.split(details['description'], '<BR>')[1] return details
def create_declarations(self): status, declaration_template_lines = file_io.readFromFile( '%s.template' % (self.db_name)) line_index = 0 for line in declaration_template_lines: field = string.split(line) if len(field) < 3: line_index = line_index + 1 continue if field[0][:8] == "pmt_info": if field[1] == '=': if field[2] == "'{{{DB_NAME}}}'": declaration_template_lines[line_index] = field[ 0] + ' ' + field[1] + " '" + self.db_name + "'" elif field[2] == "'{{{DOMAIN_NAME}}}'": declaration_template_lines[line_index] = field[ 0] + ' ' + field[1] + " '" + self.domain_name + "'" elif field[2] == "'{{{BROWSER_USERNAME}}}'": declaration_template_lines[ line_index] = field[0] + ' ' + field[ 1] + " '" + self.visitor_username + "'" elif field[2] == "'{{{BROWSER_PASSWORD}}}'": declaration_template_lines[ line_index] = field[0] + ' ' + field[ 1] + " '" + self.visitor_password + "'" elif field[2] == "'{{{HELP_URL}}}'": declaration_template_lines[line_index] = field[ 0] + ' ' + field[1] + " '" + self.help_url + "'" line_index = line_index + 1 status, output = file_io.writeToFile('declarations.py', declaration_template_lines)
def username_in_passwd(passwd_filename, username): status, lines = file_io.readFromFile(passwd_filename) username_found = 0 for line_index in xrange(0, len(lines)): line_field = string.splitfields(lines[line_index], ':') if username == line_field[0]: username_found = 1 break if username_found: return 1 else: return 0
def password_valid(passwd_filename, crypt_salt, username, password): # salt can be at max 2 chars. crypt_salt = crypt_salt[:2] status, lines = file_io.readFromFile(passwd_filename) if status[:5] == 'error': return ('error', 0) for line_index in xrange(0, len(lines)): line_field = string.splitfields(lines[line_index],':') if (username == line_field[0]) and (crypt.crypt(password, crypt_salt) == line_field[1]): return ('success', 1) # username/password not found return ('success', 0)
def delete_pwd_entry(passwd_filename, username): status, lines = file_io.readFromFile(passwd_filename) username_found = 0 for line_index in xrange(0, len(lines)): line_field = string.splitfields(lines[line_index], ':') if username == line_field[0]: del lines[line_index] username_found = 1 break if username_found: status, output = file_io.writeToFile(passwd_filename, lines) return ('success', 'username deleted') else: return ('error', 'username not found')
def insert_from_file(db, table_data, table_name, filename, delimiter=',', echo_statement=0, commit_after=1, leave_cursor_open=1): status, lines = file_io.readFromFile(filename) sorted_columns = sort_table_columns(table_data, table_name) for line_index in xrange(0, len(lines)): line_field = string.splitfields(lines[line_index], delimiter) if len(line_field) != len(sorted_columns): return { 'status': 'error', 'message': "Not enough fields specified on line %d" % (line_index + 1), 'result': None } field_index = 0 for field_name in sorted_columns: table_data[table_name][field_name]['value'] = line_field[ field_index] field_index = field_index + 1 result = insert_into_table(db, table_data, table_name, echo_statement, commit_after, leave_cursor_open) if result['status'] != 'success': break return result
def add_pwd_entry(passwd_filename, crypt_salt, username, password): # salt can be at max 2 chars. crypt_salt = crypt_salt[:2] status, lines = file_io.readFromFile(passwd_filename) # if files does not exist if status == 'error': del lines lines = [] if lines != []: if username_in_passwd(passwd_filename, username): return ('error', 'username already in passwd file, can not add') # add new pw entry to lines lines.append(username + ':' + crypt.crypt(password, crypt_salt)) status, output = file_io.writeToFile(passwd_filename, lines) return (status, 'username added')
def modify_password(passwd_filename, crypt_salt, username, password): # salt can be at max 2 chars. crypt_salt = crypt_salt[:2] status, lines = file_io.readFromFile(passwd_filename) if status == 'error': return ('error', 0) for line_index in xrange(0, len(lines)): line_field = string.splitfields(lines[line_index], ':') if (username == line_field[0]): lines[line_index] = line_field[0] + ':' + crypt.crypt( password, crypt_salt) break status, output = file_io.writeToFile(passwd_filename, lines) # username/password not found return ('success', 0)
def doUpload(req, form, username, password, db_name): verifyUserPass(req, form, username, password, db_name) html_msg = '' if form.has_key('archive'): # check for filesize is within allowable range archive_size = len(form['archive'].value) if archive_size == 0: msg = "Suspicious import file size of 0. Import aborted." html_msg = html_msg + msg + "<BR>" upload_results(req, html_msg) sys.exit() archive_name = form['archive'].filename archive_name = string.strip(archive_name) # strip off leading \\,/,: if string.rfind(archive_name, "\\") >= 0: archive_name = archive_name[string.rfind(archive_name, "\\") + 1:] if string.rfind(archive_name, "/") >= 0: archive_name = archive_name[string.rfind(archive_name, "/") + 1:] if string.rfind(archive_name, ":") >= 0: archive_name = archive_name[string.rfind(archive_name, ":") + 1:] full_path = '/home/phoenix/importer/' full_path_name = full_path + archive_name # write the archive to the website try: archive_file = open(full_path_name, "wb") except IOError, exception_details: html_msg = "No permissions to import file to the website %s. " % db_name html_msg = html_msg + "Import aborted.<BR>" html_msg = html_msg + 'File: ' + full_path_name upload_results(req, html_msg) sys.exit() archive_file.write(form['archive'].value) archive_file.close() fileSize = os.stat(full_path_name)[6] html_msg = html_msg + '<b>Import Filename: </b>' html_msg = html_msg + '%s<BR>' % (archive_name) html_msg = html_msg + '<b>File Size (bytes): </b>' html_msg = html_msg + '%s<BR>' % (fileSize) # item table presets thresholdreorder = 0 frequencycount = 0 maxcount = 0 daysofuse = 0.0 # lot table presets # lotpk=nextkey # itemfk = itemkey inserted before the lot # lotqty # lotqty = next key # lotpkfk = refers to lot table lotpk debugReq = req dbResult = connectDB(username, password, db_name) # could not connect to db if dbResult['status'] != 'success': sys.exit(1) db = dbResult['result'] no_errors = 1 itemsInserted = 0 linesProcessed = 0 html_msg = html_msg + "<b>Alerts:</B><br>" status, lines = file_io.readFromFile(full_path_name) if status == 'success': for i in xrange(0, len(lines)): if string.strip(lines[i]) == '': continue debug('curline = :%s:' % (lines[i])) fields = string.split(lines[i], '|') for j in xrange(0, len(fields)): fields[j] = sqlFieldFormat(fields[j]) debug('fields[%d] = :%s:' % (j, fields[j])) try: item_national_product = fields[3] item_description = fields[4] lot_manufacturer = fields[2] lot_expirationdate = fields[10] lot_num = fields[9] lotqty_qtyonhand = fields[5] unittext = fields[6] except: no_errors = 0 html_msg = html_msg + 'Error invalid importer file format.<BR>' os.remove(full_path_name) break result = executeSQL(db, "BEGIN") result = insertItem(db, item_national_product, item_description, thresholdreorder, frequencycount, maxcount, daysofuse, unittext) if result['status'] == 'success': result = insertLot(db, result['itempk'], result['itempksk'], lot_manufacturer, lot_expirationdate, lot_num) if result['status'] == 'success': result = insertLotQty(db, result['lotpk'], result['lotpksk'], lotqty_qtyonhand) if result['status'] == 'success': result = executeSQL(db, "COMMIT") itemsInserted += 1 else: result = executeSQL(db, "ROLLBACK") no_errors = 0 html_msg = html_msg + 'Error inserting lot quantity table from data on line %d of import file.<BR>' % ( i) else: result = executeSQL(db, "ROLLBACK") no_errors = 0 html_msg = html_msg + 'Error inserting lot table from data on line %d of import file.<BR>' % ( i) else: result = executeSQL(db, "ROLLBACK") no_errors = 0 html_msg = html_msg + 'Error inserting item table from data on line %d of import file.<BR>' % ( i) linesProcessed += 1 html_msg = html_msg + '%d lines processed, %d items have been successfully imported.<BR>' % ( linesProcessed, itemsInserted) if no_errors: pass else: html_msg = html_msg + 'The import file could not be imported in its entirety.<BR>' else: html_msg = html_msg + "Can not read import file %s<br>" % ( archive_name)
def display_form(form): module_name = '' release = '' if form.has_key('module_name'): module_name = form['module_name'].value if form.has_key('release'): release = form['release'].value if form.has_key('encapsulation_type'): encapsulation_type = form['encapsulation_type'].value print '<html><head><title>Web CVS Export</title></head>' print '<body bgcolor="#B7BAB7" TEXT="#000000"><FONT SIZE="2" COLOR=BLUE><B>Web CVS Export</B></FONT>' exportable_modules = [] status, module_lines = file_io.readFromFile(cvsroot + '/CVSROOT/modules') if status != 'success': print 'ERROR: Module data can not be found contact <A HREF="mailto:[email protected]">CM</A> for more information' print '</body></html>' sys.exit(1) for i in xrange(0, len(module_lines)): fields = string.split(string.strip(module_lines[i])) if fields != []: if fields[0] != '#': exportable_modules.append(fields[0]) exportable_modules.sort() print '<form action="/rwebexport-cgi-bin/rweb_cvs_export.cgi" method="POST" enctype="application/x-www-form-urlencoded">' print '<FONT SIZE=2 COLOR=BLACK><B>Proprietary Software Download Site</B><BR><BR>' print '<FONT SIZE=2 COLOR=RED>NOTE:</FONT><BR><B>' print ' Some of the CVS modules that you download from this site are ISR proprietary<BR>' print ' You must be authorized to download these CVS modules. Once any module(s)<BR>' print ' have been downloaded from this site they must not be released to any other<BR>' print ' party other than NASA DFRC personnel who have been approved for access to <BR>' print ' these modules. <BR><BR> ' print ' Some of the module(s) on this site have been provided by other parties for<BR>' print ' These modules may have their set of copyrights or access restrictions.<BR>' print ' It is the responsibility of the party who downloads such modules to recognize<BR>' print ' any copyrights or access restrictions associated with these module(s).</B><BR><BR>' print '<FONT SIZE=2 COLOR=RED><B>Instructions:</B></FONT><BR><BR>' print 'Enter the following information to retrieve the module for download.<BR>' print 'The module name is the module name found in the CVS repository.<BR>' print 'The release name is the release of the module or enter "now" to retrieve the latest version.<BR>' print 'The encapsulation type is Tar. If you select Tar the encapsulation will be a tar file that is gzipped.<BR><BR>' print '<B>NOTE:</B> WinZip 8.0 can extract tar gzipped files as well.<BR><BR>' print 'Contact <A HREF="mailto:[email protected]">CM</A> for more information.' print '<TABLE BORDER=0>' print '<TR><TD><B>Module Name</B>:</TD><TD>' optionMenu('module_name', '1', exportable_modules, select_list(exportable_modules, '')) print '</TD></TR>' print '<TR><TD><B>Release:</B></TD><TD><input name="release" type="text" size="48" maxlength="48" value="%s"></TD></TR>' % ( release) print '<TR><TD><B>Encapsulation Type:</b></TD><TD>' optionMenu('encapsulation_type', '1', encapsulation_types, select_list(encapsulation_types, 'zip')) print '</TD></TR>' print """</TABLE> <HR> <input name="submit" type="submit" value="Export">""" print """</form>
def pmt_utils_web(self): project_name = self.db_name status, dist_list = file_io.readFromFile( os.path.expandvars(os.path.join('${PWD}', self.db_name + '.files'))) if not os.path.exists(os.path.join('/home', project_name)): os.mkdir(os.path.join('/home', project_name)) if not os.path.exists(os.path.join('/home', project_name, 'html')): os.mkdir(os.path.join('/home', project_name, 'html')) if not os.path.exists(os.path.join('/home', project_name, 'cgi-bin')): os.mkdir(os.path.join('/home', project_name, 'cgi-bin')) if not os.path.exists(os.path.join('/home', project_name, 'images')): os.mkdir(os.path.join('/home', project_name, 'images')) if not os.path.exists(os.path.join('/home', project_name, 'admin')): os.mkdir(os.path.join('/home', project_name, 'admin')) if os.path.exists(os.path.join('.', 'staging')): os_utils.super_remove(os.path.join('.', 'staging')) os.mkdir(os.path.join('.', 'staging')) for curfile in dist_list: shutil.copy(curfile, os.path.join('.', 'staging')) os.chdir(os.path.join('.', 'staging')) compileall.compile_dir('.', 0, None, 0) os.chdir(os.path.join('..')) for curfile in glob.glob(os.path.join('.', 'staging', '*.pyc')): shutil.copy(curfile, os.path.join('/home', project_name, 'cgi-bin')) shutil.copy(os.path.join('images', 'imageMissing.gif'), os.path.join('/home', project_name, 'images')) os_utils.set_file_mode(filename=os.path.join('/home', project_name), user=['r', 'w', 'x']) os_utils.set_file_mode(filename=os.path.join('/home', project_name, 'html'), user=['r', 'w', 'x']) for curfile in glob.glob( os.path.join('/home', project_name, 'html', '*')): os_utils.set_file_mode(filename=curfile, user=['r', 'w']) os_utils.set_file_mode(filename=os.path.join('/home', project_name, 'cgi-bin'), user=['r', 'w', 'x']) for curfile in glob.glob( os.path.join('/home', project_name, 'cgi-bin', '*')): os_utils.set_file_mode(filename=curfile, user=['r', 'w', 'x']) os_utils.set_file_mode(filename=os.path.join('/home', project_name, 'images'), user=['r', 'w', 'x']) for curfile in glob.glob( os.path.join('/home', project_name, 'images', '*')): os_utils.set_file_mode(filename=curfile, user=['r', 'w']) os_utils.set_file_mode(filename=os.path.join('/home', project_name, 'admin'), user=['r', 'w', 'x']) for curfile in glob.glob( os.path.join('/home', project_name, 'admin', '*')): os_utils.set_file_mode(filename=curfile, user=['r', 'w']) status, output = os_utils.super_chown(directory_name=os.path.join( '/home', project_name), username='******', groupname='nobody') if status != 'success': print 'Ownership settings of directory tree %s failed.' % ( os.path.join('/home', project_name))
def writeTable( form, username, edit_priv, # edit data item details del_priv, # delete data items (and folders) up_priv, # upload data items private_priv, # view private data items admin_priv): # change permissions and add folders if form.has_key('directory'): if form['directory'].value != '/': if string.find(form['directory'].value, '..') >= 0: sys.exit() dir_name = form['directory'].value + '/' else: dir_name = '/' else: dir_name = '/' if dir_name[0] != '/': dir_name = '/' + dir_name setupTable(dir_name, form) # List each file and info files = os.listdir("/home/%s/documents%s" % (db_name, dir_name)) files.sort() for filename in files: if dir_name != '': full_path_name = dir_name + filename else: full_path_name = filename serverpath = '/home/%s/documents/%s' % (db_name, full_path_name) if not os.path.exists(serverpath): continue if filename == 'b00kmarkz' or filename == 'b00kmarkz.backup': continue base, ext = os.path.splitext(full_path_name) # skip html details files if ext == '.html': status, lines = file_io.readFromFile(serverpath) if status != 'success': continue word = string.split(lines[0]) if len(word) > 4: # skip over processing data item details html file if word[0] == '<HTML><HEAD><TITLE>Data' and \ word[1] == 'Item' and \ word[2] == 'Details' and word[3] == 'for:': continue html_filename = full_path_name if string.count(filename, ".") > 1: # replace multiple periods with underscores html_filename = string.replace(filename, ".", "_") html_filename = dir_name + html_filename details = getDetails(form, html_filename, filename, edit_priv) if filename == "private": if private_priv: displayDataItem(form, username, details, serverpath, full_path_name, filename, del_priv, admin_priv) else: displayDataItem(form, username, details, serverpath, full_path_name, filename, del_priv, admin_priv) display_links(username, dir_name, edit_priv, del_priv) print '</TABLE>' print '<hr>' print "<TABLE><TR>" if admin_priv: print '<TD><CENTER><FONT SIZE="-1">' print '<FORM method=post action=/%s-cgi-bin/add.pyc>' % db_name url = '/%s-cgi-bin/add.pyc?location=%s' % (db_name, dir_name) java = "return popup('%s','Add_Folder',500,300)" % url #print '<INPUT TYPE=hidden name=location value="%s">' % (dir_name) print '<INPUT TYPE=button name=addlink value="Add Folder" ' print 'onClick="%s">' % java print '</form></CENTER></TD>' if db_name != 'usafsr': print '<TD><CENTER><FONT SIZE="-1">' print '<FORM method=post action=/%s-cgi-bin/addlink.pyc>' % db_name url = '/%s-cgi-bin/addlink.pyc?dest=%s' % (db_name, dir_name) java = "return popup('%s','Add_Link',500,300)" % url print '<INPUT TYPE=button name=addlink value="Add Link" ' print 'onClick="%s">' % java print '</form></CENTER></TD>' if up_priv == 1: print '<TD><CENTER><FONT SIZE="-1">' print '<FORM method=post action=/%s-cgi-bin/upload.pyc>' % (db_name) print '<INPUT TYPE=submit name=uplink value="Upload File">' print '<INPUT TYPE=hidden name=dest value="%s">' % dir_name print '</form></CENTER><TD>' print "<TR></TABLE>"
def getDetails(form, html_filename, filename, priv): details = { 'item_name': '', 'version': '', 'date': '', 'description': '', 'priv': 'View' } dir, file = os.path.split(html_filename) path = '/home/%s/documents/%s/%s' % (db_name, dir, filename) serverpath = '/home/%s/documents/%s' % (db_name, html_filename + '.html') status, lines = file_io.readFromFile(serverpath) if form.has_key('directory'): if string.find(form['directory'].value, '..') >= 0: sys.exit() directory = form['directory'].value else: directory = '/' noFile = 0 # if can't read file if status != 'success': details['item_name'] = filename details['version'] = "N/A" mod_time = time.localtime(os.stat(path)[stat.ST_MTIME]) details['date'] = time.strftime('%m/%d/%y', mod_time) noFile = 1 else: # parse the details file for item_name, version, and date entered for line in lines: word = string.split(line) if len(word) == 0: continue else: end_index = len(word) - 1 if string.find(word[0], 'Data') != -1: details['item_name'] = string.join(word[3:end_index]) elif string.find(word[0], 'Version') != -1: details['version'] = string.join(word[1:end_index]) elif string.find(word[0], 'Date') != -1: if word[2][0] == '[': mod_time = time.localtime(os.stat(path)[stat.ST_MTIME]) details['date'] = time.strftime('%m/%d/%y', mod_time) else: details['date'] = string.join(word[2:end_index]) details['date'] = string.split(details['date'], '@')[0] if priv == 1: details['priv'] = 'Edit' link = "/%s-cgi-bin/edit.pyc" % declarations.pmt_info['db_name'] if noFile == 1: details['priv'] = 'Create' link = "/%s-cgi-bin/edit.pyc" % declarations.pmt_info['db_name'] else: if noFile == 1: details['priv'] = 'None' link = '' else: details['priv'] = 'View' link = "/%s-cgi-bin/view.pyc" % declarations.pmt_info['db_name'] link = link + '?project=%s&directory=%s' % (db_name, directory) link = link + '&filename=%s' % filename details['description'] = link return details
def create_db(self): import declarations os.system('destroydb %s' % (self.db_name)) os.system("createdb %s" % (self.db_name)) os.system("/usr/bin/destroyuser " + self.db_admin_username) print "Answer NO to the next prompt" os.system("/usr/bin/createuser -i 1000 -D -U " + self.db_admin_username) os.system("/usr/bin/destroyuser " + self.visitor_username) print "Answer NO to the next prompt" os.system("/usr/bin/createuser -i 2000 -D -U " + self.visitor_username) dbResult = ecommerce.connectDB(self.postgres_username, self.postgres_password, self.db_name) if dbResult['status'] != "success": print dbResult['message'] sys.exit(1) db = dbResult['result'] queryResult = ecommerce.executeSQL( db, "DELETE FROM pg_group WHERE groname = 'admins'") queryResult = ecommerce.executeSQL( db, "INSERT INTO pg_group (groname, grosysid, grolist) VALUES ('admins', '1', '{1000}')" ) if queryResult["status"] != 'success': print queryResult["status"] sys.exit(1) queryResult = ecommerce.executeSQL( db, "DELETE FROM pg_group WHERE groname = 'users'") queryResult = ecommerce.executeSQL( db, "INSERT INTO pg_group (groname, grosysid, grolist) VALUES ('users', '2', '{2000}')" ) if queryResult["status"] != 'success': print queryResult["status"] sys.exit(1) queryResult = ecommerce.executeSQL( db, "ALTER USER postgres WITH PASSWORD " + self.postgres_password) if queryResult["status"] != 'success': print queryResult['message'] sys.exit(1) queryResult = ecommerce.executeSQL( db, "ALTER USER %s WITH PASSWORD %s IN GROUP admins" % (self.db_admin_username, self.db_admin_password)) if queryResult["status"] != 'success': print queryResult['message'] sys.exit(1) queryResult = ecommerce.executeSQL( db, "ALTER USER %s WITH PASSWORD %s IN GROUP users" % (self.visitor_username, self.visitor_password)) if queryResult["status"] != 'success': print queryResult['message'] sys.exit(1) queryResult = ecommerce.create_tables(db, declarations.define_tables(), 1) if queryResult["status"] != 'success': print queryResult['message'] sys.exit(1) status, populate_tables = file_io.readFromFile(self.db_name + '.tables') for index in xrange(0, len(populate_tables)): populate_tables[index] = string.strip(populate_tables[index]) if populate_tables[index] == '': del populate_tables[index] elif populate_tables[index][:4] == 'COPY': populate_tables[index] = os.path.expandvars( populate_tables[index]) queryResult = ecommerce.executeSqlItemList(db, populate_tables, 1, 1) if queryResult["status"] != 'success': print queryResult print "Failed to execute all populate table statements" sys.exit(1) grantList = [] privileges = declarations.table_privileges() for table_name in privileges.keys(): for user_name in privileges[table_name].keys(): grantStatement = "GRANT " for privilege in privileges[table_name][user_name]: grantStatement = grantStatement + privilege + ", " grantStatement = grantStatement[: -2] + " ON " + table_name + " TO " + user_name grantList.append(grantStatement) # grant all privileges to the db admin grantList.append("GRANT ALL ON " + table_name + " TO " + self.db_admin_username) queryResult = ecommerce.executeSqlItemList(db, grantList, 1) if queryResult["status"] != 'success': print "Failed to execute all GRANTS" sys.exit(1)
print '<TABLE BORDER=0>' print '<TR><TD>' if not form.has_key('encapsulation_type'): msg = "No encapsulation type specified" exit(msg) elif string.upper(string.strip(form['encapsulation_type'].value)) == 'TAR': module_filename = string.strip(form['module_name'].value) + '.tar.gz' elif string.upper(string.strip(form['encapsulation_type'].value)) == 'ZIP': module_filename = string.strip(form['module_name'].value) + '.zip' module_path = None module_list_file = cvsroot + '/CVSROOT/%s.modules' % db_name #print "<BR>module_list_file:%s<BR>" % module_list_file status, module_lines = file_io.readFromFile(module_list_file) if status != 'success': msg = "Module data can not be found." msg = "%s Contact [email protected] for more information." % msg exit(msg) # for each line in the modules file ... for i in xrange(0, len(module_lines)): # ... split the line into fields fields = string.split(string.strip(module_lines[i])) # if this is a blank line... if fields == []: # ...skip to next line continue
def display_form(form): module_name = '' release = '' if form.has_key('module_name'): module_name = form['module_name'].value if form.has_key('release'): release = form['release'].value if form.has_key('encapsulation_type'): encapsulation_type = form['encapsulation_type'].value print '<html><head><title>Web CVS Export</title></head>' print '<body background="/%s/icons/circ_bg.jpg"' % db_name print 'bgcolor="#B7BAB7" TEXT="#000000">' print '<FONT SIZE="2" COLOR=BLUE><B>Web CVS Export</B></FONT>' exportable_modules = [] modFilename = cvsroot + '/CVSROOT/%s.modules' % db_name status, module_lines = file_io.readFromFile(modFilename) if status != 'success': msg = "ERROR: Module data can not be found." msg = "%s Contact [email protected] for more information" % msg exit(msg) #print 'ERROR: Module data can not be found. Contact' #print '<A HREF="mailto:[email protected]">CM</A> for more information' #print '</body></html>' #sys.exit(1) for i in xrange(0, len(module_lines)): fields = string.split(string.strip(module_lines[i])) if fields != []: if fields[0] != '#': if len(fields) >= 3: if fields[2] != '#web_export_disabled': exportable_modules.append(fields[0]) else: exportable_modules.append(fields[0]) exportable_modules.sort() link = '/%s-cgi-bin/web_cvs_export.pyc' % db_name print '<form action="%s" method="POST"' % link print 'enctype="application/x-www-form-urlencoded">' print '<FONT SIZE="2" COLOR=RED><B>Instructions:</B></FONT><BR><BR>' print 'Enter the following information to retrieve' print 'the module for download.<BR>' print 'The module name is the module name found in the CVS repository.<BR>' print 'The release name is the release of the module ' print 'or enter "now" to retrieve the latest version.<BR>' print 'The encapsulation type is Tar. If you select Tar the' print 'encapsulation will be a tar file that is gzipped.<BR><BR>' print '<B>NOTE:</B> WinZip 8.0 can extract tar gzipped files.<BR><BR>' print 'Contact <A HREF="mailto:[email protected]">CM</A> for more info.' print '<TABLE BORDER=0>' print '<TR><TD><B>Module Name</B>:</TD><TD>' optionMenu('module_name', '1', exportable_modules, select_list(exportable_modules, '')) print '</TD></TR>' print '<TR><TD><B>Release:</B></TD><TD>' print '<input name="release" type="text" size="48" maxlength="48"' print 'value="%s"></TD></TR>' % (release) print '<TR><TD><B>Encapsulation Type:</b></TD><TD>' optionMenu('encapsulation_type', '1', encapsulation_types, select_list(encapsulation_types, 'zip')) print '</TD></TR>' print '</TABLE><HR>' print '<input name="submit" type="submit" value="Download">' print '</form></body></html>'
def install_to_destination(self): status, dist_list = file_io.readFromFile(os.path.expandvars(os.path.join('${PWD}',self.application_name + '.files'))) if not os.path.exists(os.path.join(os.sep, 'home', self.application_name)): os.mkdir(os.path.join(os.sep, 'home', self.application_name)) if not os.path.exists(os.path.join(os.sep, 'home', self.application_name, 'db')): os.mkdir(os.path.join(os.sep, 'home', self.application_name, 'db')) if not os.path.exists(os.path.join(os.sep, 'home', self.application_name, 'bin')): os.mkdir(os.path.join(os.sep, 'home', self.application_name, 'bin')) if not os.path.exists(os.path.join(os.sep, 'home', self.application_name, 'images')): os.mkdir(os.path.join(os.sep, 'home', self.application_name, 'images')) if not os.path.exists(os.path.join(os.sep, 'home', self.application_name, 'icons')): os.mkdir(os.path.join(os.sep, 'home', self.application_name, 'icons')) if os.path.exists(os.path.join('.', 'staging')): os_utils.super_remove(os.path.join('.', 'staging')) os.mkdir(os.path.join('.', 'staging')) for curfile in dist_list: shutil.copy(curfile,os.path.join('.','staging')) os.chdir(os.path.join('.','staging')) compileall.compile_dir('.',0,None,0) os.chdir(os.path.join('..')) for curfile in glob.glob(os.path.join('.','staging','*.pyc')): shutil.copy(curfile,os.path.join(os.sep, 'home',self.application_name,'bin')) for curfile in glob.glob(os.path.join('.','images','*')): shutil.copy(curfile,os.path.join(os.sep, 'home',self.application_name,'images')) for curfile in glob.glob(os.path.join('.','icons','*')): shutil.copy(curfile,os.path.join(os.sep, 'home',self.application_name,'icons')) os_utils.set_file_mode(filename = os.path.join(os.sep, 'home',self.application_name), user = ['r','w','x']) os_utils.set_file_mode(filename = os.path.join(os.sep, 'home',self.application_name,'db'), user = ['r','w','x']) for curfile in glob.glob(os.path.join(os.sep, 'home',self.application_name,'db','*')): os_utils.set_file_mode(filename = curfile, user = ['r','w','x']) os_utils.set_file_mode(filename = os.path.join(os.sep, 'home',self.application_name,'bin'), user = ['r','w','x']) for curfile in glob.glob(os.path.join(os.sep, 'home',self.application_name,'bin','*')): os_utils.set_file_mode(filename = curfile, user = ['r','w','x']) os_utils.set_file_mode(filename = os.path.join(os.sep, 'home',self.application_name,'images'), user = ['r','w','x']) for curfile in glob.glob(os.path.join(os.sep, 'home',self.application_name,'images','*')): os_utils.set_file_mode(filename = curfile, user = ['r','w']) os_utils.set_file_mode(filename = os.path.join(os.sep, 'home',self.application_name,'icons'), user = ['r','w','x']) for curfile in glob.glob(os.path.join(os.sep, 'home',self.application_name,'icons','*')): os_utils.set_file_mode(filename = curfile, user = ['r','w']) status, output = os_utils.super_chown( directory_name=os.path.join(os.sep,'home',self.application_name), username='******', groupname='davis') if status != 'success': print 'Ownership settings of tec %s failed.' % (os.path.join(os.sep,'home',self.application_name))