웹마스터 팁

계정 추가하는 부분입니다.
편리님이 만드신 부분에 계정 쿼터부분 조금 업데이트하였습니다.

#File Name : adduser.sh
#!/bin/bash
# Usage : ./adduser.sh id password e-mail
# 2002/11/3 최초 작성 (created by 편리)
# 2002/11/4 제로보드 설치지원 추가,
#                메일보내기 지원, 안내페이지 변경, 사용자 체크
# 2002/12/4 (updated by mildsoft, powerjava )
# 날짜와 시간 얻기
dateis=$(date -I)
timeis=$(date | awk '{print $4}')

# 사용자 계정 생성 ( 사용자 체크 )
# public_html 은 /etc/skel/ 에 위치해서 계정생성시 자동으로 생성
# public_html 퍼미션은 /etc/skel 생성 후 퍼미션 지정 해주면 지정해준 퍼미션으로 생성됨
# user 추가시 해당 유저 디렉토리 퍼미션은 /etc/login.defs 에 UMASK    076 을 추가해 퍼미션이701 로 생성  된다.

        if useradd -g hosting $1
        then
        echo $2 | /usr/bin/passwd --stdin $1

# 제로보드 설치 지원
#        echo -n "Zeroboard Install - [Y/N](default N) : "
#        read zero
#        if [ "$zero" = "y" ] || [ "$zero" = "Y" ]; then
#                 cp -R /home/참조할계정/public_html/bbs/ /home/$1/public_html/
#                 chmod 707 /home/$1/public_html/bbs
#        fi

# weblogs 디렉토리 생성 (webalizer 실행 결과 출력 디렉토리)
         mkdir /home/$1/public_html/weblogs

# Mysql 에 새로운 DB 를 추가합니다.
        touch /tmp/mysql_dbusersetup_temp
        echo "create database $1;" >> /tmp/mysql_dbusersetup_temp
        echo "insert into db values('localhost','$1','$1','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');" >> /tmp/mysql_dbusersetup_temp
        echo "insert into user values('localhost','$1',password('$2'),'N','N','N','N','N','N','N','N','N','N','N','N','N'+ ','N');" >> /tmp/mysql_dbusersetup_temp
        /usr/bin/mysql -u root -p@비번 mysql < /tmp/mysql_dbusersetup_temp
        rm -f /tmp/mysql_dbusersetup_temp
        /usr/bin/mysqladmin -u root -p@비번 reload

# quota 설정
         edquota -p 참조할계정 `awk -F: '$3 > 499 {print $1}' /etc/passwd`

# 아파치 가상호스트 추가 (httpd.conf 마지막에 include conf/vhost.conf 추가 )
         echo " " >> /etc/httpd/conf/ezca.conf
         echo "<VirtualHost 211.214.161.67>" >> /etc/httpd/conf/ezca.conf
         echo "    ServerAdmin $3" >> /etc/httpd/conf/ezca.conf
         echo "    DocumentRoot /home/$1/public_html" >> /etc/httpd/conf/ezca.conf
         echo "    ServerName  $1.ezca.net" >> /etc/httpd/conf/ezca.conf
         echo "    ThrottlePolicy Volume 1000M 1d" >> /etc/httpd/conf/ezca.conf
         echo "    ErrorLog /var/weblog/$1-error_log" >> /etc/httpd/conf/ezca.conf
         echo "    CustomLog /var/weblog/$1-access_log common env=!not_log" >> /etc/httpd/conf/ezca.conf
         echo "</VirtualHost>" >> /etc/httpd/conf/ezca.conf

