Welcome to Forums Sign in | Join | Help | Forums
in Search


Authenticate users for your CMS / website, etc VIA NetClassroom

Last post 04-08-2010 2:16 PM by Dan Baker. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-23-2008 10:42 AM

    • Dan Baker
    • Top 500 Contributor
    • Posts 33
    • Organization: Ursuline Academy
    • Products:  The Education Edge, The Raiser's Edge

    Authenticate users for your CMS / website, etc VIA NetClassroom

    Using PHP and cURL you can easily authenticate users using NetClassroom.

     You will have to create a login page with a form that contains username and password fields, and then post it to the file below:

     We have NetClassroom running in HTTPS on IIS, if you dont (you should) remove the following line:   

     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

     The script takes the username and password and then using cURL sends it to the NetClassroom login.aspx page where it scrapes the authentication information from the cookie. Because the way NC was designed you can not scrape any information off of the NC pages (they use javascript for everything) but we can authenticate users securely.

    A successfull login will say: Sucessfull Login!

    A failed login will say: Login Failed

    Due to posting limitations here I had to modify the $viewstate variable - it should be on ONE line.

    <?
    $username = urlencode($HTTP_POST_VARS['username']);
    $password = urlencode($HTTP_POST_VARS['password']);


    session_start();
    $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
    $file = tempnam('/tmp', 'netclass');
    $viewstate = urlencode("/wEPDwUKMTU0MTYwMzU4NA9kFggCAw8WAh4JaW5uZXJodG1
    sBUQ8aW1nIHNyYz0nLi4vaW1hZ2VzL25jbG9naW4uZ2lmJyBib3JkZXI9JzAnIFdJRFRIPScyNTAnIEhFSUdIVD0
    nMjknPmQCBQ8PFgIeBFRleHQFZVBsZWFzZSBlbnRlciB5b3VyIFVzZXIgSUQgYW5kIFBhc3N3b3JkPGJyPnRvIGFjY2
    VzcyBOZXRDbGFzc3Jvb20uIFByZXNzIHRoZSBMb2dpbiBidXR0b24gdG8gY29udGludWUuZGQCCQ8
    PFgIfAQVoPGI+VXJzdWxpbmUgQWNhZGVteTwvYj48QlI+MzQxIFNvdXRoIFNhcHBpbmd0b24gUm9hZDxCUj5
    TYWludCBMb3VpcyZuYnNwO01PJm5ic3A7NjMxMjI8QlI+KDMxNCkgOTg0LTI4MDBkZAILDw8WAh8BBWU8
    QSBIUkVGPSdodHRwOi8vd3d3LmJsYWNrYmF1ZC5jb20nIHRhcmdldD0nX3RvcCc+wqkxOTk3LTIwMDggQmxhY2
    tiYXVkLCBJbmMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuPC9hPmRkZElubcQD6l6US/YZDvUEFRl9G53R");

       $curl = curl_init();
       curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
       curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
       curl_setopt($curl, CURLOPT_URL, "https://netclassroom.yourdomain.com:10443/NetClassroom7/Forms/login.aspx");
       curl_setopt($curl, CURLOPT_VERBOSE, false); // Display communication with server
       curl_setopt($curl, CURLOPT_COOKIEJAR, $file);
       curl_setopt($curl, CURLOPT_COOKIEFILE, $file);
       curl_setopt($curl, CURLOPT_POST, 1);
       curl_setopt($curl, CURLOPT_POSTFIELDS, "btnLogin=Login&sid=".$username."&pin=".$password."&__VIEWSTATE=".$viewstate);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

    $store = curl_exec($curl);
    curl_close($curl);

     $handle = fopen($file, "r");
     $contents = fread($handle, filesize($file));
    if (preg_match("/\.ASPXFORMSAUTH/", $contents, $matches)) {
      echo "Sucessfull Login! <br />";
      $_SESSION['student'] = 1;

    }
    else { echo "Login Failed";}
    fclose($handle);
            if(file_exists("$file"))
            {
            unlink("$file");
            }


    ?>

  • 09-27-2009 12:58 PM In reply to

    • Daniel McGee
    • Not Ranked
    • Posts 1
    • Organization: Our Lady of the Elms
    • Products:  The Education Edge, The Raiser's Edge

    Re: Authenticate users for your CMS / website, etc VIA NetClassroom

    This is exactly what I want to do. I'm not sure how to get the form I've created to talk to the NetClassroom login page - I am a bit of a novice on web authentication. Can you give me a little more detail on the setup? That would be MUCH appreciated!

  • 09-28-2009 3:32 PM In reply to

    • Dan Baker
    • Top 500 Contributor
    • Posts 33
    • Organization: Ursuline Academy
    • Products:  The Education Edge, The Raiser's Edge

    Re: Authenticate users for your CMS / website, etc VIA NetClassroom

    Yeah - I actually have an updated PHP script that will regex out the "viewstate" from the ASPX, so you dont have to update it manually everytime you update your NC software.

    Shoot me an email - dbaker [at] ursulinestl.org

    I will post everything on here once I get it cleaned up :)

     

  • 03-08-2010 12:44 AM In reply to

    Re: Authenticate users for your CMS / website, etc VIA NetClassroom

    Hi. I am also a PHP programer, and would really like to be able to scrape data to be able to do such things as make CSV files and such. Any idea? I have tried for hours with curl, and can not even login to see a home page.
  • 04-08-2010 2:16 PM In reply to

    • Dan Baker
    • Top 500 Contributor
    • Posts 33
    • Organization: Ursuline Academy
    • Products:  The Education Edge, The Raiser's Edge

    Re: Authenticate users for your CMS / website, etc VIA NetClassroom

    yeah well because this is all javascript stuff within NC you cant scrape anything. I was able to check for a valid login, by checking the status of the cookie generated after sending the login credentials... But I dont think you will be able to do much else with curl as you would need some type of javascript processor... -Dan
Page 1 of 1 (5 items)