]> git.sesse.net Git - betaftpd/blob - disp.c
Updated documentation to tell that root can't FTP anymore.
[betaftpd] / disp.c
1 /*  disp.c: BetaFTPD full-screen stats
2     Copyright (C) 1999-2000 Steinar H. Gunderson
3
4     This program is is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License, version 2 if the
6     License as published by the Free Software Foundation.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 #if HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #if HAVE_SYS_TYPES_H
23 #include <sys/types.h>
24 #endif
25
26 #if HAVE_STDIO_H
27 #include <stdio.h>
28 #endif
29
30 #if HAVE_NETINET_IN_H
31 #include <netinet/in.h>
32 #endif
33
34 #if HAVE_TIME_H
35 #include <time.h>
36 #endif
37
38 #if HAVE_SYS_TIME_H
39 #include <sys/time.h>
40 #endif 
41
42 #include <ftpd.h>
43
44 #if WANT_FULLSCREEN
45 time_t last_update = 0;
46
47 void update_display(const struct conn * const first_conn)
48 {
49         struct conn *c = first_conn->next_conn;
50         int i = 0;
51         time_t now;
52
53         time(&now);
54         if (now - last_update < 1) return;
55         last_update = now; 
56
57         printf("%c[H", (char)27);        /* clear the screen */
58         printf("%c[44m                                                                         \n", (char)27);
59         printf("%c[44m                                                                         \n", (char)27);
60         printf("%c[38m                         BetaFTPD FTP server                             \n", (char)27);
61         printf("%c[44m                                                                         \n", (char)27);
62         printf("%c[44m                                                                         \n", (char)27);
63         printf("%c[40m", (char)27);
64         while (c != NULL && ++i < 20) {
65                 const struct ftran * const f = c->transfer;
66                 printf("%4u ", c->sock);
67                 if (f == NULL) {
68                         printf("%-16s %-50s\n", c->username, c->last_cmd);
69                 } else {
70                         char trunc_filename[256];
71                         strcpy(trunc_filename, f->filename);
72                         trunc_filename[22] = 0;
73
74 #if WANT_UPLOAD
75                         if (f->upload) {
76                                 printf("%-16s%-22s%12lu %7.2fkb/s (upl)\n", c->username,
77                                 trunc_filename, f->size, (float)(f->pos - c->rest_pos) /
78                                         (float)(difftime(now, f->tran_start)) / 1024);
79                         } else
80 #endif
81                         printf("%-16s%-22s%12lu %7.2fkb/s %.2f%%\n", c->username,
82                                 trunc_filename, f->size, (float)(f->pos - c->rest_pos) /
83                                         (float)(difftime(now, f->tran_start)) / 1024,
84                                 (float)(f->pos) / (float)(f->size) * 100.0f);
85                 }
86                 c = c->next_conn;
87         }
88         printf("%79s", "");
89 }
90 #endif