# 사용자별 Webalizer 설정
        echo "LogFile        /var/weblog/$1-access_log" >> /etc/webalizer/$1-webalizer.conf
        echo "LogType   clf" >> /etc/webalizer/$1-webalizer.conf
        echo "OutputDir      /home/$1/public_html/weblogs" >> /etc/webalizer/$1-webalizer.conf
        echo "HistoryName       webalizer.hist" >> /etc/webalizer/$1-webalizer.conf
        echo "Incremental       yes" >> /etc/webalizer/$1-webalizer.conf
        echo "IncrementalName   webalizer.current" >> /etc/webalizer/$1-webalizer.conf
        echo "HostName       $1.ezca.net" >> /etc/webalizer/$1-webalizer.conf
        echo "PageType  htm*" >> /etc/webalizer/$1-webalizer.conf
        echo "PageType  cgi" >> /etc/webalizer/$1-webalizer.conf
        echo "PageType  php" >> /etc/webalizer/$1-webalizer.conf
        echo "PageType  php3" >> /etc/webalizer/$1-webalizer.conf

        echo "/usr/bin/webalizer -c /etc/webalizer/$1-webalizer.conf" >> /root/webalizer.cron
       chmod 755 /home/$1/public_html/weblogs
# 안내페이지( index.html) 생성
# /etc/skel/public_html 에 index.html 과 gif 파일 위치
# index.html 파일에 아래 안내페이지 내용 전의 tag 는 이미 포함되어 있음
# 아래 내용은 그 다음부터 추가되는 것임

        echo "                 <td><p><b>EZCA의 가족이 되신 것을 진심으로 축하드립니다!!<br>" >> /home/$1/public_html/index.html
        echo "                          현재($dateis $timeis) $1 님의 계정 세팅 작업이 완료되었습니다.<br>" >> /home/$1/public_html/index.html
        echo "                          아래 내용은 신청하신 정보입니다.</b><br><br>" >> /home/$1/public_html/index.html
        echo "                          ID : $1 / 신청하신 Password / E-mail : $3<br>" >> /home/$1/public_html/index.html
        echo "                          웹주소 : http://$1.ezca.net<br>" >> /home/$1/public_html/index.html
        echo "                          FTP : ftp.ezca.net / SSH : ssh.ezca.net <br>" >> /home/$1/public_html/index.html
      #  if [ "$zero" = "y" ] || [ "$zero" = "Y" ]; then
      #  echo "                          제로보드 설치지원 : <a
#href=http://$1.ezca.net/bbs/install.php target=_blank>제로보드설치</a><br><br>" >>
#/home/$1/public_html/index.html
#       else
        echo "                          <br>" >> /home/$1/public_html/index.html
  #      fi
        echo "                          <b>기타 문의 사항은 </b><a href=http://ezca.net><b>http://ezca.net</b></a><b> 을 방문해 주시기 바랍니다</b></p>" >> /home/$1/public_html/index.html
        echo "                          </td>" >> /home/$1/public_html/index.html
        echo "              </tr>" >> /home/$1/public_html/index.html
        echo "            </table>" >> /home/$1/public_html/index.html
        echo "          </td>" >> /home/$1/public_html/index.html
        echo "          <td bgcolor=#76CBED width=1></td>" >> /home/$1/public_html/index.html
        echo "        </tr>" >> /home/$1/public_html/index.html
        echo "        <tr>" >> /home/$1/public_html/index.html
        echo "          <td colspan=3><img src=title_error02.gif width=586 height=9 border=0></td>" >> /home/$1/public_html/index.html
        echo "        </tr>" >> /home/$1/public_html/index.html
        echo "      </table>" >> /home/$1/public_html/index.html
        echo "     </td>" >> /home/$1/public_html/index.html
        echo "  </tr>" >> /home/$1/public_html/index.html
        echo "</table>" >> /home/$1/public_html/index.html
        echo "        </td>" >> /home/$1/public_html/index.html
        echo "    </tr>" >> /home/$1/public_html/index.html
        echo "</table>" >> /home/$1/public_html/index.html
        echo " </body>" >> /home/$1/public_html/index.html
        echo "</html>" >> /home/$1/public_html/index.html
        chmod 755 /home/$1/public_html/index.html  
