Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.81 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3.  
  4. #    
  5. #       Copyright 2010 systemoveride <system_overide@live.it>
  6. #      
  7. #       This program is free software; you can redistribute it and/or modify
  8. #       it under the terms of the GNU General Public License as published by
  9. #       the Free Software Foundation; either version 2 of the License, or
  10. #       (at your option) any later version.
  11. #
  12. #       This program is distributed in the hope that it will be useful,
  13. #       but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #       GNU General Public License for more details.
  16. #      
  17. #       You should have received a copy of the GNU General Public License
  18. #       along with this program; if not, write to the Free Software
  19. #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. #       MA 02110-1301, USA.
  21. #
  22.  
  23.  
  24.  
  25.  
  26.  
  27. import os
  28. import ftplib
  29.  
  30. #INIZIO CLASSE COLORI
  31. #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  32. class color:
  33.     PINK = '\033[95m'
  34.     BLUE = '\033[94m'
  35.     GREEN = '\033[92m'
  36.     YELLOW = '\033[93m'
  37.     RED = '\033[91m'
  38.     END = '\033[0m'
  39.  
  40.     def disable(self):
  41.         self.PINK = ''
  42.         self.BLUE = ''
  43.         self.GREEN = ''
  44.         self.YELLOW = ''
  45.         self.RED = ''
  46.         self.END = ''
  47.  
  48. def blue(word) :
  49.     print color.BLUE + word + color.END
  50.  
  51. def pink(word) :
  52.     print color.PINK + word + color.END
  53.    
  54. def green(word) :
  55.     print color.GREEN + word + color.END
  56.  
  57. def yellow(word) :
  58.     print color.YELLOW + word + color.END
  59.    
  60. def red(word) :
  61.     print color.RED + word + color.END
  62.  
  63.  
  64. #FINE CLASSE CLORI
  65. #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. #INIZIO COMANDI DI SISTEMA
  73. #####################################################################################################
  74.  
  75. def menucmd():
  76.     print 'Sei nei comandi di sistema\n'
  77.     blue('[1]Vedi utilizzo RAM\n')
  78.     blue('[2]Vedi utilizzo spazio\n')
  79.     blue('[3]Vedi processi\n')
  80.     blue('[4]Vedi interfaccia di rete\n')
  81.     blue('[5]Riavvia la rete\n')
  82.     blue('[6]Aggiorna pacchetti sistema\n')
  83.     blue('[7]Installa pacchetto\n')
  84.     blue('[8]Mostra opzioni\n')
  85.     blue('[9]Torna indietro\n')
  86.     blue('[0]Esci')
  87.            
  88.  
  89.     while 1:
  90.         cmds=raw_input("\nCommand: \n")
  91.         if cmds=="1":
  92.             showram()
  93.         elif cmds=="2":
  94.             showspace()
  95.         elif cmds=="3":
  96.             processctrl()
  97.         elif cmds=="4":
  98.             netinterface()
  99.         elif cmds=="5":
  100.             netrestart()
  101.         elif cmds=="6":
  102.             update()
  103.         elif cmds=="7":
  104.             install()
  105.         elif cmds=="8":
  106.             yellow('Sei nei comandi di sistema\n')
  107.             blue('[1]Vedi utilizzo RAM\n')
  108.             blue('[2]Vedi utilizzo spazio\n')
  109.             blue('[3]Vedi processi\n')
  110.             blue('[4]Vedi interfaccia di rete\n')
  111.             blue('[5]Riavvia la rete\n')
  112.             blue('[6]Aggiorna pacchetti sistema\n')
  113.             blue('[7]Installa pacchetto\n')
  114.             blue('[8]Mostra opzioni\n')
  115.             blue('[9]Torna indietro\n')
  116.             blue('[0]Esci')
  117.  
  118.         elif cmds=="9":
  119.             menug()
  120.         elif cmds=="0":
  121.             exit()
  122.         else:
  123.             red('Command error')
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.    
  131.        
  132.  
  133.  
  134. def showram():
  135.     command="free -m"
  136.     os.system(command)
  137.  
  138. def showspace():
  139.     command="df -h"
  140.     os.system(command)
  141.  
  142. def processctrl():
  143.     command="top"
  144.     os.system(command)
  145.     KeyboardInterrupt
  146.  
  147. def netinterface():
  148.     command="ifconfig"
  149.     os.system(command)
  150.  
  151. def netrestart():
  152.     command="/etc/init.d/networking restart"
  153.     os.system(command)
  154.  
  155. def update():
  156.     command="apt-get update && apt-get upgrade"
  157.     os.system(command)
  158.  
  159. def install():
  160.     i=raw_input("Inserisci il nome del pacchetto da installare\n")
  161.     command="apt-get install "+i
  162.     os.system(command)
  163.  
  164.  
  165. #FINE COMANDI DI SISTEMA
  166. #####################################################################################################
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. #INIZIO COMANDI FTP
  175. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  176.  
  177.  
  178.    
  179.  
  180.  
  181.      
  182.  
  183. def ftp():
  184.    
  185.     host=raw_input("Insert Host: \n")
  186.     user=raw_input("Insert User: \n")
  187.     pwd=raw_input("Insert Password: \n")
  188.     ftp=ftplib.FTP()
  189.     ftp.connect(host,21)
  190.     if ftp.login(user, pwd):
  191.         yellow('Connect!\n')
  192.         ftp.retrlines('LIST')
  193.         yellow('Sei nella Gestione FTP')
  194.         blue('[1]Mostra file\n')
  195.         blue('[2]New Directory\n')
  196.         blue('[3]Upload File\n')
  197.         blue('[4]Download File\n')
  198.         blue('[5]Cancella File\n')
  199.         blue('[6]Cancella Directory\n')
  200.         blue('[7]Crea directory\n')
  201.         blue('[8]Rinomina file\n')
  202.         blue('[9]Mostra Opzioni\n')
  203.         blue('[0]Disconnect\n')
  204.              
  205.        
  206.     else:
  207.         print "Connect Error.\n"
  208.         blue('[1]Mostra file\n')
  209.         blue('[2]New Directory\n')
  210.         blue('[3]Upload File\n')
  211.         blue('[4]Download File\n')
  212.         blue('[5]Cancella File\n')
  213.         blue('[6]Cancella Directory\n')
  214.         blue('[7]Crea directory\n')
  215.         blue('[8]Rinomina file\n')
  216.         blue('[9]Mostra Opzioni\n')
  217.         blue('[0]Disconnect\n')
  218.              
  219.     while 1:
  220.         cmftp=raw_input(color.YELLOW+user+'@'+host+'~#: '+color.END)
  221.  
  222.         if cmftp=="2":
  223.             ct=raw_input("Percorso directory: \n")
  224.             try:
  225.                 ftp.cwd(ct)
  226.                 print "Succes!"
  227.             except:
  228.                
  229.                 red('Directory not found')
  230.  
  231.         elif cmftp=="1":
  232.             ftp.retrlines('LIST')
  233.  
  234.  
  235.         elif cmftp=="3":
  236.             try:
  237.                 fil=raw_input("Path del file: \n")
  238.                 filefull = os.path.split(fil)[1]
  239.                 file = open(fil,'rb')
  240.                 ftp.storbinary('STOR ' + filefull, file)
  241.                 file.close()
  242.                 print "Uploades Successfull!"
  243.             except:
  244.                 red('Upload Failed')
  245.                
  246.         elif cmftp=="4":
  247.             pt=raw_input("Inserisci la path dove scaricare il file:\n")
  248.             fl2=raw_input("Inserisci il nome del file:\n")
  249.             try:
  250.                 os.chdir(pt)
  251.                 output=open(fl2, 'wb')
  252.                 ftp.retrbinary("RETR " + fl2, output.write)
  253.                 output.close()
  254.                 print "File "+fl2+" scaricato nella cartella "+pt
  255.             except:
  256.                 red('Download Error!')
  257.  
  258.                
  259.         elif cmftp=="5":
  260.             kill=raw_input("File da eliminare:\n")
  261.             try:
  262.                
  263.                ftp.delete(kill)
  264.                print "File "+kill+" eliminato."
  265.             except:
  266.                 red('Removal Failed')
  267.                
  268.  
  269.  
  270.         elif cmftp=="6":
  271.             di=raw_input("Inserisci la direcotry da eliminare:\n")
  272.             try:
  273.                 ftp.rmd(di)
  274.                 print "Directory "+di+" eliminata."
  275.             except:
  276.                 red('Delete Error')
  277.  
  278.  
  279.         elif cmftp=="7":
  280.             mk=raw_input("Nome della directory da creare:\n")
  281.             try:
  282.                 ftp.mkd(mk)
  283.                 print "Creata directory con il nome "+k
  284.             except:
  285.                 red('Error directory creation')
  286.  
  287.      
  288.  
  289.         elif cmftp=="8":
  290.             fr=raw_input("File da rinominare:\n")
  291.             nm=raw_input("Nuovo nome:\n")
  292.             try:
  293.                 ftp.rename(fr, nm)
  294.                 print "File "+fr+" rinominato in "+nm
  295.             except:
  296.                 red('Rename Error')
  297.  
  298.         elif cmftp=="9":
  299.            
  300.            
  301.             yellow('Comandi FTP')
  302.             blue('[1]Mostra file\n')
  303.             blue('[2]New Directory\n')
  304.             blue('[3]Upload File\n')
  305.             blue('[4]Download File\n')
  306.             blue('[5]Cancella File\n')
  307.             blue('[6]Cancella Directory\n')
  308.             blue('[7]Crea directory\n')
  309.             blue('[8]Rinomina file\n')
  310.             blue('[9]Mostra Opzioni\n')
  311.             blue('[0]Disconnect\n')
  312.  
  313.         elif cmftp=="0":
  314.             ftp.close()
  315.             print "Disconnect"
  316.             menug()
  317.  
  318.            
  319.         else:
  320.             red('Command Error')
  321.  
  322.        
  323.  
  324.  
  325.  
  326.  
  327. #FINE COMANDI FTP
  328. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. #MENU GENERALE
  336. #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  337.  
  338.  
  339. def menug():
  340.    
  341.     yellow('OService\n')
  342.     blue('[1]Utilità di sistema\n')
  343.     blue('[2]Servizi\n')
  344.     blue('[0]Uscita')
  345.              
  346.  
  347.     while 1:
  348.         cmd=raw_input("\nCommand: \n")
  349.        
  350.         if cmd=="1":
  351.             menucmd()
  352.             break
  353.         elif cmd=="2":
  354.             service()
  355.             break
  356.         elif cmd=="0":
  357.             exit()
  358.            
  359.         else:
  360.              red('Command error')
  361.  
  362.  
  363. def service():
  364.     yellow('Servizi disponibili:\n')
  365.     blue('[1]ftp\n')
  366.     blue('[0]Indietro')
  367.    
  368.     chose=raw_input("Command: \n")
  369.  
  370.     if chose=="1":
  371.         ftp()
  372.  
  373.     elif chose=="0":
  374.         menug()
  375.    
  376.     else:
  377.         red('Command Error')
  378.        
  379.  
  380.        
  381.  
  382. #FINE MENU GENERALE
  383. #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390. #MAIN PROGRAMMA
  391. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  392.        
  393.  
  394.  
  395.  
  396.  
  397. if os.getuid() == 0:
  398.     menug()
  399.  
  400. else:
  401.     print "Eseguire l'accesso root per utilizzare tutte le funzioni\n"
  402.    
  403.    
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432. #FINE MAIN PROGRAMMA
  433. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement