+ if ( ! CRM.length ) {
+ self.message.CRM = 'no results';
+ return;
+ }
+ self.message.CRM = null;
+ if ( CRM.length == 1 ) {
+ self.selected_username = CRM[0].USERNAME;
+ $log.info( 'auto-selected ', self.selected_username );
+ }
+ });
+ };
+
+ self.r.LDAP_search = $resource('/g/LDAP_search/:username', {username:'@selected_username'});
+ self.LDAP_search = function(username) {
+ if ( self.selected_username == username ) {
+ $log.error("LDAP_search - not changed", username);
+ return;
+ }
+
+ if ( ! username ) username = self.selected_username;
+
+ if ( ! username ) {
+ self.message.LDAP = 'no username';
+ return;
+ }
+ $log.info( 'LDAP_search', username );
+ self.clear_LDAP();
+ self.selected_username = username;
+ self.message.LDAP = 'search '+username;
+ self.r.LDAP_search.query({ username: username }, function(LDAP) {
+ self.LDAP = LDAP;
+ $log.info( 'LDAP', LDAP );
+ if ( self.LDAP.length == 0 ) {
+ self.message.LDAP ='no results for '+username;
+ return;
+ }
+ self.cpe.parser = LDAP[0]._cpe_parser;
+ self.cpe.table_name = 'cpe_' + LDAP[0]._cpe_parser;
+ self.username = LDAP[0].cn;
+ self.message.LDAP = null;
+ $log.info( 'cpe', self.cpe );
+ });
+ };
+ self.$watch('selected_username', self.LDAP_search );
+
+ self.gnuplot_draw = function(h_cols) {
+ $log.info( 'gnuplot_draw', h_cols );
+ if (h_cols.length) {
+ self.gnuplot.cols = h_cols;
+ } else {
+ $log.warn("no columns for gnuplot");
+ return;
+ }
+
+ self.message.gnuplot = 'redrawing '+h_cols.join(' ');
+
+ var cols = [ 'timestamp' ];
+ for ( var i = 0; i < h_cols.length; i++ ) {
+ cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
+ }
+console.debug( cols );
+ self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
+
+ $log.info( 'gnuplot', self.gnuplot );
+ self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
+
+ };
+
+ self.r.table = $resource('/table/:table');
+ self.table_update = function () {
+ if ( ! self.username || ! self.cpe.table_name ) return;
+ self.message.table = self.username + ' loading from ' + self.cpe.table_name;
+ self.r.table.get({ username: self.username, table: self.cpe.table_name, limit: self.cpe.limit }, function(table) {
+ $log.info( 'table', table );
+ self.cpe.table = table;
+ self.message.table = table.rows.length == 0 ? 'no results' : null;
+
+ if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
+ self.gnuplot_draw( h_cols );
+ } else {
+ self.message.gnuplot = 'no graph for ' + self.cpe.parser;
+ }