jeudi 27 juillet 2017

Eclipse static web project HTTP Preview/Server module conflicts with relative paths

So I start a static web project on eclipse. Let's say MySite. And then I start a jetty web server on eclipse and open localhost:8080 on my browser.

This is what I'll see:

Error 404 - Not Found
No context on this server matched or handled this request.
Contexts known to this server are:

    MySite(/MySite)

So I go to localhost:8080/MySite/index.html and see my homepage... except the css/js files are not loaded and the links don't work.

That's all because of the relative paths. css/main.css directs to localhost:8080/css/main.css while it should direct to localhost:8080/MySite/main.css

How to fix this without using a workaround?




web api saving files to temporary folder but visual studio wants to compile them

We have an MVC web API in which some typescript code keeps getting placed here:

C:...\WebAPI\obj\Test\Package\PackageTmp\scripts\bowtie\bowtie.d.ts

I don't midn code being copied to a temporary folder, but Visual Studio tries to compile the code there and runs into issues. I have to go to that folder, delete the files, and the compile again.

Why do files get copied to that directory? Can I tell Visual Studio not to compile those files? Can I tell it not to copy those files to that location?




Having trouble with web security

The login web page of my website is not secure, whenever typing a username or password on the login page in firefox I get a dialog box saying this : The connection is not secure. Logins entered here could be compromised. Should I try prepared statements, or is there another issue? Sorry this is a broad question, but I'm not all too familiar with web security.

Here's my login page code:

<?php 
include("connect.php"); 
include('PHPMailer/PHPMailer-master/examples/gmail_xoauth.phps');
   if (isset($_POST['createaccount'])) {
        $username = $_POST['username'];
        $password = $_POST['password'];
        $email = $_POST['email'];
        if (!connect::query('SELECT username FROM accounts WHERE username=:username', array(':username'=>$username))) {
                if (strlen($username) >= 3 && strlen($username) <= 32) {
                        if (preg_match('/[a-zA-Z0-9_]+/', $username)) {
                                if (strlen($password) >= 6 && strlen($password) <= 60) {
                                if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                                if (!connect::query('SELECT email FROM accounts WHERE email=:email', array(':email'=>$email))) {

                                        connect::query('INSERT INTO accounts VALUES (null, :username, :password, :email, \'0\')', array(':username'=>$username, ':password'=>password_hash($password, PASSWORD_BCRYPT), ':email'=>$email));
                                        gmail_xoauth::sendMail('Welcome to the Website!', 'Your account has been created!', $email);
                                        echo "<h3 class = 'errmessage'>Success!</h3>";


                                } else {
                                        echo '<h3 class = "errmessage">Email already in use!</h3>';
                                }
                        } else {
                                        echo '<h3 class = "errmessage">Invalid email!</h3>';
                                }
                        } else {
                                echo '<h3 class = "errmessage">Invalid password, at least 6 characters!</h3>';
                        }
                        } else {
                                echo '<h3 class = "errmessage">Invalid username, at least 3 characters</h3>';
                        }
                } else {
                        echo '<h3 class = "errmessage">Invalid username</h3>';
                }
        } else {
                echo '<h3 class = "errmessage">User already exists!</h3>';
        }
    }

    if (isset($_POST['login'])) {
        $username = $_POST['username'];
        $password = $_POST['password'];
        if (connect::query('SELECT username FROM accounts WHERE username=:username', array(':username'=>$username))) {
                if (password_verify($password, connect::query('SELECT password FROM accounts WHERE username=:username', array(':username'=>$username))[0]['password'])) {
                        $cstrong = True;
                        $token = bin2hex(openssl_random_pseudo_bytes(64, $cstrong));
                        $user_id = connect::query('SELECT id FROM accounts WHERE username=:username', array(':username'=>$username))[0]['id'];
                        connect::query('INSERT INTO users VALUES (null, :token, :user_id)', array(':token'=>sha1($token), ':user_id'=>$user_id));
                        setcookie("SNID", $token, time() + 60 * 60 * 24 * 7, '/', NULL, NULL, TRUE);
                        setcookie("SNID_", '1', time() + 60 * 60 * 24 * 3, '/', NULL, NULL, TRUE);
        setcookie("username", $username, time()+3600);
        header("Location: home.php");

                } else {
                        echo '<h3 class = "errmessage">Incorrect Password!Try again</h3><br><br><br>';
                }
        } else {
                echo '<h3 class = "errmessage">User not registered!Try again</h3><br><br><br>';
        }


    }

?> 

Here's the connect.php file:

<?php
class connect
{
    private static function db()
    {
        $pdo = new PDO('mysql:host=localhost;dbname=database_name;charset = utf8','username','password');

        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    return $pdo;
}

