#!/usr/bin/perl require("cgilib.pl"); $addurl = "http://ind.ntou.edu.tw/home/addhomepage.html"; $filename = "/home/admin/www/htdocs/home/addhomepage.html"; $linksurl = "http://ind.ntou.edu.tw/home/main.html"; $linkscgi = "/cgi-bin/addhomepage.pl"; $linkstitle = "http://ind.ntou.edu.tw/home/images/back1.gif"; # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<([^>]|\n)*>//g; $value =~ s///g; $FORM{$name} = $value; } # check input data if ($FORM{'url'} eq 'http://ind.ntou.edu.tw/~' || $FORM{'url'} !~ /^http:\/\/\w+\.\w+/) { &no_url; } if ($FORM{'url'} !~ /ntou.edu.tw/) { &no_ntou; } if (!($FORM{'title'})) { &no_title; } # check exist if in ind if ($FORM{'url'} =~ /\/$/) {chop($FORM{'url'});} if ($FORM{'url'} =~ m|^http://ind\.ntou\.edu\.tw/(.*)$|) { $info=$1; if ($info =~ /^~(\w+)(.*)$/) { my $home=(getpwnam($1))[7]; if ($home eq "") {Output("Error username", "在 ind 上找不到 $1 這個帳號哦", "你要填正確的 URL 才行");} my $path="$home/www$2"; # if ($path =~ /\/$/) {chop($path);} unless (-f $path) { unless (-f "$path/index.htm" || -f "$path/index.html" || -f "$path/welcome.htm" || -f "$path/welcome.html") { Output("Error URL", "找不到你的 homepage 哦", "請檢查看看是不是填錯了"); } } } else { Output('Error format', '你必須使用', 'http://ind.ntou.edu.tw/~username', '這樣的格式才行。'); } } # read data file and put date to array @lines open(FILE,"$filename") || die Output("ERROR","Cannot open file: $filename"); @lines = ; close(FILE); # find repeat url foreach $line (@lines) { if ($line =~ /$FORM{'url'}/) { &repeat_url; } } # Open Link File to Output open (FILE,">$filename") || die Output("ERROR","Cannot open file: $filename"); foreach $line (@lines) { # For every line in our data print FILE $line; if ($line =~ // ) { print FILE "
  • $FORM{'title'}"; print FILE `/bin/date +""`; } } close (FILE); # Return Link File #print "Location: $linksurl\n\n"; &PrintHeader; print<<"end";

    謝謝你的登錄


    你的Homepage名稱是:$FORM{'title'}

    你的網址是:$FORM{'url'}


    注意喔!若沒有看見記得要按 Reload 喔! end sub no_url { &PrintHeader; print <<"end"; 你沒填入網址啦!

    你沒填入網址啦!


    你沒有填入網址啦!一定要填入喔!不然大家看不見你的Homepage喔! 而且一定要正確,不然是連不過去的啦!

    網址:

    *


    end exit; } sub no_ntou { &PrintHeader; print <<"end"; 本網頁只提供海大師生登錄

    本網頁只提供海大師生登錄


    對不起,本網頁只提供海大師生登錄,若是填錯,請從填過。
    網址:

    *


    end exit; } sub no_title { &PrintHeader; print << "end"; 沒說明檔

    你沒有填入說明檔啦!


    你忘記填入說明檔了,一定要記得喔!不然是會看不到的啦!

    說明:

    *


    end exit; } sub repeat_url { &PrintHeader; print << "end"; 重覆填入了

    重覆填入了啦!


    對不起,在資料檔中,已經有了你的網址了 你不可以重覆登錄 Homepage,若有問題請 mail root\@ind.ntou.edu.tw


    end exit; }