function get_part($file, $searchfor, $name, $start) { // get the file contents, assuming the file to be readable (and exist) $contents = file_get_contents($file); // escape special characters in the query $pattern = preg_quote($searchfor, '/'); // finalise the regular expression, matching the whole line $pattern = "/^.*{$pattern}.*\$/m"; // search, and store all matching occurences in $matches if (preg_match_all($pattern, $contents, $matches)) { $text = implode("\n", $matches[0]); //echo $text; replace_in_file($file, $text, $start . '="' . $name . '"'); //replaceInFile($text, 'blog.title='+$name, $file); } else { echo "No matches found"; } }
$admin_partner->save(); // replace admin console config file secret to match replace_in_file($admin_console_config_file, '/settings.secret(\\s)*=(\\s)*(.+)/', 'settings.secret = ' . $admin_partner->getAdminSecret()); // replace batch partner secrets $batch_partner = PartnerPeer::retrieveByPK($batch_partner_id); $batch_partner->setSecret(generate_secret()); $batch_partner->setAdminSecret(generate_secret()); $batch_partner->save(); // replace batch config file secret to match replace_in_file($batch_config_file, '/secret(\\s)*=(\\s)*(.+)/', 'secret = ' . $batch_partner->getAdminSecret()); // replace batch full status script secret to match replace_in_file($batch_full_status_file, '/\\$secret(\\s)*=(\\s)*(.+)/', '$secret = \'' . $batch_partner->getAdminSecret() . '\';'); // replace kconf system pages login password replace_in_file($kconf_file, '/"system_pages_login_password"(\\s)*=>(\\s)*(.+),/', "\"system_pages_login_password\" => '" . generate_secret() . "',"); // change parameter in kconf so secret replacement will not happen again replace_in_file($kconf_file, '/"replace_passwords"(\\s)*=>(\\s)*(.+),/', "\"replace_passwords\" => false,"); //------------------------------------------------ function replace_in_file($file_name, $regexp, $replace) { $file_data = file_get_contents($file_name); $file_data = preg_replace($regexp, $replace, $file_data); @file_put_contents($file_name, $file_data); } function generate_secret() { $secret = md5(str_makerand(5, 10, true, false, true)); return $secret; } function str_makerand($minlength, $maxlength, $useupper, $usespecial, $usenumbers) { $charset = "abcdefghijklmnopqrstuvwxyz";
$artisan_file_path = getcwd() . '/app/Console/Kernel.php'; $commands = array('App\\Console\\Commands\\RunWorker', 'App\\Console\\Commands\\UploadWorker'); $worker_boot_path = $current_path . '/workers/libs/worker_boot.php'; $register_command_text = ""; foreach ($commands as $command) { $register_command_text .= "'" . $command . "',\n"; } insert_to_file($artisan_file_path, "protected \$commands", $register_command_text); insert_to_file($current_path . 'commands/UploadWorker.php', "<?php", "namespace App\\Console\\Commands;\nuse Config;\n"); insert_to_file($current_path . 'commands/RunWorker.php', "<?php", "namespace App\\Console\\Commands;\nuse Queue;\n"); replace_in_file(getcwd() . '/vendor/laravel/framework/src/Illuminate/Queue/Connectors/IronConnector.php', 'IronMQ\\IronMQ', 'IronMQ'); replace_in_file(getcwd() . '/vendor/laravel/framework/src/Illuminate/Queue/IronQueue.php', 'IronMQ\\IronMQ', 'IronMQ'); replace_in_file($worker_boot_path, 'start.php', 'app.php'); replace_in_file($worker_boot_path, '$app->setRequestForConsoleEnvironment();', ''); replace_in_file($worker_boot_path, '$app->boot()', '$app->make(Illuminate\\Contracts\\Console\\Kernel::class)->bootstrap()'); replace_in_file($worker_boot_path, 'Config::get(\'app.key\')', 'config(\'app.key\'), config(\'app.cipher\')'); } else { echo "Error: unrecognized version of Laravel"; return; } //copy config if (!file_exists($config_destination_path . '/ironworker.php')) { recurse_copy($current_path . '/config', $config_destination_path); } recurse_copy($current_path . '/config', $config_destination_path); //copy commands recurse_copy($current_path . '/commands', $command_destination_path); //copy example worker with worker_boot recurse_copy($current_path . '/workers', $workers_dir_path); echo "LaraWorker package installed." . PHP_EOL; function remove_extension($filename)
} return $Result; } $error = ""; if (isset($_POST['install'])) { if ($_POST['host'] == "" || $_POST['db_username'] == "" || $_POST['db_password'] == "" || $_POST['db_name'] == "" || $_POST['site_name'] == "") { $error = "All filed are required!"; echo "<script>setTimeout(function() { alert('{$error}'); }, 1); </script>"; } else { if ($error == "") { $Result = replace_in_file("../config/psl-config.php", "localhost", $_POST['host']); if ($Result['status'] == "success") { replace_in_file("../config/psl-config.php", "root", $_POST['db_username']); replace_in_file("../config/psl-config.php", "pass", $_POST['db_password']); replace_in_file("../config/psl-config.php", "db_name", $_POST['db_name']); replace_in_file("../config/psl-config.php", "/site_name", $_POST['site_name']); $dbconn = mysql_connect($_POST['host'], $_POST['db_username'], $_POST['db_password']); mysql_select_db($_POST['db_name'], $dbconn); $file = 'users.sql'; if ($fp = file_get_contents($file)) { $var_array = explode(';', $fp); foreach ($var_array as $value) { mysql_query($value . ';', $dbconn); } } echo "<script>alert(" . $Result['status'] . "', your website is now installed')<script>"; } else { echo "<script>setTimeout(function() { alert('gabim " . $Result['status'] . "'); }, 1); </script>"; } } }
function mailconfiguration($params) { global $app, $ehcpinstalldir, $ip, $hostname, $user_email, $user_name, $ehcpmysqlpass, $rootpass, $newrootpass, $ehcpadminpass; echo "configuring mail ... " . __FUNCTION__ . "\n"; # very similar to: https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto #print_r($params); # echo 'var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass);\n'; # var_dump($ehcpmysqlpass,$rootpass,$newrootpass,$ehcpadminpass); /* courier'e alternatif: dovecot: * http://www.opensourcehowto.org/how-to/mysql/mysql-users-postfixadmin-postfix-dovecot--squirrelmail-with-userprefs-stored-in-mysql.html http://www.howtoforge.com/virtual-users-and-domains-postfix-dovecot-mysql-centos4.5 http://workaround.org/articles/ispmail-etch/ Gerekli arama: /etc/dovecot-mysql.conf files to edit: /etc/postfix/mysql-virtual_domains.cf /etc/postfix/mysql-virtual_forwardings.cf /etc/postfix/mysql-virtual_mailboxes.cf /etc/postfix/mysql-virtual_email2email.cf /etc/postfix/mysql-virtual_mailbox_limit_maps.cf /etc/postfix/mysql-virtual_transports.cf maybe we can switch to dovecot, if i can, a good start: http://workaround.org/ispmail/etch */ $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = domains\nselect_field = 'virtual'\nwhere_field = domainname\nhosts = localhost\nadditional_conditions = and domainname in (select DISTINCT domainname from emailusers union select domainname from forwardings union select domainname from emailusers)\n"; writeoutput("/etc/postfix/mysql-virtual_domains.cf", $filecontent, "w"); $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = forwardings\nselect_field = destination\nwhere_field = source\nhosts = localhost\n"; writeoutput("/etc/postfix/mysql-virtual_forwardings.cf", $filecontent, "w"); $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = emailusers\nselect_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')\nwhere_field = email\nhosts = localhost\n"; writeoutput("/etc/postfix/mysql-virtual_mailboxes.cf", $filecontent, "w"); $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = emailusers\nselect_field = email\nwhere_field = email\nhosts = localhost\n"; writeoutput("/etc/postfix/mysql-virtual_email2email.cf", $filecontent, "w"); $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = emailusers\nselect_field = quota\nwhere_field = email\nhosts = localhost\n"; writeoutput("/etc/postfix/mysql-virtual_mailbox_limit_maps.cf", $filecontent, "w"); # autoreply configuration: coded like: http://www.progression-asia.com/node/87 /* I used ehcp's own php application, autoreply.php, instead of yaa.pl, since yaa.pl failed somehow, I wrote autoreply simply.. required db tables:(these will be setup in sql section) CREATE TABLE transport ( domainname varchar(128) NOT NULL default '', transport varchar(128) NOT NULL default '', UNIQUE KEY domainname (domainname) ) TYPE=MyISAM; */ $filecontent = "\nuser = ehcp\npassword = "******"\ndbname = ehcp\ntable = transport\nselect_field = transport\nwhere_field = domainname\nhosts = localhost\n"; writeoutput("/etc/postfix/mysql-virtual_transports.cf", $filecontent, "w"); # edit main.cf: $add = "\n# ehcp: autoresponder code:\nehcp_autoreply unix - n n - - pipe\n user=vmail\n argv=" . $app->ehcpdir . "/misc/autoreply.php \$sender \$recipient\n"; add_if_not_exists2($add, '/etc/postfix/master.cf'); # this function may also be used to setup spamassassin and related stuff. soon to implement spamassassin support in ehcp automatically. (manually always possible..) replace_in_file("#submission inet n - - - - smtpd", "submission inet n - - - - smtpd", '/etc/postfix/master.cf', '/etc/postfix/master.cf'); add_if_not_exists2("submission inet n - - - - smtpd", '/etc/postfix/master.cf'); # 587 kullanan yerler icin.. # classapp'da checktable yapılacak yenile.. # end autoreply configuration copyPostFixConfig(); add_if_not_exists3("# lines added by ehcp ", "/etc/mysql/my.cnf", "[mysqld]"); add_if_not_exists3("bind-address=127.0.0.1", "/etc/mysql/my.cnf", "[mysqld]"); #add_if_not_exists3("skip-innodb","/etc/mysql/my.cnf","[mysqld]"); # disable innodb by default, because it consumes a lot of memory # innodb is needed by some applications add_if_not_exists3("character-set-server=utf8", "/etc/mysql/my.cnf", "[mysqld]"); add_if_not_exists3("collation-server=utf8_general_ci", "/etc/mysql/my.cnf", "[mysqld]"); add_if_not_exists3("default-storage-engine=myisam", "/etc/mysql/my.cnf", "[mysqld]"); add_if_not_exists3("# end lines added by ehcp ", "/etc/mysql/my.cnf", "[mysqld]"); passthru3("chmod o= /etc/postfix/mysql-virtual_*.cf"); passthru3("chgrp postfix /etc/postfix/mysql-virtual_*.cf"); #Now we setup a user and group called vmail with the home directory /home/vmail. This is where all mail boxes will be stored. passthru3("groupdel vmail"); passthru3("userdel vmail"); echo "----------- Other user/group with uid/gid of 5000, you need to delete them, if any -----------"; passthru3("grep 5000 /etc/passwd "); passthru3("grep 5000 /etc/group "); echo "----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------"; passthru3("groupadd -g 5000 vmail"); passthru3("useradd -g vmail -u 5000 vmail -d /home/vmail -m"); passthru3("chown -Rf vmail /home/vmail"); passthru3("adduser postfix sasl"); // burda input vardi... initialize a aktarildi.. $hostname = exec("hostname"); // ipnin ilk uc rakami alinip network alınacak $ips = explode(".", $ip); array_pop($ips); $ips[] = "0/24"; // calculate C class net number. $net = implode(".", $ips); passthru3("openssl req -new -config {$ehcpinstalldir}/LocalServer.cnf -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 365 -x509"); passthru3("chmod o= /etc/postfix/smtpd.key"); passthru3("openssl req -passout pass:{$ehcpmysqlpass} -new -x509 -keyout /etc/postfix/cakey.pem -out /etc/postfix/cacert.pem -days 3650 -config {$ehcpinstalldir}/LocalServer.cnf"); ## yeni 13.6.2009 passthru3("postconf -e \"myhostname = {$hostname}\""); passthru3("postconf -e \"relayhost = \""); passthru3("postconf -e \"mydestination = localhost, {$ip} \""); passthru3("postconf -e 'mynetworks = 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/16, 10.0.0.0/8, {$net} '"); passthru3("postconf -e 'virtual_alias_domains ='"); passthru3("postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, proxy:mysql:/etc/postfix/mysql-virtual_email2email.cf'"); passthru3("postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'"); #autoresponder passthru3("postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'"); passthru3("postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'"); passthru3("postconf -e 'virtual_mailbox_base = /home/vmail'"); passthru3("postconf -e 'virtual_uid_maps = static:5000'"); passthru3("postconf -e 'virtual_gid_maps = static:5000'"); passthru3("postconf -e 'smtpd_sasl_auth_enable = yes'"); passthru3("postconf -e 'smtpd_sasl_security_options = noanonymous'"); passthru3("postconf -e 'broken_sasl_auth_clients = yes'"); passthru3("postconf -e 'smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,check_client_access hash:/var/lib/pop-before-smtp/hosts,reject_unauth_destination'"); // this is used with pop-before-smtp #passthru3("postconf -e 'smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination'"); // this is used with sasl authenticated passthru3("postconf -e 'smtp_use_tls = yes'"); ## yeni passthru3("postconf -e 'smtpd_use_tls = yes'"); passthru3("postconf -e 'smtpd_tls_auth_only = no'"); ## yeni passthru3("postconf -e 'smtpd_tls_CAfile = /etc/postfix/cacert.pem'"); ## yeni 13.6, dd.mm passthru3("postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'"); passthru3("postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'"); # this is partially taken from https://help.ubuntu.com/8.04/serverguide/C/postfix.html passthru3("postconf -e 'smtpd_tls_loglevel = 1'"); ## yeni 13.6, dd.mm passthru3("postconf -e 'smtpd_tls_received_header = yes'"); ## yeni 13.6, dd.mm passthru3("postconf -e 'smtpd_tls_session_cache_timeout = 3600s'"); ## yeni 13.6, dd.mm passthru3("postconf -e 'tls_random_source = dev:/dev/urandom'"); ## yeni 13.6, dd.mm # passthru3("postconf -e 'virtual_create_maildirsize = yes'"); # passthru3("postconf -e 'virtual_mailbox_extended = yes'"); passthru3("postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'"); # passthru3("postconf -e 'virtual_mailbox_limit_override = yes'"); # passthru3("postconf -e 'virtual_maildir_limit_message = \"The user you are trying to reach is over quota.\"'"); # passthru3("postconf -e 'virtual_overquota_bounce = yes'"); # deprecated passthru3("postconf -e 'debug_peer_list = '"); passthru3("postconf -e 'sender_canonical_maps = '"); passthru3("postconf -e 'debug_peer_level = 1'"); passthru3("postconf -e 'proxy_read_maps = \$local_recipient_maps \$mydestination \$virtual_alias_maps \$virtual_alias_domains \$virtual_mailbox_maps \$virtual_mailbox_domains \$relay_recipient_maps \$canonical_maps \$sender_canonical_maps \$recipient_canonical_maps \$relocated_maps \$mynetworks \$virtual_mailbox_limit_maps \$transport_maps'"); passthru3("postconf -e 'smtpd_banner =\$myhostname ESMTP \$mail_name powered by Easy Hosting Control Panel (ehcp) on Ubuntu, www.ehcp.net'"); passthru3("postconf -e 'default_process_limit = 3'"); # diğer türlü, onlarca proses açıyor, hiç gerek yok. # many of above config became useless, for postfix. I will remove them later. # passthru3("dpkg-statoverride --force --update --add root sasl 755 /var/run/saslauthd"); # may be required on some systems... echo "configuring saslauthd \n"; passthru3("mkdir -p /var/spool/postfix/var/run/saslauthd"); # here, both params, options added, in case it may be changed. $filecontent = "\nNAME=\"saslauthd\"\nSTART=yes\nMECHANISMS=\"pam\"\nPARAMS=\"-m /var/spool/postfix/var/run/saslauthd -r\"\nOPTIONS=\"-m /var/spool/postfix/var/run/saslauthd -r\"\n"; writeoutput("/etc/default/saslauthd", $filecontent, "w"); replacelineinfile("PIDFILE=", "PIDFILE=\"/var/spool/postfix/var/run/\${NAME}/saslauthd.pid\"", '/etc/init.d/saslauthd'); configurepamsmtp(array('ehcppass' => $ehcpmysqlpass)); echo "editing: /etc/postfix/sasl/smtpd.conf\n"; $filecontent = "\npwcheck_method: saslauthd\nmech_list: plain login\nallow_plaintext: true\n"; writeoutput("/etc/postfix/sasl/smtpd.conf", $filecontent, "w"); echo "Configuring Courier\n"; echo "Now configuring to tell Courier that it should authenticate against our MySQL database."; addifnotexists("authmodulelist=\"authmysql\"", "/etc/courier/authdaemonrc"); //** tablo ismi degisirse, asagidaki emailusers da degismeli configureauthmysql(array('ehcppass' => $ehcpmysqlpass)); passthru("chown -Rvf postfix /var/lib/postfix/"); passthru("chmod -R 755 /var/spool/postfix"); passthru("chmod 1733 /var/spool/postfix/maildrop"); passthru2("newaliases"); # on some systems, aliases.db is deleted by user or somehow, this fixes that. passthru("cp -vf pop-before-smtp.conf /etc/pop-before-smtp/"); if (!file_exists("/var/lib/pop-before-smtp/hosts.db")) { passthru2("mkdir /var/lib/pop-before-smtp"); passthru2("touch /var/lib/pop-before-smtp/hosts"); passthru2("postmap /var/lib/pop-before-smtp/hosts"); } # adjust roundcube: # adjust symlink for roundcube passthru2("ln -s /usr/share/roundcube /var/www/new/ehcp/webmail2"); replacelineinfile("\$rcmail_config['default_host']", "\$rcmail_config['default_host']='localhost';", '/etc/roundcube/main.inc.php'); # end adjust roundcube foreach (array('active', 'bounce', 'corrupt', 'defer', 'deferred', 'flush', 'incoming', 'maildrop', 'private', 'public', 'saved') as $dir) { passthru("chown -Rf postfix /var/spool/postfix/{$dir}"); } # fix dir ownerships, if broken somehow... foreach (array('pop-before-smtp', 'postfix', 'saslauthd', 'courier-authdaemon', 'courier-imap', 'courier-imap-ssl', 'courier-pop', 'courier-pop-ssl') as $service) { passthru("service {$service} restart"); } passthru("postfix check"); }
$admin_partner->save(); // replace admin console config file secret to match replace_in_file($admin_console_config_file, '/settings.secret(\\s)*=(\\s)*(.+)/', 'settings.secret = ' . $admin_partner->getAdminSecret()); // replace batch partner secrets $batch_partner = PartnerPeer::retrieveByPK($batch_partner_id); $batch_partner->setSecret(generate_secret()); $batch_partner->setAdminSecret(generate_secret()); $batch_partner->save(); // replace batch config file secret to match replace_in_file($batch_config_file, '/secret(\\s)*=(\\s)*(.+)/', 'secret = ' . $batch_partner->getAdminSecret()); // replace batch full status script secret to match replace_in_file($batch_full_status_file, '/\\$secret(\\s)*=(\\s)*(.+)/', '$secret = \'' . $batch_partner->getAdminSecret() . '\';'); // replace kconf system pages login password replace_in_file($kconf_file, '/system_pages_login_password(\\s)*=(\\s)*(.+)/', "system_pages_login_password = "******"replace_passwords = false"); //------------------------------------------------ function replace_in_file($file_name, $regexp, $replace) { $file_data = file_get_contents($file_name); $file_data = preg_replace($regexp, $replace, $file_data); @file_put_contents($file_name, $file_data); } function generate_secret() { $secret = md5(str_makerand(5, 10, true, false, true)); return $secret; } function str_makerand($minlength, $maxlength, $useupper, $usespecial, $usenumbers) { $charset = "abcdefghijklmnopqrstuvwxyz";