Beispiel #1
0
function RunKinit($username, $password)
{
    $unix = new unix();
    $kinit = $unix->find_program("kinit");
    $klist = $unix->find_program("klist");
    $echo = $unix->find_program("echo");
    if (!is_file($kinit)) {
        echo2("Unable to stat kinit");
        return;
    }
    exec("{$klist} 2>&1", $res);
    $line = @implode("", $res);
    if (strpos($line, "No credentials cache found") > 0) {
        unset($res);
        echo2($line . " -> initialize..");
        exec("{$echo} \"{$password}\"|{$kinit} {$username} 2>&1", $res);
        while (list($num, $a) = each($res)) {
            if (preg_match("#Password for#", $a, $re)) {
                unset($res[$num]);
            }
        }
        $line = @implode("", $res);
        if (strlen(trim($line)) > 0) {
            echo2($line . " -> Failed..");
            return;
        }
        unset($res);
        exec("{$klist} 2>&1", $res);
    }
    while (list($num, $a) = each($res)) {
        if (preg_match("#Default principal:(.+)#", $a, $re)) {
            echo2(trim($re[1]) . " -> success");
            break;
        }
    }
}
Beispiel #2
0
function BuildTunServer(){
LoadArgvs();
   $unix=new unix();
   if(isset($GLOBALS["CLASS_SOCKETS"])){$sock=$GLOBALS["CLASS_SOCKETS"];}else{$GLOBALS["CLASS_SOCKETS"]=new sockets();$sock=$GLOBALS["CLASS_SOCKETS"];}
   $servername=$unix->hostname_g();	
   $routess=array();
   $duplicate_cn=null;
 
   
  if(preg_match("#^(.+?)\.#",$servername,$re)){$servername=$re[1];}
   $servername=strtoupper($servername);       
   echo "Starting......: OpenVPN building settings for $servername...\n";
   
   
   
   $ini=new Bs_IniHandler();
   
   $ini->loadString($sock->GET_INFO("ArticaOpenVPNSettings"));
   if(!isset($ini->_params["GLOBAL"]["ENABLE_BRIDGE_MODE"])){$ini->_params["GLOBAL"]["ENABLE_BRIDGE_MODE"]=0;}
   if(!isset($ini->_params["GLOBAL"]["IP_START"])){$ini->_params["GLOBAL"]["IP_START"]="10.8.0.0";}
   if(!isset($ini->_params["GLOBAL"]["NETMASK"])){$ini->_params["GLOBAL"]["NETMASK"]="255.255.255.0";}
   
   
   if($ini->_params["GLOBAL"]["ENABLE_BRIDGE_MODE"]==1){
   		echo "Starting......: OpenVPN building settings mode bridge enabled...\n";
   		BuildBridgeServer();
   		return;
   }
   
   
   $IPTABLES_ETH=$GLOBALS["IPTABLES_ETH"];
   $DEV_TYPE=$ini->_params["GLOBAL"]["DEV_TYPE"];
   $port=$ini->_params["GLOBAL"]["LISTEN_PORT"];
   $IP_START=$ini->_params["GLOBAL"]["IP_START"];
   $NETMASK=$ini->_params["GLOBAL"]["NETMASK"];
   $bind_addr=$ini->_params["GLOBAL"]["LOCAL_BIND"];
   $LISTEN_PROTO=$ini->_params["GLOBAL"]["LISTEN_PROTO"];
   if($LISTEN_PROTO==null){$LISTEN_PROTO="udp";}
   if($LISTEN_PROTO=="udp"){$proto="--proto udp";}else{$proto="--proto tcp-server";}
   
    
   if(trim($port)==null){$port=1194;}
   if(trim($IP_START)==null){$IP_START="10.8.0.0";}
   if(trim($NETMASK)==null){$NETMASK="255.255.255.0";}
   
$nic=new networking();

while (list ($num, $ligne) = each ($nic->array_TCP) ){
	if($ligne==null){continue;}
		$eths[][$num]=$num;
		$ethi[$num]=$ligne;
	} 

if($IPTABLES_ETH<>null){
		echo "Starting......: OpenVPN linked to $IPTABLES_ETH ({$ethi[$IPTABLES_ETH]})...\n";
		$IPTABLES_ETH_ROUTE=IpCalcRoute($ethi[$IPTABLES_ETH]);
}else{
	echo "Starting......: OpenVPN no local NIC linked...\n";
}
	
   $ca='/etc/artica-postfix/openvpn/keys/allca.crt';
   $dh='/etc/artica-postfix/openvpn/keys/dh1024.pem';
   $key="/etc/artica-postfix/openvpn/keys/vpn-server.key";
   $crt="/etc/artica-postfix/openvpn/keys/vpn-server.crt";
   $route='';
   
   //$IPTABLES_ETH_IP=

if (is_file('/etc/artica-postfix/settings/Daemons/OpenVPNRoutes')){
   $routes=(explode("\n",@file_get_contents("/etc/artica-postfix/settings/Daemons/OpenVPNRoutes")));
   while (list ($num, $ligne) = each ($routes) ){
   	if(!preg_match("#(.+?)\s+(.+)#",$ligne,$re)){continue;}
   	$routess[]="--push \"route {$re[1]} {$re[2]}\"";
   }
}
$GetRoutes=GetRoutes();
$routess=$routess+$GetRoutes;



if(count($routess)==0){
	if($IPTABLES_ETH_ROUTE<>null){
		echo "Starting......: OpenVPN IP adding default route \"$IPTABLES_ETH_ROUTE\"\n";
		$routess[]="--push \"route $IPTABLES_ETH_ROUTE\"";
	}
  }else{
  	echo "Starting......: OpenVPN IP adding ".count($routess)." routes\n";
  }
   

	
   if(trim($bind_addr)<>null){
   	$local=" --local $bind_addr";
   	echo "Starting......: OpenVPN IP bind $bind_addr\n";
   }
   
   $IP_START=FIX_IP_START($IP_START,$local);
   $ini->set("GLOBAL","IP_START",$IP_START); 	
  
   if(preg_match("#(.+?)\.([0-9]+)$#",$IP_START,$re)){
   	$calc_ip=" {$re[1]}.0";
   	$calc_ip_end="{$re[1]}.254";
   	echo "Starting......: OpenVPN IP pool from {$re[1]}.2 to {$re[1]}.254 mask:$NETMASK\n";
   	$server_ip="{$re[1]}.1";
   	$IP_START_PREFIX=$re[1];
   }

   if($NETMASK==null){
			$ip=new IP();
			$cdir=$ip->ip2cidr($calc_ip,$calc_ip_end);
			$arr=$ip->parseCIDR($cdir);
			$rang=$arr[0];
			$netbit=$arr[1];
			$ipv=new ipv4($calc_ip,$netbit);
			$NETMASK=$ipv->netmask();	   
			if($NETMASK=="255.255.255.255"){$NETMASK="255.255.255.0";}		
   			echo "Starting......: OpenVPN Netmask is null for the range $calc_ip, assume $NETMASK\n";
   			$ini->set("GLOBAL","NETMASK",$NETMASK);
   	}
   	
	$OpenVpnPasswordCert=$sock->GET_INFO("OpenVpnPasswordCert");
	if($OpenVpnPasswordCert==null){$OpenVpnPasswordCert="MyKey";}
   
	$askpass=null;
   	if(is_file("/etc/artica-postfix/openvpn/keys/password")){
   		$askpass="******";
   	}
   	
   	$ifconfig_pool_persist=" --ifconfig-pool-persist /etc/artica-postfix/openvpn/ipp.txt ";
   	
 	if(isset($GLOBALS["OPENVPNPARAMS"]["duplicate-cn"])){
 		echo "Starting......: OpenVPN duplicate-cn is enabled\n";
 		$duplicate_cn=" --duplicate-cn ";
 		$ifconfig_pool_persist=null;
 	}
 	
 	if(isset($GLOBALS["OPENVPNPARAMS"]["script-security"])){
 		echo "Starting......: OpenVPN script-security is enabled\n";
 		$script_security=" --script-security 2";
 	} 	
 	
	if(!is_dir("/etc/openvpn/cdd")){@mkdir("/etc/openvpn/cdd");}
	$already=array();
 	echo "Starting......: OpenVPN get remote sites routes...\n";
 	$sql="SELECT sitename,IP_START,netmask,remote_site_routes,FixedIPAddr FROM vpnclient WHERE connexion_type=1";
 	$q=new mysql();
	$results=$q->QUERY_SQL($sql,"artica_backup");
	if(!$q->ok){echo2("Starting......: OpenVPN : $q->mysql_error");}
 	while($ligne=mysql_fetch_array($results,MYSQL_ASSOC)){
 		$iroute=array();
 		$sitename=$ligne["sitename"];
 		$FixedIPAddr=$ligne["FixedIPAddr"];
 		if(!is_numeric($FixedIPAddr)){$FixedIPAddr=0;}
 		
 		if($IP_START_PREFIX<>null){
 			if($FixedIPAddr>2){
 				if($FixedIPAddr<255){
 					echo "Starting......: OpenVPN $sitename $IP_START_PREFIX.$FixedIPAddr fixed IP address\n";
 					$iroute[]="ifconfig-push $IP_START_PREFIX.$FixedIPAddr $IP_START_PREFIX.2";
 				}
 			}
 		}
 		
 		if(!isset($already[$ligne["IP_START"]])){
 			echo "Starting......: OpenVPN $sitename ({$ligne["IP_START"]} {$ligne["netmask"]})\n";
 			$rou[]=" --route {$ligne["IP_START"]} {$ligne["netmask"]}";
 			$iroute[]="iroute {$ligne["IP_START"]} {$ligne["netmask"]}";
 			$already[$ligne["IP_START"]]=true;
 		}
 		
 		$remote_site_routes=unserialize(base64_decode($ligne["remote_site_routes"]));
		while (list ($num, $site_mask) = each ($remote_site_routes) ){
			if(!isset($already[$num])){
				echo "Starting......: OpenVPN $sitename ($num $site_mask)\n";
				$rou[]=" --route $num $site_mask";
				$iroute[]="iroute $num $site_mask";
				$already[$num]=true;
			}
		}
 		echo "Starting......: OpenVPN cdd $sitename\n";
 		@file_put_contents("/etc/openvpn/cdd/$sitename",@implode("\n", $iroute) );
 		
 	}
 	if(count($rou)>0){
 		$localroutes=@implode(" ", $rou);
 		$client_config_dir=" --client-config-dir /etc/openvpn/cdd";
 	}
 	
 	 
 	
 	$LDAP_AUTH=$ini->_params["GLOBAL"]["LDAP_AUTH"];
 	if($LDAP_AUTH==1){
 		if(is_file("/usr/lib/openvpn/openvpn-auth-pam.so")){
 		$plugin=" --plugin /usr/lib/openvpn/openvpn-auth-pam.so common-auth";
 		echo "Starting......: OpenVPN auth is enabled\n";
 		shell_exec("/usr/share/artica-postfix/bin/artica-install --nsswitch");
 		}
 	}
   
   @mkdir("/etc/openvpn/ccd",0666,true);
   $php5=$unix->LOCATE_PHP5_BIN();
   $me=__FILE__;
   $cmd=" --port $port --dev tun $proto --server $IP_START $NETMASK$localroutes$client_config_dir --comp-lzo $local --ca $ca --dh $dh --key $key --cert $crt";
   $cmd=$cmd. "$ifconfig_pool_persist " . implode(" ",$routess);
   $cmd=$cmd. " $askpass$duplicate_cn--client-to-client$script_security$plugin --learn-address \"$php5 $me --client-connect\" --keepalive 10 60 --persist-tun --verb 5 --daemon --writepid /var/run/openvpn/openvpn-server.pid --log \"/var/log/openvpn/openvpn.log\"";
   $cmd=$cmd. " --status /var/log/openvpn/openvpn-status.log 10";
   echo "Starting......: OpenVPN building /etc/openvpn/cmdline.conf done\n";
   @file_put_contents("/etc/openvpn/cmdline.conf",$cmd);
  
   
   $sock->SaveConfigFile($ini->toString(),"ArticaOpenVPNSettings");
   send_email_events("OpenVPN was successfully reconfigured",$cmd,"VPN");
   echo "Starting......: OpenVPN building settings done.\n";
   if($GLOBALS["VERBOSE"]){writelogs("$cmd",__FUNCTION__,__FILE__,__LINE__);}
}
Beispiel #3
0
function RunKinit($username, $password, $progress = 1)
{
    $unix = new unix();
    $kinit = $unix->find_program("kinit");
    $klist = $unix->find_program("klist");
    $echo = $unix->find_program("echo");
    $function = __FUNCTION__;
    if (!is_file($kinit)) {
        echo2("Unable to stat kinit");
        return;
    }
    resolve_kdc();
    sync_time();
    exec("{$klist} 2>&1", $res);
    $line = @implode("", $res);
    if (strpos($line, "No credentials cache found") > 0) {
        unset($res);
        echo2($line . " -> initialize..");
        $password = $unix->shellEscapeChars($password);
        $cmd = "{$echo} \"{$password}\"|{$kinit} {$username} 2>&1";
        progress_logs($progress, "{kerberaus_authentication}", "{$cmd}");
        progress_logs($progress, "{kerberaus_authentication}", "{$function}, kinit `{$username}`");
        exec("{$echo} {$password}|{$kinit} {$username} 2>&1", $res);
        while (list($num, $a) = each($res)) {
            if (preg_match("#Password for#", $a, $re)) {
                unset($res[$num]);
            }
            progress_logs($progress, "{kerberaus_authentication}", "{$a}");
        }
        $line = @implode("", $res);
        if (strlen(trim($line)) > 0) {
            progress_logs($progress, "{kerberaus_authentication}", $line . " -> Failed..");
            return;
        }
        unset($res);
        progress_logs($progress, "{kerberaus_authentication}", $klist);
        exec("{$klist} 2>&1", $res);
    }
    while (list($num, $a) = each($res)) {
        progress_logs($progress, "{kerberaus_authentication}", "{$a}");
        if (preg_match("#Default principal:(.+)#", $a, $re)) {
            progress_logs($progress, "{kerberaus_authentication}", "{$a} SUCCESS");
            break;
        }
    }
    progress_logs($progress, "{kerberaus_authentication}", "DONE LINE: " . __LINE__);
    return true;
}
function set_permisions()
{
    global $thissite;
    echo2("Set the permissions for the new site '{$thissite->name}'...");
    $thissite->set_permisions();
    echo2("done.\n");
}
Beispiel #5
0
function mostrar_error($error)
{
    echo '<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>';
    echo2($error);
}
Beispiel #6
0
function duplicate_vps($from_id, $to_id)
{
    $q = new mysql();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$from_id}.{$to_id}.pid";
    $pid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        echo2("Starting......: VPS server: vps-{$to_id}: Already instance executed {$pid}");
        return;
    }
    $pid = getmypid();
    @file_put_contents($pidfile, $pid);
    $q->QUERY_SQL("UPDATE lxc_machines SET `state`='configure' WHERE ID='{$to_id}'", "artica_backup");
    $source_dir = root_directory($from_id);
    $destdir = root_directory($to_id);
    @mkdir($destdir);
    echo2("Starting......: VPS server: vps-{$to_id}: copying {$source_dir} to {$source_dir}");
    shell_exec("/bin/cp -rf {$source_dir}/* {$destdir}/");
    buildconfig($to_id);
    $q->QUERY_SQL("UPDATE lxc_machines SET `state`='installed' WHERE ID='{$to_id}'", "artica_backup");
    vps_start($to_id);
}
function disconnect_sites()
{
    global $db, $claspages, $pages, $thissite;
    echo2("\n");
    echo2("Disconnecting sites...");
    $db->disconnect();
    $claspages->disconnect();
    $pages->disconnect();
    $thissite->disconnect();
    echo2("done.\n");
}
?>
</ul>

