#!/usr/bin/perl #--------------------------------------------------- # C R O O K E D B U S H . C O M - Internet TreePad # Designed by Jason Silver. Please don't # remove this copyright notice. Thanks! # # Visit www.crookedbush.com to register this script # Registration is only $10.00 U.S.A Currency. # Includes latest version, updates, support, and more. # #--------------------------------------------------- # User Defined Variables #--------------------------------------------------- # this is the path, not the URL to the TreePad file (make sure it ends with /) # (it's a good idea to place iTreePad in a new directory) $datapath = ''; $image_directory = '/itree/'; # no trailing slash, URL, not path. # this is the password to use for editing your file online $password = 'password'; $folders_open = 1; # Set this to 1 to view all folders open upon first viewing. # this is the body info which gives your iTreePad the right 'look.' $background_image = ""; $background_color = "white"; $visited_link_color = "#990000"; $text_color = "#000000"; $link_color = "#cc0000"; $active_link_color = "#cc0000"; $title_image_location = 'logo_itree.gif'; $image_description = 'xxcªº¾\Ūµ§°O'; $home_page = 'http://www.xxc.idv.tw/itree/'; # full url link for left pane $home_page_text = 'http://www.xxc.idv.tw/itree/ '; $CSS_style = 'style.css'; # S T O P E D I T I N G - Y O U ' R E A L L S E T ! #___________________________________________________ #--------------------------------------------------- # Program #--------------------------------------------------- print "Content-type: text/html\n\n"; # set up print type for browser $copyright_year = "2000"; $version = "5.03"; #--------------------------------------------------- # READ VARIABLES - take info from web environment #--------------------------------------------------- $referring_page = $ENV{'HTTP_REFERER'}; $url = $ENV{'SERVER_NAME' }; $script_url = $ENV{'SCRIPT_NAME' }; #--------------------------------------------------- # Parse Form - take info from get ('QUERY_STRING' ?asdjkl=asjkl) #--------------------------------------------------- read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @input_chunks = split(/&/, $buffer); foreach $chunk (@input_chunks) { ($name, $value) = split(/=/, $chunk); $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $FROMWEB{$name} = $value; } # end of foreach @input_chunks = split(/&/, $ENV{'QUERY_STRING'}); foreach $chunk (@input_chunks) { ($name, $value) = split(/=/, $chunk); $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $FROMWEB{$name} = $value; } # end of foreach $chunk if($FROMWEB{'password'} eq $password){ $edit = "true"; } # end of if if($FROMWEB{'password'} eq 'login' ){ &do_login; } # end of if if($FROMWEB{'action'} eq 'save' ){ &save_edit; } # end of if if($FROMWEB{'action'} eq 'search' ){ &search; } # end of if #____________________________________________ # check for a file name in URL (query_string) $treepad_file = $FROMWEB{'file'}; if ($treepad_file eq ""){ #________________________________________ # no file name? go to subroutine to show # open file dialog &list_directory; &open_dialog; } # end of of $treepad_file eq "" #_________________________________________ # set folder level to 0 for the JavaScript $folder_level = 0; #___________________________ # set spacing string length $spacing_nbsp = '    '; #____________________ # Fill TreePad array &open_file; #--------------------------------------------------- # If ?link= contains data, then print that data page. #--------------------------------------------------- if ($FROMWEB{'link'} ne ""){ &print_link_data; } # end of from web link #________________________ # Set up Title, Div, etc. if ($folders_open == 1){ $folder_display_status = ""; } else{ $folder_display_status = "None"; } &print_header_html; #------------------------------------------- # Go line by line #------------------------------------------- for $count (0..$#treepad_line){ chomp($treepad_line[$count]); # remove carriage returns from end of line if ($treepad_line[$count] eq ""){ &print_node; } # end of if $treepad_line[$count] eq "" } # end of for $count (1..$#treepad_line) #____________________________ # Now print HTML ending tags print ""; exit; #------------------------------------------- # SUB Print Node #------------------------------------------- sub print_node{ $level = $count + 2; #___________________________________ # Set up ID tags for JavaScript to work $folder_level_i = "Out$folder_level i"; $folder_level_i =~ s/ //; $folder_level_s = "Out$folder_level s"; $folder_level_s =~ s/ //; $folder_level_t = "Out$folder_level t"; $folder_level_t =~ s/ //; $folder_level_top = "Top$folder_level"; #________________________________ # Figure out indentation spacing $indent_factor = $treepad_line[$level] + 1; #__________________ # Now print indent $indent = 0; print "\n"; while ($indent < $indent_factor){ print $spacing_nbsp; $indent++; } # end of while $count < $indent_factor print"\n"; #_________________________________ # Calculate Link info for tag $target_link = $folder_level+1; chomp ($treepad_line[$count+1]); &find_child; #_________________________________ # Print Folder and link to browser if($child eq "false"){ print <  $treepad_line[$count+1]
HTML } # end of if child is false else { print <  $treepad_line[$count+1]
HTML } # end of else &count_and_print_divs; $folder_level++; } # end of sub print_node #--------------------------------------------------- # Determine if has children #--------------------------------------------------- sub find_child{ $child = "true"; #__________________________________ # Look ahead to find the next node. $a = $count + 1 ; # Don't want to count the current "" for $new_count ($a..$#treepad_line){ chomp ($treepad_line[$new_count]); if ($treepad_line[$new_count] eq ""){ $new_level = $new_count + 2; #_______________________________________________________ # If the node has a lower number, it doesn't have a child. # Print a
, then subtract parent number from child # number and print that many additional
s # If the next number is equal, just print a if ($treepad_line[$new_level] <= $treepad_line[$level]){ # That Node has no children $child = "false"; } # end of while $divs_to_print < 0 $done = 1; if ($done == 1){ last; } # end of if done } # end of if found if ($done == 1){ last; } # end of if done } # end of for $new_count if ($done == 0){ $child = "false"; } $done = 0; } # end of sub find child #--------------------------------------------------- # Count and Print #--------------------------------------------------- sub count_and_print_divs{ #__________________________________ # Look ahead to find the next node. $a = $count + 1 ; # Don't want to count the current "" for $new_count ($a..$#treepad_line){ chomp ($treepad_line[$new_count]); if ($treepad_line[$new_count] eq ""){ $new_level = $new_count + 2; #_______________________________________________________ # If the node has a lower number, it doesn't have a child. # Print a , then subtract parent number from child # number and print that many additional s # If the next number is equal, just print a if ($treepad_line[$new_level] > $treepad_line[$level]){ # Higher level, so don't print a and stop loop. $done = 1; } # end of if if ($treepad_line[$new_level] == $treepad_line[$level]){ # Same level, so print a and stop loop. print "\n"; $done = 1; } # end of if if ($treepad_line[$new_level] < $treepad_line[$level]){ # That Node has no children so print a print "\n"; # Now calculate how many additional to print $divs_to_print = $treepad_line[$level] - $treepad_line[$new_level]; while ($divs_to_print > 0){ print "\n"; $divs_to_print = $divs_to_print - 1; } # end of while $divs_to_print > 0 $done = 1; $divs_to_print = 0; } # end of if if ($done == 1){ last; } # end of if done } # end of if found if ($done == 1){ last; } # end of if done } # end of for $new_count $done = 0; } # end of sub count_and_print_divs #--------------------------------------------------- # SUB Print Link Data #--------------------------------------------------- sub print_link_data{ print < $treepad_line[2] HTML for $count (0..$#treepad_line){ chomp($treepad_line[$count]); # remove carriage returns from end of line if ($treepad_line[$count] eq ""){ $folder_level++; if ($folder_level == $FROMWEB{'link'}){ &show_info; } # end of if } # end of if $treepad_line[$count] eq "" } # end of for $count (1..$#treepad_line) } # end of sub print_link_data #--------------------------------------------------- # Print Text to Browser #--------------------------------------------------- sub show_info{ $line_break = "
"; #_______________________ # Display Node Heading $view_down_node = $FROMWEB{'link'} + 1; $view_up_node = $FROMWEB{'link'} - 1; # TEMP $id = "Out$FROMWEB{'link'} s"; $id =~ s/ //; print < Powered by CrookedBush.com
and FreeByte.com
Search | Hide Tree | Show Tree | View Up Node | View Next Node | Edit
$treepad_line[$count+1]
HTML if ($edit eq "true"){ print "

Title:
"; print "

HTML } # End if if $edit eq true #____________________________ # Now print HTML ending tags print < HTML exit; } # end of sub #------------------------------------------- # Check For Node Link #------------------------------------------- sub check_for_node_link{ @check_for_links = split(/\"/, $treepad_line[$i]); foreach $item (@check_for_links){ #_______________________ # take out the 'node://' $item =~ s/node:\/\///; #____________________________________________ # now split the rest of the link on the slash @node_breakdown = split (/\//, $item); #________________ # Reset Variables $link_number = 0; $id = 0; $start_point = 0; #___________________________________ # now follow the link down the file. for $c ($start_point..$#treepad_line){ chomp($treepad_line[$c]); # remove carriage returns from end of line if ($treepad_line[$c] eq ""){ $link_number++; if ($treepad_line[$c+1] eq $node_breakdown[$id]){ # Found child $id++; $start_point = $c; if ($id == scalar(@node_breakdown)){ last; } # end of if } # end of if } # end of if } # end of for $c } # end of foreach $item } # end of sub check_for_node_link #------------------------------------------- # SUB Print Header HTML #------------------------------------------- sub print_header_html{ print < $treepad_line[2] HTML if (($FROMWEB{'self'} != 1) and ($FROMWEB{'hide'} ne "true")){ if ($FROMWEB{'self'}){ $link_for_main_window = $FROMWEB{'self'}; } # end of if else { $link_for_main_window = 1; } # end of else print < <body> <font face="Tahoma, Arial"><b>This TreePad Browser requires frame compatibility, but your browser doesn't understand them. </b></font> </body> HTML }# end of if print <
$image_description
$home_page_text