    public static function query($query,$params = array())
    {

        $statement = self :: db()->prepare($query);
        $statement->execute($params);
        if(explode(' ',$query)[0] == 'SELECT')
        {
            $data = $statement->fetchAll();
            return $data;
        }

    }

}

?>




Get sound frequency with web Audio API

I would like to get the real time frequency of a sound but it does not work. here is my code:

navigator.getUserMedia({audio:true,video:false}, function (stream) {
document.querySelector("#music").src = window.URL.createObjectURL(stream)
document.querySelector("#music").play()
var contexteAudio = new (window.AudioContext || window.webkitAudioContext)();
var analyseur = contexteAudio.createAnalyser();
source = contexteAudio.createMediaStreamSource(stream);
source.connect(analyseur);
var tab = new Float32Array();

for (var i=0;i<=100;i++) {
    var datas = analyseur.getFloatFrequencyData(tab);
  document.querySelector("#datas").innerHTML = tab[i];
}

}, function(error) {
console.log(error)
})

You can test it here: http://ift.tt/2w4qwgg

Why can't I get the float value of my real time frequency microphone based ? the value is undefined....




Dynamic Proxy CXF Web Service

I have two identical CXF 3.1 web services Service_A and Service_B that have the same WSDL files. Service_A is deployed on Server_X and Service_B is deployed on Service_Y. Is there a way to implement a CXF web service Service_C deployed on Server_Z that will play the role of a dynamic proxy web service. Service_C is supposed to have the same WSDL file as Service_A and Service_B but it will redirect the SOAP requests to Service_A or Service_B and send back the SOAP response to the client. Thank you in advance!




Haml produces "{}" text on webpage

I am trying to convert from application.html.erb to application.haml and I get one small annoying problem being "{}" in top left corner.

problem

My code looks like this:

  %body
    = render 'shared/header'
    .container
      = flash.each do |message_type, message|
        .alert{class: "alert-#{message_type}"}= message
        -# = content_tag :div, message, class: "alert alert-#{message_type}"
      = yield
      = render 'shared/footer'

Commented out line is a second way to create div, but it produces same error.

HTML before conversion looked like this:

  <body>
    <%= render 'shared/header' %>
    <div class="container">
      <% flash.each do |message_type, message| %>
          <%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
      <% end %>
      <%= yield %>
      <%= render 'shared/footer' %>
    </div>
  </body>

What's wrong with that? How do I fix it?




Show different HTML on page depending on origin file's directory location using PHP

I am working on my employer's website and I am relatively new to PHP. I am decent at deciphering code others have written, but I can't seem to figure out how to write additional code to integrate into the current page's PHP. I'm trying to figure out a way to display an image instead of displaying the ordered list if the file is not in a directory that has pre-defined "links" on spelled out.

The site that I am working on is http://ift.tt/1KfChnZ and the following is code that uses an array to choose what links go in the rightNav bar depending on what directory the html file is located in:

