#!/usr/sbin/perl #************************************************************************** #* * #* Copyright (c) 1996 Silicon Graphics, Inc. * #* All Rights Reserved * #* * #* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI * #* * #* The copyright notice above does not evidence any actual of intended * #* publication of such source code, and is an unpublished work by Silicon * #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is * #* the property of Silicon Graphics, Inc. Any use, duplication or * #* disclosure not specifically authorized by Silicon Graphics is strictly * #* prohibited. * #* * #* RESTRICTED RIGHTS LEGEND: * #* * #* Use, duplication or disclosure by the Government is subject to * #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in * #* Technical Data and Computer Software clause at DFARS 52.227-7013, * #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR * #* Supplement. Unpublished - rights reserved under the Copyright Laws of * #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. * #* Shoreline Blvd., Mountain View, CA 94039-7311 * #************************************************************************** # DEMO_add.tree.pl # # Routines to add and remove new trees 1; # Return true # INPUT: %in # Create the appropriate add a tree page based on user input sub Generate_Maint_Tree_Page { if ($in{$CGI_TREE_ADD_SWITCH}) { &Generate_New_Tree_Page; } elsif ($in{$CGI_TREE_DELETE_SWITCH}) { &Generate_Delete_Tree_Page; } elsif ($in{$CGI_TREE_OLD_NAME_SWITCH}) { &Generate_Tree_Change_Name_Page; } elsif ($in{$CGI_TREE_VIEW_SWITCH}) { &Pop_Tree_Demos; } else { &Print_Main_Tree_Page; } } # INPUT: %in # Delete a tree by performing the following actions # - Remove the tree from namespace # - Remove the list file # - Remove all references to that tree in the "All Demos" list # - Remove references in custom lists # - Update all tables and demo lists inthe background # - Notify user of table update in progress # - Print the final page after deletion sub Generate_Delete_Tree_Page { local($tree_delete_name, $tree_delete_path, $tree_delete_file, $file_list, @custom_list_files); $tree_delete_name = $in{$CGI_TREE_DELETE_SWITCH}; $tree_delete_path = &Tree_Path_From_Name("$tree_delete_name"); $tree_delete_file = &Tree_File_From_Name("$tree_delete_name"); &Delete_Tree_From_Name_Space("$tree_delete_name"); #remove its list `$CMD_RM $PATH_TREES_DIR/$tree_delete_file $CMD_NULLIFY`; #remove references in All Demos `$CMD_PERL $CMD_PERL_FLAGS 's/.*$TREES_DELIM$tree_delete_name\\n//g' $FILE_DEMOLIST $CMD_NULLIFY`; #remove references from custom lists @custom_list_files = &List_Custom_List_Files; grep(($_ = "$PATH_CUSTOM_DIR/$_"), @custom_list_files); $file_list = join(" ", @custom_list_files); `$CMD_PERL $CMD_PERL_FLAGS 's/.*$TREES_DELIM$tree_delete_name\\n//g' $file_list $CMD_NULLIFY`; &Print_Delete_Tree_Success_Page; } # INPUT:($tree_name) # Remove a tree from name space sub Delete_Tree_From_Name_Space { local($tree_path, $tree_file, $tree_name, $tree_delete_name); $tree_delete_name = shift; open(NAMESPACE, "$FILE_TREES_NAMESPACE") || &Print_Error("$ERROR_NO_OPEN", "$FILE_TREES_NAMESPACE", "$STATUS_SERIOUS"); open(TMP_FILE, ">$FILE_NAMESPACE_TMP") || &Print_Error("$ERROR_NO_OPEN", "$FILE_NAMESPACE_TMP", "$STATUS_SERIOUS"); while () { chop; ($tree_name, $tree_path, $tree_file) = /(.*)$TREES_DELIM(.*)$TREES_DELIM(.*)/; print TMP_FILE "$tree_name$TREES_DELIM$tree_path$TREES_DELIM$tree_file\n" if ("$tree_name" ne "$tree_delete_name"); } close(NAMESPACE); close(TMP_FILE); rename("$FILE_NAMESPACE_TMP", "$FILE_TREES_NAMESPACE"); } # INPUT: %in # Print the post-delete page sub Print_Delete_Tree_Success_Page { &Print_Maint_Top("Demo List Deleted", "$IMGSRC_HEADER_TREE",0,0,1); &Print_Error("$ERROR_INFO","Tree \"$in{$CGI_TREE_DELETE_SWITCH}\" deleted.","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "Demo List $in{$CGI_TREE_DELETE_SWITCH} deleted."; print "

