/***************************************************
*  DF C++ Miner                    Version 1.00
*  Copyright 2001 DF             dfmail@inbox.ru
*  DF WEB site:                http://www.dfservice.com
****************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/stat.h>

const float
 VERSION = 1.00;

char *strperm(unsigned short int perm, char *line)
 {
 char string[10];
 unsigned short int i;

 i=perm/010000;
 if(i == 010) line[0] = '-';
 else if(i == 04) line[0] = 'd';
 else if(i == 012) line[0] = 'l';
 else if(i == 02) line[0] = 'c';
 else if(i == 014) line[0] = 's';
 else if(i == 06) line[0] = 'b';
 else line[0] = '!';
line[1] = 0;

sprintf(string, "%ho", (perm & 07777));
 for(i=0;string[i];i++)
  {
  if(string[i] == '7') strcat(line," rwx");
  else if(string[i] == '6') strcat(line," rw-");
  else if(string[i] == '5') strcat(line," r-x");
  else if(string[i] == '4') strcat(line," r--");
  else if(string[i] == '3') strcat(line," -wx");
  else if(string[i] == '2') strcat(line," -w-");
  else if(string[i] == '1') strcat(line," --x");
  else if(string[i] == '0') strcat(line," ---");
  else strcat(line," !!!");
  }
return(line);
}

char *getlocaltime(void)
{
 time_t timer;
 timer = time(NULL);
 return  ctime(&timer);
}

int main(int argc, char * argv[], char * env[])
{
int i;
char *ptr;

puts("Content-type:  text/html\n\n");
printf("<HTML><HEAD><TITLE>C++ Miner %.2f</TITLE></HEAD>",VERSION);
puts("<style>\
body, td {\
	font-family : Verdana, sans serif;\
	font-size : 13px;\
}\
td.g{background: GHOSTWHITE;}\
</style>\
<BODY TOPMARGIN=0 LEFTMARGIN=0 BGCOLOR=White>");
printf("<CENTER><FONT FACE=\"Courier New,mono\" SIZE=6 COLOR=#BF0425><B>C++ Miner %.2f</B></FONT>", VERSION);
puts("<BR><BR><TABLE WIDTH=100% BGCOLOR=#FDB900><Th><FONT SIZE=4>Main Information</FONT></TABLE>");
puts("<P><TABLE BORDER=0 CELLPADDING=3 WIDTH=95%>");

puts("<TR><TD WIDTH=35% class=g><B>Current time:</B></TD><TD WIDTH=65%>");
printf("%s\n", getlocaltime());
puts("</TD></TR>\n");

puts("<TR><TD WIDTH=35% class=g><B>File path:</B></TD><TD WIDTH=65%>");
printf("%s\n", argv[0]);
puts("</TD></TR>\n");

struct stat statbuf;
stat(argv[0], &statbuf);

puts("<TR><TD WIDTH=35% class=g><B>This file Owner User:</B></TD><TD WIDTH=65%>");
printf("%d\n", statbuf.st_uid);
puts("</TD></TR>\n");

puts("<TR><TD WIDTH=35% class=g><B>This file Owner Group:</B></TD><TD WIDTH=65%>");
printf("%d\n", statbuf.st_gid);
puts("</TD></TR>\n");

puts("<TR><TD WIDTH=35% class=g><B>This file Permissions:</B></TD><TD WIDTH=65%>");
char line[10];
printf("%s (%04lo)\n",strperm(statbuf.st_mode, line), statbuf.st_mode & 07777);
puts("</TD></TR>\n");

puts("</TABLE><P>\n");
puts("<TABLE WIDTH=100% BGCOLOR=#FDB900><Th><FONT SIZE=4>Environment Variables</FONT></TABLE>\
<P><TABLE BORDER=0 CELLPADDING=3 WIDTH=95%><TR><TD WIDTH=35%></TD><TD WIDTH=65%></TD></TR>\n");

for(i=0;env[i]!= NULL;i++)
 {
 if(ptr=strstr(env[i],"=")){*ptr=0; ptr++; }
  else break;
 printf("<TR><TD class=g><B>%s</B></TD><TD>%s</TD></TR>\n", env[i], ptr);
 }

puts("</TD></TR></TABLE><P>\n");
puts("<TABLE WIDTH=100% BGCOLOR=#FDB900><Th ALIGN=center><FONT SIZE=4 color=#FFFFFF><i><b><a href=\"http://www.dfservice.org/\">&copy; 2001 DF&trade;</a></b></i></FONT></TABLE>\n");
puts("</BODY></HTML>");

}

