summaryrefslogtreecommitdiffstats
path: root/util/inndBM.c
blob: 8f1a69a03b13cf3f4de9a73715e278a381267df2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* 依據 .BOARD檔 & newsfeeds.bbs 列出參與轉信的所有板資料 */

#include "bbs.h"

#define INNDHOME  BBSHOME"/innd"

#define INND_NEWSFEED  INNDHOME "/newsfeeds.bbs"
#define INND_NODELIST  INNDHOME "/nodelist.bbs"
#define INND_BADFEED   INNDHOME "/badfeeds.bbs" 
#define INND_SCRIPT    INNDHOME "/bbsnnrpall.auto.sh"

int istran[MAX_BOARD];

typedef 
struct newssvr_t
{
  char name[30];
  char address[256];
  char type[10];
}newssvr_t; 

typedef
struct newsfeed_t
{
  char group[128];
  char board[15];
  char server[30];
}newsfeed_t;   

newssvr_t server[128];
newsfeed_t feedline[MAX_BOARD];
int servercount;
int feedcount;

int newsfeed_cmp(const void *a, const void *b)
{
   int i;
   i=strcasecmp(((newsfeed_t*)a)->server,((newsfeed_t*)b)->server);
   if(i) return i;
   return strcasecmp(((newsfeed_t*)a)->board,((newsfeed_t*)b)->board);
}

int get_server(char *name)
{
  int i;
  for(i=0;i<servercount;i++)
     if(!strcasecmp(server[i].name,name)) 
    {return i;}
  return -1;
}

int load_server()
{
    FILE *fp;
    char str[128];

    if (!(fp = fopen(INND_NODELIST, "r")))
    {
    return 0;
    }

    for(servercount=0; fgets(str, 128, fp); servercount++)
    {
        if(str[0]=='#') continue;
        sscanf(str,"%s %s %s",server[servercount].name,
        server[servercount].address,
        server[servercount].type);
    }
    fclose(fp);
   return servercount;
}

int load_newsfeeds()
{
    int bid;
    FILE *fp, *fo;
    char str[128];
    if (!(fp = fopen(INND_NEWSFEED, "r")))
    {
    return 0;
    }
    if (!(fo = fopen(INND_BADFEED, "w")))
    {
    return 0;
    }

    for(feedcount=0; fgets(str, 128, fp); feedcount++)
    {
        if(str[0]=='#') continue;
        sscanf(str,"%s %s %s",
        feedline[feedcount].group,feedline[feedcount].board,
        feedline[feedcount].server);
        bid=getbnum(feedline[feedcount].board);
        if(!bid) {
        fprintf(fo,"%s %s\n", feedline[feedcount].board, feedline[feedcount].group );
        feedcount--;
        continue; /*移除沒有的看板i*/}

        strcpy(feedline[feedcount].board,bcache[bid-1].brdname);
        /*校正大小寫 */

        istran[bid-1]=1; 
        
    }
    fclose(fp);
    fclose(fo);
   qsort(feedline, feedcount, sizeof(newsfeed_t), newsfeed_cmp);
   return feedcount;
}

int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript)
{
    char buf[256];
    printf("set %s\r\n",serverstr);
    strtok(serverstr,";\r\n");
    strtok(server[serverid].address,";\r\n"); //防hack
    sprintf(buf, INNDHOME"/bbsnnrp -c %s "
        INNDHOME "/active/%s.auto.active "
        " >> " INNDHOME"/log/inndBM.log &\r\n",
        server[serverid].address,
        serverstr);
    system(buf);
    sprintf(buf, INNDHOME"/bbsnnrp %s "
        INNDHOME "/active/%s.auto.active "
        " >> " INNDHOME"/log/inndBM.log &\r\n",
        server[serverid].address,
        serverstr);
    if(fpscript)
    fprintf(fpscript, buf);
    return 0;
}
int main()
{
    int i,serverid=0;
    FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w");
    char buf[256],serverstr[30]="";
    chdir(BBSHOME "/innd");
    resolve_boards();
    memset(istran,0,sizeof(int)*MAX_BOARD);
    load_server();
    load_newsfeeds();

    for(i=0;i<feedcount;i++)
    {
      if(strcasecmp(serverstr,feedline[i].server))
       {
         if(get_server(feedline[i].server)==-1) continue;
         if(fp) {
            fclose(fp); 
                        dobbsnnrp(serverstr,serverid,fpscript);
            }
         strcpy(serverstr,feedline[i].server);
         serverid=get_server(feedline[i].server);
         sprintf(buf,INNDHOME"/active/%s.auto.active",serverstr);
         fp=fopen(buf,"w");
       }
          if(fp)
             fprintf(fp,"%-35s 0000000000 0000000000 y\r\n",feedline[i].group);
    }
    if(fp) 
    {
      dobbsnnrp(serverstr,serverid,fpscript);
      fclose(fp);
    }
    if(fpscript)
     {
    fclose(fpscript);
    chmod(INND_SCRIPT,0700);
     }

    // 重設轉信與不轉信板標記
    for(i=0;i<numboards;i++)
     {
       if(bcache[i].brdname[0]=='\0' ||
       (bcache[i].brdattr & BRD_GROUPBOARD) ) continue;
       if((bcache[i].brdattr & BRD_NOTRAN )&& istran[i])
         {
       while(SHM->Bbusystate) {safe_sleep(1);}
       SHM->Bbusystate = 1;
           bcache[i].brdattr = bcache[i].brdattr & ~BRD_NOTRAN;
           strncpy(bcache[i].title + 5, "●", 2);
       SHM->Bbusystate = 0;

           substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
     }
       else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i]) 
         {
       while(SHM->Bbusystate) {safe_sleep(1);}
           SHM->Bbusystate = 1;
           bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN;
           strncpy(bcache[i].title + 5, "◎", 2);
           SHM->Bbusystate = 0;
           substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1);
     }

     }
    return 0;
}