| 1 | #!/usr/bin/perl -w |
|---|
| 2 | # |
|---|
| 3 | # Author: Nathan "i am not y2k compliant" Benson |
|---|
| 4 | # Email: phuzz@phactor.org |
|---|
| 5 | # URL: http://www.phactor.org/ |
|---|
| 6 | # Date: 01.19.1900 |
|---|
| 7 | # |
|---|
| 8 | ################################################################### |
|---|
| 9 | # |
|---|
| 10 | # tested using: kicq-0.3.0 and licq-0.75.2, on slackware 7.0 |
|---|
| 11 | # |
|---|
| 12 | ################################################################### |
|---|
| 13 | # |
|---|
| 14 | # this is a little script i whipped up to convert my kicq list |
|---|
| 15 | # to an licq list. i have no idea if this will work for anyone |
|---|
| 16 | # else (besides me), but hopefully it will be of some use to |
|---|
| 17 | # someone somewhere. anyways, here is how you use it: |
|---|
| 18 | # |
|---|
| 19 | # |
|---|
| 20 | # ./kicq2licq.pl <UIN> <TEMPLATE> |
|---|
| 21 | # |
|---|
| 22 | # **NOTE** - TEMPLATE may be an existing Licq UIN.uin file: |
|---|
| 23 | # |
|---|
| 24 | # |
|---|
| 25 | # $ licq.kicqconvert 29690151 ~/.licq/users/1234567.uin |
|---|
| 26 | # |
|---|
| 27 | # or you may use this template (remove all leading #'s). |
|---|
| 28 | # copy from CUT line to CUT line, paste it into another |
|---|
| 29 | # file, and remove all the leading #'s (; |
|---|
| 30 | # |
|---|
| 31 | # don't uncomment them here, or you are in for hard times. |
|---|
| 32 | # |
|---|
| 33 | ########### CUT ############### |
|---|
| 34 | |
|---|
| 35 | #[user] |
|---|
| 36 | #History = |
|---|
| 37 | #Groups.System = |
|---|
| 38 | #Groups.User = |
|---|
| 39 | #Ip = |
|---|
| 40 | #Port = |
|---|
| 41 | #NewUser = |
|---|
| 42 | #NewMessages = |
|---|
| 43 | #LastOnline = |
|---|
| 44 | #Alias = |
|---|
| 45 | #FirstName = |
|---|
| 46 | #LastName = |
|---|
| 47 | #Email1 = |
|---|
| 48 | #Email2 = |
|---|
| 49 | #City = |
|---|
| 50 | #State = |
|---|
| 51 | #PhoneNumber = |
|---|
| 52 | #FaxNumber = |
|---|
| 53 | #Address = |
|---|
| 54 | #CellularNumber = |
|---|
| 55 | #Zipcode = |
|---|
| 56 | #Country = |
|---|
| 57 | #Timezone = |
|---|
| 58 | #Authorization = |
|---|
| 59 | #HideEmail = |
|---|
| 60 | #Age = |
|---|
| 61 | #Gender = |
|---|
| 62 | #Homepage = |
|---|
| 63 | #BirthYear = |
|---|
| 64 | #BirthMonth = |
|---|
| 65 | #BirthDay = |
|---|
| 66 | #Language1 = |
|---|
| 67 | #Language2 = |
|---|
| 68 | #Language3 = |
|---|
| 69 | #CompanyCity = |
|---|
| 70 | #CompanyState = |
|---|
| 71 | #CompanyPhoneNumber = |
|---|
| 72 | #CompanyFaxNumber = |
|---|
| 73 | #CompanyAddress = |
|---|
| 74 | #CompanyName = |
|---|
| 75 | #CompanyDepartment = |
|---|
| 76 | #CompanyPosition = |
|---|
| 77 | #CompanyHomepage = |
|---|
| 78 | |
|---|
| 79 | ########### CUT ############### |
|---|
| 80 | # |
|---|
| 81 | # |
|---|
| 82 | # if one were so inclined, they could do their entire list at |
|---|
| 83 | # once doing something like this: |
|---|
| 84 | # |
|---|
| 85 | # cd ~/.kde/share/apps/kicq/contacts |
|---|
| 86 | # for i in *.uin; do |
|---|
| 87 | # UIN=`echo $i | cut -f1 -d.` |
|---|
| 88 | # /path/to/kicq2licq.pl $UIN /path/to/template |
|---|
| 89 | # done |
|---|
| 90 | # |
|---|
| 91 | # this script doesn't require you to blow away your current |
|---|
| 92 | # users.conf, it will rebuild it with the person you just added. |
|---|
| 93 | # |
|---|
| 94 | # i.e. - you have 1 person on your Kicq list, and 3 on your Licq |
|---|
| 95 | # list, and you run the script on your single Kicq user, the script |
|---|
| 96 | # should update your users.conf file to 4 users. if you have no |
|---|
| 97 | # clue what i'm talking about, then you are out of luck. it's 3 |
|---|
| 98 | # a.m. and i haven't a clue either. you can email me if you want |
|---|
| 99 | # i'll try and help. |
|---|
| 100 | # |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | use strict; |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | my ($licq_template, $kicq_user); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | ## make sure we have proper args |
|---|
| 110 | $kicq_user = $ARGV[0] || die("usage: $0 <UIN> <template>\n"); |
|---|
| 111 | $licq_template = $ARGV[1] || die("usage: $0 <UIN> <template>\n"); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | ## let the fun begin |
|---|
| 116 | write_licq_list($kicq_user, $licq_template); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | ## |
|---|
| 120 | ## this function will break the kicq user.uin list |
|---|
| 121 | ## into a hash, break the licq template into |
|---|
| 122 | ## a hash, then break the licq users.conf file into |
|---|
| 123 | ## a hash, create a new users.conf (updated for the |
|---|
| 124 | ## new user), and create a UIN.uin file in the users/ |
|---|
| 125 | ## directory with information from the kicq UIN.uin |
|---|
| 126 | ## file |
|---|
| 127 | ## |
|---|
| 128 | |
|---|
| 129 | sub write_licq_list() |
|---|
| 130 | { |
|---|
| 131 | my ($kicq_uin, $licq_template) = @_; |
|---|
| 132 | my ($output_file, $key, $value, %kicq_hash, %licq_hash, %conf_hash, $licq_conf); |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | ## change these if you have a weird install of |
|---|
| 136 | ## licq, or i'm a dork and screwed something |
|---|
| 137 | ## up. |
|---|
| 138 | $licq_conf = "$ENV{'HOME'}/.licq/users.conf"; |
|---|
| 139 | $output_file = "$ENV{'HOME'}/.licq/users/$kicq_uin.uin"; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | ## parse the kicq list (; |
|---|
| 143 | %kicq_hash = parse_kicq_list($kicq_uin); |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | ## parse the licq template. |
|---|
| 147 | %licq_hash = parse_licq_list($licq_template); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | ## parse the users.conf file, and store it in a hash |
|---|
| 151 | %conf_hash = parse_licq_conf(); |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | ## if we already have an existing UIN.uin, lets die. |
|---|
| 156 | die("$output_file exists exiting") if -e $output_file; |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | ## print basic headers for the UIN.uin file. |
|---|
| 160 | open(OUT, ">$output_file"); |
|---|
| 161 | print(OUT "\n"); |
|---|
| 162 | print(OUT "[user]\n"); |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | ## sort through all the licq template values |
|---|
| 166 | ## and see if we have a matching kicq key. |
|---|
| 167 | ## if we do, we take the value of what the |
|---|
| 168 | ## kicq user.uin file had for it. if not |
|---|
| 169 | ## we just leave it blank. |
|---|
| 170 | |
|---|
| 171 | while (($key, $value) = each(%licq_hash)) |
|---|
| 172 | { |
|---|
| 173 | ## we have a match. |
|---|
| 174 | if (exists($kicq_hash{$key})) |
|---|
| 175 | { |
|---|
| 176 | print(OUT "$value = $kicq_hash{$key}\n"); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | ## leave it blank. |
|---|
| 180 | else |
|---|
| 181 | { |
|---|
| 182 | print(OUT "$value =\n"); |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | ## close the output file |
|---|
| 186 | close(OUT); |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | ## open the users.conf file now. |
|---|
| 191 | open(CONF, ">$licq_conf"); |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | ## we are adding one user at a time, so we |
|---|
| 195 | ## increment the value of NumOfUsers we got |
|---|
| 196 | ## from parse_licq_conf() by one. |
|---|
| 197 | $conf_hash{'NumOfUsers'}++; |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | # print normal users.conf header stuff. |
|---|
| 201 | print(CONF "[users]\n"); |
|---|
| 202 | print(CONF "NumOfUsers = $conf_hash{'NumOfUsers'}\n"); |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | ## sort through the rest of the keys and values |
|---|
| 206 | ## we pulled out of the users.conf, and put them |
|---|
| 207 | ## back into place. NOTE - these aren't sorted |
|---|
| 208 | ## so you may get User10, then User2. Licq does |
|---|
| 209 | ## not seem to care, so i don't either. (= |
|---|
| 210 | |
|---|
| 211 | while (($key, $value) = each(%conf_hash)) |
|---|
| 212 | { |
|---|
| 213 | ## we printed this already, so lets skip it |
|---|
| 214 | if ($key ne "NumOfUsers") |
|---|
| 215 | { |
|---|
| 216 | print(CONF "$key = $value\n"); |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | ## this is the user we are wanting to add. |
|---|
| 222 | ## so we add this at the end of the list. |
|---|
| 223 | print(CONF "User$conf_hash{'NumOfUsers'} = $kicq_uin\n"); |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | ## close the users.conf file |
|---|
| 227 | close(CONF); |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | ## all done. |
|---|
| 231 | exit(1); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | ## |
|---|
| 236 | ## this function will user read the users.conf |
|---|
| 237 | ## file into a hash, skipping any newlines, |
|---|
| 238 | ## comments or [user] type lines. |
|---|
| 239 | ## |
|---|
| 240 | sub parse_licq_conf() |
|---|
| 241 | { |
|---|
| 242 | ## change this to suit you. this is where mine was. |
|---|
| 243 | my ($licq_conf) = "$ENV{'HOME'}/.licq/users.conf"; |
|---|
| 244 | |
|---|
| 245 | my (%conf_hash, $key, $value); |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | ## can't read it if it's not there. |
|---|
| 249 | die("could not find your $licq_conf\n") if ! -e $licq_conf; |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | ## open the config file for reading |
|---|
| 253 | open(CONF, $licq_conf); |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | ## read the whole config file. |
|---|
| 257 | while (<CONF>) |
|---|
| 258 | { |
|---|
| 259 | chomp; |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | ## skip comments, [user] type stuff, and blank lines |
|---|
| 263 | next if /^[#\[]|^$/; |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | ## split the line into 2 values |
|---|
| 267 | ($key, $value) = split(/ = /, $_); |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | ## create the hash element with the 2 values. |
|---|
| 271 | $conf_hash{$key} = $value; |
|---|
| 272 | } |
|---|
| 273 | ## close the config file. |
|---|
| 274 | close(CONF); |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | ## return the hash we built. |
|---|
| 278 | return(%conf_hash); |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | ## |
|---|
| 283 | ## this function just reads the kicq UIN.uin file, |
|---|
| 284 | ## and creates a hash all the values we have set. |
|---|
| 285 | ## this is done so later we can compare the licq |
|---|
| 286 | ## keys, against these and see if we have any that |
|---|
| 287 | ## are the same (as opposed to losing that info). |
|---|
| 288 | ## |
|---|
| 289 | |
|---|
| 290 | sub parse_kicq_list() |
|---|
| 291 | { |
|---|
| 292 | my ($kicq_file) = @_; |
|---|
| 293 | my (%kicq_hash, $key, $value); |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | ## this is where my kicq UIN.uin files were stored, |
|---|
| 297 | ## change this if it is different for you. |
|---|
| 298 | $kicq_file = "$ENV{'HOME'}/.kde/share/apps/kicq/contacts/$kicq_file.uin"; |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | ## can't read it if it doesn't exist right? |
|---|
| 302 | open(KICQ, $kicq_file) || die("couldn't open $kicq_file - $!\n"); |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | ## read through all the entries in the UIN.uin file |
|---|
| 306 | while (<KICQ>) |
|---|
| 307 | { |
|---|
| 308 | chomp; |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | ## skip comments, [user] type stuff, and blank lines |
|---|
| 312 | next if /^[#\[]|^$/; |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | ## split the line into 2 values |
|---|
| 316 | ($key, $value) = split(/=/, $_); |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | ## make the key all lowercase, so we don't have to |
|---|
| 320 | ## worry about case issues with the licq hash. |
|---|
| 321 | $key =~ tr/[A-Z]/[a-z]/; |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | ## create the hash element. |
|---|
| 325 | $kicq_hash{$key} = $value; |
|---|
| 326 | } |
|---|
| 327 | ## close the UIN.uin file. |
|---|
| 328 | close(KICQ); |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | ## return the hash we built |
|---|
| 332 | return(%kicq_hash); |
|---|
| 333 | } |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | ## |
|---|
| 337 | ## this function will just read the template |
|---|
| 338 | ## specified on the command line, create a |
|---|
| 339 | ## hash of all the keys (everything on the |
|---|
| 340 | ## right side of the ='s are tossed). so |
|---|
| 341 | ## in the end we end up with this: |
|---|
| 342 | ## |
|---|
| 343 | ## $hash{lower_case_key} = Lower_Case_Key; |
|---|
| 344 | ## |
|---|
| 345 | |
|---|
| 346 | sub parse_licq_list() |
|---|
| 347 | { |
|---|
| 348 | my ($licq_file) = @_; |
|---|
| 349 | my (%licq_hash, $key, $tmp_key, $value); |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | ## can't read it if it doesn't exist right? |
|---|
| 353 | open(LICQ, $licq_file) || die("couldn't open $licq_file - $!\n"); |
|---|
| 354 | |
|---|
| 355 | while (<LICQ>) |
|---|
| 356 | { |
|---|
| 357 | chomp; |
|---|
| 358 | |
|---|
| 359 | ## skip comments, [user] type stuff, and blank lines |
|---|
| 360 | next if /^[#\[]|^$/; |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | ## split the line into 2 values |
|---|
| 364 | ($key, $value) = split(/ = /, $_); |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | ## we store the key in a temp variable |
|---|
| 368 | ## because we are going to turn the key |
|---|
| 369 | ## to all lower case, and i don't know |
|---|
| 370 | ## if Licq would freak with that. |
|---|
| 371 | |
|---|
| 372 | $tmp_key = $key; |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | ## make the key all lowercase, so we don't have to |
|---|
| 376 | ## worry about case issues with the kicq hash. |
|---|
| 377 | $key =~ tr/[A-Z]/[a-z]/; |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | ## since we don't have any real values (we discarded |
|---|
| 381 | ## everything on the right of the =), we will store |
|---|
| 382 | ## the unmodified (real key) name. |
|---|
| 383 | $licq_hash{$key} = $tmp_key; |
|---|
| 384 | |
|---|
| 385 | } |
|---|
| 386 | ## close the template |
|---|
| 387 | close(LICQ); |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | ## return the hash we built |
|---|
| 391 | return(%licq_hash); |
|---|
| 392 | } |
|---|
| 393 | # EOF |
|---|