1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,55 @@ |
1 |
+/* |
|
2 |
+ * kakumei-invite.c |
|
3 |
+ * |
|
4 |
+ * generate invitations for kakumei. |
|
5 |
+ * |
|
6 |
+ * Author: Dario Rodriguez dario@softhome.net |
|
7 |
+ * This program is licensed under the terms of the Affero GPL v1+ |
|
8 |
+ */ |
|
9 |
+ |
|
10 |
+#include <stdio.h> |
|
11 |
+#include <stdlib.h> |
|
12 |
+#include <unistd.h> |
|
13 |
+#include <string.h> |
|
14 |
+#include <sys/stat.h> |
|
15 |
+#include <sys/types.h> |
|
16 |
+ |
|
17 |
+#define INVITATIONUSER "invitation" |
|
18 |
+#define INVITESDIR "data/invitations" |
|
19 |
+ |
|
20 |
+int |
|
21 |
+main(int argc, char *argv[]) |
|
22 |
+{ |
|
23 |
+ int numinvites; |
|
24 |
+ FILE *invite,*f; |
|
25 |
+ int i; |
|
26 |
+ char *name,*ptr; |
|
27 |
+ if(argc<3 || (numinvites=atoi(argv[1]))<1 || (f=fopen(argv[2],"a"))==NULL) { |
|
28 |
+ printf("Syntax: %s numinvites invitedoc.txt\n",argv[0]); |
|
29 |
+ return(1); |
|
30 |
+ } |
|
31 |
+ mkdir("data",0770); |
|
32 |
+ mkdir("data/invites",0700); |
|
33 |
+ setenv("TMPDIR",INVITESDIR,1); |
|
34 |
+ for(i=0;i<numinvites;i++) { |
|
35 |
+ name=tempnam(INVITESDIR,"ka"); |
|
36 |
+ if((ptr=strrchr(name,'/'))!=NULL) |
|
37 |
+ ptr++; |
|
38 |
+ else |
|
39 |
+ ptr=name; |
|
40 |
+ if((invite=fopen(name,"w"))==NULL) { |
|
41 |
+ printf("ERROR: Couldn't generate invitation number %i, exiting\n",i+1); |
|
42 |
+ free(name),name=NULL; |
|
43 |
+ fclose(f),f=NULL; |
|
44 |
+ return(1); |
|
45 |
+ } |
|
46 |
+ printf("%s\n",ptr); |
|
47 |
+ fprintf(invite,"%s\n",ptr); |
|
48 |
+ fprintf(f,"Invitation number %i:\n\n\tUser: %s\n\tPass: %s\n\n",i+1,INVITATIONUSER,ptr); |
|
49 |
+ fclose(invite),invite=NULL; |
|
50 |
+ free(name),name=NULL; |
|
51 |
+ } |
|
52 |
+ fclose(f),f=NULL; |
|
53 |
+ printf("%i invitations generated in file %s\n",i,argv[2]); |
|
54 |
+ return(0); |
|
55 |
+} |