Browsing:

Month: April 2015

Installing Shoutcast on CentOs – shoutcast version 1 and 2

And now for something completly different, since it isn’t all about work hard, we need to shoutcastplay hard too. I was asked to build a shoutcast server on a linux centOs 6.6 server.

 

It’s not that hard to set up a shoutcast stream:

Fire up your linux server and add a new shoutcast user:

adduser shoutcast
passwd shoutcast

now sign in using this new account

su - shoutcast

create a new directory

mkdir shoutcast

and go there

cd shoutcast

Now I am gonna dowload shoutcast, im using 64x but you can find more installs here:

http://mirror.lchost.net/download.nullsoft.com/shoutcast/tools/

wget http://mirror.lchost.net/download.nullsoft.com/shoutcast/tools/sc_serv2_linux_x64_07_31_2011.tar.gz
wget http://mirror.lchost.net/download.nullsoft.com/shoutcast/tools/sc_trans_linux_x64_10_07_2011.tar.gz

Let’s open up the packages

tar -zxvf http://mirror.lchost.net/download.nullsoft.com/shoutcast/tools/sc_serv2_linux_x64_07_31_2011.tar.gz
tar -zxvf http://mirror.lchost.net/download.nullsoft.com/shoutcast/tools/sc_serv2_linux_x64_07_31_2011.tar.gz
[shoutcast@test shoutcast]$ ls -l

If you already downloaded a shoutcast versiom locally (f.e. the outdated, but populair shoutcast version 1.9.8), you can upload the zipped .tar.gz folder to your ftp and skip wget part and just tar from the location on your server.

tar -zxvf sc_serv_1.9.8_Linux.tar.gz

Just remember, shoutcast v1 is 32bit and your server probably is 64, in this case, update your library with 32bit support. For more info on this subject: 64bit bad elf interpreter

yum install glibc.i686
sudo yum install glibc.i686

Next we are gonna edit the config files in nano.

nano sc_serv.conf

If nano isnt installed yet, you must install this first:

yum install nano

you need to configure these config files to your settings.

I will highlight the most important changes

sc_serv_basic.conf:

logfile=logs/sc_serv.log
w3clog=logs/sc_w3c.log
banfile=control/sc_serv.ban
ripfile=control/sc_serv.rip
password=chaneg this
adminpassword=change this
streamid=1
streampath=http://myIP or dns:80/

and sc_trans_basic.conf

streamtitle=My first Shoutcast Server
streamurl=http://www.myurl.com/
genre=Misc
inheritconfig=sc_serv.conf
logfile=sc_trans.log
uvoxradiometadata=1
uvoxnewmetadata=0
playlistfile=playlist.lst
shuffle=0

also add:

streamauthhash= you can leave this open now, w’ll get back to it later!

serverport=8555
serverip=localhost
encoder=mp3
mp3quality=1
bitrate=192000

we need to restart the server

./sc_serv sc_serv.conf sc_trans.conf

now go to your browser and type in your IP and port number and you will see your shoutcast server up ad running.

You can use the stream addres to bring up your performance,

you’ll see ity streams only local , you need to add one more important step

last but important step to take, you added the streamauthhash, you need to get an authentication hash, you can get one using this link from your shoutcast admin:

http://yourIP:your port/index.html?sid=0

Now restart the shoutcast server and stream your podcast or music show

 


Beginning Node.js – local authentication with Passport-Local Mongoose – part 6

Disclaimer: This is a series about me, creating a web application in Node.js. The completed example is available here.

I have a deep respect for all those developers out there that write fantastic modules I can use in my projects. One little gem is passport-local-mongoose. I’ve written about it before but as you see I’m doing it again.

What is passport-local-mongoose?

You can plug-in passport-local-mongoose into your Mongoose Userschema. This decorates the User object with a set of methods. E.g.

  • authenticate
  • register
  • setPassword
  • serialize
  • deserialize

It also hashes the passwords. This saves a lot of work.

What we should work on

  • Users should be able to register
  • Users should be able to authenticate
  • Users should be able to change their password
  • Users should be able to change their e-mail address
  • There should be a ‘forgot password’ procedure
  • Users should be able to delete their accounts