HTML } # end of sub print_header_html #--------------------------------------------------- # sub Login - Display Password Box #--------------------------------------------------- sub do_login{ print < Password Login


Please enter a valid password:

 




HTML exit; } # End of sub login #--------------------------------------------------- # Search Directory for HJT Files #--------------------------------------------------- sub list_directory{ opendir (FILELIST, "$datapath"); rewinddir (FILELIST); @dirlist = grep(!/^\.\.?$/, readdir (FILELIST)); closedir (FILELIST); $num_in_dir = @dirlist; # the number of items in @dirlist $counter = 0; while ($num_in_dir > $counter) { @check = split(/\./, $dirlist[$counter]); if (($check[1] eq "hjt")|($check[1] eq "HJT")){ push (@directory, $dirlist[$counter]); } # end of if $counter++; } # end of while } # end of sub list_directory #--------------------------------------------------- # Display 'open file' dialog if multiple files exist #--------------------------------------------------- sub open_dialog{ # @durectory contains all HJT files on server. if (scalar(@directory) > 1){ print < Choose TreePad File


Please select a file:
HTML foreach $item(@directory){ print " $item
\n"; } # end of foreach $item print <

 




HTML exit; } # end of if $#directory > 1 else { $treepad_file = $directory[0]; } # end of else }# end of sub open_dialog #--------------------------------------------------- # Open File on Server #--------------------------------------------------- sub open_file{ open (server_file, "$datapath$treepad_file") or &dienice("I can't open the TreePad file: $datapath$treepad_file.
Error Code: $!"); @treepad_line = ; $FROMWEB{'file'} = $treepad_file; close (server_file); } # end of sub open_file #--------------------------------------------------- # Save File to Server #--------------------------------------------------- sub save_edit{ $treepad_file = $FROMWEB{'file'}; &open_file; #______________________________________ # Count Nodes to find $FROMWEB{'LINK'} $count_node = 0; for $edit_node_line_number (0..$#treepad_line){ chomp($treepad_line[$edit_node_line_number]); # remove carriage returns from end of line if ($treepad_line[$edit_node_line_number] eq ""){ $count_node++; if ($count_node == $FROMWEB{'link'}){ &replace_node; exit; } # end of if $count_node... } # end of if $treepad_line[$count] eq "" } # end of for $count (1..$#treepad_line) print < Error - Node not found Looking for node number $FROMWEB{'link'} Search loop got to node $count_node Variables: Treepad Line Length: $#treepad_line - this should be the number of lines in the treepad file. Edit Node Line Number: $edit_node_line_number - this is how many lines were counted through during the search Actual Treepad File: @treepad_line HTML exit; } # end of sub save_edit sub replace_node{ # $edit_node_line_number is the line number to replace with new edits. # $FROMWEB{'edited_text'} contains new edits to replace. # We need to insert the edits at $treepad_line[$edit_node_line_number], # and then empty all the lines after $edit_node_line_number until we come # to #_________________________________________ # First Step: find 5P9i0s8y19Z. $done = 0; for $endnode_line_number ($edit_node_line_number..$#treepad_line){ chomp($treepad_line[$endnode_line_number]); # remove carriage returns from end of line if ($treepad_line[$endnode_line_number] eq " 5P9i0s8y19Z" && $done == 0){ # Found , # so now place edited data in position at $edit_node_line_number + 1. $treepad_line[$edit_node_line_number + 1] = "$FROMWEB{'node_title'}\n$FROMWEB{'child_number'}\n$FROMWEB{'edited_text'}\n 5P9i0s8y19Z"; # Now empty the treepad lines up to the which we found at $endnode_line_number. $later_text = $endnode_line_number + 1; for $count ($edit_node_line_number + 2..$#treepad_line){ $treepad_line[$count] = $treepad_line[$later_text]; chomp $treepad_line[$count]; $later_text++; }#end of for. $done = 1; } # end of if $treepad_line[$count] eq "" } # end of for $count (1..$#treepad_line) # Now save @treepad_line to server as the new treepad file. $file = join("\n", @treepad_line); open (server_file, ">$datapath$treepad_file") or &dienice("I can't open the TreePad file: $datapath$treepad_file.
Error Code: $!"); print server_file "$file"; close (server_file); #------------------------------------- # Print save confirmation to browser print < Changes Have Been Saved.

