summaryrefslogtreecommitdiffstats
path: root/util/deluserfile.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
commitae31e19f92e717919ac8e3db9039eb38d2b89aae (patch)
treec70164d6a1852344f44b04a653ae2815043512af /util/deluserfile.c
downloadpttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/deluserfile.c')
-rw-r--r--util/deluserfile.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/util/deluserfile.c b/util/deluserfile.c
new file mode 100644
index 00000000..63cfefba
--- /dev/null
+++ b/util/deluserfile.c
@@ -0,0 +1,147 @@
+/* $Id: deluserfile.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */
+/* 自動砍user目錄檔案程式 */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include "config.h"
+#include "pttstruct.h"
+#include "util.h"
+
+#define HOLDWRITELOG
+#define DELZEROFILE
+#define USERHOME BBSHOME "/home"
+
+int bad_user_id(char *userid)
+{
+ register char ch;
+
+ if (strlen(userid) < 2)
+ return 1;
+
+ if (!isalpha(*userid))
+ return 1;
+
+ if (!strcasecmp(userid, "new"))
+ return 1;
+
+ while ((ch = *(++userid)))
+ if (!isalnum(ch))
+ return 1;
+ return 0;
+}
+
+void del_file(char *userid)
+{
+ char buf[200], buf1[200];
+ struct dirent *de;
+ DIR *dirp;
+ char *ptr;
+
+ sprintf(buf, BBSHOME "/home/%c/%s", userid[0], userid);
+
+ if (chdir(buf) == -1)
+ return;
+
+ if (!(dirp = opendir(buf)))
+ return;
+
+ while ((de = readdir(dirp)))
+ {
+ ptr = de->d_name;
+ if (ptr[0] > ' ' && ptr[0] != '.')
+ {
+ if (strstr(ptr, "writelog"))
+#ifdef HOLDWRITELOG
+ {
+ fileheader_t mymail;
+
+ stampfile(buf, &mymail);
+ mymail.savemode = 'H'; /* hold-mail flag */
+ mymail.filemode = FILE_READ;
+ strcpy(mymail.owner, userid);
+ strcpy(mymail.title, "熱線記錄");
+ sprintf(buf1, BBSHOME "/home/%c/%s/writelog",
+ userid[0], userid);
+ rename(buf1, buf);
+ sprintf(buf1, BBSHOME "/home/%c/%s/.DIR", userid[0], userid);
+ append_record(buf1, &mymail, sizeof(mymail));
+ }
+#else
+ unlink(ptr);
+#endif
+ else if (strstr(ptr, "chat_"))
+ unlink(ptr);
+ else if (strstr(ptr, "ve_"))
+ unlink(ptr);
+ else if (strstr(ptr, "SR."))
+ unlink(ptr);
+ else if (strstr(ptr, ".old"))
+ unlink(ptr);
+ else if (strstr(ptr, "talk_"))
+ unlink(ptr);
+ }
+ }
+ closedir(dirp);
+}
+
+void mv_user_home(char *ptr)
+{
+ char buf[200];
+
+ printf("move user %s to tmp\n", ptr);
+ sprintf(buf, "cp -R " BBSHOME "/home/%c/%s " BBSHOME "/tmp", ptr[0], ptr);
+// sprintf(buf,"rm -rf " BBSHOME "/home/%c/%s",ptr[0],ptr);
+ if (!system(buf))
+ { //Copy success
+
+ sprintf(buf, "rm -rf " BBSHOME "/home/%c/%s", ptr[0], ptr);
+ system(buf);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ struct dirent *de;
+ DIR *dirp;
+ char *ptr, buf[200], ch;
+ int count = 0;
+/* visit all users */
+
+ printf("new version, deleting\n");
+
+ for (ch = 'A'; ch <= 'z'; ch++)
+ {
+ if(ch > 'Z' && ch < 'a')
+ continue;
+ printf("Cleaning %c\n", ch);
+ sprintf(buf, USERHOME "/%c", ch);
+ if (!(dirp = opendir(buf)))
+ {
+ printf("unable to open %s\n", buf);
+ continue;
+ }
+
+ while ((de = readdir(dirp)))
+ {
+ ptr = de->d_name;
+
+ /* 預防錯誤 */
+ if (!bad_user_id(ptr))
+ {
+ if (!(count++ % 300))
+ printf(".\n");
+ if (!searchuser(ptr))
+ mv_user_home(ptr);
+ else
+ del_file(ptr);
+ }
+ }
+ closedir(dirp);
+ }
+ return 0;
+}