def pageSetup(): print "<HTML>" print "<HEAD>" print '<meta name="robots" content="noindex,follow">' pmt_utils.title("Document Listing") print ' <SCRIPT TYPE="text/javascript">' print ' <!--' print ' function popup(mylink, windowname,w,h)' print ' {' print ' if (! window.focus)return true;' print ' var href;' print " if (typeof(mylink) == 'string')" print ' href=mylink;' print ' else' print ' href=mylink.href;' print ' LeftPosition=(screen.width)?(screen.width-w)/2:100;' print ' TopPosition=(screen.height)?(screen.height-h)/2:100;' settings = "'width='+ w + ',height='+ h + ',top=' + TopPosition + " settings = settings + "',left=' + LeftPosition + ',scrollbars=yes'" print " settings=%s" % settings print ' popWindow=window.open(href, windowname, settings);' print ' popWindow.focus()' print ' return false;' print ' }' print ' //-->' print ' </SCRIPT>' print "</HEAD>" pmt_utils.bodySetup() print '<Font Face="SerpentineSansICG,Arial">'
def pageInit(subHeading=None, formJS=0): table_data = declarations.define_tables() print "<HTML>" print "<HEAD>" if formJS: pmt_utils.generate_form_javascript(table_data, 'inventory', 'inv_admin', 0) else: pmt_utils.javaScript("inv_admin") pmt_utils.title("Inventory") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Inventory') if subHeading != None: pmt_utils.subHeading(subHeading) pmt_utils.formSetup("inv_admin", declarations.pmt_info['db_name'], "inv_admin", "return submitForm(document.inv_admin)") dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) if dbResult['status'] != 'success': db = None status = dbResult['message'] else: db = dbResult['result'] status = 'success' return status, table_data, db
def viewDetails(): # get the current data if it exists html_filename = form['filename'].value # if the filename has more than 1 period in it replace them with _ if string.count(html_filename, ".") > 1: html_filename = string.replace(html_filename, ".", "_") file = '/home/%s/documents/%s/%s.html' % ( form['project'].value, form['directory'].value, form['filename'].value) details = getDetails(file) # write detail info in HTML format print '<HTML><HEAD><TITLE>Data Item Details for: %s</TITLE></HEAD><BODY>' % ( form['filename'].value) pmt_utils.bodySetup() print '<CENTER><B><FONT COLOR="#000099">Data Item Details Page</FONT></B><HR SIZE=1 NOSHADE WIDTH=100%>' print '<TABLE border=0>' print '<TR><TD><B>Data Item Name:</B></TD><TD> %s <BR>' % (details['name']) print '<TR><TD><B>Date Entered:</B></TD><TD> %s <BR>' % (details['date']) print '<TR><TD><B>Filename:</B></TD><TD> %s <BR>' % ( form['filename'].value) print '<TR><TD><B>Version:</B></TD><TD> %s <BR>' % (details['version']) print '<TR><TD><B>Location:</B></TD><TD> %s <BR>' % ( form['directory'].value) print '<TR><TD><B>Description:</B></TD><TD> %s <BR>' % ( details['description']) print '</TABLE>' print '<HR><form method="POST"' print '<input type="button" value="Close Window" onClick="self.close()">' print '</form>' print '</BODY></HTML>'
def displayLogin(form,alert=None): print "<HTML>" print "<HEAD>" pmt_utils.javaScript("cvsweb") pmt_utils.title("Development Library") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Development Library') pmt_utils.subHeading('Login') pmt_utils.formSetup("cvsweb", db_name, "cvsweb", "return submitForm(document.cvsweb)") pmt_utils.usernamePasswordDisplay() if alert!=None: pmt_utils.alertsArea(form, alert) print "<hr><INPUT TYPE='submit' NAME='submit' value='Submit' >"
def displayLogin(alert=None): print "<HTML>" print "<HEAD>" pmt_utils.javaScript("upload") pmt_utils.title("Upload") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Upload') pmt_utils.subHeading('Login') pmt_utils.formSetup("upload",declarations.pmt_info['db_name'], "upload","return submitForm(document.upload)") pmt_utils.usernamePasswordDisplay() if alert!=None: pmt_utils.alertsArea(form,alert) print "<hr><INPUT TYPE='submit' NAME='submit' value='Submit' >" if form.has_key('dest'): print '<INPUT TYPE=hidden NAME=dest value="%s">' % form['dest'].value
def displayLogin(form, alert=None): print "<HTML>" print "<HEAD>" pmt_utils.javaScript("list_docs") pmt_utils.title("Data Item Listing") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Data Item Listing') pmt_utils.subHeading('Login') java = "return submitForm(document.list_docs)" pmt_utils.formSetup("list_docs", db_name, "list_docs", java) pmt_utils.usernamePasswordDisplay() if alert != None: pmt_utils.alertsArea(form, alert) print "<hr><INPUT TYPE='submit' NAME='submit' value='Submit' >" if form.has_key('directory'): if string.find(form['directory'].value, '..') >= 0: sys.exit() print "<INPUT TYPE='hidden' NAME='directory' " print "value='%s'>" % form['directory'].value
def viewLinkDetails(): name = href = date = description = None if os.path.exists(form['file'].value): bookmarks = open(form['file'].value, 'r') else: sys.exit() lines = bookmarks.readlines() for line in lines: words = string.split(line) if words[0] == form['link'].value: name = words[2] i = 3 while words[i] != '|': name = name + ' ' + words[i] i = i + 1 href = words[i + 1] date = words[i + 3] description = string.join(words[i + 5:], ' ') bookmarks.close() print '<HTML><HEAD><TITLE>Data Item Details for: %s</TITLE></HEAD><BODY>' % ( name) pmt_utils.bodySetup() print '<CENTER><B><FONT COLOR="#000099">Data Item Details Page</FONT></B><HR SIZE=1 NOSHADE WIDTH=100%>' print '<TABLE border=0>' print '<TR><TD><B>Data Item Name:</B></TD><TD> %s <BR>' % (name) print '<TR><TD><B>Date Entered:</B></TD><TD> %s <BR>' % (date) print '<TR><TD><B>Target:</B></TD><TD> %s <BR>' % (href) print '<TR><TD><B>Description:</B></TD><TD> %s <BR>' % (description) print '</TABLE>' print '<HR><form method="POST"' print '<input type="button" value="Close Window" onClick="self.close()">' print '</form>' print '</BODY></HTML>'
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------ pmt_utils.htmlContentType() form = pmt_utils.getFormData() db_name=declarations.pmt_info['db_name'] username,password=pmt_utils.getUserPass(form) print "<HTML>" print "<HEAD>" pmt_utils.title("Edit Project Options") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading("Project Option Manager") pmt_utils.subHeading("Add/Delete Options") if username!=None: dbResult=pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) if dbResult['status'] != 'success': message="Can not connect to database,\n" + dbResult['message'] pmt_utils.alertsArea(form,message) sys.exit() db=dbResult['result']
def display_form(display_files=0,alerts=None): print "<HTML>" print "<HEAD>" pmt_utils.javaScript("doc_maintenance") pmt_utils.title("Documentation Maintenance") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Documentation Maintenance') pmt_utils.subHeading('Create and Delete Folders/Files') pmt_utils.formSetup("doc_maintenance",db_name,"doc_maintenance",None) dbResult=pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) if dbResult['status']!='success': exit(dbResult['message']) db=dbResult['result'] status,details = db_authentication.password_valid(db, crypt_salt=db_name, username=username, password=password) if status!='success': exit(details) if not pmt_utils.hasPriv(db,username,'folder_admin'): msg="User %s does not have folder maintenance priviledges" % username exit(msg) print '<hr><br><CENTER><B>Delete Folders/Files</B></CENTER>' stripped_db=string.lower(string.strip(db_name)) os.chdir(os.path.join('/home',stripped_db,'documents')) file_list = os_utils.walk_list_files( directory_name='.', list_only_files=0, exclude_list = [], include_file_type=1) if len(file_list) > 25: list_size = 25 else: list_size = len(file_list) print '<BLINK><B>WARNING:</B></BLINK><br>' print 'Any folders or files that you select for deletion are ' print 'permanently deleted. You should have a local backup of ' print 'any folders/files you delete in case you really did not mean ' print 'to delete. Backups are crucial. You have been warned.' print '<p>Selecting a folder will delete the folder and all files ' print 'under it including sub folders. ' print 'Select folder names with caution.' print '<p>Your deletes will not be confirmed. ' print 'When you press [Delete Folders/Files] your files are deleted.' print '<BR><CENTER><B>Select folders/files to delete</B>:<BR>' print '<SELECT NAME="files_to_remove" SIZE="8" MULTIPLE>' for curfile in file_list: print '<OPTION>%s' % (curfile) print "</SELECT><br>" java_call="return execute('delete_folder','1')" print '<input name="delete_folder" type="button" ' print 'value=" Delete Folders/Files " onClick="%s">' % java_call print '<input name ="website_name_hidden" ' print 'type="hidden" value="%s">' % (db_name) print "<hr><BR><BR>" print '<CENTER><B>Create Folder</B></CENTER><BR>' print '<B>Folder Name</B>: ' print '<input name="folder" type="text" size="50" maxlength="100"><BR>' java_call="return execute('create','1')" print '<input name="create" type="button" ' print 'value=" Create Folder " onClick="%s">' % java_call print '<input name ="website_name_hidden" ' print 'type="hidden" value="%s"><hr>' % (db_name) if alerts != None: pmt_utils.alertsArea(form,alerts) print '</CENTER>' pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'key_id', '1', '10', '10', None, None,'hidden') print '</form>' print '<p align="right">' print '<A HREF="mailto:[email protected]">Contact Support Team</a>' print "</body></html>"
def display_form(display_files=0, alerts=None): print "<HTML>" print "<HEAD>" pmt_utils.title("Site Maintenance (Clean)") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Site Maintenance') pmt_utils.subHeading('Clean') pmt_utils.formSetup("clean_site", declarations.pmt_info['db_name'], "clean_site", None) if not display_files: print '<TABLE BORDER=0><TR><TD><B>Username</B>:</TD><TD><input name="username" type="text" size="9" maxlength="9"></TD></TR><TR><TD><B>Password:</B></TD><TD><input name="password" type="password" size="8" maxlength="8"></TD></TR></TABLE>' if display_files: os.chdir( os.path.join( '/home', string.lower(string.strip(declarations.pmt_info['db_name'])), 'documents')) file_list = os_utils.walk_list_files(directory_name='.', list_only_files=0, exclude_list=[], include_file_type=1) if len(file_list) > 25: list_size = 25 else: list_size = len(file_list) print """ <CENTER> <TABLE BORDER=0> <CAPTION><BLINK><B>WARNING:<B></BLINK></CAPTION> <TR><TD WIDTH=300> Any files that you select for deletion are permanently deleted. You should have a local backup of any files you delete in case you really did not mean to delete. Backups are crucial. You have been warned. <p>Selecting a directory will delete the directory and all files under it including subdirectories. Select directory names with caution. <p>Your deletes will not be confirmed. When you press [Delete Selected Files] your files are deleted.</TD></TR></TABLE> """ print '<BR><CENTER><B>Select files to delete</B>:<BR><SELECT NAME="files_to_remove" SIZE="%d" MULTIPLE>' % ( list_size) for curfile in file_list: print '<OPTION>%s' % (curfile) print "</SELECT><BR>" if alerts != None: pmt_utils.alertsArea(form, alerts) print '</CENTER>' print """ <CENTER> <HR> """ if display_files: print '<input name="submit" type="submit" value="Delete Selected Files">' else: print '<input name="submit" type="submit" value="Login">' print '</CENTER>' if display_files: print '<input name ="website_name_hidden" type="hidden" value="%s">' % ( declarations.pmt_info['db_name']) print """
def sendDataItem(email): print "<HTML>" print "<HEAD>" pmt_utils.title("Email Data") print "</HEAD>" pmt_utils.bodySetup(onLoad=None) pmt_utils.mainHeading('Send Email') link = '/%s-cgi-bin/email.pyc' % declarations.pmt_info['db_name'] print '<form method=post action=%s>' % link print '<table>' print '<tr><td>To:</td><td><input type=text name=to_box></td>' print '<tr><td>From:</td><td>' print '<input type=hidden name=from_box value="%s">%s</td>' % (email, email) print '<tr><td>Subject:</td><td><input type=text name=subject></td>' print '<tr><td>Comments:</td><td>' pmt_utils.textarea('', 'comments', '', '4', '20', None, None) print '</td></table><hr><table>' path, filename = os.path.split(form['fullpath'].value) index = string.find(path, 'documents') path = path[index + 9:] if path == '': path = '/' content = "An error has occurred while loading this page." if filename == "b00kmarkz": abs_filename = "/home/%s/documents/%s/b00kmarkz" % (db_name, path) bookmarks = open(abs_filename, 'r') lines = bookmarks.readlines() for line in lines: words = string.split(line) id = words[0] if id == form['id'].value: i = 3 while words[i] != '|': i = i + 1 href = words[i + 1] content = 'The data item can be accessed from %s' % href bookmarks.close() else: content = 'The data item %s can be accessed from:\n' % form[ 'name'].value content = content + '/%s-cgi-bin/list_docs.pyc' % form['project'].value content = content + '?project_name=%s' % form['project'].value content = content + '&directory=%s' % path htmlContent = string.replace(content, '\n', '<br>') print htmlContent print '<input type=hidden name=content value="%s">' % urllib.quote(content) print '<input type=hidden name=username ' print 'value="%s">' % username print '<input type=hidden name=project value="%s">' % form['project'].value print '<input type=hidden name=fullpath ' print 'value="%s">' % form['fullpath'].value print '<input type=hidden name=name value="%s">' % form['name'].value link = '/%s-cgi-bin/email.pyc' % declarations.pmt_info['db_name'] print '<HR><input type=submit name=send value="Send Email" ' print 'onClick="return goto_url(' + "'" + link + "'" + ')">' print '</form>'
print '<HR><input type=submit name=send value="Send Email" ' print 'onClick="return goto_url(' + "'" + link + "'" + ')">' print '</form>' #------------------------------------------------------------------------------ #------------------------------------------------------------------------------ pmt_utils.htmlContentType() form = pmt_utils.getFormData() db_name = declarations.pmt_info['db_name'] username, password = pmt_utils.getUserPass(form) if form.has_key('to_box'): #from email.py: send email pmt_utils.bodySetup(onLoad=None) sendEmail() elif form.has_key('key') and form.has_key('table'): # from ecp,pai,spr: get recipient and subject table_data = declarations.define_tables() print "<HTML>" print "<HEAD>" pmt_utils.title("Email Data") print "</HEAD>" pmt_utils.bodySetup(onLoad=None) pmt_utils.mainHeading('Send Email') print '<hr>'
def edit_project_info(performDbQuery=0, onLoad=None, queryFields=None): table_data = declarations.define_tables() print "<HTML>" print "<HEAD>" pmt_utils.javaScript("project_admin") pmt_utils.title("Project Administration") print "</HEAD>" pmt_utils.bodySetup(onLoad) pmt_utils.mainHeading('Project Administration') pmt_utils.subHeading('Project Info') pmt_utils.formSetup("project_admin", db_name, "project_admin", "return submitForm(document.project_admin)") if username == None: pmt_utils.usernamePasswordDisplay() project_adminButtons(button_name='edit') pmt_utils.textbox(None, 'key_id', '1', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden') print "</FORM>" try: pmt_utils.trailer(table_data, db) db.close() except NameError: pass print "</BODY>" print "</HTML>" return dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) # could not connect to db if dbResult['status'] != 'success': pmt_utils.alertsArea( form, "Can not connect to database,\n" + dbResult['message']) project_adminButtons() print "</FORM>" try: pmt_utils.trailer(table_data, db) db.close() except NameError: pass print "</BODY>" print "</HTML>" return db = dbResult['result'] status, details = db_authentication.password_valid(db, crypt_salt=db_name, username=username, password=password) if status != 'success': print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name pmt_utils.usernamePasswordDisplay(username) pmt_utils.alertsArea(form, 'Can not verify you as a valid user') print '<hr><input name=reload type=submit value="Query">' print '<input name=action value=edit type=hidden>' print '</form>' sys.exit() if pmt_utils.hasPriv(db, username, 'project_data') != 1: print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name pmt_utils.usernamePasswordDisplay(username) msg = 'User %s does not have project admin privileges>' % username pmt_utils.alertsArea(form, msg) print '<hr><input name=reload type=submit value="Query">' print '<input name=action value=edit type=hidden>' print '</form>' sys.exit() if form.has_key('key_id'): key_id = form['key_id'].value else: key_id = '1' sqlStatement = pmt_utils.selectAllColumnsSqlStatement( table_data, 'project_info', key_id) dbResult = pmt_utils.executeSQL(db, sqlStatement) if dbResult['status'] != 'success': msg = "Could not retrieve project information\n" + dbResult['message'] pmt_utils.alertsArea(form, msg) else: result = dbResult['result'] table_data = pmt_utils.dbToTableData(table_data, 'project_info', result[0]) table_data['project_info']['id']['value'] = '1' pmt_utils.display_form(table_data, 'project_info', 1, 'useValues', 1, db) pmt_utils.alertsArea(form, "Project Information retrieved successfully") project_adminButtons(button_name='save') pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden') print "</FORM>" try: pmt_utils.trailer(table_data, db) db.close() except NameError: pass print "</BODY>" print "</HTML>"
def doEdit(): table_data = declarations.define_tables() print "<HTML>" print "<HEAD>" pmt_utils.generate_form_javascript(table_data, 'project_info', 'project_admin', 0) pmt_utils.title("Project Info Administration") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Project Info Administration') pmt_utils.subHeading('Edit Project Info') pmt_utils.formSetup("project_admin", db_name, "project_admin", "return submitForm(document.project_admin)") dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) if dbResult['status'] != 'success': msg = "Could not connect to the database\n" pmt_utils.alertsArea(form, msg + dbResult['message']) sys.exit() db = dbResult['result'] status, details = db_authentication.password_valid(db, crypt_salt=db_name, username=username, password=password) if status != 'success': print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name pmt_utils.usernamePasswordDisplay(username) pmt_utils.alertsArea(form, 'Can not verify you as a valid user') print '<hr><input name=reload type=submit value="Query">' print '<input name=action value=edit type=hidden>' print '</form>' sys.exit() if pmt_utils.hasPriv(db, username, 'project_data') != 1: print '<form method=post action=/%s-cgi-bin/project_admin.pyc>' % db_name pmt_utils.usernamePasswordDisplay(username) msg = 'User %s does not have project admin privileges' % username pmt_utils.alertsArea(form, msg) print '<hr><input name=reload type=submit value="Query">' print '<input name=action value=edit type=hidden>' print '</form>' sys.exit() sqlStatement = pmt_utils.selectAllColumnsSqlStatement( table_data, 'project_info', '1') dbResult = pmt_utils.executeSQL(db, sqlStatement) if dbResult['status'] != 'success': msg = "Could not retrieve project info to edit\n" pmt_utils.alertsArea(form, msg + dbResult['message']) else: result = dbResult['result'] table_data = pmt_utils.dbToTableData(table_data, 'project_info', result[0]) table_data['project_info']['id']['value'] = '1' pmt_utils.display_form(table_data, 'project_info', 1, 'useValues', 1, db) pmt_utils.alertsArea(form, "Project Info retrieved successfully") project_adminButtons('save') pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden') print "</FORM>" pmt_utils.trailer(table_data, db) db.close() print "</BODY>" print "</HTML>"
def doSave(): table_data = declarations.define_tables() print "<HTML>" print "<HEAD>" pmt_utils.generate_form_javascript(table_data, 'project_info', 'project_admin', 0) pmt_utils.title("Project Info Administration") print "</HEAD>" pmt_utils.bodySetup() pmt_utils.mainHeading('Project Info Administration') pmt_utils.subHeading('Edit Project Info') pmt_utils.formSetup("project_admin", db_name, "project_admin", "return submitForm(document.project_admin)") dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) if dbResult['status'] != 'success': msg = "Project Info could not be saved, could not connect to db\n" pmt_utils.alertsArea(form, msg + dbResult['message']) # generate function button row project_adminButtons('save') # generate hidden fields for form pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden') print "</FORM>" pmt_utils.trailer(table_data, db) db.close() print "</BODY>" print "</HTML>" return db = dbResult['result'] # save the Form dbResult = pmt_utils.saveForm(table_data, db, None, "project_info", " WHERE id = '1'", form) # if the form was not successfully saved if dbResult['status'] != 'success': msg = "Project Info could not be saved due to an error during save,\n" pmt_utils.alertsArea(form, msg + dbResult['message']) else: table_data = declarations.define_tables() table_data = pmt_utils.formToTableData(table_data, 'project_info', form) table_data['project_info']['id']['value'] = '1' pmt_utils.display_form(table_data, 'project_info', 1, 'useValues', 1, db) pmt_utils.alertsArea(form, "Project Info successfully saved") # generate function button row project_adminButtons('save') # generate hidden fields for form pmt_utils.textbox(None, 'key_id', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'action', '', '10', '10', None, None, 'hidden') pmt_utils.textbox(None, 'item_no', '', '8', '8', None, None, 'hidden') print "</FORM>" pmt_utils.trailer(table_data, db) db.close() print "</BODY>" print "</HTML>"
def doUpload(): email_msg=html_msg='' dbResult = pmt_utils.connectDB(declarations.pmt_info['browser_username'], declarations.pmt_info['browser_password'], declarations.pmt_info['db_name']) # could not connect to db if dbResult['status'] != 'success': upload_results('Can not verify you as a valid user<BR>', 'Can not verify you as a valid user', form) sys.exit() db = dbResult['result'] # check for valid login status, details =db_authentication.password_valid(db, crypt_salt=db_name, username=username, password=password) if status != 'success': pmt_utils.bodySetup() pmt_utils.alerts(form, 'Can not verify username/password') print '<hr><form method=post action=/%s-cgi-bin/upload.pyc>' % db_name print '<input name=back value="Back to Upload" type=submit>' print '</body>' sys.exit() if pmt_utils.hasPriv(db, username, 'upload')!=1: pmt_utils.bodySetup() pmt_utils.alerts(form, 'User %s does not have upload privileges' % username) print '<hr><form method=post action=/%s-cgi-bin/upload.pyc>' % db_name print '<input name=back value="Back to Upload" type=submit>' print '</body>' sys.exit() # check for valid upload site if not os.path.exists('/home/%s' % db_name): html_msg=html_msg+"Upload site %s does not exist.<BR>" % db_name html_msg=html_msg+"No archive file was uploaded.<BR>" email_msg=email_msg+"Upload site %s does not exist.\n" % db_name email_msg=email_msg+"No archive file was uploaded.\n" upload_results(html_msg, email_msg, form) sys.exit() # format destination for upload if not form.has_key('folder'): destination = '' else: if form['folder'].value == '/': destination = '' else: destination = form['folder'].value + '/' if form.has_key('archive'): # check for filesize is within allowable range archive_size = len(form['archive'].value) if archive_size == 0: msg="Suspicious archive file size of 0. Upload aborted." email_msg=email_msg+msg html_msg=html_msg+msg+"<BR>" upload_results(html_msg,email_msg,form) sys.exit() if archive_size > upload_ceiling: html_msg = 'Archive file size exceeds maximum upload limit ' html_msg = html_msg + 'of %d bytes.<BR>' % (upload_ceiling) html_msg = html_msg + 'Archive file size is %d bytes.<BR>' % (archive_size) html_msg = html_msg + 'No archive file was uploaded.<BR>' email_msg=string.replace(html_msg,"<BR>",'\n') upload_results(html_msg, email_msg,form) 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/' + db_name + '/documents/' + destination 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 upload file to the website %s. " % db_name html_msg = html_msg+"Uploaded aborted.<BR>" html_msg = html_msg + 'File: '+full_path_name email_msg=string.replace(html_msg,"<BR>",'\n') email_msg=email_msg+'\nReason: ' + exception_details[1] + '\n\n' upload_results(html_msg,email_msg,form) sys.exit() archive_file.write(form['archive'].value) archive_file.close() status, type_of_archive, icon = os_utils.file_type(full_path_name) createDetails(archive_name, full_path) # extract archive if form.has_key('extract'): if status == 'success': archive_output=extract(type_of_archive, full_path_name,full_path, email_msg,html_msg) else: html_msg = 'Uploading unknown file type, in most cases this' html_msg = html_msg+'is alright but the file should be checked' email_msg='Upload to %s of an unknown file type.' % db_name upload_results(html_msg,email_msg,form) sys.exit() else: archive_output='' status='success' html_msg = '<TABLE BORDER=0>' if os.environ.has_key('REMOTE_ADDR'): html_msg = html_msg +'<TR><TD>Your IP Address:</TD>' html_msg = html_msg +'<TD>%s</TD></TR>'%(os.environ['REMOTE_ADDR']) html_msg = html_msg + '<TR><TD>Your browser I.D.:</TD>' html_msg = html_msg + '<TD><B>%s</B></TD></TR>' % (browser) fileSize=os.stat(full_path_name)[6] if type_of_archive == 'TAR' or type_of_archive == 'ZIP': html_msg = html_msg + '<TR><TD>Archive name is: </TD>' html_msg = html_msg + '<TD>%s</TD></TR>' % (archive_name) html_msg = html_msg + '<TR><TD>Archive file size (bytes): </TD>' html_msg = html_msg + '<TD>%d</TD></TR></TABLE>' %(fileSize) else: html_msg = html_msg + '<TR><TD>Filename is: </TD>' html_msg = html_msg + '<TD>%s</TD></TR>' % (archive_name) html_msg = html_msg + '<TR><TD>File size (bytes): </TD>' html_msg = html_msg + '<TD>%s</TD></TR></TABLE>' %(fileSize) if type_of_archive == 'TAR' or type_of_archive == 'ZIP': html_msg = html_msg + '<PRE>' html_msg = html_msg + archive_output html_msg = html_msg + '</PRE>' if form.has_key('extract'): html_msg=html_msg+'<CENTER><B>Your archive file has been uploaded ' html_msg = html_msg + 'and extracted successfully.</B></CENTER>' else: html_msg = html_msg + '<CENTER><B>Your file has been successfully ' html_msg = html_msg + 'uploaded.</B></CENTER>' html_msg = html_msg+'<HR><CENTER><FONT SIZE="-1">' html_msg = html_msg+"<form method=post action=/%s-cgi-bin/list_docs.pyc>" %db_name html_msg=html_msg+'<input name=project_name type=hidden value="%s">'%db_name html_msg = html_msg+"<input name=directory type=hidden " html_msg = html_msg+'value="%s">' % form['folder'].value html_msg = html_msg+'<input name=submit type=submit value="View Data Items">' html_msg = html_msg+"</form>" link = "http://%s" % (declarations.pmt_info['domain_name']) html_msg = html_msg+'<CENTER><FONT SIZE="-1"><A HREF="%s">' % link html_msg = html_msg+'%s</A></FONT></CENTER>'% declarations.pmt_info['domain_name'] if type_of_archive == 'TAR' or type_of_archive == 'ZIP': email_msg=email_msg+'Archive file was uploaded to %s.\n' % db_name email_msg=email_msg+'Archive file size (bytes): %d'%os.stat(full_path_name)[6] email_msg=email_msg+'\nArchive file location: %s' % form['folder'].value email_msg=email_msg+'\nArchive filename: %s\n' % archive_name email_msg=email_msg+archive_output + '\n' else: email_msg = email_msg+'File was uploaded to %s.\n' % db_name email_msg = email_msg+'File size (bytes): %d\n' % os.stat(full_path_name)[6] email_msg = email_msg+'Filename: %s\n' % archive_name email_msg = email_msg+"File location: %s\n" % form['folder'].value email_msg = email_msg+archive_output + '\n' if form.has_key('extract'): os.remove(full_path_name)