welcome.hs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. -- WelcomeToLCM 2.0 by Giacomo Parolini (jp)
  2. -- August 2015
  3. import System.Exit
  4. import Control.Exception (bracket_)
  5. import Control.Monad (void)
  6. import UI.HSCurses.Curses
  7. import qualified UI.HSCurses.CursesHelper as CH
  8. data ColorScheme = WhiteOnBlack
  9. | GreenOnBlack
  10. | RedOnBlack
  11. | MagentaOnBlack
  12. | CyanOnBlack
  13. | YellowOnBlack
  14. | RedOnBlue
  15. | BlackOnGreen
  16. deriving Enum
  17. data Language = Italian
  18. | English
  19. | NLangs -- keep in last position
  20. deriving Enum
  21. data Page = PageTerm
  22. | PageDoc
  23. | PageInternet
  24. | PageDevices
  25. | PageRemote
  26. | PageLCM
  27. | PageAbout
  28. | PageSSH
  29. | PageSCP
  30. main :: IO ()
  31. main = bracket_ start endWin welcome
  32. start :: IO ()
  33. start = do
  34. initCurses
  35. hasColors <- hasColors
  36. if hasColors
  37. then do
  38. startColor
  39. initPair (Pair 1) (CH.white) (defaultBackground)
  40. initPair (Pair 2) (CH.green) (defaultBackground)
  41. initPair (Pair 3) (CH.red) (defaultBackground)
  42. initPair (Pair 4) (CH.magenta) (defaultBackground)
  43. initPair (Pair 5) (CH.cyan) (defaultBackground)
  44. initPair (Pair 6) (CH.yellow) (defaultBackground)
  45. initPair (Pair 7) (CH.red) (CH.blue)
  46. initPair (Pair 8) (CH.black) (CH.green)
  47. return ()
  48. else
  49. return ()
  50. keypad stdScr True
  51. echo False
  52. cursSet CursorInvisible
  53. cBreak True
  54. -- Shortcut for mvAddStr
  55. mas :: Int -> Int -> String -> IO ()
  56. mas = mvWAddStr stdScr
  57. -- Shortcut for language checking
  58. lmas :: Language -> Int -> Int -> [String] -> IO ()
  59. lmas lang row col list = mas row col $ list !! (fromEnum lang)
  60. -- Convenient color setting helper
  61. setCol :: ColorScheme -> IO ()
  62. setCol = attrSet attr0 . Pair . (\x -> fromEnum x + 1)
  63. welcome :: IO ()
  64. welcome = mainScreen English
  65. mainScreen :: Language -> IO ()
  66. mainScreen lang = do
  67. erase
  68. printTitle lang
  69. printMainList lang 0
  70. refresh
  71. mainScreen lang
  72. printTitle :: Language -> IO ()
  73. printTitle lang = do
  74. (_, cols) <- scrSize
  75. setCol GreenOnBlack
  76. lmas lang 1 1 ["BENVENUTO/A IN LCM!", "WELCOME TO LCM!"]
  77. setCol CyanOnBlack
  78. lmas lang 3 1 ["Se non hai familiarita' con Linux ecco un tutorial sui comandi"
  79. ,"If you're not familiar with Linux, here is a tutorial about the"]
  80. lmas lang 4 1 ["piu' importanti che ti troverai ad utilizzare."
  81. ,"most common features you'll need to use."]
  82. addOpt 5 1 ["l", "l"] [": cambia lingua", ": change language"]
  83. addOpt 6 1 ["Invio", "Enter"] [": seleziona", ": select"]
  84. addOpt 7 1 ["q", "q"] [": esci", ": exit"]
  85. where
  86. addOpt :: Int -> Int -> [String] -> [String] -> IO ()
  87. addOpt row col cmds descs = do
  88. setCol YellowOnBlack
  89. lmas lang row col cmds
  90. setCol CyanOnBlack
  91. wAddStr stdScr $ descs !! (fromEnum lang)
  92. -- The list of available pages from main page
  93. printMainList = printList [(PageTerm, ["Comandi di base del terminale"
  94. ,"Basic terminal commands"])
  95. ,(PageDoc, ["Creare/modificare documenti"
  96. ,"Create/Edit documents"])
  97. ,(PageInternet, ["Internet"
  98. ,"Internet"])
  99. ,(PageDevices, ["Stampante, scanner e chiavette USB"
  100. ,"Printer, scanner and USB"])
  101. ,(PageRemote, ["Collegamento remoto: ssh, scp"
  102. ,"Remote connections: ssh, scp"])
  103. ,(PageLCM, ["Utilizzo dell'account LCM"
  104. ,"Using your LCM account"])
  105. ,(PageAbout, ["Dettagli su questo programma"
  106. ,"About this program"])]
  107. printList :: [(Page, [String])] -> Language -> Int -> IO ()
  108. printList pages lang line = do
  109. let nLines = length pages
  110. printLines lang 0 line pages
  111. refresh
  112. ch <- getCh
  113. case ch of
  114. KeyChar 'q' -> exitSuccess
  115. KeyChar 'l' -> let newlang = toEnum $ mod (fromEnum lang + 1)
  116. (fromEnum NLangs)
  117. in do erase
  118. mainScreen newlang
  119. KeyUp -> printList pages lang $ (line - 1) `mod` nLines
  120. KeyDown -> printList pages lang $ (line + 1) `mod` nLines
  121. KeyEnter -> printInfo lang $ fst $ pages !! line
  122. KeyChar '\n' -> printInfo lang $ fst $ pages !! line
  123. _ -> return () -- ignore
  124. printLines :: Language -> Int -> Int -> [(Page, [String])] -> IO ()
  125. printLines lang curLine selLine pages = do
  126. if curLine == selLine
  127. then setCol BlackOnGreen
  128. else setCol MagentaOnBlack
  129. mas (2*curLine + 9) 3 $ (snd $ pages !! curLine) !! (fromEnum lang)
  130. if curLine == length pages - 1
  131. then return ()
  132. else printLines lang (curLine + 1) selLine pages
  133. printInfo :: Language -> Page -> IO ()
  134. printInfo lang page = do
  135. erase
  136. printPage page
  137. refresh
  138. void getCh
  139. where
  140. -- moar brevity!
  141. l = lmas lang
  142. printPage :: Page -> IO ()
  143. printPage PageTerm = do
  144. setCol GreenOnBlack
  145. l 1 2 ["COMANDI FONDAMENTALI PER TERMINALE", "BASIC TERMINAL COMMANDS"]
  146. setCol CyanOnBlack
  147. l 2 2 ["ls : stampa a video il contenuto di una cartella"
  148. ,"ls : print at screen the content of a directory"]
  149. l 3 3 ["-> ls -l : per mostrare anche le proprieta' dei file (permessi,owner,size)"
  150. ,"-> ls -l : also show file properties (permissions,owner,size"]
  151. l 4 3 ["-> ls -a/A: per mostrare anche i file nascosti (che iniziano con `.')"
  152. ,"-> ls -a/A: also show hidden files (which begin with `.')"]
  153. l 6 2 ["cd : cambia la cartella corrente"
  154. ,"cd : change directory"]
  155. l 7 3 ["sintassi: cd <percorso>; 'cd ..' per tornare su di un livello"
  156. ,"syntax: cd <path>; 'cd ..' to switch to upper level"]
  157. l 9 2 ["cp : copia un file da un percorso ad un altro"
  158. ,"cp : copy a file from a given path to another"]
  159. l 10 3 ["sintassi: cp <file_da_copiare> <dove_copiarlo>"
  160. ,"syntax: cp <file_to_copy> <where_to_copy>"]
  161. l 11 3 ["e' necessaria la flag -r per copiare delle cartelle."
  162. ,"the flag -r is necessary to copy directories"]
  163. l 13 2 ["mv : sposta un file (usato anche per rinominare un file)"
  164. ,"mv : move a file (also used to rename a file)"]
  165. l 14 3 ["sintassi: come cp"
  166. ,"syntax: like cp"]
  167. l 16 2 ["cat/less : mostra il contenuto di un file"
  168. ,"cat/less : show the content of a file"]
  169. l 18 2 ["man : fornisce le istruzioni di utilizzo di un programma"
  170. ,"man : gives the instruction about a program"]
  171. l 19 3 ["sintassi: man <nomeprogramma>"
  172. ,"syntax: man <name_program>"]
  173. l 21 2 ["ps : mostra i processi attivi (ps aux per la lista completa)"
  174. ,"ps : shows active processes of the terminal (ps aux for complete list)"]
  175. l 23 2 ["whoall : mostra tutti gli utenti connessi al cluster"
  176. ,"whoall : shows all users connected to the LCM cluster."]
  177. l 25 2 ["IMPORTANTE: . indica la cartella corrente. ~ indica la home."
  178. ,"IMPORTANT: . means the current directory. ~ means the home"]
  179. printPage PageDoc = do
  180. setCol GreenOnBlack
  181. l 1 2 ["PROGRAMMI UTILI PER MODIFICARE DOCUMENTI", "UTILITIES TO EDIT DOCUMENTS"]
  182. setCol CyanOnBlack
  183. l 2 2 ["gedit : apre l'editor di testo (solit. usato per programmare)"
  184. ,"gedit : opens the default text editor (usually used for programming)"]
  185. l 4 2 ["libreoffice : apre documenti Word, Excel, PowerPoint, ecc"
  186. ,"libreoffice : opens Word, Excel, PowerPoint, etc documents"]
  187. l 6 2 ["evince : apre file .pdf, .dvi, .ps e simili"
  188. ,"evince : opens .pdf files, .dvi, .ps and similar"]
  189. l 8 2 ["gimp : apre l'editor di immagini"
  190. ,"gimp : opens the image editor"]
  191. l 10 2 ["eog : mostra l'anteprima di un'immagine"
  192. ,"eog : shows an image's preview"]
  193. l 12 2 ["vim : apre l'editor di testo da terminale (avanzato)"
  194. ,"vim : opens the console editor (advanced)"]
  195. printPage PageInternet = do
  196. setCol GreenOnBlack
  197. l 1 2 ["ANDARE SU INTERNET", "BROWSING THE INTERNET"]
  198. setCol CyanOnBlack
  199. l 2 2 ["iceweasel/firefox : apre il browser Iceweasel (consigliato)"
  200. ,"iceweasel/firefox : opens the browser Iceweasel (suggested option)"]
  201. l 3 3 ["N.B. La cache di Iceweasel viene salvata dentro la directory nascosta"
  202. ,"N.B. Iceweasel's cache is saved in the hidden directory"]
  203. l 4 3 ["~/.mozilla/firefox; dopo molto tempo che non viene svuotata, la cache"
  204. ,"~/.mozilla/firefox; after some time passes without being emptied, the cache"]
  205. l 5 3 ["puo' arrivare a pesare anche varie centinaia di MB! Se noti che la tua"
  206. ,"can start weighting even several hundreds of MB! If you notice that your"]
  207. l 6 3 ["home inizia a pesare molto senza che tu abbia file di grandi dimensioni"
  208. ,"home starts having a huge size without you having big-sized files,"]
  209. l 7 3 ["la cosa piu' probabile e' che sia ora di svuotare la cache di Iceweasel."
  210. ,"it is very likely that it's time to cancel Iceweasel's cache."]
  211. l 9 2 ["E' possibile (ma sconsigliato, in quanto e' piu' probabile che non siano"
  212. ,"It is possible (but deprecated, because they're less likely to be properly"]
  213. l 10 2 ["preconfigurati) usare altri browser, ad esempio chromium, opera o konqueror."
  214. ,"configured) to use alternative browsers, like chromium or konqueror."]
  215. l 12 2 ["Se ci sono problemi di browsing, controllare che i proxy siano settati"
  216. ,"If you find browsing problems, make sure your proxys are correctly set."]
  217. l 13 2 ["correttamente: *su Iceweasel: Edit->Preferences->Advanced->Network->Settings"
  218. ,"*on Iceweasel: Edit->Preferences->Advanced->Network->Settings"]
  219. l 14 2 ["Settare: Automatic proxy configuration URL: http://lcm.mi.infn.it/proxy.pac"
  220. ,"Set: Automatic proxy configuration URL: http://lcm.mi.infn.it/proxy.pac"]
  221. l 15 2 ["*su konqueror: Settings->Configure Konqueror->Web Browising->Proxy->Use"
  222. ,"*on konqueror: Settings->Configure Konqueror->Web Browising->Proxy->Use"]
  223. l 16 2 ["proxy configuration URL->http://lcm.mi.infn.it/proxy.pac"
  224. ,"proxy configuration URL->http://lcm.mi.infn.it/proxy.pac"]
  225. l 17 2 ["*su chromium: da terminale digitare "
  226. ,"*on chromium: type on the terminal: "]
  227. l 18 3 ["chromium --proxy-pac-url=http://lcm.mi.infn.it/proxy.pac"
  228. ,"chromium --proxy-pac-url=http://lcm.mi.infn.it/proxy.pac"]
  229. printPage PageDevices = do
  230. l 2 2 ["La stampante presente in LCM1 e' lcmprinter."
  231. ,"The printer in LCM1 is called lcmprinter."]
  232. l 3 2 ["Per stampare un documento via terminale: lpr <nome_documento>"
  233. ,"To print a document via terminal:lpr <file_name>"]
  234. l 4 2 ["Per vedere la coda di stampa della stampante: lpq"
  235. ,"To check the printing queue: lpq"]
  236. l 6 2 ["Ogni utente di LCM puo' stampare gratuitamente fino a 60 pagine"
  237. ,"Every LCM user can freely print up to 60 pagines per month."]
  238. l 7 2 ["al mese. Per vedere le pagine stampate questo mese: cupsami"
  239. ,"To check the number of printed pages this month: cupsami"]
  240. l 9 2 ["Per usare lo scanner: xsane"
  241. ,"To use the scanner: xsane"]
  242. l 11 2 ["Per montare una chiavetta USB: pmount /dev/sdxY"
  243. ,"To mount an USB device: pmount /dev/sdxY"]
  244. l 12 2 ["dove x sta per l'opportuna lettera che identifica il device"
  245. ,"where x is the proper letter which identifies the device"]
  246. l 13 2 ["(es. sdb, sdc, ...) e Y sta per il numero della partizione"
  247. ,"(e.g. sdb, sdc, ...) and Y is the partition number of the device"]
  248. l 14 2 ["del device (solitamente 1). Il device verra' montato in /media/NOMEDEVICE"
  249. ,"(1 typically). The device will be mounted in /media/NOMEDEVICE"]
  250. l 15 2 ["Nota: per conoscere la lettera che identifica la chiavetta, un modo"
  251. ,"Note: to identify the device, a quick method is to call `dmesg`"]
  252. l 16 2 ["rapido e' chiamare `dmesg` subito dopo averla pluggata."
  253. ,"immediately after plugging it."]
  254. printPage PageRemote = printList [(PageSSH, ["SSH (Secure SHell)", "SSH (Secure SHell)"])
  255. ,(PageSCP, ["SCP (Secure CoPy)", "SCP (Secure CoPy)"])] lang 0
  256. printPage PageSSH = do
  257. setCol GreenOnBlack
  258. l 1 2 ["UTILIZZO DI SSH", "SSH USAGE"]
  259. setCol CyanOnBlack
  260. l 2 2 ["E' possibile collegarsi al proprio account LCM in qualunque"
  261. ,"It is possible to connect to your LCM account anytime"]
  262. l 3 2 ["momento e da qualunque posto tramite il protocollo Secure SHell."
  263. ,"from any place using the Secure SHell protocol."]
  264. l 5 2 ["Il comando da terminale e' ssh <nome_utente>@lcm.mi.infn.it"
  265. ,"The terminal command is ssh <username>@lcm.mi.infn.it"]
  266. l 6 2 ["Aggiungendo la flag -X a ssh e' possibile abilitare l'X-forwarding"
  267. ,"By adding the flag -X to ssh, it is possible to enable X-forwarding"]
  268. l 7 2 ["che permette di utilizzare da remoto programmi che richiedono"
  269. ,"which allows the remote use of programs which require a graphical"]
  270. l 8 2 ["l'ambiente grafico (come gedit, eog, iceweasel, ...). Si tenga pero'"
  271. ,"environment (like gedit, eog, iceweasel, ...). Remember, though,"]
  272. l 9 2 ["presente che tale opzione puo' rallentare anche molto la connessione."
  273. ,"that this option may slow down the connection even heavily."]
  274. l 11 2 ["IMPORTANTE: per collegarsi in remoto da Windows e' necessario il"
  275. ,"IMPORTANT: to remotely connect from Windows you'll need the"]
  276. l 12 2 ["programma PuTTY (ed e' consigliabile integrarlo a WinSCP, che permette"
  277. ,"program PuTTY (and it is suggested to integrate it to WinSCP, which allows"]
  278. l 13 2 ["anche la copia e la gestione di file e cartelle con un'interfaccia"
  279. ,"also to copy and manage files and directories with an intuitive"]
  280. l 14 2 ["intuitiva.). Da MacOS o da Linux e' ovviamente sufficiente il normale"
  281. ,"interface.). From MacOS or from Linux clearly you'll just need the "]
  282. l 15 2 ["terminale UNIX."
  283. ,"common UNIX terminal."]
  284. printPage PageSCP = do
  285. setCol GreenOnBlack
  286. l 1 2 ["UTILIZZO DI SCP", "SCP USAGE"]
  287. setCol CyanOnBlack
  288. l 2 2 ["Per trasferire file e cartelle da un computer ad un altro esiste il"
  289. ,"To transfer files or directories from a computer to another, there is the"]
  290. l 3 2 ["comando scp. L'utilizzo e' analogo a cp, ma e' necessario specificare"
  291. ,"command scp. The usage is analogous to cp, but it is necessary to specify"]
  292. l 4 2 ["l'host su cui (o da cui) si intende trasferire il file."
  293. ,"the host whereto (or wherefrom) you wish to transfer the file."]
  294. l 6 2 ["Esempio: copiare un file dall'account LCM al proprio computer:"
  295. ,"Example: to copy a file from your LCM account to your computer:"]
  296. l 7 3 ["scp <nome_utente>@lcm.mi.infn.it:<percorso_file> ."
  297. ,"scp <username>@lcm.mi.infn.it:<file_path> ."]
  298. l 8 2 ["dove <percorso_file> e' il percorso in cui si trova il file, a partire"
  299. ,"where<file_path> is the complete path where the file is located, starting"]
  300. l 9 2 ["dalla propria home (quindi [...].lcm.mi.infn.it:. indica la home)"
  301. ,"from your home (thus [...].lcm.mi.infn.it:. means your LCM home)"]
  302. l 11 2 ["Esempio: copiare un file dal proprio computer all'account LCM:"
  303. ,"Example: to copy a file from your computer to your LCM account:"]
  304. l 12 3 ["scp <nome_file> <nome_utente>@lcm.mi.infn.it:."
  305. ,"scp <file_path> <username>@lcm.mi.infn.it:."]
  306. l 14 2 ["Si ricordi che '.' indica la cartella in cui ci si trova, per cui negli"
  307. ,"Remember that '.' means the current directory, so in the examples above"]
  308. l 15 2 ["esempi sopra abbiamo copiato nel primo caso nella cartella del computer"
  309. ,"we have copied respectively in the home of the current computer and"]
  310. l 16 2 ["in cui ci trovavamo, e nel secondo nella home dell'account LCM. E'"
  311. ,"in the LCM account's home. Obviously, it is possible to change this `.'"]
  312. l 17 2 ["ovviamente possibile modificare questo '.' con il percorso desiderato."
  313. ,"with the desired path. Remember the flag -r to copy directories."]
  314. l 18 2 ["Si ricordi anche che per copiare cartelle e' necessaria la flag -r."
  315. ,""]
  316. printPage PageLCM = do
  317. setCol GreenOnBlack
  318. l 1 2 ["UTILIZZO DELL'ACCOUNT LCM", "USING YOUR LCM ACCOUNT"]
  319. setCol CyanOnBlack
  320. l 2 2 ["L'account LCM e' strettamente personale e non puo' essere prestato a terzi."
  321. ,"Your LCM account is strictly personal and cannot be leased to others."]
  322. l 4 2 ["Esso dura 3 anni a partire dal giorno della creazione dello stesso."
  323. ,"Its duration is 3 years from the day of creation."]
  324. l 5 2 ["Trascorso questo periodo e' possibile richiedere il rinnovo dell'account"
  325. ,"After 3 years, it is possible to ask for an account renewal to the LCM staff."]
  326. l 6 2 ["allo staff di LCM."
  327. ,"Every user has a disposable disk usage limit of 800 MB. It is possible to exceed"]
  328. l 8 2 ["Lo spazio a disposizione per ogni utente e' di 800 MB. E' possibile sforare"
  329. ,"this limit up to 1.3 GB for a maximum period of 2 weeks, after which the extra"]
  330. l 9 2 ["questo limite fino a 1.3 GB per non piu' di 2 settimane, dopodiche' il"
  331. ,"content will be deleted."]
  332. l 10 2 ["contenuto in eccesso verra' cancellato."
  333. ,"To precisely monitor the disk usage: ncdu (from your home)"]
  334. l 11 2 ["Per monitorare con precisione lo spazio utilizzato: ncdu (nella home)"
  335. ,""]
  336. l 13 2 ["E' MOLTO IMPORTANTE controllare periodicamente la mail di lcm (creata assieme"
  337. ,"It is VERY IMPORTANT to check the lcm mail periodically (which is created along"]
  338. l 14 2 ["all'account: <nome_utente>@lcm.mi.infn.it), perche' e' l'unico mezzo di"
  339. ,"with the account: <username>@lcm.mi.infn.it), because it is the only way of"]
  340. l 15 2 ["comunicazione tra lo staff e l'utenza."
  341. ,"communication between the staff and the users."]
  342. l 17 2 ["E' possibile impostare una redirezione dalla mail di lcm ad una propria mail"
  343. ,"It is possible to set a mail forwarding to another mail via the hidden file"]
  344. l 18 2 ["tramite il file nascosto ~/.qmail. Sintassi: &<nome_mail_a_cui_redirigere>"
  345. ,"~/.qmail. Syntax: &<mail_where_to_forward>"]
  346. printPage PageAbout = do
  347. setCol GreenOnBlack
  348. l 1 2 ["INFO SU QUESTO PROGRAMMA", "ABOUT THIS PROGRAM"]
  349. setCol WhiteOnBlack
  350. l 2 2 ["welcometolcm 2.0", "welcometolcm 2.0"]
  351. l 3 2 ["Creato il: 4 Set 2015 (jp)", "Created on: 4 Sep 2015 (jp)"]
  352. l 4 2 ["Ultima modifica: 26 Mar 2016 (jp)", "Last Modified: 26 Mar 2016 (jp)"]
  353. setCol CyanOnBlack
  354. l 6 2 ["Questo programma viene eseguito di default durante il primo login"
  355. ,"This program is executed by default during the first login"]
  356. l 7 2 ["e in generale quando il file ~/.welcome non esiste."
  357. ,"and whenever the hidden file ~/.welcome does not exist."]
  358. l 9 2 ["E' possibile disabilitare permanentemente il lancio del programma"
  359. ,"It is possible to permanently disable the program execution"]
  360. l 10 2 ["modificando il proprio ~/.bashrc a piacimento."
  361. ,"by editing your ~/.bashrc."]