diff --git a/app/config/as-stats.yml b/app/config/as-stats.yml index 3d79979..1f764ca 100644 --- a/app/config/as-stats.yml +++ b/app/config/as-stats.yml @@ -41,6 +41,14 @@ config: ## PEERINGDB my_asn: 34863 +api: + peeringdb: + host: 'https://peeringdb.com' + url : '/api' + user: '' + pass: '' + token : '' + customlinks: PeeringDB: 'https://www.peeringdb.com/asn/%as%' robtex: 'https://www.robtex.com/as/as%as%.html' diff --git a/app/config/config.yml b/app/config/config.yml index 8ea03cc..b82d225 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -4,7 +4,7 @@ application: release: '1.0' controller: 'src/Controllers' model: 'src/Models' - locale: 'fr' + locale: 'en' debug: TRUE template_dir: 'web/template' twig: diff --git a/src/Application/ApplicationProvider.php b/src/Application/ApplicationProvider.php index f0e70f0..0627c9a 100644 --- a/src/Application/ApplicationProvider.php +++ b/src/Application/ApplicationProvider.php @@ -9,6 +9,10 @@ use Silex\Provider\SessionServiceProvider; use Silex\Provider\DoctrineServiceProvider; use Application\ConfigApplication as ConfigApplication; use DDesrosiers\SilexAnnotations\AnnotationServiceProvider; +/*use Silex\Provider\TranslationServiceProvider; +use Symfony\Component\Translation\Loader\YamlFileLoader; +use Symfony\Bridge\Twig\Extension\TranslationExtension; +use Silex\Provider\SymfonyBridgesServiceProvider;*/ use \utilphp\util as Util; use \Mobile_Detect; @@ -51,6 +55,10 @@ class ApplicationProvider implements ServiceProviderInterface return new \Models\Whois($app); }; + $app['peeringdb'] = function() use($app) { + return new \Models\PeeringDB(); + }; + $app->register(new AnnotationServiceProvider(), array( 'annot.controllerDir' => realpath(ConfigApplication::getControllerRootDirectory()), )); diff --git a/src/Application/ConfigApplication.php b/src/Application/ConfigApplication.php index 2237da7..0572717 100644 --- a/src/Application/ConfigApplication.php +++ b/src/Application/ConfigApplication.php @@ -116,4 +116,8 @@ class ConfigApplication return self::getConfigASStats()['config']['whois']; } + public static function getUrlPeeringDB() + { + return self::getConfigASStats()['api']['peeringdb']['host'].''.self::getConfigASStats()['api']['peeringdb']['url']; + } } diff --git a/src/Controllers/Asset.php b/src/Controllers/Asset.php index d125a21..da6ac68 100644 --- a/src/Controllers/Asset.php +++ b/src/Controllers/Asset.php @@ -45,6 +45,7 @@ class Asset extends BaseController $topas = $this->db->GetASStatsTop(200, Func::statsFileForHours($hours), $selected_links, $this->data['aslist']); + $this->data['asinfo'] = NULL; foreach ($topas as $as => $nbytes) { $this->data['asinfo'][$as]['info'] = Func::GetASInfo($as); diff --git a/src/Controllers/Func.php b/src/Controllers/Func.php index 3f762cb..5eb5cc3 100644 --- a/src/Controllers/Func.php +++ b/src/Controllers/Func.php @@ -127,7 +127,7 @@ class Func $active_top = $dpagename == "index" ? "active": ""; $active_searchas = $dpagename == "history" ? "active" : ""; $active_searchasset = $dpagename == "asset" ? "active" : ""; - $active_ix = $dpagename == "ix" ? "active" : ""; + $active_ix = $dpagename == "ixstats" ? "active" : ""; $return = [ 'active_top' => $active_top, diff --git a/src/Controllers/IXStats.php b/src/Controllers/IXStats.php new file mode 100644 index 0000000..0957ea6 --- /dev/null +++ b/src/Controllers/IXStats.php @@ -0,0 +1,103 @@ +data['active_page'] = Func::getRouteName($request); + $req = $request->query->all(); + + $hours = 24; + if (@$req['numhours']) $hours = (int)$req['numhours']; + + $this->data['knownlinks'] = Func::getKnowlinks(); + $selected_links = array(); + foreach($this->data['knownlinks'] as $link){ + if(isset($req["link_${link['tag']}"])) + $selected_links[] = $link['tag']; + } + $this->data['selected_links'] = $selected_links; + $this->data['hours'] = $hours; + + if ( $this->data['config']['my_asn'] ) { + $this->data['myix'] = $app['peeringdb']->GetIX('34863'); + } + + if ( isset($req['ix']) ) { + if (isset($req['n'])) $ntop = (int)$req['n']; + else $ntop = $this->data['config']['ntop']; + if ($ntop > 200) $ntop = 200; + + $this->data['request'] = $req; + + $list_asn = $app['peeringdb']->GetIXASN($req['ix']); + $topas = $this->db->GetASStatsTop($ntop, Func::statsFileForHours($hours), $selected_links, $list_asn); + + $this->data['asinfo'] = NULL; + foreach ($topas as $as => $nbytes) { + $this->data['asinfo'][$as]['info'] = Func::GetASInfo($as); + + $this->data['asinfo'][$as]['v4'] = [ + 'in' => $nbytes[0], + 'out' => $nbytes[1], + ]; + + if ( $this->data['config']['showv6'] ) { + $this->data['asinfo'][$as]['v6'] = [ + 'in' => $nbytes[2], + 'out' => $nbytes[3], + ]; + } + + $this->data['customlinks'][$as] = Func::getCustomLinks($as); + } + + $this->data['start'] = time() - $hours*3600; + $this->data['end'] = time(); + $this->data['ntop'] = $ntop; + $this->data['label'] = Func::statsLabelForHours($hours); + return $app['twig']->render('pages/ixstats/ixstats.html.twig', $this->data); + } + + return $app['twig']->render('pages/ixstats/search.html.twig', $this->data); + } + + /** + * @SLX\Route( + * @SLX\Request(method="GET", uri="get_ixname"), + * @SLX\Bind(routeName="get_ixname") + * ) + */ + public function get_ixname(Request $request, Application $app) + { + $req = $request->query->all(); + $return = NULL; + + if ( isset($req['name']) ) { + foreach ($app['peeringdb']->GetIXName($req['name']) as $key => $value) { + $return[] = array ( + 'id' => strval($value->id), + 'name' => strval($value->name) . " (".$value->city." / ".$value->country.")", + ); + } + } + + return json_encode($return); + } +} diff --git a/src/Models/PeeringDB.php b/src/Models/PeeringDB.php new file mode 100644 index 0000000..fb194b7 --- /dev/null +++ b/src/Models/PeeringDB.php @@ -0,0 +1,97 @@ +url = ConfigApplication::getUrlPeeringDB(); + } + + protected function sendRequest( $url ) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $output = curl_exec($ch); + curl_close($ch); + + return $output; + } + + public function GetInfo( $asn = NULL ) { + if ( $asn ) { + $json = $this->sendRequest($this->url."/net?asn=".$asn); + $json = json_decode($json); + if ( isset($json->meta->error) ) { return 0; } + else { return $json->data[0]; } + } + } + + public function GetIX( $asn = NULL ) { + if ( $asn ) { + $json = $this->sendRequest($this->url."/netixlan?asn=".$asn); + $json = json_decode($json); + + if ( empty($json->data) ) { return 0; } + else { return $json->data; } + } + } + + public function GetAllNet( $regex = NULL) { + if ( $regex ) { $regex = '?asn__contains='.$regex; } + $json = json_decode($this->sendRequest($this->url."/net".$regex)); + return $json->data; + } + + public function GetIXInfo( $id = NULL ) { + if ( $id ) { + $json = $this->sendRequest($this->url."/ix?id=".$id); + $json = json_decode($json); + + if ( empty($json->data) ) { return 0; } + else { return $json->data; } + } + } + + public function GetIXMembers( $id = NULL ) { + if ( $id ) { + $json = $this->sendRequest($this->url."/net?ix_id=".$id); + $json = json_decode($json); + + if ( empty($json->data) ) { return 0; } + else { return $json->data; } + } + } + + public function GetIXMembersLan( $id = NULL ) { + if ( $id ) { + $json = $this->sendRequest($this->url."/netixlan?ix_id=".$id); + $json = json_decode($json); + + if ( empty($json->data) ) { return 0; } + else { return $json->data; } + } + } + + public function GetIXASN($id = NULL) { + $return = ""; + if ( $id ) { + foreach ($this->GetIXMembers($id) as $key => $value) { + $return[] = $value->asn; + }; + } + + return $return; + } + + public function GetIXName( $regex = NULL) { + if ( $regex ) { $regex = '?name__contains='.$regex; } + $json = json_decode($this->sendRequest($this->url."/ix".$regex)); + return $json->data; + } +} diff --git a/src/Views/base/legend.html.twig b/src/Views/base/legend.html.twig new file mode 100644 index 0000000..2b9cbc8 --- /dev/null +++ b/src/Views/base/legend.html.twig @@ -0,0 +1,24 @@ + + {% for link in knownlinks %} + {% set tag = "link_#{ link.tag }" %} + {% if request[tag] is defined and request[tag] == 'on' %} + {% set checked = 'checked' %} + {% else %} + {% set checked = '' %} + {% endif %} + + + + + + {% endfor %} +
+ + {% if config.brighten_negative %} + + + {% else %} + + {% endif %} +
   
