//================================================================ // count.cc // GIFアクセスカウンタ // Copyright (C) Naoki Watanabe. 1995-1999. All rights reserved. //================================================================ #include #include #include #include #include #include //#define PATH_OF_PPMTOGIF "/usr/local/bin/ppmtogif" #define PATH_OF_PPMTOGIF "/usr/X11R6/bin/ppmtogif" // ★注目 // カウントファイルとして count.dat の名前のファイルをこのCGIと // 同じ directory に用意し、そのファイル先頭に00000000と書いておくこと。 static char image[10][12][8*3] = { { // 0 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} }, { // 1 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} } }; int IncCount( char* countfile ) { int count; FILE* fptr; if( (fptr=fopen( countfile, "r+" )) == NULL ) goto ERROR_BLOCK; lockf( fileno(fptr), F_LOCK, 0 ); if( fscanf( fptr, "%d", &count ) != 1 ) goto ERROR_BLOCK; count++; rewind( fptr ); fprintf( fptr, "%08d", count ); lockf( fileno(fptr), F_ULOCK, 0 ); fclose(fptr); return count; ERROR_BLOCK: if( fptr != NULL ) fclose(fptr); return 0; } int main(void) { int pid; int pipefds[2]; pipe(pipefds); if( (pid=fork()) == 0 ){ dup2( pipefds[0], 0 ); close(2); close(pipefds[1]); write( 1, "Content-Type: image/gif\n\n", 25 ); execl( PATH_OF_PPMTOGIF, "ppmtogif", 0 ); exit(1); }else{ close(pipefds[0]); } char narray[9]; sprintf( narray, "%08d", IncCount("count.dat") ); for( int n=0 ; n<8 ; n++ ){ narray[n] -= '0'; } write( pipefds[1], "P6\n64 12\n1\n", 11 ); for( int i=0 ; i<12 ; i++ ){ for( int n=0 ; n<8 ; n++ ){ write( pipefds[1], &image[narray[n]][i], 8*3 ); } } close(pipefds[1]); waitpid( pid, 0, 0 ); return 0; }