Listing 3 The status page
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <sys/file.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8
9 int gen_www_info( char *db_name, double size, double quota )
10 {
11 FILE *file;
12 char www_info_file_path[128];
13 double free = 0;
14 bzero( www_info_file_path, 128 );
15
16 /*
17 * Generate the complete path the file that the
18 * information will be saved to:
19 */
20 sprintf( www_info_file_path, "%s/%s", "/var/lib/apache/htdocs/quota", db_name );
21
22 /* Calculate the number of free megabytes: */
23 free = (quota-size);
24
25 /* Open the file for writing: */
26 if( (file = fopen( www_info_file_path, "w" )) == NULL )
27 {
28 perror( "fdopen(fd,\"w\")" );
29 }
30
31 /* Ouput the information to the file: */
32 fprintf( file, "<table width=\"30%%\" border=\"0\" cellpadding=\"5\"
cellpadding=\"0\"><tr><td bgcolor=\"#fced63\" colspan=\"2\"
align=\"center\" valign=\"middle\"><font size=\"4\"
face=\"Verdana, Arial, Helvetica, sans-serif\"
color=\"#666666\">Database Status:</td></tr><tr><td
align=\"right\" valign=\"middle\" width=\"50%%\"><font
size=\"3\" face=\"Verdana, Arial, Helvetica, sans-serif\"
color=\"#666666\">Used Space:</td><td align=\"left\"
valign=\"middle\" width=\"50%%\"><font size=\"3\"
face=\"Verdana, Arial, Helvetica, sans-serif\"
color=\"#666666\">%.2fMb</td><tr><td align=\"right\"
valign=\"middle\"><font size=\"3\" face=\"Verdana, Arial,
Helvetica, sans-serif\" color=\"#666666\">Free Space:</td><td
align=\"left\" valign=\"middle\"><font size=\"3\"
face=\"Verdana, Arial, Helvetica, sans-serif\"
color=\"#666666\">%.2fMb</td></tr><tr><td align=\"right\"
valign=\"middle\"><font size=\"3\" face=\"Verdana, Arial,
Helvetica, sans-serif\" color=\"#666666\">Total Space:</td><td
align=\"left\" valign=\"middle\"><font size=\"3\"
face=\"Verdana, Arial, Helvetica, sans-serif\"
color=\"#666666\">%.2fMb</td></tr></table>", size, free, quota );
33
34 /* Close the file: */
35 if( (fclose( file )) != 0 )
36 {
37 perror( "fclose(file)" );
38 }
39
40 /* Everyting seem to be fine, so we'll return 0: */
41 return 0;
42 }
|