# 계정 발급 완료 메일 보내기
        title="계정 발급 안내 입니다."          # 메일 제목

        echo " 계정 발급 및 세팅이 완료되었습니다." > /tmp/contents         # 보낼 메일 내용
        echo " ==================================" >> /tmp/contents      # 보낼 메일 내용
        echo " 계정 세팅이 완료 되었습니다. ($dateis $timeis)" >> /tmp/contents
        echo " 아래는 신청하신 정보입니다. 확인해보세요." >> /tmp/contents
        echo " 확인 후 일치하지 않으면 메일 (mildsoft@korea.com) 주세요.</b>" >> /tmp/contents
        echo " " >> /tmp/contents
        echo " ID : $1" >> /tmp/contents
        echo " PASS : $2" >> /tmp/contents
        echo " e-mail : $3" >> /tmp/contents
        echo " " >> /tmp/contents
        echo " WEB주소 : http://$1.ezca.net" >> /tmp/contents
        echo " FTP주소 : ftp.ezca.net " >> /tmp/contents
        echo " SSH주소 : ssh.ezca.net " >> /tmp/contents
        echo " " >> /tmp/contents
        echo " 웹주소로 접속하면 안내페이지를 보실 수 있습니다." >> /tmp/contents
        echo " " >> /tmp/contents
        echo " 트래픽 보기 : http://$1.ezca.net/throttle-me">>/tmp/contents
        echo " " >>/tmp/contents
        echo " DB 관리: http://$1.ezca.net/phpMyAdmin/">>/tmp/contents
        echo " " >>/tmp/contents
        echo " DB 아이디와 패스워드는 계정 과 동일합니다.">>/tmp/contents
        echo " " >>/tmp/contents
    
        echo " 기타 궁금하신 점은 http://ezca.net 을 방문해주세요." >> /tmp/contents

        cat /tmp/contents >> /tmp/data.txt
        rm -f /tmp/contents

        mail -s "$title" $3 < /tmp/data.txt
        rm -f /tmp/data.txt

# 아파치 서버 재 구동
         /etc/init.d/httpd restart

        exit 0

         else
         echo " User $1 already exist!!"
         exit 1

        fi
계정 삭제하는 부분입니다.
위에 소스랑 연동됩니다.
#!/bin/bash
# Usage : ./deluser.sh id email
# Create by mildsoft ( mildsoft@korea.com)
# 2002/12/2 최초 작성

# 날짜와 시간 얻기
dateis=$(date -I)
timeis=$(date | awk '{print $4}')

# 사용자 계정 삭제

     if userdel -r $1
     then

         clear
         echo ">> UserDEL Setting Ok!!"
         echo "----------------------------------------------------------"


# Mysql 에 있는 DB 삭제.
        touch /tmp/mysql_dbusersetup_temp
        echo "drop database $1;" >> /tmp/mysql_dbusersetup_temp
        echo "delete from db where Db = '$1';" >> /tmp/mysql_dbusersetup_temp
        echo "delete from user where User = '$1';" >> /tmp/mysql_dbusersetup_temp
        /usr/bin/mysql -u root -p@비번 mysql < /tmp/mysql_dbusersetup_temp
        rm -f /tmp/mysql_dbusersetup_temp
        /usr/bin/mysqladmin -u root -p@비번 reload


# 아파치 가상호스트 추가 (httpd.conf 마지막에 include conf/ezca.conf 추가 )
        php -q deluser.php login=$1

# 사용자별 Webalizer 설정
                rm -f /etc/webalizer/$1-webalizer.conf
                
# 안내페이지( index.html) 생성
# /etc/skel/public_html 에 index.html 과 gif 파일 위치
# index.html 파일에 아래 안내페이지 내용 전의 tag 는 이미 포함되어 있음
# 아래 내용은 그 다음부터 추가되는 것임

# 계정 발급 완료 메일 보내기
        title="계정 삭제 통보 입니다."          # 메일 제목

        echo " 계정 삭제가 완료되었습니다." > /tmp/contents         # 보낼 메일 내용
        echo " ==================================" >> /tmp/contents      # 보낼 메일 내용
        echo " 계정이 삭제되었습니다. ($dateis $timeis)" >> /tmp/contents

        cat /tmp/contents >> /tmp/data.txt
        rm -f /tmp/contents

        mail -s "$title" $2 < /tmp/data.txt
        rm -f /tmp/data.txt

# 아파치 서버 재 구동
         /etc/init.d/httpd restart

        exit 0

         else
         echo " User $1 already deleted!!"
         exit 1

        fi

