101 |
static void do_service_process(HttpRequest, HttpResponse, Service_T); |
static void do_service_process(HttpRequest, HttpResponse, Service_T); |
102 |
static void do_service_host(HttpRequest, HttpResponse, Service_T); |
static void do_service_host(HttpRequest, HttpResponse, Service_T); |
103 |
|
|
|
extern ssl_server_connection * mySSLServerConnection; |
|
104 |
|
|
105 |
/** |
/** |
106 |
* Implementation of doGet and doPost routines used by the cervlet |
* Implementation of doGet and doPost routines used by the cervlet |
575 |
static void print_status(Service_T s, HttpResponse res) { |
static void print_status(Service_T s, HttpResponse res) { |
576 |
|
|
577 |
pid_t pid= -1; |
pid_t pid= -1; |
578 |
FILE *out= res->outputstream; |
Socket_T S= res->S; |
579 |
struct stat stat_buf; |
struct stat stat_buf; |
580 |
|
|
581 |
res->is_committed= TRUE; |
res->is_committed= TRUE; |
586 |
|
|
587 |
if((pid= is_process_running(s))) { |
if((pid= is_process_running(s))) { |
588 |
|
|
|
char *uptime= get_process_uptime(s->path, " "); |
|
|
char buf[STRLEN]; |
|
589 |
ProcInfo_T pi= s->procinfo; |
ProcInfo_T pi= s->procinfo; |
590 |
|
char *uptime= get_process_uptime(s->path, " "); |
591 |
|
|
592 |
if(Run.doprocess) { |
if(Run.doprocess) { |
593 |
|
|
594 |
snprintf(buf,STRLEN, |
socket_print(S, |
595 |
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
596 |
"CPU: %.1f%% Memory w/o children: %.1f%% [%ldkB]\n" |
"CPU: %.1f%% Memory w/o children: %.1f%% [%ldkB]\n" |
597 |
"\tChildren: %i Memory w/ children: %.1f%% [%ldkB]\n" |
"\tChildren: %i Memory w/ children: %.1f%% [%ldkB]\n" |
598 |
"\tMonitoring status: %s\n", |
"\tMonitoring status: %s\n", |
599 |
s->name, (int)pid, uptime, pi->cpu_percent/10.0, |
s->name, (int)pid, uptime, pi->cpu_percent/10.0, |
600 |
pi->mem_percent/10.0,pi->mem_kbyte, |
pi->mem_percent/10.0,pi->mem_kbyte, |
601 |
pi->children,pi->total_mem_percent/10.0,pi->total_mem_kbyte, |
pi->children,pi->total_mem_percent / |
602 |
statusnames[s->do_monitor]); |
10.0,pi->total_mem_kbyte, |
603 |
|
statusnames[s->do_monitor]); |
604 |
|
|
605 |
} else { |
} else { |
606 |
|
|
607 |
snprintf(buf,STRLEN, |
socket_print(S, |
608 |
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
"Process '%s' is running with pid [%d]\n\tUptime: %s " |
609 |
"\tMonitoring status: %s\n", |
"\tMonitoring status: %s\n", |
610 |
s->name, (int)pid, uptime,statusnames[s->do_monitor]); |
s->name, (int)pid, uptime,statusnames[s->do_monitor]); |
611 |
|
|
612 |
} |
} |
613 |
|
|
|
if( Run.httpdssl) { |
|
|
|
|
|
printf_ssl_socket(res->ssl, "%s", buf); |
|
|
|
|
|
} else { |
|
|
|
|
|
fprintf(out, "%s", buf); |
|
|
|
|
|
} |
|
|
|
|
614 |
free(uptime); |
free(uptime); |
615 |
|
|
616 |
} else { |
} else { |
617 |
|
|
618 |
if( Run.httpdssl) { |
socket_print(S, "Process '%s' is not running\n", s->name); |
|
|
|
|
printf_ssl_socket(res->ssl, "Process '%s' is not running\n", |
|
|
s->name); |
|
|
|
|
|
} else { |
|
|
|
|
|
fprintf(out, "Process '%s' is not running\n", s->name); |
|
619 |
|
|
|
} |
|
|
|
|
620 |
} |
} |
621 |
break; |
break; |
622 |
|
|
626 |
|
|
627 |
if(s->devinfo->f_files > 0) { |
if(s->devinfo->f_files > 0) { |
628 |
|
|
629 |
if( Run.httpdssl) { |
socket_print(S, |
630 |
|
"Device '%s' %s\n\t" |
631 |
printf_ssl_socket(res->ssl, |
"Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t" |
632 |
"Device '%s' %s\n\t" |
"UID: %d GID: %d Permission: %o\n\t" |
633 |
"Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t" |
"Monitoring status: %s\n", |
634 |
"UID: %d GID: %d Permission: %o\n\t" |
s->name, |
635 |
"Monitoring status: %s\n", |
(s->perm&&s->perm->has_error)? |
636 |
s->name, |
"permission error": |
637 |
(s->perm&&s->perm->has_error)? |
(s->uid&&s->uid->has_error)? |
638 |
"permission error": |
"UID error": |
639 |
(s->uid&&s->uid->has_error)? |
(s->gid&&s->gid->has_error)? |
640 |
"UID error": |
"GID error": |
641 |
(s->gid&&s->gid->has_error)? |
"is accessible", |
642 |
"GID error": |
(float) 100 * |
|
"is accessible", |
|
|
(float) 100 * |
|
643 |
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
644 |
s->devinfo->f_blocks, |
s->devinfo->f_blocks, |
645 |
(float) (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
(float) (s->devinfo->f_blocks - |
646 |
1048576 * s->devinfo->f_bsize, |
s->devinfo->f_blocksfreetotal) / |
647 |
(float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree) / |
1048576 * s->devinfo->f_bsize, |
648 |
s->devinfo->f_files, |
(float) 100 * (s->devinfo->f_files - |
649 |
s->devinfo->f_files - s->devinfo->f_filesfree, |
s->devinfo->f_filesfree) / |
650 |
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
s->devinfo->f_files, |
651 |
(int)(stat_buf.st_mode & 07777), |
s->devinfo->f_files - s->devinfo->f_filesfree, |
652 |
statusnames[s->do_monitor]); |
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
653 |
|
(int)(stat_buf.st_mode & 07777), |
654 |
} else { |
statusnames[s->do_monitor]); |
|
|
|
|
fprintf(out, |
|
|
"Device '%s' %s\n\t" |
|
|
"Space: %.1f%% [%.1f MB] Inodes: %.1f%% [%ld objects]\n\t" |
|
|
"UID: %d GID: %d Permission: %o\n\t" |
|
|
"Monitoring status: %s\n", |
|
|
s->name, |
|
|
(s->perm&&s->perm->has_error)? |
|
|
"permission error": |
|
|
(s->uid&&s->uid->has_error)? |
|
|
"UID error": |
|
|
(s->gid&&s->gid->has_error)? |
|
|
"GID error": |
|
|
"is accessible", |
|
|
(float) 100 * |
|
|
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
|
|
s->devinfo->f_blocks, |
|
|
(float) (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
|
|
1048576 * s->devinfo->f_bsize, |
|
|
(float) 100 * (s->devinfo->f_files - s->devinfo->f_filesfree) / |
|
|
s->devinfo->f_files, |
|
|
s->devinfo->f_files - s->devinfo->f_filesfree, |
|
|
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
|
|
(int)(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
} |
|
655 |
} else { |
} else { |
656 |
if( Run.httpdssl) { |
socket_print(S, |
657 |
printf_ssl_socket(res->ssl, |
"Device '%s' %s\n\t" |
658 |
"Device '%s' %s\n\t" |
"Space: %.1f%% [%.1f MB]\n\t" |
659 |
"Space: %.1f%% [%.1f MB]\n\t" |
"UID: %d GID: %d Permission: %o\n\t" |
660 |
"UID: %d GID: %d Permission: %o\n\t" |
"Monitoring status: %s\n", |
661 |
"Monitoring status: %s\n", |
s->name, |
662 |
s->name, |
(s->perm&&s->perm->has_error)? |
663 |
(s->perm&&s->perm->has_error)? |
"permission error": |
664 |
"permission error": |
(s->uid&&s->uid->has_error)? |
665 |
(s->uid&&s->uid->has_error)? |
"UID error": |
666 |
"UID error": |
(s->gid&&s->gid->has_error)? |
667 |
(s->gid&&s->gid->has_error)? |
"GID error": |
668 |
"GID error": |
"is accessible", |
669 |
"is accessible", |
(float) 100 * |
670 |
(float) 100 * |
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
671 |
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
s->devinfo->f_blocks, |
672 |
s->devinfo->f_blocks, |
(float) (s->devinfo->f_blocks - |
673 |
(float) (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
s->devinfo->f_blocksfreetotal) / |
674 |
1048576 * s->devinfo->f_bsize, |
1048576 * s->devinfo->f_bsize, |
675 |
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
676 |
(int)(stat_buf.st_mode & 07777), |
(int)(stat_buf.st_mode & 07777), |
677 |
statusnames[s->do_monitor]); |
statusnames[s->do_monitor]); |
|
} else { |
|
|
fprintf(out, |
|
|
"Device '%s' %s\n\t" |
|
|
"Space: %.1f%% [%.1f MB]\n\t" |
|
|
"UID: %d GID: %d Permission: %o\n\t" |
|
|
"Monitoring status: %s\n", |
|
|
s->name, |
|
|
(s->perm&&s->perm->has_error)? |
|
|
"permission error": |
|
|
(s->uid&&s->uid->has_error)? |
|
|
"UID error": |
|
|
(s->gid&&s->gid->has_error)? |
|
|
"GID error": |
|
|
"is accessible", |
|
|
(float) 100 * |
|
|
(s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
|
|
s->devinfo->f_blocks, |
|
|
(float) (s->devinfo->f_blocks - s->devinfo->f_blocksfreetotal) / |
|
|
1048576 * s->devinfo->f_bsize, |
|
|
(int)stat_buf.st_uid, (int)stat_buf.st_gid, |
|
|
(int)(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
} |
|
678 |
} |
} |
679 |
} else { |
} else { |
680 |
if( Run.httpdssl) { |
socket_print(S, |
681 |
|
"Device '%s' is not accessible\n\t" |
682 |
printf_ssl_socket(res->ssl, |
"Space: - Inodes: -\n\t" |
683 |
"Device '%s' is not accessible\n\t" |
"UID: - GID: - Permission: -\n\t" |
684 |
"Space: - Inodes: -\n\t" |
"Monitoring status: %s\n", |
685 |
"UID: - GID: - Permission: -\n\t" |
s->name, statusnames[s->do_monitor]); |
686 |
"Monitoring status: %s\n", |
|
|
s->name, statusnames[s->do_monitor]); |
|
|
} else { |
|
|
fprintf(out, |
|
|
"Device '%s' is not accessible\n\t" |
|
|
"Space: - Inodes: -\n\t" |
|
|
"UID: - GID: - Permission: -\n\t" |
|
|
"Monitoring status: %s\n", |
|
|
s->name, statusnames[s->do_monitor]); |
|
|
} |
|
687 |
} |
} |
688 |
break; |
break; |
689 |
|
|
690 |
case TYPE_FILE: |
case TYPE_FILE: |
691 |
if( (stat(s->path, &stat_buf) == 0) && S_ISREG(stat_buf.st_mode)) { |
if( (stat(s->path, &stat_buf) == 0) && S_ISREG(stat_buf.st_mode)) { |
692 |
if( Run.httpdssl) { |
|
693 |
|
socket_print(S, |
694 |
printf_ssl_socket(res->ssl, |
"File '%s' %s\n\t" |
695 |
"File '%s' %s\n\t" |
"Size: %luB UID: %d GID: %d Permission: %o\n\t" |
696 |
"Size: %luB UID: %d GID: %d Permission: %o\n\t" |
"Monitoring status: %s\n", |
697 |
"Monitoring status: %s\n", |
s->name, |
698 |
s->name, |
(s->perm&&s->perm->has_error)? |
699 |
(s->perm&&s->perm->has_error)? |
"permission error": |
700 |
"permission error": |
(s->uid&&s->uid->has_error)? |
701 |
(s->uid&&s->uid->has_error)? |
"UID error": |
702 |
"UID error": |
(s->gid&&s->gid->has_error)? |
703 |
(s->gid&&s->gid->has_error)? |
"GID error": |
704 |
"GID error": |
"exist", |
705 |
"exist", |
(unsigned long)stat_buf.st_size, (int)stat_buf.st_uid, |
706 |
(unsigned long)stat_buf.st_size, |
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
707 |
(int)stat_buf.st_uid, |
statusnames[s->do_monitor]); |
|
(int)stat_buf.st_gid, |
|
|
(int)(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
|
|
|
} else { |
|
|
|
|
|
fprintf(out, |
|
|
"File '%s' %s\n\t" |
|
|
"Size: %luB UID: %d GID: %d Permission: %o\n\t" |
|
|
"Monitoring status: %s\n", |
|
|
s->name, |
|
|
(s->perm&&s->perm->has_error)? |
|
|
"permission error": |
|
|
(s->uid&&s->uid->has_error)? |
|
|
"UID error": |
|
|
(s->gid&&s->gid->has_error)? |
|
|
"GID error": |
|
|
"exist", |
|
|
(unsigned long)stat_buf.st_size, (int)stat_buf.st_uid, |
|
|
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
|
|
|
} |
|
708 |
} else { |
} else { |
709 |
if( Run.httpdssl) { |
|
710 |
printf_ssl_socket(res->ssl, |
socket_print(S, "File '%s' doesn't exist\n\tMonitoring status: %s\n", |
711 |
"File '%s' doesn't exist\n\tMonitoring status: %s\n", |
s->name, statusnames[s->do_monitor]); |
|
s->name, statusnames[s->do_monitor]); |
|
|
} else { |
|
|
fprintf(out, "File '%s' doesn't exist\n\tMonitoring status: %s\n", |
|
|
s->name, statusnames[s->do_monitor]); |
|
|
} |
|
712 |
} |
} |
713 |
break; |
break; |
714 |
|
|
715 |
case TYPE_DIRECTORY: |
case TYPE_DIRECTORY: |
716 |
if( (stat(s->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) { |
if( (stat(s->path, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) { |
717 |
if( Run.httpdssl) { |
|
718 |
|
socket_print(S, |
719 |
printf_ssl_socket(res->ssl, |
"Directory '%s' %s\n\t" |
720 |
"Directory '%s' %s\n\t" |
"UID: %d GID: %d Permission: %o\n\t" |
721 |
"UID: %d GID: %d Permission: %o\n\t" |
"Monitoring status: %s\n", |
722 |
"Monitoring status: %s\n", |
s->name, |
723 |
s->name, |
(s->perm&&s->perm->has_error)? |
724 |
(s->perm&&s->perm->has_error)? |
"permission error": |
725 |
"permission error": |
(s->uid&&s->uid->has_error)? |
726 |
(s->uid&&s->uid->has_error)? |
"UID error": |
727 |
"UID error": |
(s->gid&&s->gid->has_error)? |
728 |
(s->gid&&s->gid->has_error)? |
"GID error": |
729 |
"GID error": |
"exist", |
730 |
"exist", |
(int)stat_buf.st_uid, |
731 |
(int)stat_buf.st_uid, |
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
732 |
(int)stat_buf.st_gid, (int) |
statusnames[s->do_monitor]); |
733 |
(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
} else { |
|
|
fprintf(out, |
|
|
"Directory '%s' %s\n\t" |
|
|
"UID: %d GID: %d Permission: %o\n\t" |
|
|
"Monitoring status: %s\n", |
|
|
s->name, |
|
|
(s->perm&&s->perm->has_error)? |
|
|
"permission error": |
|
|
(s->uid&&s->uid->has_error)? |
|
|
"UID error": |
|
|
(s->gid&&s->gid->has_error)? |
|
|
"GID error": |
|
|
"exist", |
|
|
(int)stat_buf.st_uid, |
|
|
(int)stat_buf.st_gid, (int)(stat_buf.st_mode & 07777), |
|
|
statusnames[s->do_monitor]); |
|
|
} |
|
734 |
} else { |
} else { |
735 |
if( Run.httpdssl) { |
|
736 |
printf_ssl_socket(res->ssl, |
socket_print(S, |
737 |
"Directory '%s' doesn't exist\n\tMonitoring status: %s\n", |
"Directory '%s' doesn't exist\n\tMonitoring status: %s\n", |
738 |
s->name, statusnames[s->do_monitor]); |
s->name, statusnames[s->do_monitor]); |
|
} else { |
|
|
fprintf(out, |
|
|
"Directory '%s' doesn't exist\n\tMonitoring status: %s\n", |
|
|
s->name, statusnames[s->do_monitor]); |
|
|
} |
|
739 |
} |
} |
740 |
break; |
break; |
741 |
|
|
752 |
} |
} |
753 |
|
|
754 |
if(!available) { |
if(!available) { |
755 |
if( Run.httpdssl) { |
|
756 |
printf_ssl_socket(res->ssl, |
socket_print(S, |
757 |
"Host '%s'\n\tPort %d is not available\n" |
"Host '%s'\n\tPort %d is not available\n" |
758 |
"\tMonitoring status: %s\n", |
"\tMonitoring status: %s\n", |
759 |
s->name, port->port, statusnames[s->do_monitor]); |
s->name, port->port, statusnames[s->do_monitor]); |
760 |
} else { |
|
|
fprintf(out, |
|
|
"Host '%s'\n\tPort %d is not available\n" |
|
|
"\tMonitoring status: %s\n", |
|
|
s->name, port->port, statusnames[s->do_monitor]); |
|
|
} |
|
761 |
} else { |
} else { |
762 |
if( Run.httpdssl) { |
|
763 |
printf_ssl_socket(res->ssl, |
socket_print(S, |
764 |
"Host '%s'\n\tAll monitored ports are available\n" |
"Host '%s'\n\tAll monitored ports are available\n" |
765 |
"\tMonitoring status: %s\n", |
"\tMonitoring status: %s\n", |
766 |
s->name, statusnames[s->do_monitor]); |
s->name, statusnames[s->do_monitor]); |
|
} else { |
|
|
fprintf(out, |
|
|
"Host '%s'\n\tAll monitored ports are available\n" |
|
|
"\tMonitoring status: %s\n", |
|
|
s->name, statusnames[s->do_monitor]); |
|
|
} |
|
767 |
} |
} |
768 |
} |
} |
769 |
break; |
break; |
778 |
static void printPixel(HttpResponse res) { |
static void printPixel(HttpResponse res) { |
779 |
|
|
780 |
static int l; |
static int l; |
781 |
|
Socket_T S= res->S; |
782 |
static unsigned char *pixel= NULL; |
static unsigned char *pixel= NULL; |
783 |
|
|
784 |
if(! pixel) { |
if(! pixel) { |
785 |
pixel= xcalloc(sizeof(unsigned char), strlen(PIXEL_GIF)); |
pixel= xcalloc(sizeof(unsigned char), strlen(PIXEL_GIF)); |
786 |
l= decode_base64(pixel, PIXEL_GIF); |
l= decode_base64(pixel, PIXEL_GIF); |
787 |
} |
} |
788 |
if (l) { |
if (l) { |
789 |
if(Run.httpdssl) { |
res->is_committed= TRUE; |
790 |
res->is_committed= TRUE; |
socket_print(S, "HTTP/1.0 200 OK\r\n"); |
791 |
printf_ssl_socket(res->ssl, "HTTP/1.0 200 OK\r\n"); |
socket_print(S, "Content-length: %d\r\n", l); |
792 |
printf_ssl_socket(res->ssl, "Content-length: %d\r\n", l); |
socket_print(S, "Content-Type: image/gif\r\n"); |
793 |
printf_ssl_socket(res->ssl, "Content-Type: image/gif\r\n"); |
socket_print(S, "Connection: close\r\n\r\n"); |
794 |
printf_ssl_socket(res->ssl, "Connection: close\r\n\r\n"); |
socket_write(S, pixel, l); |
|
send_ssl_socket(res->ssl, pixel, l); |
|
|
} else { |
|
|
FILE *out= res->outputstream; |
|
|
res->is_committed= TRUE; |
|
|
fprintf(out, "HTTP/1.0 200 OK\r\n"); |
|
|
fprintf(out, "Content-length: %d\r\n", l); |
|
|
fprintf(out, "Content-Type: image/gif\r\n"); |
|
|
fprintf(out, "Connection: close\r\n\r\n"); |
|
|
fwrite(pixel, sizeof(unsigned char), l, out); |
|
|
} |
|
795 |
} |
} |
796 |
|
|
797 |
} |
} |