summaryrefslogblamecommitdiffstats
path: root/modules-available/dnbd3/inc/dnbd3.inc.php
blob: 7f873f236d6b47ecec8b47e83294dd739045048d (plain) (tree)
1
2
3
4
5
6
7
8
9




                                             
                                                       
 
                                                
         
                                                                  




                                                                 
                                            

         
                                                     
         
                                                                       





                                                                      
 




                                                                                      
                                                                                                    






                                                                                              
 
<?php

class Dnbd3 {

	const PROP_ENABLED = 'dnbd3.enabled';
	const PROP_NFS_FALLBACK = 'dnbd3.nfs-fallback';

	public static function isEnabled(): bool
	{
		return (bool)Property::get(self::PROP_ENABLED, 0);
	}

	public static function setEnabled($bool)
	{
		Property::set(self::PROP_ENABLED, $bool ? 1 : 0);
		Trigger::mount(false, true);
	}

	public static function hasNfsFallback(): bool
	{
		return (bool)Property::get(self::PROP_NFS_FALLBACK, 0);
	}

	public static function setNfsFallback($bool)
	{
		Property::set(self::PROP_NFS_FALLBACK, $bool ? 1 : 0);
	}

	public static function getActiveServers(): array
	{
		$res = Database::simpleQuery('SELECT s.serverid, m.clientip, s.fixedip
			FROM dnbd3_server s
			LEFT JOIN machine m ON (s.machineuuid = m.machineuuid)
			WHERE s.lastseen > :cutoff', ['cutoff' => CONFIG_DEBUG ? 0 : time() - 310]);
		$lookup = [];
		foreach ($res as $row) {
			$lookup[$row['fixedip'] ?? $row['clientip'] ?? ''] = $row['serverid'];
		}
		return $lookup;
	}

}