(An example of a page with a rightNav with links is this page: http://ift.tt/2v1K87D

An example of a page with no links is this page: http://ift.tt/2uGJ46I)

<?PHP

/*
Array:
    0:URL (Path, or URL.  If a Path it must be an absolute link. ie: starts with a /).
    1:Text (Try to limit length).
    2:Icon (Glyph Sets:Font-Awesome).
*/






if(isset($n)){
switch($n)
{
    case "High School":
        $links = [
            ["/highschool/principal.html","Principal","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/highschool/Guidance","Guidance & Scholarships","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["/highschool/lrc/index.htm","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/district/athletics.html","Athletics","<i class='fa fa-futbol-o' aria-hidden='true'></i>"],
            ["/highschool/clubs/index.html","Clubs & Groups","<i class='fa fa-coffee' aria-hidden='true'></i>"],
            ["/highschool/boosterClub/","Booster Club","<i class='fa fa-arrow-circle-up' aria-hidden='true'></i>"],
            ["/highschool/chsband/index.html","Band","<i class='fa fa-music' aria-hidden='true'></i>"],
            ["/highschool/attachment/2017courseBook.pdf","2017 Course Book","<i class='fa fa-list-alt' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OeN7","Claymont On-line Learning","<i class='fa fa-globe' aria-hidden='true'></i>"],
            ["/highschool/bellschedule/bell_schedule.htm","Bell Schedule","<i class='fa fa-bell' aria-hidden='true'></i>"],
            ["/attachment/handbook/CHS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGODlL","Video Editing","<i class='fa fa-video-camera' aria-hidden='true'></i>"],
            ["/highschool/about-mustang/","Mustang","<i class='fa fa-paw' aria-hidden='true'></i>"]         
        ];
        break;

    case "Middle School":
        $links = [
            ["cjhslrc/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/district/athletics.html","Athletics","<i class='fa fa-futbol-o' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OeN7","Claymont On-line Learning","<i class='fa fa-globe' aria-hidden='true'></i>"],
            ["/juniorhigh/bellschedule/bell_schedule.htm","Bell Schedule","<i class='fa fa-bell' aria-hidden='true'></i>"],
            ["/attachment/handbook/CMS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["/juniorhigh/attachment/dcInfo.PDF","DC Trip","<i class='fa fa-university' aria-hidden='true'></i>"],
            ["/juniorhigh/attachment/7tripPit.PDF","Pittsburgh Trip","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1D6jt","Guidance","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["/juniorhigh/honorroll/02-16.html","Honor Roll","<i class='fa fa-bars' aria-hidden='true'></i>"],
            ["/juniorhigh/PrincipalNewsletter.html","Principal's Newsletters","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["/attachment/supply/middleSuppyList.pdf","Supply List","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"]             
        ];
        break;

    case "Intermediate":
        $links = [
            ["attachment/newsMar17.pdf","March <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["attachment/events.pdf","Events","<i class='fa fa-calendar' aria-hidden='true'></i>"],
            ["LRC/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGwZyb","Guidance","<i class='fa fa-map' aria-hidden='true'></i>"],
            ["dare/darekg/index.html","D.A.R.E.","<i class='fa fa-child' aria-hidden='true'></i>"],
            ["http://ift.tt/2v1OP1n","Harcourt School","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/1bHYQwp","Study Island","<i class='fa fa-tree' aria-hidden='true'></i>"],
            ["video.html","Video Gallery","<i class='fa fa-video-camera' aria-hidden='true'></i>"],
            ["/attachment/handbook/CIS_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["photoGallery.html","Photo Gallery","<i class='fa fa-photo' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/attachment/supply/intermediateSuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"]            
        ];
        break;

    case "Elementary":
        $links = [
            ["attachments/newsletter/may17.pdf","May <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["LRC/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["/attachment/handbook/Elementary_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"],
            ["/attachment/supply/elementarySuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"]          
        ];
        break;

    case "Primary":
        $links = [
            ["attachments/apr17.pdf","April <br>Newsletter","<i class='fa fa-newspaper-o' aria-hidden='true'></i>"],
            ["gallery/gallery.html","Photo Gallery","<i class='fa fa-photo' aria-hidden='true'></i>"],
            ["lrc/index_new.html","Library","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["trentoninfo.htm","General Information","<i class='fa fa-info-circle' aria-hidden='true'></i>"],
            ["/attachment/handbook/Primary_Handbook.pdf","Student Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["/attachment/supply/primarySuppyList.pdf","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"],
            ["http://ift.tt/2v0WRI0","Renaissance <br>Parent Connection","<i class='fa fa-user' aria-hidden='true'></i>"]
        ];
        break;

    case "Preschool":
        $links = [
            ["pre/pre.html","Message from the Principal","<i class='fa fa-envelope' aria-hidden='true'></i>"],
            ["FAMILY_HANDBOOK_WEB.pdf","Family Handbook","<i class='fa fa-list-ul' aria-hidden='true'></i>"],
            ["SNACK_12-13.pdf","Snack Calendar","<i class='fa fa-calendar' aria-hidden='true'></i>"],
            ["/attachment/supply/preschoolSuppyList.PDF","Supply List","<i class='fa fa-pencil' aria-hidden='true'></i>"],
            ["History.html","History","<i class='fa fa-clock-o' aria-hidden='true'></i>"],
            ["attachment/2017application.pdf","Preschool Application","<i class='fa fa-file' aria-hidden='true'></i>"],
            ["/district/Wellness/KindImmun.htm","Immunization<br> Information","<i class='fa fa-medkit' aria-hidden='true'></i>"],
            ["LRC_DISTRICT.PDF","LRC Newsletter","<i class='fa fa-book' aria-hidden='true'></i>"],
            ["http://ift.tt/2uGAtB3?","Symbaloo","<i class='fa fa-arrows' aria-hidden='true'></i>"]
        ];
        break;

    default:
        $links = [];
        break;
}
}else{
    $links = [];

}   



?>


<nav id="navRight" class="dispBox">
<h3>Links</h3>
    <ul>
    <?PHP
    if(count($links)!= 0){
        foreach($links as $link){
            $url = $link[0];
            $text = $link[1];
            $icon = $link[2];   
            echo ("<li><a href='$url'>$text$icon</a></li>");        

        //<li><a href="cjhslrc/index_new.html">Library<i class="fa fa-book" aria-hidden="true"></i></a></li>

        }}
    ?>


    </ul>
</nav>
<?PHP ?>