+
  {{ link.descr }} 
diff --git a/src/Views/base/legend_small.html.twig b/src/Views/base/legend_small.html.twig new file mode 100644 index 0000000..3f78eec --- /dev/null +++ b/src/Views/base/legend_small.html.twig @@ -0,0 +1,28 @@ + + + + + + {% endfor %} + + +
+ {% for link in knownlinks %} + {% set tag = "link_#{ link.tag }" %} + {% if request[tag] is defined and request[tag] == 'on' %} + {% set checked = 'checked' %} + {% else %} + {% set checked = '' %} + {% endif %} + + + + {% if config.brighten_negative %} + + + {% else %} + + {% endif %} + +
   
+
  {{ link.descr }}   
diff --git a/src/Views/base/menu.html.twig b/src/Views/base/menu.html.twig index baa46dd..e123115 100644 --- a/src/Views/base/menu.html.twig +++ b/src/Views/base/menu.html.twig @@ -22,18 +22,38 @@ {% endif %}
  • View AS
  • View AS-SET
  • -
  • View IX Stats
  • +
  • View IX Stats
  • - {% if active_page.active_top == "active" %} + {% if active_page.active_top == "active" or active_page.active_ix == "active" %} {% endif %} diff --git a/src/Views/macros/macros.html.twig b/src/Views/macros/macros.html.twig index 15b3362..e2b500f 100644 --- a/src/Views/macros/macros.html.twig +++ b/src/Views/macros/macros.html.twig @@ -33,9 +33,11 @@ {% endif %} {% endset %} + {% if outispositive != "NONE" %} + {% endif %}
    {% endmacro %} diff --git a/src/Views/pages/asset/asset.html.twig b/src/Views/pages/asset/asset.html.twig index 3bfd289..111e18d 100644 --- a/src/Views/pages/asset/asset.html.twig +++ b/src/Views/pages/asset/asset.html.twig @@ -85,64 +85,6 @@ History for AS-SET: {{ asset }} {% endif %} {% endset %} -{% set legend %} - - {% for link in knownlinks %} - {% set tag = "link_#{ link.tag }" %} - {% if request[tag] is defined and request[tag] == 'on' %} - {% set checked = 'checked' %} - {% else %} - {% set checked = '' %} - {% endif %} - - - - - - {% endfor %} -
    - - {% if config.brighten_negative %} - - - {% else %} - - {% endif %} -
       
    -
      {{ link.descr }} 
    -{% endset %} - -{% set legend_small %} - - - - - - {% endfor %} - - -
    - {% for link in knownlinks %} - {% set tag = "link_#{ link.tag }" %} - {% if request[tag] is defined and request[tag] == 'on' %} - {% set checked = 'checked' %} - {% else %} - {% set checked = '' %} - {% endif %} - - - - {% if config.brighten_negative %} - - - {% else %} - - {% endif %} - -
       
    -
      {{ link.descr }}   
    -{% endset %} - {% set counter = 0 %} {% set aff_astable %} @@ -269,9 +211,9 @@ History for AS-SET: {{ asset }}
    {% if mobile %} - {{ legend_small }} + {{ include('/base/legend_small.html.twig') }} {% else %} - {{ legend }} + {{ include('/base/legend.html.twig') }} {% endif %}