\n"; print "Use this utility to make further modifications to your demo lists.\n"; print "

\n"; print "

\n

\n


\n"; &Print_Main_Tree_Forms; } # INPUT: %in # Create the correct new tree page based on user input sub Generate_New_Tree_Page { $in{$CGI_TREE_ADD_SWITCH} = &Make_HTTP_Safe("$in{$CGI_TREE_ADD_SWITCH}"); if ( &Safe_Tree_Name("$in{$CGI_TREE_ADD_SWITCH}") && &Safe_Tree_Path_Name("$in{$CGI_TREE_PATH_SWITCH}") ) { &Add_Tree("$in{$CGI_TREE_ADD_SWITCH}", "$in{$CGI_TREE_PATH_SWITCH}", &Generate_File_Name); &Print_Add_Tree_Success_Page; } else { &Print_Add_Tree_Failure_Page; } } # INPUT: ($tree_path) # Check a tree path to see if it exists and is not already loaded sub Safe_Tree_Path_Name { local($doesExist, $notTaken, @treePaths); $doesExist = chdir("$_[0]"); @treeNames = &List_Tree_Names; for (@treeNames) { push(@treePaths, &Tree_Path_From_Name("$_")); } $notTaken = (! grep(/^$_[0]$/, @treePaths) ); return( ($notTaken && $doesExist) ); } # INPUT: %in # Print the post-add failure page sub Print_Add_Tree_Failure_Page { &Print_Maint_Top("Error: Can't Create Tree", "$IMGSRC_HEADER_TREE"); &Print_Error("$ERROR_INFO","Tree \"$in{$CGI_TREE_ADD_SWITCH}\" for \"$in{$CGI_TREE_PATH_SWITCH}\" could not be created.","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "Demo List $in{$CGI_TREE_ADD_SWITCH} for $in{$CGI_TREE_PATH_SWITCH} could not be created."; print "

\n"; print "Use this utility to make further modifications to your demo lists.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Tree_Forms; } # INPUT: ($tree_name, $tree_path, $tree_file, $stop_notify) # Add a tree to the interface by performing the following actions # - Add the tree to namespace # - Parse the list of demos # - Update all tables in the background # - Notify the user if "$stop_notify" not defined sub Add_Tree { local($tree_name, $tree_path, $tree_file); $tree_name = shift; $tree_path = shift; $tree_file = shift; # add to namespace open(NAMESPACE, ">>$FILE_TREES_NAMESPACE") || &Print_Error("$ERROR_NO_OPEN", "$FILE_TREES_NAMESPACE", "$STATUS_SERIOUS"); print NAMESPACE "$tree_name$TREES_DELIM$tree_path$TREES_DELIM$tree_file\n"; close(NAMESPACE); } # INPUT: %in # Print post-add success page sub Print_Add_Tree_Success_Page { &Print_Maint_Top("Demo List Created", "$IMGSRC_HEADER_TREE", 0, 0, 1); &Print_Error("$ERROR_INFO","Tree \"$in{$CGI_TREE_ADD_SWITCH}\" created for \"$in{$CGI_TREE_PATH_SWITCH}\".","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "Demo List $in{$CGI_TREE_ADD_SWITCH} created for $in{$CGI_TREE_PATH_SWITCH} ."; print "

