Example #1
0
            exports.get(username, function (err, user, options) {
                if (err) {
                    return callback(err);
                }
                if (_.indexOf(properties.roles, "_admin") === -1) {
                    _.extend(user, properties);
                }
                if (password) {
                    user.password_sha = sha1.hex(password + user.salt);
                }

                saveUser(options.authdb, user, function (err, user) {
                    
                    session.info(function(err, session_info){
                        if (session_info.userCtx.roles && _.indexOf(session_info.userCtx.roles, "_admin") !== -1) {
                            if (_.indexOf(properties.roles, "_admin") !== -1) {
                                createAdmin(username, password, function () {
                                    callback(null, user);
                                });
                            }
                            else {
                                getAdmin(username, function(err, admin) {
                                    if (err) {
                                        if (err.status !== 404) {
                                            return callback(err);
                                        }
                                        return callback(null, user);
                                    }
                                    else {
                                        deleteAdmin(username, callback);
                                    }
                                });
                            }
                        } else {
                            callback(err, user);
                        }
                    });
                    
                });
            });
Example #2
0
exports.handleResponse = function (req, res) {
    //console.log('response');
    //console.log(res);
    if (req && typeof res === 'object') {
        if (res.headers) {
            if (res.headers['Set-Cookie']) {
                document.cookie = res.headers['Set-Cookie'];
            }
            var loc = res.headers['Location'];
            if (loc && _.indexOf([301, 302, 303, 307], res.code) !== -1) {
                if (exports.isAppURL(loc)) {
                    // reset method to GET unless response is a 307
                    var method = res.code === 307 ? req.method || 'GET': 'GET';
                    exports.setURL(method, exports.appPath(loc));
                }
                else {
                    document.location = loc;
                }
            }
        }
    }
};
Example #3
0
 removeUnit: function(unit) {
     'use strict';
     var index = _.indexOf(this.units, unit);
     this.units.splice(index, 1);
     this.unitsMap.update();
 },
Example #4
0
        var result = '';

        for(var i = 0; i < arr.length; i++) {
            var str = arr.slice(i).join('.');

            if(tld_list[str] === 1 || tld_list['*.' + str] === 1) {
                // match
                if(i > 0) {
                    result = arr.slice(i - 1).join('.');
                } else {
                    result = arr.slice(i).join('.');
                }
                break;
            }
        }

        if(result === '') {
            if(us.indexOf(['localhost', 'test', 'invalid'], arr[arr.length - 1]) !== -1) {
                result = arr[arr.length - 1];
            } else {
                result = arr.join('.');
            }
        }

        return result;
    }

};

				_.each(sentence.words, function(word){
					if (_.indexOf(words, word) == -1) {
						words.push(word);
					}
				});
				_.each(sentence.words, function(word){
					var previousIndex = _.indexOf(words, previousWord);
					var thisIndex = _.indexOf(words, word);
					bigram[previousIndex][thisIndex]++;
					previousWord = word;
				});
Example #7
0
 var validatePosition = function() {
   if ( _.indexOf(allowedPositions, this.position) == -1 ) {
     this.validationErrors.push("On line " + ( this.line ) + " usage of unknown Player Position. Legal values are: " + allowedPositions.toString());
   }
 };
Example #8
0
 var matches = _.filter(quotes[haystack], function(quote) {
     return _.indexOf(quote, needle) != -1;
 }, this);
Example #9
0
function language_order(track) {
    var i = _.indexOf(language_priority, track.language);
    return i >= 0 ? i : language_priority.length;
}
Example #10
0
 return _.every(rest, function(other) {
   return _.indexOf(other, item) >= 0;
 });