<p>You can see why we need to normalize the punctuation (make it look pretty) and use macros (simplify our expression-writing needs). Let's see how it all works:
<ul>
<?php 
foreach ([['{*_a centurion} {_perfactv$(caught sight of)$(_a young man)} {said} {_quot$(I recognize (this [man|guy]|him)!)}.', 'thecenturionhavingcaughtsightoftheyoungmansaidirecognizehim'], ['{*{, {himself} {_a young man}, } {_a centurion}} {smiled|was smiling}.', 'the centurion a young man himself was smiling'], ['{*{, {himself} {_a young man}, } {_a centurion}} {smiled|was smiling}.', 'a young man himself the centurion was smiling'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou dost not know me'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou dost know me not'], ['_opts$(*thou} {not} {me)$(dost} {know)$(knowest).', 'thou not me knowest'], ['_Appos$(_a centurion)$(having seen _a child) {wept} _quot$({*have mercy} {on me} {,O deity,}).', 'the centurion having seen the child wept on me have mercy O deity']] as $example) {
    ?>
<li><?php 
    echo2($example[0]);
    echo "makes this syntax";
    echo2(nanomacro($example[0], $dict, 4));
    echo "and matches";
    echo2($example[1]);
    echo "creating";
    echo2(compare_syntax3($example[0], $example[1], $dict));
    ?>
<br><?php 
}
?>
</ul>

