#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void quit_cb(Widget,XtPointer,XtPointer); void ok_cb(Widget,XtPointer,XtPointer); typedef struct { String file; String message; String command; String logo; } app_res; XtResource resources[] = { {"file","File",XmRString,sizeof(String), XtOffset(app_res*,file),XmRString,NULL}, {"message","Message",XmRString,sizeof(String), XtOffset(app_res*,message),XmRString,NULL}, {"command","Command",XmRString,sizeof(String), XtOffset(app_res*,command),XmRString,NULL}, {"logo","Logo",XmRString,sizeof(String), XtOffset(app_res*,logo),XmRString,NULL} }; String defaults[] = { "Motd*clientDecoration: border", "Motd*shadowThickness: 4", "*okLabelString: OK", "*cancelLabelString: Exit", "*font: -*-helvetica-bold-o-*--14-*-*-*-*-*-*-*", "*textFontList: -*-courier-bold-r-*--14-*-*-*-*-*-*-*", "*labelFontList: -*-times-bold-i-*--36-*-*-*-*-*-*-*", "*buttonFontList: -*-times-bold-i-*--18-*-*-*-*-*-*-*", "*dialogTitle: Message of the DoomsDay", "*message: Welcome to %s", "*command: quota -v", "*symbolPixmap: xlogo64", "*Separator*separatorType: XmSHADOW_ETCHED_OUT", "*geometry: +200+100", "*text*foreground: black", "*text*background: gray80", "*text*columns: 80", "*text*rows: 24", "*usertext*foreground: black", "*usertext*background: gray80", "*usertext*columns: 80", "*usertext*rows: 5", "*file: /etc/motd", NULL }; XrmOptionDescRec options[] = { { "-f","*file",XrmoptionSepArg, (XtPointer) NULL}, { "-m","*message",XrmoptionSepArg, (XtPointer) NULL}, { "-c","*command",XrmoptionSepArg, (XtPointer) NULL}, { "-p","*symbolPixmap",XrmoptionSepArg, (XtPointer) NULL}, { "-tf","*textFontList",XrmoptionSepArg, (XtPointer) NULL}, }; XtAppContext app_context; Display *theDisp; int theScreen; XmStringCharSet theCharset; Widget app_shell; Widget main_window; Widget form; Widget text,usertext; app_res myres; void main ( int argc, char *argv[] ) { Arg al[10]; Cardinal ac; int fd; struct stat status; struct utsname un; char *t,*ut,msg[1024],tmp[MAXPATHLEN]; app_shell = XtAppInitialize(&app_context,"Motd", options,XtNumber(options), &argc,argv,defaults,NULL,0); XtGetApplicationResources(app_shell,&myres, resources,XtNumber(resources),NULL,0); theDisp = XtDisplay(app_shell); theScreen = DefaultScreen(theDisp); theCharset = (XmStringCharSet)XmSTRING_DEFAULT_CHARSET; t = NULL; fd = open((char*)myres.file,O_RDONLY); if (fd!=-1) { if (!fstat(fd,&status)) { t = XtMalloc((unsigned)(status.st_size+16)); read(fd,t,status.st_size); t[status.st_size] = 0; } close(fd); } if (t==NULL) { t = "No message for today"; } /* sprintf(msg,"%s > %s",myres.command,tmpnam(tmp)); system(msg); ut = NULL; fd = open(tmp,O_RDONLY); if (fd!=-1) { if (!fstat(fd,&status)) { ut = XtMalloc((unsigned)(status.st_size+16)); read(fd,ut,status.st_size); ut[status.st_size] = 0; } close(fd); } if (ut==NULL) { ut = "Good guy..."; } unlink(tmp); */ { FILE *f; size_t nc; sprintf(msg,"%s",myres.command); if (( f = popen( msg, "r")) != NULL) { if ( NULL != (ut = XtMalloc((unsigned)(256)))) { nc = fread( ut, 1, 256, f ); *(ut + nc)=0x00; } else ut = "duh?"; pclose(f); } } uname(&un); sprintf(msg,(char*)myres.message,un.nodename); sprintf(tmp,"\n%s %s",un.sysname,un.release); strcat(msg,tmp); ac = 0; XtSetArg(al[ac],XmNdefaultPosition,True); ac++; XtSetArg(al[ac],XmNnoResize,True); ac++; /* XtSetArg(al[ac],XmNdialogStyle,XmDIALOG_SYSTEM_MODAL); ac++;*/ XtSetArg(al[ac],XmNdialogType,XmDIALOG_INFORMATION); ac++; XtSetArg(al[ac],XmNmessageAlignment,XmALIGNMENT_CENTER); ac++; XtSetArg(al[ac],XmNmessageString, XmStringCreateLtoR(msg,theCharset)); ac++; main_window = XmCreateMessageBox(app_shell,"box",al,ac); XtManageChild(main_window); XtAddCallback(main_window,XmNokCallback,ok_cb,NULL); XtAddCallback(main_window,XmNcancelCallback,quit_cb,NULL); XtUnmanageChild(XmMessageBoxGetChild(main_window, XmDIALOG_HELP_BUTTON)); ac = 0; form = XmCreateForm(main_window,"form",al,ac); XtManageChild(form); ac = 0; XtSetArg(al[ac],XmNeditable,False); ac++; XtSetArg(al[ac],XmNcursorPositionVisible,False); ac++; XtSetArg(al[ac],XmNwordWrap,False); ac++; XtSetArg(al[ac],XmNeditMode,XmMULTI_LINE_EDIT); ac++; XtSetArg(al[ac],XmNresizeWidth, True); ac++; XtSetArg(al[ac],XmNresizeHeight, True); ac++; XtSetArg(al[ac],XmNscrollVertical, True); ac++; XtSetArg(al[ac],XmNscrollHorizontal, False); ac++; XtSetArg(al[ac],XmNvalue,t); ac++; XtSetArg(al[ac],XmNtopAttachment,XmATTACH_FORM); ac++; text = XmCreateScrolledText(form,"text",al,ac); XtManageChild(text); ac = 0; XtSetArg(al[ac],XmNeditable,False); ac++; XtSetArg(al[ac],XmNcursorPositionVisible,False); ac++; XtSetArg(al[ac],XmNwordWrap,False); ac++; XtSetArg(al[ac],XmNeditMode,XmMULTI_LINE_EDIT); ac++; XtSetArg(al[ac],XmNresizeWidth, True); ac++; XtSetArg(al[ac],XmNresizeHeight, True); ac++; XtSetArg(al[ac],XmNscrollVertical, True); ac++; XtSetArg(al[ac],XmNscrollHorizontal, False); ac++; XtSetArg(al[ac],XmNvalue,ut); ac++; XtSetArg(al[ac],XmNtopAttachment,XmATTACH_WIDGET); ac++; XtSetArg(al[ac],XmNtopWidget,text); ac++; XtSetArg(al[ac],XmNbottomAttachment,XmATTACH_FORM); ac++; usertext = XmCreateScrolledText(form,"usertext",al,ac); XtManageChild(usertext); XtRealizeWidget(app_shell); XtAppMainLoop(app_context); } void quit_cb(Widget w,XtPointer client,XtPointer app) { puts("exit"); exit(0); } void ok_cb(Widget w,XtPointer client,XtPointer app) { puts("ok"); exit(0); }