function getSearchSql(value, schemas, filter) {
    var sql = '';

    var s = [];
    for(var i = 0; i < schemas.length; i++) {
        s.push(schemas[i].name);
    }

    var tableSql = sqlBuilder.create()
        .query("TABLE_SCHEMA id, TABLE_NAME name, TABLE_COMMENT comment, 'TABLE' dbType")
        .from("INFORMATION_SCHEMA.TABLES")
        .where()
        .ands("TABLE_TYPE = 'BASE TABLE'")
        .like(['table_name', 'table_comment'], value)
        .in('TABLE_SCHEMA', s)
        .build();

    var viewSql = sqlBuilder.create()
        .query("TABLE_SCHEMA id, TABLE_NAME name, TABLE_COMMENT comment, 'VIEW' dbType")
        .from("INFORMATION_SCHEMA.TABLES")
        .where()
        .ands("TABLE_TYPE in ('VIEW', 'SYSTEM VIEW')")
        .like(['table_name', 'table_comment'], value)
        .in('TABLE_SCHEMA', s)
        .build();

    var columnSql = sqlBuilder.create()
        .query("concat(col.TABLE_SCHEMA, '.', col.TABLE_NAME) id, col.COLUMN_NAME name , col.COLUMN_COMMENT comment,")
        .query("(case when (col.COLUMN_KEY = 'PRI' and kcu.COLUMN_NAME is not null) then 'PK_FK_COLUMN' when (col.COLUMN_KEY = 'PRI') then 'PK_COLUMN' when (kcu.COLUMN_NAME is not null) then 'FK_COLUMN' else 'COLUMN' end) dbType")
        .from("INFORMATION_SCHEMA.`COLUMNS` col left join (select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where REFERENCED_COLUMN_NAME is not null) kcu on kcu.TABLE_SCHEMA = col.TABLE_SCHEMA and kcu.TABLE_NAME = col.TABLE_NAME and kcu.COLUMN_NAME = col.COLUMN_NAME")
        .where()
        .like(['col.COLUMN_NAME', 'col.COLUMN_COMMENT'], value)
        .in('col.TABLE_SCHEMA', s)
        .build();

    var constraintSql = sqlBuilder.create()
        .query("concat(tc.TABLE_SCHEMA, '.', tc.TABLE_NAME) id, tc.CONSTRAINT_NAME name, '' comment, 'CONSTRAINT' dbType")
        .from("INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc")
        .where()
        .ands("tc.CONSTRAINT_TYPE <> 'PRIMARY KEY' and tc.CONSTRAINT_TYPE <> 'UNIQUE'")
        .like("tc.CONSTRAINT_NAME", value)
        .in('tc.TABLE_SCHEMA', s)
        .build();

    var indexSql = sqlBuilder.create()
        .query("distinct concat(TABLE_SCHEMA, '.', TABLE_NAME, '.', COLUMN_NAME) id, INDEX_NAME name, '' comment, 'INDEX' dbType")
        .from("INFORMATION_SCHEMA.STATISTICS")
        .where()
        .like("index_name", value)
        .in('TABLE_SCHEMA', s)
        .build();

    var triggerSql = sqlBuilder.create()
        .query("concat(EVENT_OBJECT_SCHEMA, '.', EVENT_OBJECT_TABLE) id, TRIGGER_NAME name, '' comment, 'TRIGGER' dbType")
        .from("INFORMATION_SCHEMA.TRIGGERS")
        .where()
        .like("TRIGGER_NAME", value)
        .in('TRIGGER_SCHEMA', s)
        .build();

    var procedureSql = sqlBuilder.create()
        .query("ROUTINE_SCHEMA id, ROUTINE_NAME name, '' comment, 'PROCEDURE' dbType")
        .from("INFORMATION_SCHEMA.ROUTINES")
        .where()
        .like("ROUTINE_NAME", value)
        .build();

    var functionSql = sqlBuilder.create()
        .query("ROUTINE_SCHEMA id, ROUTINE_NAME name, '' comment, 'FUNCTION' dbType")
        .from("INFORMATION_SCHEMA.ROUTINES")
        .where()
        .like("ROUTINE_NAME", value)
        .build();

    var self = this;

    /**
     *
     * @param unionSql
     * @returns {getSearchSql}
     */
    this.union = function(unionSql) {
        if(sql.length == 0) {
            sql += unionSql;
        } else {
            sql += ' UNION ALL ' + unionSql;
        }
        return self;
    };

    if(filter) {
        var array = filter.split(',');
        if(underscore._.indexOf(array, 'TABLE') > -1) {
            this.union(tableSql)
        }
        if(underscore._.indexOf(array, 'VIEW') > -1) {
            this.union(viewSql)
        }
        if(underscore._.indexOf(array, 'COLUMN') > -1) {
            this.union(columnSql)
        }
        if(underscore._.indexOf(array, 'INDEX') > -1) {
            this.union(indexSql)
        }
        if(underscore._.indexOf(array, 'CONSTRAINT') > -1) {
            this.union(constraintSql)
        }
        if(underscore._.indexOf(array, 'TRIGGER') > -1) {
            this.union(triggerSql)
        }
        if(underscore._.indexOf(array, 'PROCEDURE') > -1) {
            this.union(procedureSql)
        }
        if(underscore._.indexOf(array, 'FUNCTION') > -1) {
            this.union(functionSql)
        }
    } else {
        this.union(tableSql).union(viewSql).union(columnSql).union(constraintSql).union(indexSql).union(triggerSql).union(procedureSql).union(functionSql);
    }

    return sql;
}
Example #12
0
    scriptLoader.on('message', function (event) {
        var chan = event.channel.getName(),
            net = event.channel.connection.config.id;
        if (_.has(database.disabled, net) && database.disabled[net].indexOf(chan) > -1) {
            return;
        }
        var URL, match;
        if ((match = event.message.match(/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?\^=%&amp;:\/~\+#]*[\w\-\@?\^=%&amp;\/~\+#])?/i)) !== null) {
            URL = url.parse(match[0], true, true);

            if (_.indexOf(['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtu.be', 'www.y2u.be', 'y2u.be'], URL.hostname) !== -1) {
                getYoutubeTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['i.imgur.com', 'www.i.imgur.com', 'imgur.com', 'www.imgur.com'], URL.hostname) !== -1) { /* Imgur URL */
                getImgurTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['vimeo.com', 'www.vimeo.com'], URL.hostname) !== -1) { /* Vimeo URL */
                getVimeoTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['reddit.com', 'redd.it', 'www.reddit.com', 'www.redd.it'], URL.hostname) !== -1) { /* Reddit URL */
                getRedditTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['github.com', 'www.github.com', 'gist.github.com', 'www.gist.github.com'], URL.hostname) !== -1) { /* Github URL */
                getGithubTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['4chan.org', 'boards.4chan.org'], URL.hostname) !== -1) { /* 4chan URL */
                get4chanTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['soundcloud.com'], URL.hostname) !== -1) { /* souncloud URL */
                getSoundcloudTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['sa-mp.de', 'forum.sa-mp.de'], URL.hostname) !== -1) { /* Breadfish URL */
                getBreadfishTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else if (_.indexOf(['twitter.com'], URL.hostname) !== -1) { /* Twitter URL */
                getTiwtterTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            } else { /* Anything else */
                getTitle(URL, function (success, title) {
                    if (success) {
                        event.channel.say(title);
                    }
                });
            }
        } else if ((match = event.message.match(/(?:spotify)\:(artist|album|track)\:(.+)/i)) !== null) {
            if (match[1] === 'artist') {
                request({
                    'url': 'http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:' + match[2] + '&extras=album',
                    'json': true,
                    'headers': {
                        'User-Agent': database.useragent
                    }
                }, function (error, response, data) {
                    if (!error && response.statusCode === 200) {
                        event.channel.say('Spotify: %s (%s albums).', ircC.cyan.bold(data.artist.name), data.artist.albums.length);
                    } else {
                        scriptLoader.debug('[spotify/artist] %s', error);
                    }
                });
            } else if (match[1] === 'album') {
                request({
                    'url': 'http://ws.spotify.com/lookup/1/.json?uri=spotify:album:' + match[2] + '&extras=track',
                    'json': true,
                    'headers': {
                        'User-Agent': database.useragent
                    }
                }, function (error, response, data) {
                    if (!error && response.statusCode === 200) {
                        event.channel.say('Spotify: %s by %s. %s tracks, released %s.',
                            ircC.olive.bold(data.album.name),
                            ircC.cyan.bold(data.album.artist),
                            data.album.tracks.length,
                            data.album.released
                            );
                    } else {
                        scriptLoader.debug('[urltitle/spotify/album] %s', error);
                    }
                });
            } else if (match[1] === 'track') {
                request({
                    'url': 'http://ws.spotify.com/lookup/1/.json?uri=spotify:track:' + match[2],
                    'json': true,
                    'headers': {
                        'User-Agent': database.useragent
                    }
                }, function (error, response, data) {
                    if (!error && response.statusCode === 200) {
                        var artistStr = '', time, artists = _.map(data.track.artists, function (artist) {
                            return artist.name;
                        });
                        if (artists.length > 1) {
                            artistStr = ' & ' + artists.pop();
                            artistStr = artists.join(', ') + artistStr;
                        } else {
                            artistStr = artists[0];
                        }
                        time = utils.formatTime(Math.round(data.track.length));
                        event.channel.say('Spotify: %s (Track No. %s on %s) [%s]',
                            ircC.cyan.bold(artistStr + ' - ' + data.track.name),
                            data.track['track-number'],
                            ircC.olive.bold(data.track.album.name),
                            time
                            );
                    } else {
                        scriptLoader.debug('[urltitle/spotify/track] %s', error);
                    }
                });
            }
        }
    });