<h2>Try it!</h2>
<p>IT'S ALIVE!!</p>

Damerau-Levenshtein error: <input id="dist" style="width:150px" type="number" placeholder="Max Distance">
<label><input type="checkbox" id="debug">Debug</label>
<label><input type="checkbox" checked id="matchall">Only match whole string</label>
<br>
<input style="width: 100%" id="syntax" placeholder="Expression">
<br>
 public function find_missing_tables()
 {
     global $db, $claspages, $pages;
     echo2("\n   Gettting tables lists...");
     $claspages_tables = $claspages->get_table_list(TRUE);
     $pages_tables = $pages->get_table_list(TRUE);
     echo2("done.\n");
     echo2("   Analyzing lists...");
     $count = 0;
     $missed_tables = array();
     foreach ($this->blogs as $blog) {
         $count++;
         if ($count % 100 === 0) {
             echo2('.');
         }
         $old_table_list = $db->get_table_list_by_prefix($blog->old_site->dbname, $blog->old_site->dbprefix . $blog->old_id . '_');
         $new_table_list = $db->get_table_list_by_prefix($this->dbname, $this->dbprefix . $blog->new_id . '_');
         foreach ($old_table_list as &$table_name) {
             $table_name = $blog->old_site->remove_table_prefix($table_name);
         }
         foreach ($new_table_list as &$table_name) {
             $table_name = $this->remove_table_prefix($table_name);
         }
         $mtables = array_diff($old_table_list, $new_table_list);
         foreach ($mtables as $table_name) {
             $missed_tables[] = $blog->old_site->dbprefix . $blog->old_id . '_' . $table_name;
         }
     }
     echo2("done.\n");
     if (0 === count($missed_tables)) {
         echo2("   No missed tables.\n");
     } else {
         echo2("   " . count($missed_tables) . " missed tables:\n");
         foreach ($missed_tables as $table_name) {
             echo2("      {$table_name}\n");
         }
     }
 }