Ejemplo n.º 1
0
function save()
{
    $databasename = $_GET["databasename"];
    $databasename = format_mysql_table($databasename);
    $ou = base64_decode($_GET["ou"]);
    $q = new mysql();
    $tpl = new templates();
    //CheckTableEmailingContacts
    while (list($key, $line) = each($_GET)) {
        if (preg_match("#DB_ADD_[0-9]+#", $key)) {
            $tables[] = "emailing_{$line}";
        }
    }
    if (count($tables) == 0) {
        echo $tpl->javascript_parse_text("{NODB_SELECTED}");
        return;
    }
    $q->CheckTableEmailingContacts("emailing_{$databasename}", $tables);
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    $sql = "INSERT INTO emailing_db_paths (databasename,progress,finish,ou,zDate,merged)\n\tVALUES('{$databasename}','100','1','{$ou}',NOW(),'1');";
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
}
Ejemplo n.º 2
0
function parse_db($id)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".{$id}.pid";
    $pid = trim(@file_get_contents($pidfile));
    if ($unix->process_exists($pid)) {
        $pid = getmypid();
        echo "[{$pid}]:: Process {$pid} already running...\n";
        die;
    }
    $pid = getmypid();
    file_put_contents($pidfile, $pid);
    $sql = "SELECT * FROM emailing_db_paths WHERE ID={$id}";
    $q = new mysql();
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    $unzipbin = $unix->find_program("unzip");
    if ($unzipbin == null) {
        echo "[{$pid}]:: unzip tool no such file or directory...\n";
        update_status($id, "110", 1, "unzip tool no such file or directory");
        die;
    }
    $zip_path = $ligne["filepath"];
    if (!is_file($zip_path)) {
        echo "[{$pid}]:: {$zip_path} no such file or directory\n";
        update_status($id, "110", 1, "zip db no such file or directory");
        die;
    }
    $tmp_path = "/tmp/emailing-import/{$id}";
    writeevent("using {$tmp_path}", $id);
    @mkdir($tmp_path, 666, true);
    writeevent("Uncompress {$zip_path}", $id);
    echo "{$unzipbin} -o {$zip_path} -d {$tmp_path}\n";
    shell_exec("{$unzipbin} -o {$zip_path} -d {$tmp_path}");
    $files = $unix->DirFiles($tmp_path);
    if (!is_array($files)) {
        update_status($id, "110", 1, "{$zip_path} corrupted or no files stored");
        die;
    }
    while (list($filename, $file_name) = each($files)) {
        writeevent("parsing {$file_name}", $pid);
        $max = $unix->COUNT_LINES_OF_FILE("{$tmp_path}/{$file_name}");
        writeevent("parsing {$file_name} {$max} entries", $pid);
        $handle = @fopen("{$tmp_path}/{$file_name}", "r");
        $ligne["databasename"] = format_mysql_table($ligne["databasename"]);
        $q = new mysql();
        $q->CheckTableEmailingContacts("emailing_{$ligne["databasename"]}");
        $sql = "INSERT INTO emailing_{$ligne["databasename"]} (`gender`,`firstname`, `lastname`,`email`,`phone`,`city`,`cp`,`postaladdress`,`domain`) VALUES";
        if ($handle) {
            while (!feof($handle)) {
                $tw = $tw + 1;
                $count = $count + 1;
                unset($re);
                $buffer = fgets($handle, 4096);
                if (trim($buffer) == null) {
                    continue;
                }
                $buffer = str_replace('"', "", $buffer);
                $buffer = str_replace(';', ",", $buffer);
                $lines = explode(",", addslashes($buffer));
                if (!is_array($lines)) {
                    if (preg_match("#.+?@.+#", $buffer)) {
                        for ($i = 0; $i < 8; $i++) {
                            $lines[$i] = "";
                        }
                        $lines[3] = trim($buffer);
                    }
                }
                if (count($lines) < 2) {
                    if (preg_match("#.+?@.+#", $buffer)) {
                        for ($i = 0; $i < 8; $i++) {
                            $lines[$i] = "";
                        }
                        $lines[3] = trim($buffer);
                    }
                }
                $lines[3] = str_replace(";", ".", $lines[3]);
                $lines[3] = str_replace("?", ".", $lines[3]);
                $lines[3] = str_replace("@.", "@", $lines[3]);
                $lines[3] = str_replace('^', '@', $lines[3]);
                $lines[3] = str_replace(',', '.', $lines[3]);
                if (trim($lines[3]) == null) {
                    writeevent("failed 3:[{$buffer}] [" . __LINE__ . "]", $pid);
                    $GLOBALS["FAILED_CONTACTS"] = $GLOBALS["FAILED_CONTACTS"] + 1;
                    unset($lines);
                    continue;
                }
                if (!preg_match("#(.+?)@(.+?)\\.(.+)#", $lines[3], $re)) {
                    writeevent("failed 3:{$lines[3]} bad email address [" . __LINE__ . "]", $pid);
                    $GLOBALS["FAILED_CONTACTS"] = $GLOBALS["FAILED_CONTACTS"] + 1;
                    unset($lines);
                    continue;
                }
                $domain = $re[2];
                if (substr($domain, strlen($domain) - 1, 1) == '.') {
                    $domain = substr($domain, 0, strlen($domain) - 1);
                }
                if (preg_match("#^\\..+#", $domain)) {
                    writeevent("failed 3:{$lines[3]} bad domain {$domain} [" . __LINE__ . "]", $pid);
                    $GLOBALS["FAILED_CONTACTS"] = $GLOBALS["FAILED_CONTACTS"] + 1;
                    unset($lines);
                    continue;
                }
                if ($GLOBALS["EMAILS"][$lines[3]]) {
                    writeevent("failed 3:{$lines[3]} already exists [" . __LINE__ . "]", $pid);
                    $GLOBALS["FAILED_CONTACTS"] = $GLOBALS["FAILED_CONTACTS"] + 1;
                    continue;
                }
                if (isBlockedMail($lines[3])) {
                    writeevent("failed 3:{$lines[3]} is blacklisted [" . __LINE__ . "]", $pid);
                    $GLOBALS["FAILED_CONTACTS"] = $GLOBALS["FAILED_CONTACTS"] + 1;
                    continue;
                }
                $sqla[] = "('{$lines[0]}',\n\t\t\t\t'{$lines[1]}',\n\t\t\t\t'{$lines[2]}',\n\t\t\t\t'{$lines[3]}',\n\t\t\t\t'{$lines[4]}',\n\t\t\t\t'{$lines[5]}',\n\t\t\t\t'{$lines[6]}',\n\t\t\t\t'{$lines[7]}','{$domain}')";
                $GLOBALS["SUCCESS_CONTACTS"] = $GLOBALS["SUCCESS_CONTACTS"] + 1;
                $GLOBALS["EMAILS"][$lines[3]] = true;
                if (count($GLOBALS["EMAILS"]) > 10000) {
                    $GLOBALS["EMAILS"] = array();
                }
                unset($lines);
                if ($tw > 100) {
                    $fullsql = $sql . "\n" . @implode(",", $sqla);
                    $q = new mysql();
                    $q->QUERY_SQL($fullsql, "artica_backup");
                    if (!$q->ok) {
                        writeevent($id, "{$q->mysql_error}\n{$fullsql}");
                    }
                    unset($sqla);
                    $purc = $count / $max;
                    $purc = $purc * 100;
                    $purc = round($purc, 0);
                    update_status($id, $purc, 0);
                    $tw = 0;
                }
            }
            fclose($handle);
            if (is_array($sqla)) {
                $fullsql = $sql . "\n" . @implode(",", $sqla);
                $q->QUERY_SQL($fullsql, "artica_backup");
                if (!$q->ok) {
                    writeevent($id, "{$q->mysql_error}\n{$fullsql}");
                }
            }
        }
    }
    if ($GLOBALS["SUCCESS_CONTACTS"] > 0) {
        writeevent("Failed.:{$GLOBALS["FAILED_CONTACTS"]}", $id);
        writeevent("Success:{$GLOBALS["SUCCESS_CONTACTS"]}", $id);
        update_status($id, 100, 1, null);
    } else {
        update_status($id, 110, 0, null);
    }
}
Ejemplo n.º 3
0
function popup_add_contact_save()
{
    $db = $_GET["database"];
    $ID = $_GET["ID"];
    $_GET["ou"] = base64_decode($_GET["ou"]);
    if (trim($_GET["db_add"]) != null) {
        $db = $_GET["db_add"];
    }
    $db = format_mysql_table($db);
    $email = $_GET["email"];
    if (preg_match("#.+?@(.+)#", $email, $re)) {
        $domain = $re[1];
    }
    $sql_add = "INSERT INTO emailing_{$db} (gender,firstname,lastname,email,domain,phone,city,cp,postaladdress)\n\tVALUES('{$_GET["gender"]}','{$_GET["firstname"]}','{$_GET["lastname"]}','{$_GET["email"]}','{$domain}',\n\t'{$_GET["phone"]}','{$_GET["city"]}','{$_GET["cp"]}','{$_GET["postaladdress"]}');\n\t";
    $sql_edit = "UPDATE emailing_{$db} SET \n\tgender='{$_GET["gender"]}',\n\tlastname='{$_GET["lastname"]}',\n\temail='{$_GET["email"]}',\n\tdomain='{$domain}',\n\tphone='{$_GET["phone"]}',\n\tcity='{$_GET["city"]}',\n\tcp='{$_GET["cp"]}',\n\tpostaladdress='{$_GET["postaladdress"]}'\n\tWHERE ID={$ID}\n\t";
    if ($ID > 0) {
        $sql = $sql_edit;
    } else {
        $sql = $sql_add;
    }
    $q = new mysql();
    writelogs("Checking emailing_{$db}", __FUNCTION__, __FILE__, __LINE__);
    if (!$q->TABLE_EXISTS("emailing_{$db}", "artica_backup")) {
        writelogs("Create emailing_{$db}", __FUNCTION__, __FILE__, __LINE__);
        $q->CheckTableEmailingContacts("emailing_{$db}");
        $sql_table = "INSERT INTO emailing_db_paths(databasename,ou,zDate,finish,progress)\n\t\tVALUES ('{$db}','{$_GET["ou"]}',NOW(),1,100);\n\t\t";
        $z = new mysql();
        $z->QUERY_SQL($sql_table, "artica_backup");
        writelogs("{$z->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
        if (!$z->ok) {
            echo "\n{$z->mysql_error}\n{$sql_table}\n\n";
        }
    }
    $q->QUERY_SQL($sql, "artica_backup");
    if (!$q->ok) {
        echo "\n{$q->mysql_error}\n{$sql}\n\n";
    }
}
Ejemplo n.º 4
0
function database_infos(){
	$ID=$_GET["database-infos"];
	$ou=$_GET["ou"];
	$tpl=new templates();
	$sql="SELECT * FROM emailing_db_paths WHERE ID=$ID";
	$q=new mysql();
	$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));	
	$databasename=$ligne["databasename"];
	$merged=$ligne["merged"];
	$make_unique_table_text=$tpl->javascript_parse_text("{make_unique_table_text}");
	$page=CurrentPageName();
	
	$tbl=@explode("\n",$ligne["reports_import"]);
	while (list ($index, $line) = each ($tbl)){
		$t[]="<div><code>$line</code></div>";
	}
	$q=new mysql();
	if(!$q->TABLE_EXISTS("emailing_{$databasename}","artica_backup")){$q->CheckTableEmailingContacts("emailing_{$databasename}");}
	
	$nb_contacts=$q->COUNT_ROWS("emailing_{$databasename}","artica_backup");
	
	$sql="SELECT domain FROM emailing_{$databasename} GROUP BY domain";
	$q=new mysql();
	$results=$q->QUERY_SQL($sql,"artica_backup");
	$nb_domains=mysql_num_rows($results);

	//table-synonyms-settings-96.png
	//table-synonyms-settings-32.png
	
	
	$are_you_sure_to_delete=$tpl->javascript_parse_text("{are_you_sure_to_delete}");
	$add_contact_js="Loadjs('domains.emailings.contacts.php?ou=$ou&dbname=$databasename')";
	
	$add_contact_icon="<td width=1% style='border-right:2px solid #CCCCCC;padding:4px'>". imgtootltip("contact-card-add-32.png","{add_contact_text}","$add_contact_js")."</td>";
	$synonym="<td width=1% style='border-right:2px solid #CCCCCC;padding:4px'>". imgtootltip("table-synonyms-settings-32.png","{make_unique_table_text}","MakeUniqueTable()")."</td>";
	$infos_plus=null;
	$explain_plus=null;
	
	
	
	if($merged==1){
		$add_contact_icon=null;
		$synonym=null;
		$infos_plus="&nbsp;{merged_database}";
		$explain_plus="<div class=explain>{merged_database_explain}</div>";
	}
	
	$html="
	<div id='db_$ID'>
	<table style='width:100%'>
	<tr>
	<td width=1% style='border-right:2px solid #CCCCCC;padding:4px'>". imgtootltip("delete-32.png","{delete}","DeleteDB();")."</td>
	<td width=1% style='border-right:2px solid #CCCCCC;padding:4px'>". imgtootltip("user-migrate-32.png","{migrate_user_tini_text}","MigrateUsersToLdap($ID,'$databasename');")."</td>
	$add_contact_icon
	$synonym
	
	
	
	<td nowrap><H4>$databasename (ref:$ID)</H4></td>
	</tr>
	</table>
	<table style='width:100%'>
	<tr>
	<td valign='top' width=1%><img src='img/table-show-90.png'></td>
	<td valign='top' width=99%>
		<table style='width:100%'>
		<tr>
			<td valign='top' style='font-size:13px' class=legend>{contacts}:</td>
			<td valign='top' style='font-size:13px'><strong style='font-size:13px'>$nb_contacts</strong></td>
		</tr>
		<tr>
			<td valign='top' style='font-size:13px' class=legend>{nb_domains}:</td>
			<td valign='top' style='font-size:13px'><strong style='font-size:13px'>$nb_domains</strong></td>
		</tr>		
		<tr>
			<td colspan=2>
			<H3>{infos}$infos_plus</H3>$explain_plus
			<br>
			<div style='height:220px;overflow:auto;border-top:1px solid #005447'>".@implode("\n",$t)."</div></td>
		</tr>
	</table>
	</div>
	</tr>
	</table>
	</div>
	<script>
	
	var x_DeleteDB= function (obj) {
			var tempvalue=obj.responseText;
			if(tempvalue.length>0){alert(tempvalue)};
			YahooWin4Hide();
			RefreshTab('emailing_campaigns');	
		}		
	
		function DeleteDB(ID){
			if(confirm('$are_you_sure_to_delete $databasename')){
			 	var XHR = new XHRConnection();
	      		XHR.appendData('delete-db','$ID');
	      		XHR.appendData('ou','{$_GET["ou"]}');
	      		if(document.getElementById('db_$ID')){
	      			document.getElementById('db_$ID').innerHTML='<center style=\"margin:20px;padding:20px\"><img src=\"img/wait_verybig.gif\"></center>';
				}
		  		XHR.sendAndLoad('$page', 'GET',x_DeleteDB);	
				}
		}
		
		function MakeUniqueTable(){
			if(confirm('$make_unique_table_text')){
				var XHR = new XHRConnection();
	      		XHR.appendData('make-unique-table','yes');
	      		XHR.appendData('ou','{$_GET["ou"]}');
	      		XHR.appendData('source-table','$ID');
				XHR.sendAndLoad('$page', 'GET',x_DeleteDB);	
			}
		}
		
		
</script>
		
	
	";

	

echo $tpl->_ENGINE_parse_body($html);	
	
}