forked from oZONo32/EHCP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classapp_bck23sept2016.php
executable file
·11445 lines (8970 loc) · 448 KB
/
classapp_bck23sept2016.php
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
<?php
$ehcpversion="0.38.2.b";
$known_to_work="Ubuntu-16.04";
$emailenable=True;
/*
EASY HOSTING CONTROL PANEL MAIN CLASS FILE - www.ehcp.net
mail&msn: [email protected]
# last modified by ehcpdeveloper on 14.8.2016 (d-m-y)
ehcp in launchpad: https://launchpad.net/~ehcp
About ssl:
We currently try to use ssl automatically.
Necessary info will be taken from admin/user and CSR will be built.
All will be webbased.
ChangeLog (Nearest upper):
2016-07..2016-08:
* Many changes related to Ubuntu 16.04 LTS, especially related to php7 changes, so,
* many php5 references fixed according to php7
* server ip detection fixed (not so important)
* Using python based ftp, instead of vsftp, this layer is new.. should be tested throughly
* default number of processes are reduced for some daemons, such as courier-imapd etc. ; to save server resources..
* adodb upgraded to latest version.. which supports php7
* new options in options page, to take more control
* similarfunctions improved by better css based display
* minor fixes
2016-01:
* login brute force attack detection, disallow password retry for more than 5 times from same ip
2015-05:
* similar functions & some text moved to language files for easier localization
* Initial plans for more modular design with separate classes.
2015-03:
* new module functions added,
* ssl module, vps module, vpn module designed (pro version)
2014-07:
* Switched to mariadb as sql server,
* deprecated mysql_connect functions and other deprecated php code removed
* Ubuntu 14.04 related issues solved.
* Other code cleanup and improvements
2013-06:
* Light, normal, extra installation modes added. light is for only crucial parts of softwares that comes with ehcp.
* unattended install added, suppress many inputs for fast installation, for testing purposes
* will do: ehcp testing suite, for testing an ehcp installation automatically, such as ftp, domain etc.
2013-05:
* added new Easy Install Scripts
* fixed vsftpd bug for some Ubuntu versions, thanks to enrolmartin
* added manual slave dns functionality (earnolmartin)
2013-03:
* Added custom permissions for dirs.
* account activation for new panelusers.
* page rewrite testing for nginx, not working yet.
* file upload code inside ehcp, for ssl etc.
* adjust ssl functions, testing, not working yet.
* freedns.afraid.org integration
* passworded dirs for nginx too, not tested fully, please test
* improved nginx install a little for newer systems
* "multiple Ip" bug resolved. more than one IP can be used in a server, to host different domains.
2012-12:
* fixapacheconfig2 added,
* fixed some small bugs
* worked a few new features, do not remember all now.
2013-1:
* added failed login indicator
*
2012-12:
* fixed some bugs.
*
2012-4:
* fixed subdomain configuration for IP based configs
* fixed backup bug
2012-3:
* gziping backup option added
* fix db add with "-" in name, (create database db-dene: not work, create database `db-dene`: works)
* fix subdomain issue
* minor fixes (usage&security)
* new options (such as wildcard domains)
* default template is sky
2011-11:
* file ownerships changed to: vsftpd:www-data
* file ownerships are more flexible and adjustable. all ftp/web configs follow those ownerships, when changed in classapp config section.
* one quota bug fixed
* one security fix
2011-08: (ver 0.30)
* new "easy install scripts" added, sqlbuddy etc.
* a clean, "sky" template added, by 7skyhost, thanks
* auto check for ehcp version, if upgrade needed..
* logrotate for all domain done, autom.
* different custom http for different webservers in dhcp db, so, switching webserver while having custom http is not a problem anymore
* code fixes, cleanup
* chive (mysql admin tool) added
* template_reseller added
* password reset improved/fixed
* ftp active/passive bug fixed
2011-05:
* fixed an ftp insert, security
* do not remember all
*
2011-01:
* Roundcube added,
* add domain to different IP on same server.
*
*
2010-11:
* multiserver, apache2+nginx on remote servers,
* some bugfix,
* ported ehcp dir to a new location: /var/www/new/ehcp
*
2010-09:
* nginx is supported directly in ehcp, automatically.
* multiserver concept improved. now, can produce config files for multiple webservers, it will be controlling multiple webservers soon.
* ssl is handled better now, i hope,
2010-03:
* a few fixes, I dont remember all,
* fixmailconfig does fix a few things too,
* ubuntu theme added by [email protected]
* more stable "fixapacheconfig" command
* bulk add email (bulk add domain/hosting already exist)
2010-01:
* Added webmail, pass change plugin in webmail (squirrelmail), by [email protected]
2009-11:
* Added autoreply using only php,ehcp, postfix transport maps, without 3rd party software
* added: function adjustEmailAutoreply
*
2009-09:
* fixmailconfiguration,
* fixapachewithssl # ssl support..
* fixapachenonssl
* default charset for new databases...
2009-06-08:
deleteFtpUserDirect() added
2009-06-07:
$this->showSimilarFunctions($func); function added
function addFtpToThisPaneluser() and similars added,
*
security issues: (now handled by beforeinputcontrols and afterinputcontrols)
steps to control when doing something:
1- is user active?
2- is user limit exceeded for that action?
3- is user permitted to do that?
4- is user owner of that or authorized?
5- is target entity already exists ? that is, is domain exists, or is panel users exists ?
*/
# include_once("config/dbutil.php"); # some old routines.. being ported to this class...
error_reporting (E_ALL ^ E_NOTICE );
ini_set('display_errors', '1');
@date_default_timezone_set('Europa/Istanbul'); # this is mandatory in php 5.3 and up for date commands
include_once(dirname(__FILE__).'/adodb5/adodb.inc.php'); # bu dirname muhabbeti: classapp, başka biyerden bile include edilse, bunların calısması icin.. fix for this: http://www.ehcp.net/?q=comment/2921#comment-2921 ; with this code, no chdir should be required in api
include_once(dirname(__FILE__).'/localutils.php');
@include_once(dirname(__FILE__).'/modules/module_index.php');
include_once(dirname(__FILE__).'/config/randomstring.php');
# bu harici fonksiyonlar, localutils icine tasinacak..
class Application
{
var $appname = '',$sitename='ehcp', $headers="From: [email protected]";
var $output='', $requirePassword=True, $checkinstall=True,$miscconfig=null;
var $queries=[], $selecteddomain='',$isreseller=false;
var $check_webserver_enabled=True; # disable this to overcome false switchover of webservers... false alarms..
var $wwwuser="www-data"; # these vars should be used are "user related" places, to unify all user settings.. #equivalent: var $wwwowner="vsftpd:www-data";
var $wwwgroup="www-data";
var $ftpuser="vsftpd"; # equivalent: var $ftpowner="vsftpd:www-data";
var $ftpgroup="www-data"; # with this config, ftp user is able to see/delete files written by webserver.
var $ftp_server_progname="ftp_server2.py";
# debuglevel: 4: shows some functions, 3: shows queries
var $debuglevel=0;
var $myversion='';
var $dbhost;
var $dbname;
var $dbusername;
var $dbpass;
var $conn;
var $defaultlanguage="en",$clientip,$referer;
var $currentlanguage='en';
var $status_active="active",$status_passive="passive",$statusActivePassive,$passivefilt,$activefilt,$isDemo=false;
var $emailfrom='[email protected]';
# language strings will be defined in $lang['en']['error1'] in language/en.php or so on...
var $usertable,$dnsemail,$template,$templatefile,$op,$userinfo;
var $dnszonetemplate="dnszonetemplate";
var $dnsnamedconftemplate="dnsnamedconftemplate"; # aynen apache gibi oluturulacak...
var $dnsnamedconftemplate_slave="dnsnamedconftemplate_slave"; # for slave DNS replication
var $activeuser,$isloggedin,$globalfilter,$commandline=false,$erroroccured=false;
var $connected_mysql_servers=[];
var $ehcpdir='';
var $tr="<tr class='list'>", $td="<td class='list'>", $th="<th class='list'>"; # used in some html buildup
var $sslkeyfile="/etc/ehcp/server.key";
var $conf=[
# config section
# yavas yavas conf sistemine gecmek lazim. aslinda kod icinde sabit bilgi kullanmamak lazim. string bile... ama nerdee...
# this is like configuration of many system settings, tablenames etc. by this, changing something is easier, without need to change code..
# apache and dns defs:
'adminname'=>'ehcpdeveloper',
'adminemail'=>'[email protected]',
'wwwbase'=>'/var/www',
'ehcpdir'=>'',
'vhosts'=>'/var/www/vhosts',
'namedbase'=>'/etc/bind',
'dnsip' => '10.0.0.10',
'dnsemail' => 'your.email.here',
# mysql definitions
'mysqlrootuser'=>'root', # this is for db creation.
'mysqlrootpass'=>'12345',
# ehcp db table definitions, this is to make code more db-independent...
'logintable'=>[
'tablename'=>'panelusers',
'passwordfunction'=>'md5',
'usernamefield'=>'panelusername',
'passwordfield'=>'password'
],
'roles'=> [
'tablename'=>'roles',
#'baslik'=>array('id','rolename','ilgili proje','ilgili kullanıcı'),
'listfields'=>['id','rolename','panelusername'],
'linkimages'=>['images/edit.gif','images/delete1.jpg'],
'linkfiles'=>['?op=roleditor&rolsec=1','?op=roleditor&rolsil=1'],
'linkfield'=>'id',
'createtable'=>
'
CREATE TABLE `roles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`rolename` varchar(30) COLLATE utf8_turkish_ci DEFAULT NULL,
`panelusername` varchar(30) COLLATE utf8_turkish_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci
'
],
'settingstable2'=>[
'tablename'=>'settings',
'createtable'=>
"CREATE TABLE IF NOT EXISTS `settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
`reseller` varchar(30) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
`panelusername` varchar(30) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
`name` varchar(40) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
`value` varchar(200) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
`longvalue` text CHARACTER SET utf8 COLLATE utf8_turkish_ci,
`comment` varchar(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `group` (`group`,`reseller`,`panelusername`,`name`,`value`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci COMMENT='ehcp db - Table for settings of ehcp'"
],
'vpstable'=>[
'tablename'=>'vps',
'listfields'=>['vpsname','ip','ip2','ram','description','reseller','panelusername','hostip','state','image_template'],
'linkimages'=>['images/incele.jpg','images/poweron.gif','images/poweroff.gif','images/pause.gif','images/edit2.gif','images/delete1.jpg'],
'linkfiles'=>['?op=vps&op2=select','?op=vps&op2=start','?op=vps&op2=shutoff','?op=vps&op2=pause','?op=vps&op2=edit','?op=vps&op2=delete'],
'linkfield'=>'vpsname',
'checkfields'=>[
'addvpscmd'=>'text',
'ip2'=>'varchar(20)',
'cdimage'=>'varchar(100)'
],
'createtable'=>
"CREATE TABLE `vps` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`reseller` varchar(30) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`panelusername` varchar(30) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`status` varchar(10) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`vpsname` varchar(30) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`description` varchar(100) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`hostip` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`ip` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`netmask` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`broadcast` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`gateway` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`image_template` varchar(100) DEFAULT NULL,
`ram` int(11) DEFAULT NULL,
`cpu` int(11) DEFAULT NULL,
`state` varchar(20) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`ping` varchar(10) CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
`hdimage` varchar(200) DEFAULT NULL,
`addvpscmd` text CHARACTER SET utf8 COLLATE utf8_turkish_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci COMMENT='ehcp db - list of vps and their properties'"
],
'domainstable'=>[
'tablename'=>'domains',
'ownerfield'=>'panelusername',
'resellerfield'=>'reseller',
'domainfields'=>['id','reseller','panelusername','domainname','status','comment'],
'listfields'=>['id','reseller','panelusername','domainname','webserverips','status','diskquotaused','diskquota'],
'checkfields'=>[
'serverip'=>'varchar(30)',
'dnsserverips'=>'varchar(200)',
'webserverips'=>'varchar(200)',
'mailserverips'=>'varchar(200)',
'mysqlserverips'=>'varchar(200)',
'host'=>'varchar(30)',
'apachetemplate'=>'text',
'apache2template'=>'text',
'nginxtemplate'=>'text',
'dnstemplate'=>'text',
'aliases'=>'text',
'diskquotaused'=>'int(4)',
'diskquota'=>'int(4)',
'diskquotaovernotified'=>'int(4)',
'diskquotaoversince'=>'date',
'graceperiod'=>'int(4) default 7',
'theorder'=>'int(11)',
'dnsmaster'=>'varchar(15) default NULL'
]
],
'domainstable2'=>[
'tablename'=>'domains',
'listfields'=>['domainname']
],
'subdomainstable'=>[
'tablename'=>'subdomains',
'listfields'=>['reseller','panelusername','subdomain','domainname','homedir','ftpusername','comment'],
'linkimages'=>['images/delete1.jpg'],
'linkfiles'=>['?op=delsubdomain'],
'linkfield'=>'id',
'checkfields'=>[
'ftpusername'=>'varchar(30)',
'password'=>'varchar(20)',
'email'=>'varchar(50)',
'webserverips'=>'varchar(200)'
]
],
'paneluserstable'=> [
'tablename'=>'panelusers',
'resellerfield'=>'reseller',
'usernamefield'=>'panelusername',
'passwordfield'=>'password',
'listfields'=>['id','reseller','panelusername','maxdomains','maxemails','quota','maxpanelusers','maxftpusers','maxdbs','name','email'],
'clickimages'=>['images/edit.gif','images/delete1.jpg'],
'clickfiles'=>['?op=editpaneluser','?op=deletepaneluser'],
'insertfields'=>['panelusername',['password','password'],['maxdomains','default'=>5],['maxemails','default'=>20],['quota','default'=>500],['maxpanelusers','default'=>5],['maxftpusers','default'=>5],['maxdbs','default'=>10],'name','email'],
'insertfieldlabels'=>['panelusername','Password','maxdomains','maxemails','Quota (Mb)','maxpanelusers','maxftpusers','Max Mysql Databases','Name','Email'],
'mandatoryinsertfields'=>['panelusername'], # zorunlu insert alanlari
'editfields'=>['maxdomains','maxemails','quota','maxpanelusers','maxftpusers','maxdbs','name','email'], # edit edildigi zaman görünecek alanlar..
'editlabels'=>['maxdomains','maxemails','quota (MB)','maxpanelusers','maxftpusers','maxdbs','name','email'], # edit edildigi zaman görünecek alanlar..
'viewfields'=>['id','panelusername','maxdomains','maxemails','quota','maxpanelusers','maxdbs','name','email'],
'linkfield'=>'id',
'checkfields'=>[
'comment'=>'varchar(100)'
],
'help'=>'description of this table... ehcp control panel users... '
],
'customstable'=>[ # custom dns and http settings
'tablename'=>'customsettings',
'listfields'=>['id','domainname','name','comment','value','value2','webservertype'],
'linkimages'=>['images/delete1.jpg'],
'linkfiles'=>['?op=deletecustom'],
'orderby'=>'id',
'linkfield'=>'id',
'checkfields'=>[
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)',
'webservertype'=>'varchar(30)',
'value2'=>'text'
]
],
'emailuserstable'=>[
'tablename'=>'emailusers', # going to be array as above..
'listfields'=>['email','quota','domainname'],
'linkimages'=>['images/delete1.jpg','images/edit.gif'],
'linkfiles'=>['?op=userop&action=emailuserdelete','?op=editemailuser'],
'linkfield'=>'id',
'ownerfield'=>'panelusername',
'resellerfield'=>'reseller',
# for use with email user logins
'passwordfunction'=>'encrypt',
'usernamefield'=>'email',
'passwordfield'=>'password',
'checkfields'=>[
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)',
'status'=>'varchar(10)',
'autoreplysubject'=>'varchar(100)',
'autoreplymessage'=>'text'
]
],
'ftpuserstable'=>[
'tablename'=>'ftpaccounts', # going to be array as above..
'ownerfield'=>'panelusername',
'resellerfield'=>'reseller',
'listfields'=>['domainname','ftpusername','status','homedir','type'],
'checkfields'=>[
'type'=>'varchar(10)',
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)',
'homedir'=>'varchar(100)',
'datetime'=>'datetime'
]
],
'operations_table'=>[
'tablename'=>'operations', # going to be array as above..
'listfields'=>['id','user','ip','op','status','tarih','try','info','info2','info3','action'],
'checkfields'=>[
'info'=>'varchar(200)',
'info2'=>'varchar(200)',
'info3'=>'varchar(200)',
'user'=>'varchar(30)',
'ip'=>'varchar(30)'
]
],
'backups_table'=>[
'tablename'=>'backups',
'listfields'=>['id','domainname','backupname','filename','date','size','status'],
'linkimages'=>['images/delete1.gif'],
'linkfiles'=>['?op=backups&op2=delete&filename='],
'linkfield'=>'filename',
'checkfields'=>[
'status'=>'varchar(100)',
'domainname'=>'varchar(100)',
'filename'=>'varchar(200)'
]
],
'mysqldbstable'=>[
'tablename'=>'mysqldb',
'listfields'=>['domainname','dbname','host'],
'linkimages'=>['images/delete1.jpg'],
'linkfiles'=>['?op=domainop&action=deletedb'],
'linkfield'=>'id',
'checkfields'=>[
'host'=>'varchar(30)',
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)'
]
],
'mysqldbuserstable'=>[
'tablename'=>'mysqlusers',
'listfields'=>['domainname','dbname','dbusername','host'],
'linkimages'=>['images/edit.gif'],
'linkfiles'=>['?op=dbedituser'],
'linkfield'=>'id',
'checkfields'=>[
'host'=>'varchar(30)',
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)'
]
],
'serverstable'=>[
'tablename'=>'servers',
'listfields'=>['servertype','ip','accessip','mandatory','location'],
'linkimages'=>['images/edit.gif'],
'linkfiles'=>['?op=editserver'],
'linkfield'=>'id',
'checkfields'=>['accessip'=>'varchar(30)']
],
'passwddirectoriestable'=>[
'tablename'=>'directories',
'listfields'=>['domainname','username','directory','expire'],
'linkimages'=>['images/delete1.jpg'],
'linkfiles'=>['?op=deletedirectory'],
'linkfield'=>'id',
'checkfields'=>[
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)'
]
],
'emailforwardingstable'=>[
'tablename'=>'forwardings',
'listfields'=>['panelusername','domainname','source','destination'],
'linkimages'=>['images/delete1.jpg'],
'linkfiles'=>['?op=delemailforwarding'],
'linkfield'=>'id',
'checkfields'=>[
'reseller'=>'varchar(30)',
'panelusername'=>'varchar(30)',
'domainname'=>'varchar(50)'
]
],
'transporttable'=>[ # for email autoreply
'tablename'=>'transport',
'createtable'=>
"
CREATE TABLE transport (
domainname varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domainname (domainname)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci
"
],
'settingstable'=>[
'tablename'=>'misc',
'checkfields'=>[
'name'=>'varchar(40)',
'panelusername'=>'varchar(30)'
]
],
'scriptstable'=>[
'tablename'=>'scripts',
'checkfields'=>[
'homepage'=>'varchar(50)',
'description'=>'text',
'customfileownerships'=>'text'
]
],
'daemonopstable'=>'operations',
'hashtable'=>[
'tablename'=>'hash',
'createtable'=>"
CREATE TABLE IF NOT EXISTS `hash` (
`email` varchar(100) COLLATE utf8_turkish_ci NOT NULL DEFAULT 'NULL',
`hash` varchar(100) COLLATE utf8_turkish_ci DEFAULT NULL,
KEY `email_index` (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci COMMENT='to store password remind hash'
"
],
'logtable'=>[
'tablename'=>'log',
'listfields'=>['tarih','panelusername','notified','ip','log'],
'checkfields'=>[
'panelusername'=>'varchar(50)',
'notified'=>'varchar(5)'
],
],
'hostingplans'=>[
'tablename'=>'hostingplans',
'listfields'=>['shortname','maxpanelusers','maxdomains','maxemails','maxftpusers','maxmysqldbs'],
'createtable'=>"
CREATE TABLE IF NOT EXISTS `hostingplans` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`shortname` varchar(30) COLLATE utf8_turkish_ci DEFAULT NULL,
`longname` varchar(100) COLLATE utf8_turkish_ci DEFAULT NULL,
`details` text COLLATE utf8_turkish_ci,
`maxpanelusers` int(11) DEFAULT NULL,
`maxdomains` int(11) DEFAULT NULL,
`maxsubdomains` int(11) DEFAULT NULL,
`maxemails` int(11) DEFAULT NULL,
`maxftpusers` int(11) DEFAULT NULL,
`maxmysqldbs` int(11) DEFAULT NULL,
`maxmysqlusers` int(11) DEFAULT NULL,
`diskquota` int(11) DEFAULT NULL,
`bwquota` int(11) DEFAULT NULL COMMENT 'MB, per month, has no affect yet',
`maxdirectories` int(11) DEFAULT NULL COMMENT 'password protected dir',
`pricepermonth` int(11) DEFAULT NULL,
`priceperyear` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `shortname` (`shortname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci AUTO_INCREMENT=1 ;
"
]
]; # end config
/*
for almost every record:
panelusername: who is the owner of that, who setuped that. cannot be empty.
resellername: who is the reseller of that panelusername. cannot be empty.
domainname: to which domain is that related. empty if not related to domainname
*/
function set_ehcp_dir($dirname){
# extra variables will be removed later, only one should be used.
$this->ehcpdir=$dirname;
$this->mydir=$dirname;
$this->conf['ehcpdir']=$dirname;
}
public function __construct() {
global $skipUpdateWebstats,$debuglevel;
include('config.php');
$this->set_ehcp_dir(dirname(__FILE__));
$this->vhostsdir=$this->conf['vhosts'];
$this->skipupdatediskquota=$skipupdatediskquota;
$this->dbhost=$dbhost;
$this->dbusername=$dbusername;
$this->dbpass=$dbpass;
$this->dbname=$dbname;
$this->conf['mysqlrootpass']=$dbrootpass;
$this->defaultlanguage=$defaultlanguage;
$this->isDemo=$isdemo;
if(!(isset($this->isDemo))) $this->isDemo=False;
$this->statusActivePassive=["active"=>"active","passive"=>"passive"];
if(isset($this->debuglevel)){
#....
}
$debuglevel=$this->debuglevel; # for outer functions using debuglevel
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { # Suggestion by [email protected]
$ipproxy = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ipproxy=$_SERVER["REMOTE_ADDR"];
}
$this->clientip = $ipproxy;
$this->referer = getenv("HTTP_REFERER");
$this->wwwowner=$this->wwwuser.':'.$this->wwwgroup;
$this->ftpowner=$this->ftpuser.':'.$this->ftpgroup;
}
function run() {
#echo "\n\nPid:".$this->get_pid("progname")."\n\n";
$this->debugecho("file:".__FILE__.", Line:".__LINE__.", Function:".__FUNCTION__,4,false);
#$this->serverPlan=new serverPlan();
# $this->output.=$this->debug();
global $commandline;
$this->commandline=$commandline;
$this->initialize();
# this is actual application runner, maps urls to functions..
$this->runOp($this->op);
$this->show();
}
function check_php_version(){
# same cod exists in install_lib also. sync both code
# used in php, fpm etc installations.
if(version_compare(phpversion(), '7.0.0', '<')) { # make compatible install in many versions of Ubuntu/Debian, Ubuntu 16.04 comes with php7, while olders are different
$this->php_version=5;
$this->php_version_tag="5";
$this->php_etc_dir="/etc/php5";
$this->php_fpm="php7.0-fpm";
} else {
$this->php_version=7;
$this->php_version_tag="";
$this->php_etc_dir="/etc/php/7.0";
$this->php_fpm="php5-fpm";
}
}
function initialize(){
# burda herhangi class initialization yapilacak.. basta yapilacak isler..
global $commandline,$ehcpversion;
#if(!$commandline)$this->output.="<font size=+2>".$this->appname."<br><br></font>";
$this->myversion=$ehcpversion;
$this->connectTodb();
$this->check_php_version();
$this->debugecho("file:".__FILE__.", Line:".__LINE__.", Function:".__FUNCTION__,4,false);
$this->syncConfigs();
$this->passivefilt="status<>'".$this->status_active."' or status is null";
$this->activefilt="status='".$this->status_active."'";
$this->loadLanguage(); # load default en to handle errors in loadconfig,
$this->checkInstall();
$this->loadConfig();
if(!$this->isNoPassOp() and $this->requirePassword ) $this->securitycheck();
$this->loadLanguage(); # load again to activate actual lang in config.
#functions that has to be after securitycheck
#$this->output.=print_r3($this->userconfig);
if($this->isadmin()) {
$this->globalfilter=''; # burasi, securitycheck den sonra olmali. isadmin yoksa calismaz.
} else $this->globalfilter="(reseller='".$this->activeuser."' or panelusername='".$this->activeuser."')";
if(!$this->isadmin()) {
$userinfo=$this->query("select * from ".$this->conf['paneluserstable']['tablename']." where panelusername='$this->activeuser'", "dologin2");
$this->userinfo=$userinfo[0];
if($this->userinfo['maxpanelusers']>0) $this->isreseller=True;
}
$this->loadServerPlan();
$this->url='http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$this->output.=$this->check_failed_logins();
if($commandline) {
$this->restart_webserver(); # Starting with Ubuntu 16.04, apache config needs to be reloaded after server restart.. strange situation for U16.04, apache config is not loaded after server restart.. !
$this->restart_ftp_daemon();
$this->echoln("Finished initialize");
}
#$this->check_mysql_connection();
}
function check_webserver($retry=0){
# checks webserver in regular intervals, try to restart it with different configs..
print __FUNCTION__.": checking webserver: \n";
$f=file_get_contents("http://localhost");
if(strlen($f)>0) {
print __FUNCTION__.": webserver seems normal. continuing normally.\n";
} else {
if($retry<1) {
sleep(5);
print __FUNCTION__.": webserver seems DOWN, checking again.. \n";
$this->check_webserver($retry+1);
}
if($this->miscconfig['switchtoapacheonerror']=='') {
print __FUNCTION__.": webserver seems DOWN, fixing apache configuration by some operations such as disabling custom http & ssl.. \n";
$this->fixApacheConfigNonSsl2();
} else {
print __FUNCTION__.": webserver seems DOWN, however, switchtoapacheonerror disabled, so, doing nothing.. \n";
}
}
return True;
}
function counter_reached($counter,$count){
# can be used to count something...
if(intval($this->miscconfig[$counter])>0) {
$nextval=intval($this->miscconfig[$counter])-1;
$this->setConfigValue($counter,$nextval);
return False; # check sometime,
}
$this->setConfigValue($counter,$count);
return True;
}
function check_ehcp_version(){
global $ehcpversion;
if($this->latest_version<>'') return; # check once
if(!$this->counter_reached('versionwarningcounter',20)) return False; # check 20 login later again.
$this->latest_version=trim(@file_get_contents("http://www.ehcp.net/latest_version.php?ip=".$this->dnsip));
if($this->latest_version<>'' and $this->latest_version<>$ehcpversion) {
$str="Your ehcp version is different($ehcpversion) than latest($this->latest_version) version. Either your ehcp is old, or you are using a new beta/test version. Look at <a target=_blank href='http://ehcp.net/?q=node/153'>here for download and upgrade</a>";
$this->warnings.=$str;
$this->infotoadminemail($str,"ehcp version warning for ".$this->dnsip,false);
}
}
function loadServerPlan(){
$this->singleserverip=$this->conf['dnsip']; # if there is only one server...
#$this->output.=__FUNCTION__.":".$this->singleserverip."<br>";
# more servers will be coded here...
}
function load_module($name){
if(!defined($name.'_file_loaded')) {
$this->echoln2(__FUNCTION__.": Sory, that module file (".$name."_file_loaded) not loaded yet. check code. (php autoload does not work with CLI)");
return False;
}
if(gettype($this->$name)<>'object') $this->$name=new $name($this,$name); # initialize new module, only if not done before.
return True;
}
function call_func_in_module($name,$func,$params=Null){
if(!$this->load_module($name)) return True; # not returning False, because, if False, other parts of classapp retries the operation a few times. this is not needed now.
if($params==Null) return $this->$name->$func(); # a function with no args
else return $this->$name->$func($params); # a func with named arguments (named array), as used in many parts of this file
}
function check_module_tables(){
# to be coded later.
}
function assign_role(){
$alanlar=['rolename','panelusername'];
foreach($alanlar as $al) global ${$al};
$degerler=$this->getVariable($alanlar);
if($panelusername and $rolename) {
$this->executequery("insert into roles (rolename,panelusername) values ('$rolename','$panelusername')");
$this->output.="Added new role";
} else {
$inputparams=['rolename','panelusername'];
$this->output.=inputform5($inputparams);
}
}
function list_roles(){
$this->requireAdmin();
$this->listTable('','roles');
}
function diognise(){
$this->requireAdmin();
$this->output.="To be coded.. will copy/show necessary files, for checking server's configs.. for letting admin check webbased";
}
function runOp($op){ # these are like url to function mappers... maps op variable to some functions in ehcp; This also can be seen as a controller in MVC model.
global $id,$domainname,$op2,$_insert;
$this->getVariable(['id','domainname','op2','_insert']);
$op=strtolower($op);
$otheroperations=['advancedsettings'];
switch ($op) {
case 'diognise' : return $this->diognise();break;
case 'list_roles' : return $this->list_roles();break;
case 'assign_role' : return $this->assign_role();break;
case 'failedlogins' : return $this->failedlogins();break;
#ssl related:
case 'adjust_ssl' : return $this->call_func_in_module('ssl_module','adjust_ssl'); break;
case 'generate_ssl_config1' : return $this->call_func_in_module('ssl_module','generate_ssl_config1'); break;
case 'pagerewrite' : return $this->pagerewrite();break;
# vpn related : todo: we need to move these function mappings inside modules, if function is actuallin in module...
case 'list_vpn' : return $this->call_func_in_module('vpn_module','list_vpn'); break;
case 'add_vpn' : return $this->call_func_in_module('vpn_module','add_vpn'); break;
case 'del_vpn' : return $this->call_func_in_module('vpn_module','del_vpn'); break;
# other
case 'activate' : return $this->activate();break;
case 'settings' : return $this->settings();break;
case 'adjust_system' : return $this->adjust_system();break;
case 'redirect_domain' : return $this->redirect_domain();break;
case 'information' : return $this->information($id);break;
#multi-server operations:
case 'multiserver_add_domain' : return $this->multiserver_add_domain();break;
case 'new_sync_all' : return $this->new_sync_all();break;
case 'new_sync_domains' : return $this->new_sync_domains();break;
case 'new_sync_dns' : return $this->new_sync_dns();break;
case 'multiserver_add_ftp_user_direct': return $this->gui_multiserver_add_ftp_user_direct();break;
#single-server operations:
case 'bulkaddemail' : return $this->bulkAddEmail();break;
case 'whitelist' : return $this->whitelist();break;
case 'fixmailconfiguration' : return $this->fixMailConfiguration();break;
case 'dofixmailconfiguration' : $this->requireAdmin(); $this->requireNoDemo(); return $this->addDaemonOp('fixmailconfiguration','','','','fix mail configuration');break;
case 'dofixapacheconfigssl' : $this->requireAdmin(); $this->requireNoDemo(); return $this->addDaemonOp('fixApacheConfigSsl','','','','fixApacheConfigSsl');break;
case 'dofixapacheconfigsslonly' : $this->requireAdmin(); $this->requireNoDemo(); return $this->addDaemonOp('fixApacheConfigSslOnly','','','','fixApacheConfigSslOnly');break;
case 'dofixapacheconfignonssl' : $this->requireAdmin(); $this->requireNoDemo(); return $this->addDaemonOp('fixApacheConfigNonSsl','','','','fixApacheConfigNonSsl');break;
case 'dofixapacheconfignonssl2' : $this->requireAdmin(); $this->requireNoDemo(); return $this->addDaemonOp('fixApacheConfigNonSsl2','','','','fixApacheConfigNonSsl2');break;
case 'rebuild_webserver_configs': return $this->rebuild_webserver_configs();break;
case 'updatediskquota' : return $this->updateDiskQuota();break;
case 'doupdatediskquota' : $this->addDaemonOp('updatediskquota','',$domainname,'','update disk quota');return $this->displayHome();break;
#editing of dns/apache templates for domains, on ehcp db
case 'editdnstemplate' : return $this->editDnsTemplate();break;
case 'editwebservertemplate' :
case 'edit_webserver_template' : return $this->edit_webserver_template();break;
case 'editdomainaliases' : return $this->editDomainAliases();break;
case 'changedomainserverip' : return $this->changedomainserverip();break;
case 'warnings' : break; # this will be written just before show..
case 'bulkadddomain' : return $this->bulkaddDomain();break ;
case 'bulkdeletedomain' : return $this->bulkDeleteDomain();break ;
case 'exportdomain' : return $this->exportDomain();break;
case 'adddnsonlydomain' : return $this->addDnsOnlyDomain();break;
case 'addslavedns' : return $this->addSlaveDNS();break;
case 'removeslavedns' : return $this->removeSlaveDNS();break;
case 'addcustomftp' : return $this->addCustomFTP();break;
case 'adddnsonlydomainwithpaneluser': return $this->addDnsOnlyDomainWithPaneluser();break;
case 'getselfftpaccount' : return $this->getSelfFtpAccount();break;
case 'adddomaintothispaneluser' : return $this->addDomainToThisPaneluser();break;
case 'add_domain_install_wordpress' : return $this->add_domain_install_wordpress();break;
case 'dodownloadallscripts' : return $this->doDownloadAllscripts();break;
case 'choosedomaingonextop' : return $this->chooseDomainGoNextOp();break;
case 'getmysqlserver' : return $this->getMysqlServer();break;
case 'emailforwardingsself' : return $this->emailForwardingsSelf();break;
case 'addemailforwardingself' : return $this->addEmailForwardingSelf();break;
case 'cmseditpages' : return $this->cmsEditPages();break;
case 'listservers' : return $this->listServers();break;
case 'addserver' : return $this->addServer();break;
case 'addiptothisserver' : return $this->add_ip_to_this_server();break;
case 'setactiveserverip' : return $this->set_active_server_ip();break;
case 'advancedsettings' : return $this->advancedsettings();break;
case 'delemailforwarding' : return $this->delEmailForwarding();break;
case 'addemailforwarding' : return $this->addEmailForwarding();break;
case 'emailforwardings' : return $this->emailForwardings();break;
case 'addscript' : return $this->addScript();break;
case 'addnewscript' : return $this->addNewScript();break;
case 'suggestnewscript' : return $this->suggestnewscript();break;
case 'downloadfile' : return $this->downloadfile();break;
case 'listselectdomain' : return $this->listselectdomain();break;
case 'selectdomain' : return $this->selectdomain($id);break;
case 'deselectdomain' : return $this->deselectdomain();break;
case 'otheroperations' : return $this->otheroperations();break;
case 'loadconfig' : return $this->loadConfig();break;
#case 'showconf' : return $this->showConfig();break;
case 'changemypass' : return $this->changeMyPass();break;
# for mysql, stop and start is meaningless, because if mysql cannot run, then, panel also cannot be accessible or this functions do not work.
case 'dorestartmysql' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'mysql','info2'=>'restart']); break;
case 'dostopapache2' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'apache2','info2'=>'stop']); break;
case 'dostartapache2' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'apache2','info2'=>'start']); break;
case 'dorestartapache2' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'apache2','info2'=>'restart']); break;
case 'dostopvsftpd' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'vsftpd','info2'=>'stop']); break;
case 'dostartvsftpd' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'vsftpd','info2'=>'start']); break;
case 'dorestartvsftpd' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'vsftpd','info2'=>'restart']); break;
case 'dostopbind' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'bind9','info2'=>'stop']); break;
case 'dostartbind' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'bind9','info2'=>'start']); break;
case 'dorestartbind' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'bind9','info2'=>'restart']); break;
case 'dostoppostfix' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'postfix','info2'=>'stop']); break;
case 'dostartpostfix' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'postfix','info2'=>'start']); break;
case 'dorestartpostfix' : $this->requireAdmin(); $this->requireNoDemo(); return $this->add_daemon_op(['op'=>'service','info'=>'postfix','info2'=>'restart']); break;
case 'donewsyncdomains' : $this->requireAdmin(); return $this->add_daemon_op(['op'=>'new_sync_domains']); break;
case 'donewsyncdns' : $this->requireAdmin(); return $this->add_daemon_op(['op'=>'new_sync_dns']); break;
case 'dosyncdomains' : return $this->addDaemonOp('syncdomains','','','','sync domains');break;
case 'dosyncdns' : return $this->addDaemonOp('syncdns','','','','sync dns');break;
case 'dosyncftp' : return $this->addDaemonOp('syncftp','','','','sync ftp for nonstandard homes');break;
case 'dosyncapacheauth' : return $this->addDaemonOp('syncapacheauth','','','','sync apache auth');break;
case 'options' : return $this->options();
case 'dump_config' : return $this->dump_config();
case 'backups' : return $this->backups();break;
case 'dobackup' : return $this->doBackup();break;
case 'dorestore' : return $this->doRestore();break;
case 'listbackups' : return $this->listBackups();break;
# these sync functions are executed in daemon mode.
case 'updatehostsfile' : return $this->updateHostsFile();break;
case 'syncdomains' : return $this->syncDomains();break;