<commit_before>#!/usr/bin/env php
<?php
/**
 * Protokollen - create services and add hostnames from entity definitions
 */

require_once('../php/Protokollen.class.php');


$p = new Protokollen();

$m = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$m->set_charset(DB_CHARSET) or die("$m->error\n");

$q = 'SELECT domain FROM entities WHERE domain IS NOT NULL ORDER BY id';
$r = $m->query($q) or die("$m->error, SQL: $q\n");
while($row = $r->fetch_object()) {
	/* Load entity */
	$e = $p->getEntityByDomain($row->domain);

	/* Add HTTP service */
	$s = $p->addService($e->id, Protokollen::SERVICE_TYPE_HTTP, $e->domain, 'Webbsajt '. $e->org);
	$p->addServiceHostname($s->id, $e->domain);
	$p->addServiceHostname($s->id, 'www.'. $e->domain);

	/* Add SMTP service */
	if($e->domain_email === NULL)
		continue;

	$s = $p->addService($e->id, Protokollen::SERVICE_TYPE_SMTP, $e->domain_email, 'E-postdomän '. $e->org);
	/* Not yet implemented - should this be MX pointers instead? */
	$p->addServiceHostname($s->id, $e->domain_email);
}

$r->close();
<commit_msg>Use Protokollen class instead of raw MySQL queries<commit_after>#!/usr/bin/env php
<?php
/**
 * Protokollen - create services and add hostnames from entity definitions
 */

require_once('../php/Protokollen.class.php');


$p = new Protokollen();

foreach($p->listEntityDomains() as $domain) {
	/* Load entity */
	$e = $p->getEntityByDomain($domain);

	/* Add HTTP service */
	$s = $p->addService($e->id, Protokollen::SERVICE_TYPE_HTTP, $e->domain, 'Webbsajt '. $e->org);
	$p->addServiceHostname($s->id, $e->domain);
	$p->addServiceHostname($s->id, 'www.'. $e->domain);

	/* Add SMTP service */
	if($e->domain_email === NULL)
		continue;

	$s = $p->addService($e->id, Protokollen::SERVICE_TYPE_SMTP, $e->domain_email, 'E-postdomän '. $e->org);
	/* Not yet implemented - should this be MX pointers instead? */
	$p->addServiceHostname($s->id, $e->domain_email);
}
{'fraction_non_alphanumeric': 0.20948410630536737, 'fraction_numerical': 0.0, 'mean_word_length': 4.501432664756447, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4316582', 'n_tokens_mistral': 730, 'n_tokens_neox': 711, 'n_words': 155}