-
Notifications
You must be signed in to change notification settings - Fork 0
/
converted_masterEngineWithDBI_CLI4.pl
2843 lines (2437 loc) · 94.8 KB
/
converted_masterEngineWithDBI_CLI4.pl
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
my $global_email_Server_Name = 'localhost';
my $global_email_Main_User_Name = 'home';
my $global_email_Mail_User_Password = '1qazZAQ!';
my $global_email_url = 'localhost';
my $global_email_uses_SSL = '0';
my $global_pop3_Port = '0';
my $global_MYSQL_host = 'localhost';
my $global_MYSQL_database = 'txtCLI';
my $global_MYSQL_username = 'root';
my $global_MYSQL_password = 'mullet11';
my $global_admins = 'all';
#!/usr/bin/perl
#
#masterEngine.pl
#
#This is the central core of the gateway. Email content
#comes here to figure out what its content needs to do
#all parent scripts used to connect the sms message with the
#internet need to be in here somewhere or they cannot
#be used.
#
#
#Args = $ARGV[0]:emailaddress
#Args = $ARGV[1]:sms value
use strict;
use DBI;
use Cwd;
my $dir = getcwd;
open (LOGBLOG, "+>logs\/log_blog.txt");
my ($sec, $min, $hr, $day, $mon, $year) = localtime;
printf LOGBLOG ("#####\n#####\n#####\n%02d/%02d/%04d %02d:%02d:%02d:", $day, $mon + 1, 1900 + $year, $hr, $min, $sec);
close (LOGBLOG);
open (LOG, "+>logs\/log_masterEngine.txt");
($sec, $min, $hr, $day, $mon, $year) = localtime;
printf LOG ("#####\n#####\n#####\n%02d/%02d/%04d %02d:%02d:%02d:In masterEngine.pl \n", $day, $mon + 1, 1900 + $year, $hr, $min, $sec);
#print "z";
my $theApp;
my $logBlogLines = 0;
my $logLines = 0;
my $theTextCompleted = "";
my $closeUpString = "";
my $host = $global_MYSQL_host;
my $database = $global_MYSQL_database;
my $username = $global_MYSQL_username ;
my $password = $global_MYSQL_password;
#all of the blog variables
my $connectionInfo = "dbi:mysql:$database;$host";
my $connection = DBI->connect($connectionInfo, $username, $password);
my $connection2 = DBI->connect($connectionInfo, $username, $password);
my $hostBlog = $global_MYSQL_host;
my $databaseBlog = $global_MYSQL_database;
my $usernameBlog = $global_MYSQL_username;
my $passwordBlog = $global_MYSQL_password;
my $theEmailBlog;
my $theAppBlog;
my $theSubAppBlog;
my $theTextBlog;
my $theTextBlogCompleted;
my $theTextBlogForNextScript;
my $closeUpBlogStringBlog;
my $passwordBlogSet;
my @spaceDelimitedtheTextBlog;
my $nextWordBlog;
my $connectionInfoBlog = "dbi:mysql:$databaseBlog;$hostBlog";
my $connectionBlog = DBI->connect($connectionInfoBlog, $usernameBlog, $passwordBlog);
#my $str = $connection->prepare("DELETE FROM apps");
#$str->execute;
#my $str = $connection->prepare("DELETE FROM blogList");
#$str->execute;
#my $str = $connection->prepare("DELETE FROM blogPosts");
#$str->execute;
#my $str = $connection->prepare("DELETE FROM blogSubscriptions");
#$str->execute;
#arg1 is phone number of sender
#arg2 is text
my $theEmail = $ARGV[0];
chomp($theEmail);
my $theText = $ARGV[1];
chomp($theText);
#for some reason extra carriage returns are showing up at the end.
#Also, if someone wants to put carriage returns into their post we fix it here
PRINTLOG ("theText before changing the carraige returns:#\n$theText\n#\n");
$theText =~ s/\\n$//g;
$theText =~ s/\\\\n/\n/g;
$theText =~ s/\\\\\\n/\\\\n/g;
PRINTLOG ("theText after changing the carraige returns:#\n$theText\n#\n");
my $attachmentString = $ARGV[2];
chomp($attachmentString);
my $theOriginalFrom = $ARGV[3];
chomp ($theOriginalFrom);
$theOriginalFrom =~ /@(.*)$/;
my $theOriginalFromURL = $1;
my $theFrom = $theOriginalFromURL;
chomp($theFrom);
my $fromEmail;
if ($theFrom =~ /<(.*)>/) {
$theFrom = $1;
}
if ($theFrom =~ /\w/) {
$fromEmail = $theOriginalFrom;
}
if ($theText =~ /qz/) {
#this adds the last conversation onto this script
my $str = $connection->prepare("SELECT * FROM lastEmailSent WHERE (theTo = \"$theEmail\" and theFrom = \"$fromEmail\")");
$str->execute();
my @resultsCheck=$str->fetchrow_array;
$theText =~ s/qz/$resultsCheck[3]/s;
}
elsif ($theText =~ /\\q\\z/) {
#this lets us use the script qz on the script
$theText =~ s/\\q\\z/qz/s;
}
PRINTLOG ("starting values\ntheEmail=$theEmail=\ntheText=$theText=\nattachmentString=$attachmentString\n\n\n");
my $nextWord;
my @theTextForNextScriptArray;
my $theTextForNextScript = $theText;
PRINTLOG( "about to go into getNextWord with theText=$theText=\n");
getNextWord("");
PRINTLOG( "getNextWord is done. nextWord=$nextWord=\n");
#lets see if there is a number to rank the most recent item seen
if ($nextWord =~ /\d/) {
#
#
# insert ranking code here
#
#
getNextWord("");
}
while ($nextWord) {
#print "y";
PRINTLOG( "\n\n\n***********\ngoing through while loop to go into a new star sub with <$nextWord>\n");
#as long as there are nextWords, we will continue this.
if ($nextWord =~ /^\*c/) {
#starc creates a codeword and its script
starc();
}
elsif ($nextWord =~ /^\*p/) {
#starp adds a password to a subapp
starp();
}
elsif ($nextWord =~ /^\*n/) {
#starn adds a new app
starn();
}
elsif ($nextWord =~ /^\*e/) {
#look into a subApp
stare();
}
elsif ($nextWord =~ /^\*a/) {
#stara changes the admins. either removing an admin or adding one
stara();
}
elsif ($nextWord =~ /^\*x/) {
#starx adds a subapp to an app
starx();
}
elsif ($nextWord =~ /^\*z/) {
starz();
}
elsif ($nextWord =~ /^\*s/) {
#app status
stars();
}
elsif ($nextWord =~ /^\*r/) {
#app security
starr();
}
elsif ($nextWord =~ /^\*m/) {
#change From email
starm();
}
elsif ($nextWord =~ /^\*h/) {
#suggest some subapps for this app
starh();
}
elsif ($nextWord =~ /^\*b/) {
#search app
starb();
}
elsif ($nextWord =~ /^\*d/) {
#search all possible
stard();
}
elsif ($nextWord =~ /^\*g/) {
#admin accept app reader
PRINTLOG( "going into starg\n");
starg();
}
elsif ($nextWord =~ /^\*y/) {
#change user nickname
PRINTLOG( "going into stary\n");
stary();
}
elsif ($nextWord =~ /^\*(\d*)/) {
#perform a temp Code
my $theNumber = $_[0];
starNumber($theNumber);
}
#elsif ($nextWord =~ /^\*f/) {
#user request to read app
# starf();
#}
elsif ($nextWord =~ /exit/) {
PRINTLOG( "in exit\n");
$connection->do("update userUsage SET currentString=\'\' WHERE userName=\'$theEmail\'");
$theTextCompleted = "";
getNextWord();
}
elsif ($nextWord =~ /^#/ ) {
#this gets the recent usage string the recent usage string
PRINTLOG( "no codeword so lets see what user did last\n");
my $str = $connection->prepare("SELECT * FROM userUsage WHERE userName = \"$theEmail\"");
$str->execute();
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[2] =~ /\w/) {
PRINTLOG( "in if\n");
$theTextCompleted = "";
$theTextForNextScript =~ s/^\s+|\s+$//g;
my @spaceDelimitedtheText = split(/ /,$theTextForNextScript);
$nextWord = "";
}
getNextWord();
PRINTLOG( "about to get first nextWord=<$nextWord> before while\n");
}
elsif ($nextWord =~ /^\w/) {
my $variables = "";
my $CLI;
#this looks at codewords
my $str = $connection->prepare("SELECT * FROM codeWord WHERE word = \"$nextWord\"");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ( @resultsCheck[1] ) {
$CLI = $resultsCheck[1];
$CLI =~ s/qq/$theEmail/g;
while (isAnotherWordBeforeNextStar()) {
PRINTLOG( "in while and CLI=<$CLI>\n");
getNextWord();
$CLI =~ s/jj/$nextWord/;
}
$theTextForNextScript = "$CLI $theTextForNextScript";
}
else {
closeUp("");
}
getNextWord();
}
else {
PRINTLOG( "completed while loop and nothing was found\n");
closeUp("");
}
}
###############################
#############Subs##############
###############################
sub sendOutText {
PRINTLOG( "in sendOutText\n");
my $sendOutEmail = $_[0];
my $bodyOfEmail = $_[1];
my $myRepeat = $_[2];
my $execWorked;
if ($bodyOfEmail =~ /\w/) {
createOutputFileForNextScript("4", $sendOutEmail, $bodyOfEmail, $fromEmail,$myRepeat);
}
PRINTLOG( "about to make to make an email with \"$sendOutEmail\" \"$bodyOfEmail\ \"$fromEmail\")\n");
PRINTLOG( "leaving sendOutText\n");
}
sub closeUp {
PRINTLOG( "in closeup\n");
my $temp = $_[0];
PRINTLOG( "in closeUp. theTextCompleted=$theTextCompleted=\n");
$connection->do("update userUsage SET currentString=\'$theTextCompleted\' WHERE userName=\'$theEmail\'");
$closeUpString = $closeUpString . $temp;
sendOutText($theEmail,$closeUpString,0);
PRINTLOG( "leaving closeup\n");
die;
}
sub createOutputFileForNextScript {
use Time::HiRes qw(gettimeofday);
my $folder = 'workToDo/';
my $scriptName = 'masterEngine';
my $extension = 'medc';
my $numVariables = $_[0];
PRINTLOG("in createOutputFileForNextScript with this many variables <$numVariables> the first three are <$_[0]> <$_[1]> <$_[2]>\n");
my $timestamp = int (gettimeofday * 1000000000);
open(OUTVARIABLEFILE,"+>$folder$timestamp$scriptName.$extension");
PRINTLOG( " this is the output data file <$folder$timestamp$scriptName.$extension>\n");
my $temp = 1;
for ($temp = 1; $temp <= $numVariables; $temp++) {
print OUTVARIABLEFILE "iiiiiiiiBeginNewVariableiiiiiiiiiii\n";
my $nextVariableToPrint = $_[$temp];
if ($nextVariableToPrint =~ /^(.*)45454545454545\W*$/) {
$nextVariableToPrint = $1;
}
#This is where we save the last thing sent from this conversation. In case it will be used later
if ($temp == 2) {
saveThisEmail($_[1],$_[2],$_[3]);
}
print OUTVARIABLEFILE "$nextVariableToPrint\n";
}
close (OUTVARIABLEFILE);
}
sub saveThisEmail {
PRINTLOG("in saveThisEmail\n");
my $myTo = $_[0];
my $myPost = $_[1];
my $myFrom = $_[2];
#make sure this conversation doesn't exist yet
PRINTLOG("about to do the following MYSQL <SELECT * FROM lastEmailSent WHERE theTo = \'$myTo\' and theFrom = \'$myFrom\'>\n");
my $str = $connection->prepare("SELECT * FROM lastEmailSent WHERE theTo = \'$myTo\' and theFrom = \'$myFrom\'");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
PRINTLOG("about to evaluate if resultsCheck had anything <$resultsCheck[0]>\n");
if (not $resultsCheck[0]) {
PRINTLOG ("this conversation did not exist. About to add it <$myPost>\n");
$connection->do("INSERT INTO lastEmailSent (theTo,theFrom,post) VALUES (\'$myTo\',\'$myFrom\',\'$myPost\')");
PRINTLOG ("leaving saveThisEmail with everything set\n");
return;
}
else {
PRINTLOG ("This conversation did exist. We are adding it");
$connection->do("update lastEmailSent SET post=\'$myPost\' WHERE (theTo = \'$myTo\' and theFrom =\'$myFrom\')");
return;
PRINTLOG ("Leaving saveThisEmail successfully\n");
}
}
sub getNextWord {
PRINTLOG( "in getNextWord\n");
my $temp = $_[0];
if ($theTextForNextScript =~ /\w/ or $theTextForNextScript =~ /\#/ or $theTextForNextScript =~ /\*/ ) {
my @spaceDelimitedtheText = split(/ /,$theTextForNextScript);
$nextWord = $spaceDelimitedtheText[0];
chomp ($nextWord);
@theTextForNextScriptArray = shift(@spaceDelimitedtheText);
$theTextForNextScript = join(" ",@spaceDelimitedtheText);
$theTextCompleted = $theTextCompleted . " " . $nextWord;
chomp($theTextCompleted);
}
else {
PRINTLOG( "leaving getNextWord. It appears no more words exist\n");
closeUp("");
}
PRINTLOG( "leaving getNextWord with nextWord <$nextWord>\n");
}
sub isAnotherWordBeforeNextStar {
PRINTLOG( "in isAnotherWordBeforeNextStar and theTextForNextScript:<$theTextForNextScript> and nextWord:<$nextWord>\n");
if ($theTextForNextScript !~ /^$/) {
my @spaceDelimitedtheText = split(/ /,$theTextForNextScript);
my $nextWordTemp = $spaceDelimitedtheText[0];
my $tempInt = 1;
while (($nextWordTemp =~ /^\s*$/) and ($#spaceDelimitedtheText > $tempInt)) {
$nextWordTemp = $spaceDelimitedtheText[$tempInt];
$tempInt++;
}
if ($nextWordTemp =~ /^$/ or $nextWordTemp =~ /^\*\w$/ or $nextWordTemp =~ /^\#\#/) {
PRINTLOG( "leaving isAnotherWordBeforeNextStar with <0>\n");
return 0;
}
else {
PRINTLOG( "leaving isAnotherWordBeforeNextStar with <1>\n");
return 1;
}
}
}
sub isAnotherWordOfCodeWord {
PRINTLOG( "in isAnotherWordOfCodeWord and theTextForNextScript:<$theTextForNextScript> and nextWord:<$nextWord>\n");
if ($theTextForNextScript =~ /\w/ ) {
my @spaceDelimitedtheText = split(/ /,$theTextForNextScript);
my $nextWordTemp = $spaceDelimitedtheText[0];
if ($nextWordTemp =~ /^$/ or $nextWordTemp =~ /^\#\#/) {
PRINTLOG( "leaving isAnotherWordBeforeNextStar with <0>\n");
return 0;
}
else {
PRINTLOG( "leaving isAnotherWordBeforeNextStar with <1>\n");
return 1;
}
}
}
sub isAnotherWord {
PRINTLOG( "in isAnotherWord with <$theTextForNextScript>\n");
if ($theTextForNextScript =~ /^$/) {
PRINTLOG( "leaving isAnotherWord with <0> as there was no more words\n");
return 0;
}
if ($theTextForNextScript =~ /^\#\#/) {
PRINTLOG( "leaving isAnotherWord with <0> as there was a pound#\n");
getNextWord();
return 0;
}
else {
PRINTLOG( "leaving isAnotherWord with <1>\n");
return 1;
}
}
sub PRINTLOG {
$logLines++;
if ($logLines < 5000) {
print LOG $_[0];
}
else {
die;
}
}
sub starIsDone {
PRINTLOG( "in starIsDone\n");
my $temp = $_[0];
$connection->do("update userUsage SET currentString=\'\' WHERE userName=\'$theEmail\'");
$theTextCompleted = "";
$closeUpString = $closeUpString . " " . $temp;
getNextWord("$closeUpString");
PRINTLOG( "leaving starIsDone\n");
}
sub findAllOptionsOrFormat {
PRINTLOG( "in findAllOptions\n");
my $temp = "";
if (isAnotherWordBeforeHash()) {
getNextWord();
$temp = $nextWord;
}
while (isAnotherWordBeforeHash()) {
getNextWord();
$temp = $temp . " " . $nextWord;
}
PRINTLOG( "leaving findAllOptions with return <$temp> and nextWord <$nextWord> and theTextForNextScript:<$theTextForNextScript>\n");
return $temp;
}
sub isAnotherWordBeforeHash {
PRINTLOG( "in isAnotherWordBeforeHash and theTextForNextScript:<$theTextForNextScript> and nextWord:<$nextWord>\n");
my @nextWordTemp = split(/ /,$theTextForNextScript);
if ($nextWordTemp[0] =~ /^$/) {
PRINTLOG( "leaving isAnotherWordBeforeHash with <0>\n");
return 0;
}
if ($nextWordTemp[0] =~ /^\#$/) {
PRINTLOG( "leaving isAnotherWordBeforeHash with, it was a # so I am moving the getNextWord cursor to the next word <0>\n");
return 0;
}
if ($nextWordTemp[0] =~ /^\#\#$/) {
PRINTLOG( "leaving isAnotherWordBeforeHash with, it was a ## so I am moving the getNextWord cursor to the next word <0>\n");
return 0;
}
else {
PRINTLOG( "leaving isAnotherWordBeforeHash with <1>\n");
return 1;
}
}
sub addEmailUser {
PRINTLOG ("in addEmailUser with <" . $_[0] . ">\n");
my $theWord = $_[0];
open (EMAILS, ">>\/etc\/postfix\/vmailbox");
my $fullNewWord = $theWord . '@' . $theOriginalFromURL;
PRINTLOG( "about to add vmailbox user $fullNewWord\n");
print EMAILS "\n" . $fullNewWord . "\thome";
close EMAILS;
system "postmap /etc/postfix/vmailbox";
system "postfix reload";
PRINTLOG ("leaving addEmailUser after adding the following to vmailbox <$fullNewWord . \thome>\n");
}
sub getAllSubAppCode {
PRINTLOG( "in getAllSubAppCode\n");
my $temp = "";
if (isAnotherWordBeforeNextStar()) {
getNextWord();
$temp = $nextWord;
}
while (isAnotherWordBeforeNextStar()) {
getNextWord();
$temp = $temp . " " . $nextWord;
}
PRINTLOG( "leaving getAllSubAppCode with return <$temp>\n");
return $temp;
}
sub getAllCodeWord {
PRINTLOG( "in getAllCodeWord\n");
my $temp = "";
while (isAnotherWordOfCodeWord()) {
getNextWord();
$temp = $temp . " " . $nextWord;
}
PRINTLOG( "leaving getAllCodeWord with return <$temp>\n");
return $temp;
}
sub setNickname {
my $theRealName = $_[0];
PRINTLOG("In setNickname\nabout to do <select * FROM userUsage WHERE (userName = \'$theRealName\')>\n");
my $str2 = $connection2->prepare("select * FROM userUsage WHERE (userName = \'$theRealName\')");
$str2->execute;
my @resultsCheck2=$str2->fetchrow_array;
if ($resultsCheck2[4]) {
return $resultsCheck2[4];
}
else {
return $theRealName;
}
PRINTLOG("Leaving set nickname\n");
}
sub isAdminOrAll {
PRINTLOG( "in isAdminOrAll\n");
my $str = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$theApp\' AND (admin1 = \'$theEmail\' OR admin2 = \'$theEmail\' OR admin3 = \'$theEmail\'))");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[0] =~ /^$/) {
my $str1 = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$theApp\' AND security = \'all\')");
$str1->execute;
my @resultsCheck1=$str1->fetchrow_array;
if ($resultsCheck1[0] =~ /^$/) {
closeUp("");
}
else {
return 1;
}
}
else {
return 1;
}
}
sub isAllNotAdmin {
PRINTLOG( "in isAllNotAdmin\n");
my $str1 = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$theApp\' AND security = \'all\')");
$str1->execute;
my @resultsCheck1=$str1->fetchrow_array;
if ($resultsCheck1[0] =~ /^$/) {
return 0;
}
else {
return 1;
}
}
sub isAdminOrCreator {
my $mySubAppName = $_[0];
PRINTLOG( "in isAdminOrCreator\n");
PRINTLOG ("about to do <SELECT * FROM apps WHERE (appName = \'$theApp\' AND (admin1 = \'$theEmail\' OR admin2 = \'$theEmail\' OR admin3 = \'$theEmail\'))>\n");
my $str = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$theApp\' AND (admin1 = \'$theEmail\' OR admin2 = \'$theEmail\' OR admin3 = \'$theEmail\'))");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[0] =~ /^$/) {
if (isAdminOrAll()) {
PRINTLOG("about to do <SELECT * FROM blogList WHERE (appName = \'$theApp\' AND subAppName = \'$mySubAppName\' AND creator = \'$theEmail\')>\n");
my $str1 = $connection->prepare("SELECT * FROM blogList WHERE (appName = \'$theApp\' AND subAppName = \'$mySubAppName\' AND creator = \'$theEmail\')");
$str1->execute;
my @resultsCheck1=$str1->fetchrow_array;
if ($resultsCheck1[0] =~ /^$/) {
PRINTLOG ("leaving isAdminOrCreator with <0>, not an admin or creator\n");
return 0;
}
else {
PRINTLOG ("leaving isAdminOrCreator with <1>. Email is a creator\n");
return 1;
}
}
else {
PRINTLOG ("leaving isAdminOrCreator with <0>, isAdminOrAdd did not work\n");
return 0;
}
}
else {
PRINTLOG("leaving isAdminOrCreator with <1>. Email is an admin\n");
return 1;
}
}
sub takeOffHashes {
PRINTLOG("In takeOffHashes with <$_[0]>\n");
my $theCLI = $_[0];
$theCLI =~ s/\\\#\\\#/\#\#/g;
$theCLI =~ s/\\\\\#\\\\\#/\\\#\\\#/g;
$theCLI =~ s/\\\\\\\#\\\\\\\#/\\\\\#\\\\\#/g;
$theCLI =~ s/\\\\\\\\\#\\\\\\\\\#/\\\\\\\#\\\\\\\#/g;
$theCLI =~ s/\\q\\j/qj/g;
$theCLI =~ s/\\q\\b/qb/g;
$theCLI =~ s/\\j\\j/jj/g;
$theCLI =~ s/\\q\\q/qq/g;
$theCLI =~ s/\\j\\q/jq/g;
$theCLI =~ s/\\q\\j/qj/g;
$theCLI =~ s/\\q\\z/qz/g;
$theCLI =~ s/\\\\q\\\\j/\\q\\j/g;
$theCLI =~ s/\\\\q\\\\b/\\q\\b/g;
$theCLI =~ s/\\\\j\\\\j/\\j\\j/g;
$theCLI =~ s/\\\\q\\\\q/\\q\\q/g;
$theCLI =~ s/\\\\j\\\\q/\\j\\q/g;
$theCLI =~ s/\\\\q\\\\j/\\q\\j/g;
$theCLI =~ s/\\\\q\\\\z/\\q\\z/g;
$theCLI =~ s/\\\\\\q\\\\\\j/\\\\q\\\\j/g;
$theCLI =~ s/\\\\\\q\\\\\\b/\\\\q\\\\b/g;
$theCLI =~ s/\\\\\\j\\\\\\j/\\\\j\\\\j/g;
$theCLI =~ s/\\\\\\q\\\\\\q/\\\\q\\\\q/g;
$theCLI =~ s/\\\\\\j\\\\\\q/\\\\j\\\\q/g;
$theCLI =~ s/\\\\\\q\\\\\\j/\\\\q\\\\j/g;
$theCLI =~ s/\\\\\\q\\\\\\z/\\\\q\\\\z/g;
$theCLI =~ s/\\\\\\\\q\\\\\\\\j/\\\\\\q\\\\\\j/g;
$theCLI =~ s/\\\\\\\\q\\\\\\\\b/\\\\\\q\\\\\\b/g;
$theCLI =~ s/\\\\\\\\j\\\\\\\\j/\\\\\\j\\\\\\j/g;
$theCLI =~ s/\\\\\\\\q\\\\\\\\q/\\\\\\q\\\\\\q/g;
$theCLI =~ s/\\\\\\\\j\\\\\\\\q/\\\\\\j\\\\\\q/g;
$theCLI =~ s/\\\\\\\\q\\\\\\\\j/\\\\\\q\\\\\\j/g;
$theCLI =~ s/\\\\\\\\q\\\\\\\\z/\\\\\\q\\\\\\z/g;
PRINTLOG("Leaving takeOffHashes with <$theCLI>\n");
return $theCLI;
}
sub isAdmin {
#see if this guy is an admin
PRINTLOG(" in isAdmin about to do <SELECT * FROM apps WHERE (appName = \'$theApp\' AND (admin1 = \'$theEmail\' OR admin2 = \'$theEmail\' OR admin3 = \'$theEmail\'))>\n");
my $str = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$theApp\' AND (admin1 = \'$theEmail\' OR admin2 = \'$theEmail\' OR admin3 = \'$theEmail\'))");
$str->execute;
my $theAdmin = $theEmail;
my @resultsCheck=$str->fetchrow_array;
if (@resultsCheck) {
PRINTLOG( "leaving isAdmin with return <1>\n");
return 1;
}
else {
PRINTLOG( "leaving isAdmin with return <0>\n");
return 0;
}
}
sub finalPostFormat {
my $mySearchTerm = $_[0];
my $myPost = $_[1];
my $toEmail = $_[2];
my $theFromEmail = $_[3];
my $myFormat = $_[4];
$myFormat =~ s/^ //; #we seem to have a leading space. get rid of it
my $finalPost = $_[5];
my $searchResultsString = $_[6];
if ($myFormat =~ /^(?<!\\)\{/){
$finalPost = $finalPost . $myPost;
do {
$myFormat =~ s/.//;
} while ($myFormat !~ /^(?<!\\)\}/) ;
$myFormat =~ s/.//;
PRINTLOG ("It was a { myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^\\\\/) {
$myFormat =~ s/..//;
$finalPost = $finalPost . "\\";
PRINTLOG ("It was a \\ myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^\\/) {
$myFormat =~ s/.(.)//;
$finalPost = $finalPost . $1;
PRINTLOG ("It was a \ myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-st/) {
$finalPost = $finalPost . $mySearchTerm;
$myFormat =~ s/...//;
PRINTLOG ("It was a -st myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-e/) { #carrage return for the format
$finalPost = $finalPost . "45454545454545";
$myFormat =~ s/..//;
PRINTLOG ("It was a -e myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-t/) {
$finalPost = $finalPost . $toEmail;
$myFormat =~ s/..//;
PRINTLOG ("It was a -t myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-fe/) {
$finalPost = $finalPost . $theFromEmail;
$myFormat =~ s/...//;
PRINTLOG ("It was a -fe myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^$/) {
PRINTLOG ("It is done. myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return $finalPost;
}
else {
$myFormat =~ s/(.)//;
$finalPost = $finalPost . $1;
PRINTLOG ("myformat was <$myFormat> and finalPost is now <$finalPost>\n");
return finalPostFormat($mySearchTerm,$myPost,$toEmail,$theFromEmail,$myFormat,$finalPost);
}
PRINTLOG ("Leaving finalPostFormat with <$finalPost>\n");
return $finalPost;
}
sub addToPostFormat {
my $myAuthor = $_[0];
my $myDate = $_[1];
my $mySubApp = $_[2];
my $myApp = $_[3];
my $numbers = $_[4];
my $results = $_[5];
my $myFormat = $_[6];
my $finalPost = $_[7];
if ($myFormat =~ /(?<!\\)\{(.*)(?<!\\)\}/) {
$myFormat = $1;
PRINTLOG ("We found a { in myformat: <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^\\\\/) {
$myFormat =~ s/..//;
$finalPost = $finalPost . "\\";
PRINTLOG ("It was a \\ myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^\\/) {
$myFormat =~ s/.(.)//;
$finalPost = $finalPost . $1;
PRINTLOG ("It was a \ myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-ap/) {
$finalPost = $finalPost . $myApp;
$myFormat =~ s/...//;
PRINTLOG ("It was a -ap myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-sa/) {
$finalPost = $finalPost . $mySubApp;
$myFormat =~ s/...//;
PRINTLOG ("It was a -sa myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-d/) {
$finalPost = $finalPost . $myDate;
$myFormat =~ s/..//;
PRINTLOG ("It was a -d myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-a/) {
$finalPost = $finalPost . $myAuthor;
$myFormat =~ s/..//;
PRINTLOG ("It was a -a myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-b/) {
$finalPost = $finalPost . '*';
$myFormat =~ s/..//;
PRINTLOG ("It was a -b myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-p/) {
$finalPost = $finalPost . $results;
$myFormat =~ s/..//;
PRINTLOG ("It was a -p myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^-n/) {
$finalPost = $finalPost . $numbers;
$myFormat =~ s/..//;
PRINTLOG ("It was a -n myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
elsif ($myFormat =~ /^$/) {
PRINTLOG ("It is done. myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return $finalPost;
}
else {
$myFormat =~ s/(.)//;
$finalPost = $finalPost . $1;
PRINTLOG ("myformat was <$myFormat> and addToPost is now <$finalPost>\n");
return addToPostFormat($myAuthor,$myDate,$mySubApp,$myApp,$numbers,$results,$myFormat,$finalPost);
}
PRINTLOG("Leaving addToPost with <$finalPost>\n");
return $finalPost;
}
sub createEmailToRequestAdminSecurityApproval {
use Time::HiRes qw(gettimeofday);
my $timestamp = int (gettimeofday * 1000000000);
PRINTLOG ("In createEmailToRequestAdminSecurityApproval with <$_[0]> <$_[1]> <$_[2]> <$_[3]> <$_[4]>\n");
my $myApp = $_[0];
my $mySubApp = $_[1];
my $myTheEmail = $_[2];
my $mySubscribeOrRead = $_[3];
my $myCLI = $_[4];
my $myCodeName = "a" . $timestamp; #This is the myCodeName after demo version is complete. It cannot work with our email service as it makes
addEmailUser($myCodeName);
#emails with crazy numbers in them. This only works if our email service sends from any email address
#my $myCodeName = "a13284928193829";
#this is used for both subapp approvals and app approvals. So we first need to see if
#we need app admins or subapp admins
if ($mySubApp =~ /^$/) {
#this is an app admin request
PRINTLOG(" this is an app request with <INSERT INTO codeWord (word,cli,username) VALUES (\'$myCodeName\',\'$myCLI\',\'admin\')>\n");
my $myCLI = "*g $myApp -a -a $myTheEmail";
#$connection->do("INSERT INTO codeWord (word,cli,username) VALUES (\'$myCodeName\',\'$myCLI\',\'admin\')");#This is the myCodeName after demo version is complete. It cannot work with our email service as it makes
#emails with crazy num bers in them. This only works if our email service sends from any email address
#mysql uses \ as a wildcard and deletes one. So the CLI needs an additional at each locations
$myCLI =~ s/\\/\\\\/g;
$connection->do("update codeWord SET cli = \'$myCLI\' WHERE (word = \'a13284928193829\')");
my $theFromEmail = $myCodeName . '@' . $theOriginalFromURL;
my $nickname = setNickname($theEmail);
my $bodyEmail = "$nickname wishes to subscribe to $myApp. Text YES back to approve";
my $str = $connection->prepare("SELECT * FROM apps WHERE (appName = \'$myApp\')");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[3]) {
createOutputFileForNextScript("3", $resultsCheck[3],$bodyEmail , $theFromEmail);
}
if ($resultsCheck[4]) {
createOutputFileForNextScript("3", $resultsCheck[4],$bodyEmail , $theFromEmail);
}
if ($resultsCheck[5]) {
createOutputFileForNextScript("3", $resultsCheck[5],$bodyEmail , $theFromEmail);
}
PRINTLOG (" Leaving createEmailToRequestAdminSecurityApproval\n");
return;
}
else {
#this is a subapp admin request
PRINTLOG(" this is a subapp request with <INSERT INTO codeWord (word,cli,username) VALUES (\'$myCodeName\',\'myCodeName\',\'admin\')>\n");
my $myCLI = "*e $myApp $mySubApp **a -a -a $mySubscribeOrRead $myTheEmail $fromEmail";
$connection->do("INSERT INTO codeWord (word,cli,username) VALUES (\'$myCodeName\',\'$myCLI\',\'admin\')");#This is the myCodeName after demo version is complete. It cannot work with our email service as it makes
#emails with crazy numbers in them. This only works if our email service sends from any email address
#mysql uses \ as a wildcard and deletes one. So the CLI needs an additional at each locations
$myCLI =~ s/\\/\\\\/g;
PRINTLOG(" about to do <update codeWord SET cli=\'$myCLI\' where (word=\'a13284928193829\')>");
$connection->do("update codeWord SET cli=\'$myCLI\' where (word=\'a13284928193829\')");
my $theFromEmail = $myCodeName . '@' . $theOriginalFromURL;
my $subscribeOrReadSpelledOut = "subscribe to";
if ($mySubscribeOrRead =~ /r/) {
$subscribeOrReadSpelledOut = "read";
}
my $nickname = setNickname($theEmail);
my $bodyEmail = "$nickname wishes to $subscribeOrReadSpelledOut your group $mySubApp. Text me back YES to approve";
my $str = $connection->prepare("SELECT * FROM blogList WHERE (appName = \'$myApp\' and subAppName = \'$mySubApp\')");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[4]) {
createOutputFileForNextScript("3", $resultsCheck[4],$bodyEmail , $theFromEmail);
}
if ($resultsCheck[5]) {
createOutputFileForNextScript("3", $resultsCheck[5],$bodyEmail , $theFromEmail);
}
if ($resultsCheck[6]) {
createOutputFileForNextScript("3", $resultsCheck[6],$bodyEmail , $theFromEmail);
}
if ($resultsCheck[7]) {
createOutputFileForNextScript("3", $resultsCheck[7],$bodyEmail , $theFromEmail);
}
PRINTLOG (" Leaving createEmailToRequestAdminSecurityApproval\n");
return;
}
PRINTLOG (" Leaving createEmailToRequestAdminSecurityApproval\n");
return;
}#($theAppName,"",$theEmail);
####################
######stars#########
####################
sub starNumber {
PRINTLOG( "In starNumber\n");
my $theNumber = $_[0];
my $str = $connection->prepare("SELECT * FROM tempCode WHERE userName = \'$theEmail\' AND codeNumber = \'$theNumber\'");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
$theTextForNextScript = "$resultsCheck[3] $theTextForNextScript)";
$connection->do("delete FROM tempCode WHERE (userName = \'$theEmail\')");
starIsDone();
}
sub stary {
PRINTLOG( "In stary\n");
getNextWord();
my $word = $nextWord;
while (isAnotherWord() ) {
getNextWord();
$word = $word . " " . $nextWord;
}
my $str = $connection->prepare("SELECT * FROM userUsage WHERE userName = \'$theEmail\'");
$str->execute;
my @resultsCheck=$str->fetchrow_array;
if ($resultsCheck[0]) {
PRINTLOG("about to do the following<update userUsage SET nickname=\'$word\' WHERE (userName = \'$theEmail\')>\n");
$connection->do("update userUsage SET nickname=\'$word\' WHERE (userName = \'$theEmail\')");
}
else {
$connection->do("INSERT INTO userUsage (userName,nickname) VALUES (\'$theEmail\',\'$word\')");
}
PRINTLOG("Leaving stary\n");
}
sub starh {
#select subAppName, count(*) as c from blogPosts where (appName = 'wikipedia') group by appName,subAppName order by c desc limit 3
#select subAppName, count(*) as c from blogSubscriptions where (appName = 'wikipedia') group by appName,subAppName order by c desc limit 3
PRINTLOG ("In starh\n");
use Time::HiRes qw(gettimeofday);
getNextWord();
my $myApp = $nextWord;