123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 'use strict';
- * @ngdoc function
- * @name domainManagerApp.controller:MainCtrl
- * @description
- * # MainCtrl
- * Controller of the domainManagerApp
- */
- angular.module('domainManagerApp.addPost', ['firebase', 'domainManagerApp.userData'])
- .controller('AddPostController', ['$scope', 'UserData', '$firebase', '$http', function ($scope, UserData, $firebase, $http) {
- $scope.AddDomain = function() {
- console.log('Creating domain ' + $scope.domain.name);
- $scope.whoisLookup();
- }
- $scope.whoisLookup = function() {
-
- console.log("Whois lookup...");
- var whoisUrl = 'https://j1x-whois.herokuapp.com/lookup.json?url=' + $scope.domain.name;
- $http({
- method: 'GET',
- url: whoisUrl
- }).success(function(data) {
- console.log("Whois lookup successfull");
- $scope.mapData(data);
- $scope.saveToFirebase();
- }).error(function(data, status, headers, config) {
- console.log("Whois lookup error");
- });
- }
- $scope.saveToFirebase = function() {
-
- var firebaseObj = new Firebase("https://j1x-cpanel.firebaseio.com/");
- var domainsRef = firebaseObj.child("domains");
- domainsRef.push({
- name: $scope.domain.name,
- userId: UserData.getUser(),
- registrar: $scope.domain.registrar,
- registration_date: $scope.domain.registration_date,
- expiration_date: $scope.domain.expiration_date,
- owner: $scope.domain.owner
- }, function(error) {
- if (error) {
- console.log('Error - Domain not created');
- } else {
- console.log('Domain created');
- }
- });
- }
- $scope.parseWhoisData = function(data) {
- var new_data = [];
- console.log(data);
- for (var i = 0; i < data.length; i++) {
- var keys = {};
- if (data[i] != ""){
- keys = data[i].split(": ")
- console.log(data[i]);
- console.log(keys);
- if(keys.length >= 2){
- var hash = new Array();
- hash[keys[0]] = keys[1];
- hash[0].replace(/\s+/g,"_").replace(/\.+/g,"_").replace(/\#+/g,"_").replace(/\$+/g,"_").replace(/\//g,"_").replace(/\[+/g,"_").replace(/\[+/g,"_");
- console.log(hash);
- new_data.push(hash);
- }
- }
- }
- console.log(new_data);
- return new_data;
- }
-
- $scope.mapData = function(data) {
- console.log(data);
-
- if(data.registrar != undefined){
- $scope.domain.registrar = data.registrar;
- } else {
- $scope.domain.registrar = "";
- }
-
- if(data.created_on != undefined) {
- $scope.domain.registration_date = data.created_on;
- } else {
- $scope.domain.registration_date = "";
- }
-
- if(data.expires_on != undefined) {
- $scope.domain.expiration_date = data.expires_on;
- } else {
- $scope.domain.expiration_date = "";
- }
-
- if(data.owner != undefined) {
- $scope.domain.owner = data.owner;
- } else {
- $scope.domain.owner = "";
- }
- }
- }]);
|