This article covers only ‘register’ and ‘authenticate’. You can go ahead and clone the restaurant github repo for a full example.

To add local authentication to your app you’ll need to run:

Of course, you may add your own properties to the model:

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    passportLocalMongoose = require('passport-local-mongoose');

var User = new Schema({
    uuid: {
        type: String,
        required: false
    },
    firstname: {
        type: String,
        required: true
    },
    active: {
        type: String,
        required: false
    }
});

var options = ({missingPasswordError: "Wrong password"});
User.plugin(passportLocalMongoose,options);

module.exports = mongoose.model('User', User)

Now let’s hook up Passport in our app.

Controller

Let’s create a user controller which contains the register, the login and the getLogin functions (to check if a user has logged in).
Create a file named controller.user.js and put it in the app folder:

var mongoose = require('mongoose');
var User = require('./model.user');

exports.register = function (req, res) {
    console.log("registering: " + req.body.firstName);
    User.register(new User({
        username: req.body.username,
        firstname: req.body.firstname
    }), req.body.password, function (err, user) {
        if (err) {
            console.log(err);
            return res.send(err);
        } else {
            res.send({
                success: true,
                user: user
            });
        }
    });
};

exports.login = function (req, res, next) {

    User.authenticate()(req.body.username, req.body.password, function (err, user, options) {
        if (err) return next(err);
        if (user === false) {
            res.send({
                message: options.message,
                success: false
            });
        } else {
            req.login(user, function (err) {
                res.send({
                    success: true,
                    user: user
                });
            });
        }
    });

};

exports.getLogin = function (req, res) {
    console.log(req.user);
    if (req.user) {

        return res.send({
            success: true,
            user: req.user
        });

    } //res.send(500, {status:500, message: 'internal error', type:'internal'}); == deprecated


    res.send({
        success: false,
        message: 'not authorized'
    });
};

What happens?
1. User.authenticate and User.register:
The User.authenticate and User.register are functions we get from passport-local-mongoose. I just took this code as an example.

2. Check if a user is logged in with ‘if(req.user)’
If a user is logged in, the req.user property is populated with the user object.
So if it exists, the user is logged in.

Routes

//mongodb
var mongoose = require('mongoose');
var User = require('./model.user');

var users = require('./controller.user');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var cookieParser = require('cookie-parser');
var session = require('express-session');


module.exports = function (app) {

    //initialize passport
    passport.use(User.createStrategy());
    // use static serialize and deserialize of model for passport session support
    passport.serializeUser(User.serializeUser());
    passport.deserializeUser(User.deserializeUser());

    //need this according to passport guide
    app.use(cookieParser());
    app.use(session({
        secret: 'the princess and the frog',
        saveUninitialized: true,
        resave: true
    }));
    app.use(passport.initialize());
    app.use(passport.session());

    //routes
    app.route('/register').post(users.register);
    app.route('/login').post(users.login);
    app.route('/login').get(users.getlogin);
   
   
};

Add this file to main.js, like so:

require('./app/routes.user')(app);

This will be your completed main.js:

var express = require('express');
var app = express();
var bodyparser = require('body-parser');
var mongoose = require('mongoose');

app.use(bodyparser.urlencoded({
  extended: true
}));

app.use(bodyparser.json());

mongoose.connect('mongodb://localhost:27017/restaurant');

require('./app/routes.food')(app);
require('./app/routes.user')(app);

app.use(express.static(__dirname + '/public'));

app.set('port', process.env.PORT || 3001);
app.listen(app.get('port'));
console.log("the server is running on http://localhost:" + app.get('port'));

Let’s try this

Install Postman or another REST API test tool.

  • Don’t forget to configure the headers: Content-Type application/json

First, let’s register a user (click POST):

Postman_passport

Second, let’s login:

Selection_012

Check the login status:

Selection_015

The end of this series

This is where this series end. I hope anyone will enjoy this and at least learns something from my struggles. I know I did!
Your feedback is more than welcome by the way.