void um_password_dialog_set_user (UmPasswordDialog *um, UmUser *user) { GdkPixbuf *pixbuf; GtkTreeModel *model; if (um->user) { g_object_unref (um->user); um->user = NULL; } if (user) { um->user = g_object_ref (user); um->using_ecryptfs = is_using_ecryptfs (um_user_get_user_name (user)); pixbuf = um_user_render_icon (user, FALSE, 48); gtk_image_set_from_pixbuf (GTK_IMAGE (um->user_icon), pixbuf); g_object_unref (pixbuf); gtk_label_set_label (GTK_LABEL (um->user_name), um_user_get_real_name (user)); gtk_entry_set_text (GTK_ENTRY (um->password_entry), ""); gtk_entry_set_text (GTK_ENTRY (um->verify_entry), ""); gtk_entry_set_text (GTK_ENTRY (um->normal_hint_entry), ""); gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), ""); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->show_password_button), FALSE); if (um_user_get_uid (um->user) == getuid () && um_user_get_password_mode (um->user) == UM_PASSWORD_MODE_REGULAR) { gtk_widget_show (um->old_password_label); gtk_widget_show (um->old_password_entry); um->old_password_ok = FALSE; } else { gtk_widget_hide (um->old_password_label); gtk_widget_hide (um->old_password_entry); um->old_password_ok = TRUE; } if (um_user_get_uid (um->user) == getuid()) { if (um->passwd_handler != NULL) passwd_destroy (um->passwd_handler); um->passwd_handler = passwd_init (); } } model = gtk_combo_box_get_model (GTK_COMBO_BOX (um->action_combo)); if (!GTK_IS_TREE_MODEL_FILTER (model)) { model = gtk_tree_model_filter_new (model, NULL); gtk_combo_box_set_model (GTK_COMBO_BOX (um->action_combo), model); gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model), (GtkTreeModelFilterVisibleFunc) visible_func, um, NULL); } gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model)); gtk_combo_box_set_active (GTK_COMBO_BOX (um->action_combo), 0); }
void um_password_dialog_set_user (UmPasswordDialog *um, ActUser *user) { gboolean visible; if (um->user) { g_object_unref (um->user); um->user = NULL; } if (user) { um->user = g_object_ref (user); gtk_entry_set_text (GTK_ENTRY (um->password_entry), ""); gtk_entry_set_text (GTK_ENTRY (um->verify_entry), ""); gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), ""); gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), FALSE); gtk_entry_set_visibility (GTK_ENTRY (um->verify_entry), FALSE); if (act_user_get_uid (um->user) == getuid ()) { mode_change (um, ACT_USER_PASSWORD_MODE_REGULAR); gtk_widget_hide (um->action_radio_box); visible = (act_user_get_password_mode (user) != ACT_USER_PASSWORD_MODE_NONE); gtk_widget_set_visible (um->old_password_label, visible); gtk_widget_set_visible (um->old_password_entry, visible); um->old_password_ok = !visible; } else { mode_change (um, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN); gtk_widget_show (um->action_radio_box); gtk_widget_hide (um->old_password_label); gtk_widget_hide (um->old_password_entry); um->old_password_ok = TRUE; } if (act_user_get_uid (um->user) == getuid()) { if (um->passwd_handler != NULL) passwd_destroy (um->passwd_handler); um->passwd_handler = passwd_init (); } } }
int main() { int i, j, k; FILE *fp; int max, item, maxhoroscope; int act[12]; char *name[13] = {"¨d¦Ï", "ª÷¤û", "Âù¤l", "¥¨ÃÉ", "·à¤l", "³B¤k", "¤Ñ¯¯", "¤ÑÃÈ", "®g¤â", "¼¯½~", "¤ô²~", "Âù³½", "" }; char *blk[10] = { " ", "¢j", "¢k", "¢l", "¢m", "¢n", "¢o", "¢p", "¢i", "¢i", }; attach_SHM(); memset(act, 0, sizeof(act)); if(passwd_init()) exit(1); for(k = 1; k <= MAX_USERS; k++) { passwd_query(k, &user); if(!user.userid[0]) continue; switch (user.month) { case 1: if (user.day <= 19) act[9]++; else act[10]++; break; case 2: if (user.day <= 18) act[10]++; else act[11]++; break; case 3: if (user.day <= 20) act[11]++; else act[0]++; break; case 4: if (user.day <= 19) act[0]++; else act[1]++; break; case 5: if (user.day <= 20) act[1]++; else act[2]++; break; case 6: if (user.day <= 21) act[2]++; else act[3]++; break; case 7: if (user.day <= 22) act[3]++; else act[4]++; break; case 8: if (user.day <= 22) act[4]++; else act[5]++; break; case 9: if (user.day <= 22) act[5]++; else act[6]++; break; case 10: if (user.day <= 23) act[6]++; else act[7]++; break; case 11: if (user.day <= 22) act[7]++; else act[8]++; break; case 12: if (user.day <= 21) act[8]++; else act[9]++; break; } } for (i = max = maxhoroscope = 0; i < 12; i++) { if (act[i] > max) { max = act[i]; maxhoroscope = i; } } item = max / 30 + 1; if ((fp = fopen(BBSHOME"/etc/horoscope", "w")) == NULL) { printf("cann't open etc/horoscope\n"); return 1; } for (i = 0; i < 12; i++) { fprintf(fp, " [1;37m%s®y [0;36m", name[i]); for (j = 0; j < act[i] / item; j++) { fprintf(fp, "%2s", blk[9]); } /* ¬°¤Fè¦n¤@¶ */ if (i != 11) fprintf(fp, "%2s [1;37m%d[m\n\n", blk[(act[i] % item) * 10 / item], act[i]); else fprintf(fp, "%2s [1;37m%d[m\n", blk[(act[i] % item) * 10 / item], act[i]); } fclose(fp); return 0; }
int main(int argc, char *argv[]) { int bmid, i, j=0; FILE *inf, *firef; time4_t now=time(NULL); attach_SHM(); resolve_boards(); if(passwd_init()) exit(1); memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); /* write out the target file */ inf = fopen(OUTFILE, "w+"); if (inf == NULL) { printf("open file error : %s\n", OUTFILE); exit(1); } firef = fopen(FIREFILE, "w+"); if (firef == NULL) { printf("open file error : %s\n", FIREFILE); exit(1); } fprintf(inf, "警告: 板主若超過(不包含) %d天未上站,將予於免職\n", LAZY_BM_LIMIT_DAYS); fprintf(inf, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "--------------------------\n"); fprintf(firef, "免職板主\n"); fprintf(firef, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "--------------------------\n"); j = 0; for (i = 0; i < numboards; i++) { char *p, bmbuf[IDLEN * 3 + 3]; int index = 0, flag = 0, k, n; userec_t xuser; p = allbrd[i].BM; if (*p == '[') p++; if (allbrd[i].brdname[0] == '\0' || !isalpha(allbrd[i].brdname[0]) ) continue; p = strtok(p,"/ ]"); for(index=0; p && index<5; index++) { int diff; // XXX what if bmid is invalid? if(!p[0] || (bmid = passwd_load_user(p, &xuser)) < 1) { index--; p=strtok(NULL,"/ ]"); continue; } strlcpy(bms[index].bmname, p, sizeof(bms[index].bmname)); bms[index].flag = 0; diff = now - xuser.lastlogin; if (diff < 0) diff = 0; if (diff >= 45 * 86400 && !(xuser.userlevel & PERM_SYSOPHIDE) && !(xuser.userlevel & PERM_SYSOP)) { strlcpy(lostbms[j].bmname, p, sizeof(bms[index].bmname)); lostbms[j].title = allbrd[i].brdname; lostbms[j].ctitle = allbrd[i].title; lostbms[j].lostdays = diff / 86400; //超過 LAZY_BM_LIMIT_DAYS 天 免職 if (lostbms[j].lostdays > LAZY_BM_LIMIT_DAYS) { xuser.userlevel &= ~PERM_BM; bms[index].flag = 1; flag = 1; // NOTE: 好像不改也無所謂,目前拔 BM 是自動的。 passwd_update(bmid, &xuser); } j++; } p = strtok(NULL,"/ ]"); } if (flag == 1) { boardheader_t *bp = getbcache(i+1); // 確認我們沒搞錯 cache. 如果 cache 炸了就別用了 if (strcmp(bp->brdname, allbrd[i].brdname) != 0) { printf("ERROR: unmatched cache!!! (%s - %s)\n", bp->brdname, allbrd[i].brdname); bp = NULL; exit(1); // sync to latest memcpy(&allbrd[i], bp, sizeof(boardheader_t)); } bmbuf[0] = '\0'; for (k = 0, n = 0; k < index; k++) { if (!bms[k].flag) { if (n++ != 0) strcat(bmbuf, "/"); strcat(bmbuf, bms[k].bmname); } } strcpy(allbrd[i].BM, bmbuf); printf("board %s: %s -> %s\n", allbrd[i].brdname, bp->BM, allbrd[i].BM); strcpy(bp->BM, allbrd[i].BM); if (substitute_record(BBSHOME"/"FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1) { printf("Update Board Failed: %s\n", allbrd[i].brdname); } reset_board(i+1); } } qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); //write to the etc/toplazyBM for (i = 0; i < j; i++) { if (lostbms[i].lostdays > LAZY_BM_LIMIT_DAYS) { fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, lostbms[i].bmname,lostbms[i].lostdays); } else { fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, lostbms[i].bmname,lostbms[i].lostdays); } } fclose(inf); fclose(firef); //printf("Total %d boards.\n", count); //mail to the users for (i=0; i<j; i++) { fileheader_t mymail; char genbuf[200]; int lostdays; lostdays = lostbms[i].lostdays; if (lostdays != LAZY_BM_LIMIT_DAYS/2 && lostdays != LAZY_BM_LIMIT_DAYS*2/3 && lostdays != LAZY_BM_LIMIT_DAYS*5/6 && lostdays <= LAZY_BM_LIMIT_DAYS) continue; sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); stampfile(genbuf, &mymail); strcpy(mymail.owner, "[" BBSMNAME "警察局]"); if (lostdays <= LAZY_BM_LIMIT_DAYS) sprintf(mymail.title, ANSI_COLOR(32) "版主通知" ANSI_RESET " %s版版主%s", lostbms[i].title, lostbms[i].bmname); else sprintf(mymail.title, ANSI_COLOR(32) "版主自動免職通知" ANSI_RESET " %s 版主 %s", lostbms[i].title, lostbms[i].bmname); unlink(genbuf); if (lostdays <= LAZY_BM_LIMIT_DAYS) Link(OUTFILE, genbuf); else Link(FIREFILE, genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); append_record(genbuf, &mymail, sizeof(mymail)); } return 0; }