php script 부분입니다.
apache 모듈로 인스톨되어서 php 명령어가 안먹히면
lynx를 통해서 강제실행시키세요 ^^

#!/usr/local/bin/php -q
<?php
// Create by mildsoft ( mildsoft@korea.com)

        function get_commandline()
        {
                global $argc, $argv;
        
                for ($i=0; $i<$argc; $i++)
                {
                        $my_args = array();
                        if (ereg("(.*)=(.*)", $argv[$i], $my_args))
                        {
                        $GLOBALS[$my_args[1]] = $my_args[2];
                        }
                }
        }

        function zWriteFile($filename, $str) {
                $f = fopen($filename,"w");
                $lock=flock($f,2);
                if($lock) {
                        fwrite($f,$str);
                }
                flock($f,3);
                fclose($f);
        }
        
        get_commandline();

        $vhost_path = "/etc/httpd/conf/ezca.conf";
        $domain_name = ".ezca.net";
        
        $f=fopen($vhost_path,"r");
        $vhost = fread($f,filesize($vhost_path));
        fclose($f);

        list($front_part,$end_part) = split("$login$domain_name",$vhost);

        $arr_front = split('<VirtualHost',$front_part);
        $cnt_front = count($arr_front);
        $tar_front = '<VirtualHost'.$arr_front[$cnt_front-1];

        $arr_end = split('</VirtualHost>',$end_part);
        $tar_end = $arr_end[0].'</VirtualHost>';

        $tar_ref = "$tar_front$login$domain_name$tar_end";
        $result_ref = eregi_replace("n$tar_ref","",$vhost);
        
        zWriteFile($vhost_path, $result_ref);

        $webcron_path = "/root/webalizer.cron";
        $f=fopen($webcron_path,"r");
        $webcron = fread($f,filesize($webcron_path));
        fclose($f);

        $result_ref2 = eregi_replace("n/usr/bin/webalizer -c /etc/webalizer/$login-webalizer.conf","",$webcron);

        zWriteFile($webcron_path, $result_ref2);
?>
제목 글쓴이 날짜
리눅스 보안 : 기초적인 방화벽 : portsentry 설치하기 [2] 정인배 2002.11.29
cron을 이용한 자동 백업 받기 최종우 2002.12.02
cron과 rsync 그리고 replication 을 이용한 데이터 백업 [3] 최종우 2002.12.03
FTP 를 이용한 원격 백업 받기 [5] 최종우 2002.12.04
[계정삭제 스크립터] 편리님이 만드신 계정추가랑 연동됩니다. [4] file 김동현 2002.12.04
[FreeBSD] 자동으로 시간 맞추기.. [1] DeX™ 2002.12.04
계정 등록 스크립트 [8] 편리 2002.12.05
오래간만에 찾아뵙는군요^^ [2] Dopesoul 2002.12.08
Zend Optimizer Full Pass Setup [3] DukeEYS 2002.12.08
mod_gzip 적용시 php 인클루드를 실패해서 포기하신분 보세요 [2] DukeEYS 2002.12.08
apache2 + mod_jk 100번의 닭질 끝에 찾아가는 사이트 DukeEYS 2002.12.09
[FreeBSD] Proftp + MySQL 연동 설치하기 [2] file DeX™ 2002.12.09
레드햇(redhat)리눅스에서 rpm 관리 명령어 정인배 2002.12.09
srpms, alpha, i386 , i686 이 의미하는 것은? [1] Dopesoul 2002.12.12
누군가 우리서버를 공격하고 있을때 응급처치! [13] Dopesoul 2002.12.13
[re] 저의 최종의견 입니다. [5] Dopesoul 2002.12.17
SetEnvIf 와 SetEnvIfNocase 의 차이 [7] Dopesoul 2002.12.13
DeX 님의 시간 동기화 스크립트를 편하고 안정적으로 변경한 리눅스용! [4] Dopesoul 2002.12.13
리눅스 rpm 명령어 활용(1): MRTG 설치 정인배 2002.12.14
PHP 4.2.3 파워 설치 테크닉 (에러 0%에 도전) [2] 밍밍이 2002.12.17