\n"; print "Use this utility to make further modifications to your trees portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Tree_Forms; } # INPUT: %in # Create appropriate change name page from user input sub Generate_Tree_Change_Name_Page { $in{$CGI_TREE_NEW_NAME_SWITCH} = &Make_HTTP_Safe("$in{$CGI_TREE_NEW_NAME_SWITCH}"); if ( &Safe_Tree_Name("$in{$CGI_TREE_NEW_NAME_SWITCH}") ) { &Print_Maint_Top("Tree Name Changed", "$IMGSRC_HEADER_TREE"); &Change_Tree_Name("$in{$CGI_TREE_OLD_NAME_SWITCH}", "$in{$CGI_TREE_NEW_NAME_SWITCH}"); &Print_Tree_Name_Change_Success; } else { &Print_Maint_Top("Error: Can't Change Tree Name", "$IMGSRC_HEADER_TREE"); &Print_Tree_Name_Change_Failure; } } # INPUT: ($tree_name) # Check to see if tree name is legal sub Safe_Tree_Name { local(@names, $name); $name = $_[0]; @names = &List_Tree_Names; $oppRet = (! grep(/^$name$/, @names)); return($oppRet); } sub Print_Tree_Name_Change_Failure { &Print_Error("$ERROR_INFO","Tree \"$in{$CGI_TREE_OLD_NAME_SWITCH}\" Could Not Be Changed To \"$in{$CGI_TREE_NEW_NAME_SWITCH}\"","$STATUS_MINOR"); print "INFORMATION

\n"; print "

\n"; print "The tree $in{$CGI_TREE_OLD_NAME_SWITCH} could not be changed $in{$CGI_TREE_NEW_NAME_SWITCH}."; print "

\n"; print "Use this utility to make further modifications to your trees portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Tree_Forms; } sub Change_Tree_Name { local($tree_path, $tree_file, $tree_name, $tree_old_name, $tree_new_name, $file_list, @custom_list_files); $tree_old_name = shift; $tree_new_name = shift; open(NAMESPACE, "$FILE_TREES_NAMESPACE") || &Print_Error("$ERROR_NO_OPEN", "$FILE_TREES_NAMESPACE", "$STATUS_SERIOUS"); open(TMP_FILE, ">$FILE_NAMESPACE_TMP") || &Print_Error("$ERROR_NO_OPEN", "$FILE_NAMESPACE_TMP", "$STATUS_SERIOUS"); while () { chop; ($tree_name, $tree_path, $tree_file) = /(.*)$TREES_DELIM(.*)$TREES_DELIM(.*)/; $tree_name = "$tree_new_name" if ("$tree_name" eq "$tree_old_name"); print TMP_FILE "$tree_name$TREES_DELIM$tree_path$TREES_DELIM$tree_file\n"; } close(NAMESPACE); close(TMP_FILE); rename("$FILE_NAMESPACE_TMP", "$FILE_TREES_NAMESPACE"); @custom_list_files = &List_Custom_List_Files; grep(($_ = "$PATH_CUSTOM_DIR/$_"), @custom_list_files); $file_list = join(" ", $FILE_DEMOLIST, $FILE_TABLE_FEATURES, $FILE_TABLE_MARKETS, $FILE_TABLE_HARDWARE, $FILE_DEFAULT_LIST, @custom_list_files); `$CMD_PERL $CMD_PERL_FLAGS 's/$tree_old_name/$tree_new_name/g' $file_list`; } sub Make_HTTP_Safe { $tmp = shift; $tmp =~ tr/'";>:INFORMATION

\n"; print "

\n"; print "The tree $in{$CGI_TREE_OLD_NAME_SWITCH} changed its name to $in{$CGI_TREE_NEW_NAME_SWITCH}."; print "

\n"; print "Use this utility to make further modifications to your trees portfolio.\n"; print "

\n"; print "

\n


\n"; &Print_Main_Tree_Forms; } sub Pop_Tree_Demos { $file_name = &Tree_File_From_Name("$in{$CGI_TREE_VIEW_SWITCH}"); $file_name = "$PATH_TREES_DIR/$file_name"; # &Background_Execute("$CMD_XCONFIRM $CMD_XCONFIRM_HEADER \"Demos in $_[0]\" $CMD_XCONFIRM_FILE $file_name $CMD_XCONFIRM_FLAGS "); # `$CMD_XCONFIRM $CMD_XCONFIRM_HEADER \"Demos in $_[0]\" $CMD_XCONFIRM_FILE $file_name $CMD_XCONFIRM_FLAGS $CMD_NULLIFY $CMD_BACKGROUND`; &Print_HTTP_Header("$in{$CGI_TREE_VIEW_SWITCH}"); print "\n"; print "
$in{$CGI_TREE_VIEW_SWITCH}
\n"; print "

\n"; print "