Edit Saved

Your changes have been saved on the server.
Click here to view your changes.

HTML exit; } # end of sub replace_node #--------------------------------------------------- # Search Definitions #--------------------------------------------------- # 1. Find a Node # 2. Search it for keyword # 3. Display positive results (if any) using node number # with a link to start search from these results # for next results. sub search{ #____________________ # Display Search Box print < Search iTreePad
$image_description
Search Form

Type your search here:

HTML if ($FROMWEB{'search'} eq ""){exit;} #___________ # Open File $treepad_file = $FROMWEB{'file'}; &open_file; #______________________________ # Prepare Variables for search $FROMWEB{'search'} =~ tr/[A-Z]/[a-z]/; # changes case of search from upper to lower chomp($FROMWEB{'search'}); # remove trailing returns @results = (); # empty results variable #_______________ # Begin looking $joined_array = join("\n",@treepad_line); @search_array = split(/\ 5P9i0s8y19Z/, $joined_array); $start=$FROMWEB{'start'}+1; for $node ($start..$#search_array){ $look = grep(/$FROMWEB{'search'}/i,$search_array[$node]); if($look){ $link = $node + 1; $search_array[$node] =~ tr/[A-Z]/[a-z]/; # changes case of search from upper to lower $search_array[$node] =~ s/$FROMWEB{'search'}/$FROMWEB{'search'}<\/b><\/font>/; print < Next Results | Display Node
HTML print $search_array[$node]; print <
HTML exit; } } print "

No Results
"; $totalresults = scalar(@results); exit; } # end of sub search #--------------------------------------------------- # Upload files To Sever #--------------------------------------------------- sub upload_HJT_file{ } # End of sub upload_HJT_file #--------------------------------------------------- # dienice # Displays error messages (beautify this later) #--------------------------------------------------- sub dienice { my($errmsg) = @_; print <

$errmsg

\n


HTML exit; } # End of sub dienice