Guest User

Untitled

a guest
May 22nd, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # =============================================
  4. #  Dafturn Ofris Erdana - Locking your System
  5. # =============================================
  6. # Version       : 1.9.05-en
  7. # Created by    : Muhammad Faruq Nuruddinsyah
  8. # E-Mail        : faruq@dafturn.org
  9. # Created date  : October, 12th 2008
  10. # =============================================
  11. # An Open Source from Indonesia
  12. # =============================================
  13.  
  14. # =============================================
  15. # Modified by:   Kelompok 4 OSSDev Fasilkom UI
  16. # Modified date: May, 27th 2015
  17. #
  18. # Added features:
  19. #  - Password protection
  20. #  - Set or clear Ofris password
  21. # =============================================
  22.  
  23. #----- Starting ----
  24. echo
  25. echo "==================================================="
  26. echo "    Dafturn Ofris Erdana - Locking your System"
  27. echo "         By : Muhammad Faruq Nuruddinsyah"
  28. echo "==================================================="
  29. echo
  30.  
  31. #----- Password protection by Kelompok 4 OSSDev -----
  32. if [ -e .ofris-password ]; then
  33.     ofris_password=$(<.ofris-password)
  34.     echo -n "Type the password: "
  35.     read -s password
  36.     password=$(echo -n "$password" | md5sum | cut -c 1-32)
  37.    
  38.     if [ $password != $ofris_password ]; then
  39.         echo
  40.         echo
  41.         echo "Wrong password!"
  42.         echo
  43.         exit
  44.     fi
  45.    
  46.     echo
  47.     echo
  48. fi
  49.  
  50. echo "Menu:"
  51. echo "  1. Freeze the system for this User only"
  52. echo "  2. Freeze the system for specified User"
  53. echo "  3. Freeze the system for all Users"
  54. echo "  4. Unfreeze the system"
  55. echo "  5. View status"
  56. echo "  6. Set password"
  57. echo "  7. Exit"
  58. echo
  59. #-------------------
  60.  
  61. #----- Mendeklarasikan variabel -----
  62. is_opt=false
  63. is_success=true
  64. ofris_n=6
  65. ofris_tmp_co=1
  66. is_cho=false
  67. #------------------------------------
  68.  
  69. #----- Awal script untuk menentukan pilihan -----
  70. while [ $is_opt = false ]; do
  71.     echo -n "Please type the menu number you want: "
  72.     read ofris_opt
  73.  
  74.     if [[ $ofris_opt = 1 ]]; then
  75.         is_opt=true
  76.         ofris_tmp_co=1
  77.     elif [[ $ofris_opt = 2 ]]; then
  78.         is_opt=true
  79.         ofris_tmp_co=2
  80.     elif [[ $ofris_opt = 3 ]]; then
  81.         is_opt=true
  82.         ofris_tmp_co=3
  83.     elif [[ $ofris_opt = 4 ]]; then
  84.         is_opt=true
  85.     elif [[ $ofris_opt = 5 ]]; then
  86.         is_opt=true
  87.     elif [[ $ofris_opt = 6 ]]; then
  88.     #----- Password protection by Kelompok 4 OSSDev -----
  89.         is_opt=true
  90.     elif [[ $ofris_opt = 7 ]]; then
  91.         is_opt=true
  92.         echo
  93.         exit
  94.     else
  95.         echo "Sorry, you choose wrong menu. Please try again..."
  96.         echo
  97.         is_opt=false
  98.     fi
  99. done
  100. #------------------------------------------------
  101.  
  102. #----- Script utama -----------------------------
  103. if [[ $ofris_tmp_co = 1 ]]; then
  104.     ofris_user="${HOME:$ofris_n}"
  105. elif [[ $ofris_tmp_co = 3 ]]; then
  106.     ofris_user=""
  107. elif [[ $ofris_tmp_co = 2 ]]; then
  108.     is_cho=true
  109.     ofris_user=""
  110. fi
  111.  
  112. grep -v "sudo rsync -a --delete /etc/" /etc/rc.local > ofris_tmp
  113. set $(wc -l ofris_tmp)
  114. ofris_orig=$1
  115. set $(wc -l /etc/rc.local)
  116. ofris_recnt=$1
  117. ofris_rst=$[$ofris_recnt-$ofris_orig]
  118. rm ofris_tmp
  119.  
  120. if [[ $ofris_opt = '1' || $ofris_opt = '2' || $ofris_opt = '3' ]]; then
  121. #----- Mengunci sistem -----
  122.     echo
  123.     echo "===== Freeze the System ====="
  124.     echo
  125.     echo "Please wait..."
  126.     echo
  127.  
  128.     if [[ $is_cho = true ]]; then
  129.         is_cho_suc=false
  130.         while [ $is_cho_suc = false ]; do
  131.             is_cho_suc=false
  132.             echo -n "Please type the username you want to freeze: "
  133.             read ofris_cho
  134.            
  135.             if [ -d "/home/$ofris_cho" ]; then
  136.                 echo
  137.                 is_cho_suc=true
  138.                 ofris_user=$ofris_cho
  139.             else
  140.                 echo "Sorry, the username is wrong. Please try again..."
  141.                 echo
  142.             fi
  143.         done
  144.     fi
  145.  
  146.     if [ $ofris_rst = 1 ]; then
  147.         echo "Error : The system has been frozen."
  148.         echo
  149.         is_success=false
  150.     else
  151.         grep -v "exit 0" /etc/rc.local > ofris_tmp
  152.         echo "sudo rsync -a --delete /etc/.ofris/$ofris_user/ /home/$ofris_user/" >> ofris_tmp
  153.         echo "exit 0" >> ofris_tmp
  154.         sudo rm /etc/rc.local
  155.         sudo cp ofris_tmp /etc/rc.local
  156.         rm ofris_tmp
  157.     fi
  158.  
  159.     if [ $is_success = true ]; then
  160.         if [ -d /etc/.ofris ]; then
  161.             sudo rm -r /etc/.ofris
  162.         fi
  163.        
  164.         if [ -d /etc/.ofris ]; then
  165.             sudo rsync -a --delete /home/$ofris_user /etc/.ofris/
  166.         else
  167.             sudo mkdir /etc/.ofris/
  168.            
  169.             if [[ $ofris_user != "" ]]; then
  170.                 sudo mkdir /etc/.ofris/$ofris_user
  171.             fi
  172.            
  173.             sudo rsync -a --delete /home/$ofris_user /etc/.ofris/
  174.         fi
  175.        
  176.         sudo chmod +x /etc/rc.local
  177.     fi
  178.    
  179.     if [ $is_success = true ]; then
  180.         echo "The system was successfully frozen, please restart your computer to complete..."
  181.         echo
  182.     fi
  183.  
  184. elif [ $ofris_opt = '4' ]; then
  185. #----- Membuka sistem -----
  186.     echo
  187.     echo "===== Unfreeze the System ====="
  188.     echo
  189.     echo "Please wait..."
  190.     grep -v "sudo rsync -a --delete /etc/" /etc/rc.local > ofris_tmp_b
  191.     sudo rm /etc/rc.local
  192.     sudo cp ofris_tmp_b /etc/rc.local
  193.     rm ofris_tmp_b
  194.    
  195.     if [ -d /etc/.ofris ]; then
  196.         sudo rm -r /etc/.ofris
  197.     fi
  198.    
  199.     echo
  200.     echo "The system was successfully unfrozen..."
  201.     echo
  202.  
  203. elif [ $ofris_opt = '5' ]; then
  204. #----- Menampilkan status -----
  205.     if [ $ofris_rst = 1 ]; then
  206.         echo
  207.         echo "===== Status ====="
  208.         echo " The system has been locked..."
  209.         echo
  210.     else
  211.         echo
  212.         echo "===== Status ====="
  213.         echo " The system has not locked yet..."
  214.         echo
  215.     fi
  216.  
  217. elif [ $ofris_opt = '6' ]; then
  218. #----- Password protection by Kelompok 4 OSSDev -----
  219. #----- Set or clear password -----
  220.     echo
  221.     echo "===== Set Password ====="
  222.     echo
  223.     echo -n "Type new password or just hit enter to clear the password: "
  224.    
  225.     read -s new_password
  226.     echo -n "$new_password" > .ofris_tmp_pwd
  227.     password_count=$(wc -m .ofris_tmp_pwd)
  228.     rm .ofris_tmp_pwd
  229.     password_count=${password_count:0:1}
  230.    
  231.     if [[ $password_count = 0 ]]; then
  232.         if [ -e .ofris-password ]; then
  233.             rm .ofris-password
  234.         fi
  235.        
  236.         echo
  237.         echo
  238.         echo "Password successfully removed."
  239.         echo
  240.     else
  241.         hash_password=$(echo -n "$new_password" | md5sum | cut -c 1-32)
  242.         echo -n "$hash_password" > .ofris-password
  243.        
  244.         echo
  245.         echo
  246.         echo "Password successfully changed."
  247.         echo
  248.     fi
  249. fi
  250.  
  251. #----- Ending session -----
  252. echo -n "[Press any key to exit...] "
  253. read -s -n 1
  254. echo
  255. echo
  256.  
  257. #========== Selesai ===================================================================
Add Comment
Please, Sign In to add comment