12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- '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 = 'http://api.who.pm/' + $scope.domain.name;
- $http({
- method: 'GET',
- url: whoisUrl
- }).success(function(data) {
- console.log("Whois lookup successfull");
- $scope.domain.whois = 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(),
- whois: $scope.domain.whois
- }, 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;
- }
- }]);
|