]> git.mxchange.org Git - friendica.git/blobdiff - mod/admin.php
combine some versions for ~f and D*
[friendica.git] / mod / admin.php
index 6333cb53212354838dc94fb8d8630d39b561e69d..39677fb386f774e39b55651de7a5f752d09f6a29 100644 (file)
@@ -121,22 +121,24 @@ function admin_content(&$a) {
        /**
         * Side bar links
         */
-
+       $aside_tools = Array();
        // array( url, name, extra css classes )
-       $aside = Array(
+       // not part of $aside to make the template more adjustable
+       $aside_sub = Array(
                'site'   =>     Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
                'users'  =>     Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
                'plugins'=>     Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
                'themes' =>     Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
                'dbsync' =>     Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync"),
                'queue'  =>     Array($a->get_baseurl(true)."/admin/queue/", t('Inspect Queue'), "queue"),
+               'federation' => Array($a->get_baseurl(true)."/admin/federation/", t('Federation Statistics'), "federation"),
                //'update' =>   Array($a->get_baseurl(true)."/admin/update/", t("Software Update") , "update")
        );
 
        /* get plugins admin page */
 
        $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin`=1 ORDER BY `name`");
-       $aside['plugins_admin']=Array();
+       $aside_tools['plugins_admin']=Array();
        foreach ($r as $h){
                $plugin =$h['name'];
                $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
@@ -144,13 +146,14 @@ function admin_content(&$a) {
                $a->plugins_admin[] = $plugin;
        }
 
-       $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
-       $aside['diagnostics_probe'] = Array($a->get_baseurl(true).'/probe/', t('probe address'), 'probe');
-       $aside['diagnostics_webfinger'] = Array($a->get_baseurl(true).'/webfinger/', t('check webfinger'), 'webfinger');
+       $aside_tools['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
+       $aside_tools['diagnostics_probe'] = Array($a->get_baseurl(true).'/probe/', t('probe address'), 'probe');
+       $aside_tools['diagnostics_webfinger'] = Array($a->get_baseurl(true).'/webfinger/', t('check webfinger'), 'webfinger');
 
        $t = get_markup_template("admin_aside.tpl");
        $a->page['aside'] .= replace_macros( $t, array(
-                       '$admin' => $aside,
+           '$admin' => $aside_tools,
+           '$subpages' => $aside_sub,
                        '$admtxt' => t('Admin'),
                        '$plugadmtxt' => t('Plugin Features'),
                        '$logtxt' => t('Logs'),
@@ -192,6 +195,9 @@ function admin_content(&$a) {
                        case 'queue':
                                $o = admin_page_queue($a);
                                break;
+                       case 'federation':
+                               $o = admin_page_federation($a);
+                               break;
                        default:
                                notice( t("Item not found.") );
                }
@@ -208,6 +214,104 @@ function admin_content(&$a) {
        }
 }
 
+/**
+ * Admin Federation Stats Page; display some numbers from gserver
+ * @param App $a
+ * returning string
+ */
+function admin_page_federation(&$a) {
+    // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
+    // social and statusnet nodes this node is knowing
+    //
+    // We are looking for the following platforms in the DB, "Red" should find
+    // all variants of that platform ID string as the q() function is stripping
+    // off one % two of them are needed in the query
+    $platforms = array('Diaspora', 'Friendica', '%%red%%', 'Hubzilla', 'GNU Social', 'StatusNet');
+    $counts = array();
+    foreach ($platforms as $p) {
+       // get a total count for the platform, the name and version of the
+       // highest version and the protocol tpe
+       $c = q('select count(*), platform, network, version from gserver
+           where platform like "'.$p.'" and last_contact > last_failure
+           order by version asc;');
+       // what versions for that platform do we know at all?
+       // again only the active nodes
+       $v = q('select count(*), version from gserver
+           where last_contact > last_failure and platform like "'.$p.'" 
+           group by version
+           order by version;');
+       //
+       // clean up version numbers
+       //
+       // in the DB the Diaspora versions have the format x.x.x.x-xx the last
+       // part (-xx) should be removed to clean up the versions from the "head
+       // commit" information and combined into a single entry for x.x.x.x
+       if ($p=='Diaspora') {
+           $newV = array();
+           $newVv = array();
+           foreach($v as $vv) {
+               $newVC = $vv['count(*)'];
+               $newVV = $vv['version'];
+               $posDash = strpos($newVV, '-');
+               if ($posDash) 
+                   $newVV = substr($newVV, 0, $posDash);
+               if (isset($newV[$newVV]))
+               { 
+                   $newV[$newVV] += $newVC; 
+               } else { 
+                   $newV[$newVV] = $newVC; 
+               }
+           }
+           foreach ($newV as $key => $value) {
+               array_push($newVv, array('count(*)'=>$value, 'version'=>$key));
+           }
+           $v = $newVv;
+       }
+       // early friendica versions have the format x.x.xxxx where xxxx is the
+       // DB version stamp; those should be operated out and versions be
+       // conbined
+       if ($p=='Friendica') {
+           $newV = array();
+           $newVv = array();
+           foreach ($v as $vv) {
+               $newVC = $vv['count(*)'];
+               $newVV = $vv['version'];
+               $lastDot = strrpos($newVV,'.');
+               $len = strlen($newVV)-1;
+               if ($lastDot == $len-4)
+                   $newVV = substr($newVV, 0, $lastDot);
+               if (isset($newV[$newVV])) 
+               { 
+                   $newV[$newVV] += $newVC; 
+               } else { 
+                   $newV[$newVV] = $newVC; 
+               }
+           }
+           foreach ($newV as $key => $value) {
+               array_push($newVv, array('count(*)'=>$value, 'version'=>$key));
+           }
+           $v = $newVv;
+       }
+       // the 3rd array item is needed for the JavaScript graphs as JS does
+       // not like some characters in the names of variables...
+       $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p));
+    }
+    // some helpful text
+    $intro = t('This page offers you some numbers to the known part of the federated social network your Friendica node is part of. These numbers are not complete but only reflect the part of the network your node is aware of.');
+    $hint = t('The <em>Auto Discovered Contact Directory</em> feature is not enabled, it will improve the data displayed here.');
+    // load the template, replace the macros and return the page content
+    $t = get_markup_template("admin_federation.tpl");
+    return replace_macros($t, array(
+       '$title' => t('Administration'),
+       '$page' => t('Federation Statistics'),
+       '$intro' => $intro,
+       '$hint' => $hint,
+       '$autoactive' => get_config('system', 'poco_completion'),
+       '$counts' => $counts,
+       '$version' => FRIENDICA_VERSION,
+       '$legendtext' => t('Currently this node is aware of nodes from the following platforms:'),
+    ));
+}
 /**
  * Admin Inspect Queue Page
  * @param App $a
@@ -341,7 +445,7 @@ function admin_page_site_post(&$a){
                update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
                update_table("term", array('url'), $old_url, $new_url);
                update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url);
-               update_table("unique_contacts", array('url'), $old_url, $new_url);
+               update_table("gcontact", array('photo','url','nurl','server_url'), $old_url, $new_url);
                update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url);
 
                // update config
@@ -410,6 +514,7 @@ function admin_page_site_post(&$a){
        $maxloadavg             =       ((x($_POST,'maxloadavg'))               ? intval(trim($_POST['maxloadavg']))            : 50);
        $maxloadavg_frontend    =       ((x($_POST,'maxloadavg_frontend'))      ? intval(trim($_POST['maxloadavg_frontend']))   : 50);
        $optimize_max_tablesize =       ((x($_POST,'optimize_max_tablesize'))   ? intval(trim($_POST['optimize_max_tablesize'])): 100);
+       $optimize_fragmentation =       ((x($_POST,'optimize_fragmentation'))   ? intval(trim($_POST['optimize_fragmentation'])): 30);
        $poco_completion        =       ((x($_POST,'poco_completion'))          ? intval(trim($_POST['poco_completion']))       : false);
        $poco_requery_days      =       ((x($_POST,'poco_requery_days'))        ? intval(trim($_POST['poco_requery_days']))     : 7);
        $poco_discovery         =       ((x($_POST,'poco_discovery'))           ? intval(trim($_POST['poco_discovery']))        : 0);
@@ -492,6 +597,7 @@ function admin_page_site_post(&$a){
        set_config('system','maxloadavg',$maxloadavg);
        set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
        set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
+       set_config('system','optimize_fragmentation',$optimize_fragmentation);
        set_config('system','poco_completion',$poco_completion);
        set_config('system','poco_requery_days',$poco_requery_days);
        set_config('system','poco_discovery',$poco_discovery);
@@ -774,7 +880,8 @@ function admin_page_site(&$a) {
                '$poll_interval'        => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")),
                '$maxloadavg'           => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
                '$maxloadavg_frontend'  => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
-               '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimisation"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB.")),
+               '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
+               '$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(get_config('system','optimize_fragmentation')) > 0)?get_config('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),
 
                '$poco_completion'      => array('poco_completion', t("Periodical check of global contacts"), get_config('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")),
                '$poco_requery_days'    => array('poco_requery_days', t("Days between requery"), get_config('system','poco_requery_days'), t("Number of days after which a server is requeried for his contacts.")),